[vlc-commits] [Git][videolan/vlc][master] 9 commits: macosx: use native carousel scroll bounds

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Nov 19 11:26:04 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
cc6f5d71 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: use native carousel scroll bounds

Constrain carousel scrolling with NSClipView so leading and trailing
content insets determine the legal endpoints. This allows returning to
negative starting offsets and reaching the trailing padded endpoint.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
984b215e by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: add a regression test for both limits and the last card placement

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
a4133ce4 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: account for content insets in carousel arrow navigation

Subtract the scroll view's leading content inset when choosing and
positioning the next or previous card. Preserve negative target offsets
so arrow navigation can return to the native leading endpoint.

Keep navigation tests independent of the separate scrollability checks.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
6a7bcd5a by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: keep navigation tests independent of the separate scrollability checks

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
91bcb2f1 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: derive carousel arrow visibility from scrollable bounds

Expose whether the carousel can scroll in either direction by comparing
its current position with NSClipView's constrained endpoints. Account for
content insets and disable scrolling for empty or detached collections.

Use these properties to hide unavailable Home carousel arrows, including
for documents that fit within the unobscured viewport.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
866b44e2 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: extend Home carousels beneath the navigation sidebar

Use the macOS 26 split-view safe-area adjustment to draw Home carousels
beneath the glass navigation sidebar. Limit underlap to Home presentation
and turn it off for search, no-results messages and video playback.

Keep titles, static Home rows, playback controls and loading indicators
inside the safe area. Preserve the Home gutters and align the resting
carousel cards with the grid.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
cf623f59 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: limit navigation sidebar underlap to Home

AppKit retains the expanded content frame after the split-view safe-area adjustment is disabled. Wrap the library target in a presentation view that explicitly uses full bounds for Home and horizontal safe-area bounds for other presentations.

Update the presentation layout when split-view subviews resize, preserving sidebar collapse and expansion without changing the window constraint graph.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
d9793fe0 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: Fix build on older macOS versions for split view controller

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
80aba288 by Claudio Cambra at 2026-11-19T12:08:48+01:00
macosx: Fix navigation for hero-only carousels

Count supplementary views when determining whether a carousel can scroll. Use the native inset-aware bounds when no item lies in the requested direction so a standalone hero can reach both edges.

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


13 changed files:

- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/library/VLCLibraryWindowSplitViewController.h
- modules/gui/macosx/library/VLCLibraryWindowSplitViewController.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewBaseCarouselContainerView.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewController.m
- modules/gui/macosx/library/home-library/VLCLibraryHomeViewStackViewController.m
- modules/gui/macosx/library/search-library/VLCLibrarySearchOverviewController.m
- modules/gui/macosx/tests/Makefile.am
- + modules/gui/macosx/tests/VLCCarouselViewTest.m
- modules/gui/macosx/tests/VLCLibraryHomeVideoCarouselLayoutTest.m
- modules/gui/macosx/views/VLCCarouselView.h
- modules/gui/macosx/views/VLCCarouselView.m
- modules/gui/macosx/views/VLCLoadingOverlayView.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -339,6 +339,7 @@ static int ShowController(vlc_object_t * __unused p_this,
 
 - (void)displayLibraryView:(NSView *)view
 {
+    self.splitViewController.libraryContentUnderlapsNavigationSidebar = view == self.homeLibraryView;
     view.translatesAutoresizingMaskIntoConstraints = NO;
     if ([self.libraryTargetView.subviews containsObject:self.loadingOverlayView]) {
         self.libraryTargetView.subviews = @[view, self.loadingOverlayView];
@@ -383,6 +384,7 @@ static int ShowController(vlc_object_t * __unused p_this,
 
 - (void)displayNoResultsMessage
 {
+    self.splitViewController.libraryContentUnderlapsNavigationSidebar = NO;
     if (self.noResultsLabel == nil) {
         _noResultsLabel = [[VLCNoResultsLabel alloc] init];
         _noResultsLabel.translatesAutoresizingMaskIntoConstraints = NO;
@@ -630,6 +632,7 @@ static int ShowController(vlc_object_t * __unused p_this,
 
 - (void)presentVideoView
 {
+    self.splitViewController.libraryContentUnderlapsNavigationSidebar = NO;
     for (NSView *subview in _libraryTargetView.subviews) {
         [subview removeFromSuperview];
     }


=====================================
modules/gui/macosx/library/VLCLibraryWindowSplitViewController.h
=====================================
@@ -47,6 +47,7 @@ typedef NS_ENUM(NSUInteger, VLCLibraryWindowSplitViewDividerIndex) {
 @property (readonly) NSSplitViewItem *multifunctionSidebarItem;
 
 @property (readwrite, nonatomic) BOOL mainVideoModeEnabled;
+ at property (readwrite, nonatomic) BOOL libraryContentUnderlapsNavigationSidebar;
 
 - (IBAction)toggleNavigationSidebar:(id)sender;
 - (IBAction)toggleMultifunctionSidebar:(id)sender;


=====================================
modules/gui/macosx/library/VLCLibraryWindowSplitViewController.m
=====================================
@@ -26,6 +26,7 @@
 #import "library/VLCLibraryWindowNavigationSidebarViewController.h"
 #import "library/VLCLibraryWindowSidebarRootViewController.h"
 
+#import "main/CompatibilityFixes.h"
 #import "main/VLCMain.h"
 
 #import "views/VLCBottomBarView.h"
@@ -35,9 +36,61 @@
 
 #import "windows/video/VLCMainVideoViewController.h"
 
+ at interface VLCLibraryPresentationView : NSView
+ at property (nonatomic) BOOL underlapsNavigationSidebar;
+ at property (readonly, strong) NSView *contentView;
+- (instancetype)initWithContentView:(NSView *)contentView;
+ at end
+
+ at implementation VLCLibraryPresentationView
+
+- (instancetype)initWithContentView:(NSView *)contentView
+{
+    self = [super initWithFrame:contentView.frame];
+    if (self) {
+        _contentView = contentView;
+        self.autoresizesSubviews = NO;
+        contentView.translatesAutoresizingMaskIntoConstraints = YES;
+        contentView.autoresizingMask = NSViewNotSizable;
+        contentView.clipsToBounds = YES;
+        [self addSubview:contentView];
+    }
+    return self;
+}
+
+- (void)setUnderlapsNavigationSidebar:(BOOL)underlaps
+{
+    if (_underlapsNavigationSidebar == underlaps) {
+        return;
+    }
+    _underlapsNavigationSidebar = underlaps;
+    self.needsLayout = YES;
+}
+
+- (void)layout
+{
+    [super layout];
+    NSRect frame = self.bounds;
+    if (@available(macOS 26.0, *)) {
+        if (!self.underlapsNavigationSidebar) {
+            const NSRect safeArea = self.safeAreaRect;
+            frame.origin.x = NSMinX(safeArea);
+            frame.size.width = NSWidth(safeArea);
+        }
+    }
+    // Keep legacy split and scroll view sizing independent of the window's
+    // constraint graph while switching between full-width and inset content.
+    if (!NSEqualRects(self.contentView.frame, frame)) {
+        self.contentView.frame = frame;
+    }
+}
+
+ at end
+
 @interface VLCLibraryWindowSplitViewController ()
 
 @property (readwrite) BOOL priorNavSidebarCollapsedState;
+ at property (strong) VLCLibraryPresentationView *libraryPresentationView;
 
 @end
 
@@ -62,9 +115,26 @@
         [[VLCLibraryWindowSidebarRootViewController alloc] initWithLibraryWindow:VLCMain.sharedInstance.libraryWindow];
 
     self.libraryTargetViewController.view = self.libraryWindow.libraryTargetView;
+    if (@available(macOS 26.0, *)) {
+        self.libraryPresentationView =
+            [[VLCLibraryPresentationView alloc] initWithContentView:self.libraryWindow.libraryTargetView];
+        self.libraryTargetViewController.view = self.libraryPresentationView;
+        [NSNotificationCenter.defaultCenter addObserver:self
+                                               selector:@selector(splitViewLayoutChanged:)
+                                                   name:NSSplitViewDidResizeSubviewsNotification
+                                                 object:self.splitView];
+    }
 
     _navSidebarItem = [NSSplitViewItem sidebarWithViewController:self.navSidebarViewController];
     _libraryTargetViewItem = [NSSplitViewItem splitViewItemWithViewController:self.libraryTargetViewController];
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 260000
+    if (@available(macOS 26.0, *)) {
+        // AppKit retains the expanded frame after this flag is turned off.
+        // Configure it once and let the presentation view control underlap.
+        self.libraryTargetViewItem.automaticallyAdjustsSafeAreaInsets = YES;
+    }
+#endif
+    [self updateLibraryContentUnderlap];
 
     _multifunctionSidebarItem = [NSSplitViewItem splitViewItemWithViewController:self.multifunctionSidebarViewController];
 
@@ -88,14 +158,37 @@
     VLCMainWindowControlsBar * const controlsBar = libraryWindow.controlsBar;
     VLCBottomBarView * const bottomBarView = controlsBar.bottomBarView;
     bottomBarView.translatesAutoresizingMaskIntoConstraints = NO;
+    NSLayoutXAxisAnchor *leadingAnchor = self.libraryTargetViewController.view.leadingAnchor;
+    NSLayoutXAxisAnchor *trailingAnchor = self.libraryTargetViewController.view.trailingAnchor;
+    if (@available(macOS 26.0, *)) {
+        leadingAnchor = self.libraryTargetViewController.view.safeAreaLayoutGuide.leadingAnchor;
+        trailingAnchor = self.libraryTargetViewController.view.safeAreaLayoutGuide.trailingAnchor;
+    }
     [NSLayoutConstraint activateConstraints:@[
-        [bottomBarView.leadingAnchor constraintEqualToAnchor:self.libraryTargetViewController.view.leadingAnchor
+        [bottomBarView.leadingAnchor constraintEqualToAnchor:leadingAnchor
                                                     constant:VLCUIUnits.largeSpacing * 2],
-        [bottomBarView.trailingAnchor constraintEqualToAnchor:self.libraryTargetViewController.view.trailingAnchor
+        [bottomBarView.trailingAnchor constraintEqualToAnchor:trailingAnchor
                                                      constant:-(VLCUIUnits.largeSpacing * 2)],
     ]];
 }
 
+- (void)setLibraryContentUnderlapsNavigationSidebar:(BOOL)underlaps
+{
+    _libraryContentUnderlapsNavigationSidebar = underlaps;
+    [self updateLibraryContentUnderlap];
+}
+
+- (void)updateLibraryContentUnderlap
+{
+    self.libraryPresentationView.underlapsNavigationSidebar =
+        self.libraryContentUnderlapsNavigationSidebar;
+}
+
+- (void)splitViewLayoutChanged:(NSNotification *)notification
+{
+    self.libraryPresentationView.needsLayout = YES;
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath
                       ofObject:(id)object
                         change:(NSDictionary *)change


=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewBaseCarouselContainerView.m
=====================================
@@ -120,15 +120,27 @@
     _headerView = [[VLCLibraryHomeViewSectionHeaderView alloc] initWithFrame:NSZeroRect];
     self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
     [self addSubview:self.headerView];
+    NSLayoutXAxisAnchor *leadingAnchor = self.leadingAnchor;
+    NSLayoutXAxisAnchor *trailingAnchor = self.trailingAnchor;
+    if (@available(macOS 26.0, *)) {
+        leadingAnchor = self.safeAreaLayoutGuide.leadingAnchor;
+        trailingAnchor = self.safeAreaLayoutGuide.trailingAnchor;
+    }
     [NSLayoutConstraint activateConstraints:@[
-        [self.headerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
-        [self.headerView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
+        [self.headerView.leadingAnchor constraintEqualToAnchor:leadingAnchor],
+        [self.headerView.trailingAnchor constraintEqualToAnchor:trailingAnchor],
         [self.headerView.topAnchor constraintEqualToAnchor:self.topAnchor],
     ]];
 
     _collectionViewLayout = [[VLCLibraryCollectionViewFlowLayout alloc] init];
     _collectionViewLayout.scrollDirection = NSCollectionViewScrollDirectionHorizontal;
-    _collectionViewLayout.sectionInset = NSEdgeInsetsMake(0., VLCUIUnits.mediumSpacing, 0., VLCUIUnits.mediumSpacing);
+    CGFloat itemInset = VLCUIUnits.mediumSpacing;
+    if (@available(macOS 26.0, *)) {
+        // The viewport extends beyond the row by mediumSpacing. Match the grid's
+        // item inset inside the row while leaving that viewport beneath the sidebar.
+        itemInset += VLCUIUnits.collectionViewSectionInsets.left;
+    }
+    _collectionViewLayout.sectionInset = NSEdgeInsetsMake(0., itemInset, 0., itemInset);
     _collectionViewLayout.minimumLineSpacing = VLCUIUnits.mediumSpacing;
     _collectionViewLayout.minimumInteritemSpacing = VLCUIUnits.mediumSpacing;
 
@@ -148,6 +160,9 @@
     _scrollView.scrollParentY = YES;
     _scrollView.forceHideVerticalScroller = YES;
     _scrollView.forceHideHorizontalScroller = YES;
+    // Keep the viewport beneath the sidebar; automatic content insets position
+    // the resting items within the unobscured area.
+    _scrollView.automaticallyAdjustsContentInsets = YES;
     _scrollView.drawsBackground = NO;
     _scrollView.translatesAutoresizingMaskIntoConstraints = NO;
     _scrollView.documentView = _collectionView;
@@ -168,8 +183,14 @@
     self.leftButton.target = self;
     self.leftButton.action = @selector(scrollLeft:);
     [self addSubview:self.leftButton];
+    NSLayoutXAxisAnchor *leftButtonAnchor = self.scrollView.leadingAnchor;
+    NSLayoutXAxisAnchor *rightButtonAnchor = self.scrollView.trailingAnchor;
+    if (@available(macOS 26.0, *)) {
+        leftButtonAnchor = leadingAnchor;
+        rightButtonAnchor = trailingAnchor;
+    }
     [NSLayoutConstraint activateConstraints:@[
-        [self.leftButton.leadingAnchor constraintEqualToAnchor:self.scrollView.leadingAnchor],
+        [self.leftButton.leadingAnchor constraintEqualToAnchor:leftButtonAnchor],
         [self.leftButton.centerYAnchor constraintEqualToAnchor:self.scrollView.centerYAnchor],
         [self.leftButton.widthAnchor constraintEqualToConstant:buttonSize],
         [self.leftButton.heightAnchor constraintEqualToConstant:buttonSize],
@@ -183,7 +204,7 @@
     self.rightButton.action = @selector(scrollRight:);
     [self addSubview:self.rightButton];
     [NSLayoutConstraint activateConstraints:@[
-        [self.rightButton.trailingAnchor constraintEqualToAnchor:self.scrollView.trailingAnchor],
+        [self.rightButton.trailingAnchor constraintEqualToAnchor:rightButtonAnchor],
         [self.rightButton.centerYAnchor constraintEqualToAnchor:self.scrollView.centerYAnchor],
         [self.rightButton.widthAnchor constraintEqualToConstant:buttonSize],
         [self.rightButton.heightAnchor constraintEqualToConstant:buttonSize],
@@ -283,10 +304,8 @@
 
 - (void)updateCarouselButtonVisibility
 {
-    const NSRect visibleRect = self.scrollView.documentVisibleRect;
-    const NSRect documentRect = self.collectionView.frame;
-    self.leftButton.hidden = NSMinX(visibleRect) <= NSMinX(documentRect);
-    self.rightButton.hidden = NSMaxX(visibleRect) >= NSMaxX(documentRect);
+    self.leftButton.hidden = !self.collectionView.canScrollBackward;
+    self.rightButton.hidden = !self.collectionView.canScrollForward;
 }
 
 - (void)scrollViewBoundsChanged:(NSNotification *)notification


=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewController.m
=====================================
@@ -148,6 +148,11 @@
     const NSEdgeInsets defaultInsets = VLCUIUnits.libraryViewScrollViewContentInsets;
     const NSEdgeInsets scrollerInsets = VLCUIUnits.libraryViewScrollViewScrollerInsets;
 
+    if (@available(macOS 26.0, *)) {
+        // Preserve the Home gutters when the safe area starts at the sidebar edge.
+        self.homeLibraryView.additionalSafeAreaInsets = NSEdgeInsetsMake(0., defaultInsets.left, 0., defaultInsets.right);
+    }
+
     self.homeLibraryStackViewScrollView.automaticallyAdjustsContentInsets = NO;
     self.homeLibraryStackViewScrollView.contentInsets = defaultInsets;
     self.homeLibraryStackViewScrollView.scrollerInsets = scrollerInsets;


=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewStackViewController.m
=====================================
@@ -242,6 +242,17 @@
 
     view.translatesAutoresizingMaskIntoConstraints = NO;
 
+    if (@available(macOS 26.0, *)) {
+        if (![view isKindOfClass:VLCLibraryHomeViewBaseCarouselContainerView.class]) {
+            NSArray<NSLayoutConstraint *> * const constraints = @[
+                [view.leadingAnchor constraintEqualToAnchor:stackView.safeAreaLayoutGuide.leadingAnchor],
+                [view.trailingAnchor constraintEqualToAnchor:stackView.safeAreaLayoutGuide.trailingAnchor],
+            ];
+            [NSLayoutConstraint activateConstraints:constraints];
+            return constraints;
+        }
+    }
+
     NSArray<NSLayoutConstraint*> * const constraintsWithSuperview = @[
         [NSLayoutConstraint constraintWithItem:view
                                      attribute:NSLayoutAttributeLeft


=====================================
modules/gui/macosx/library/search-library/VLCLibrarySearchOverviewController.m
=====================================
@@ -26,6 +26,7 @@
 
 #import "library/VLCLibraryWindow.h"
 #import "library/VLCLibraryWindowPersistentPreferences.h"
+#import "library/VLCLibraryWindowSplitViewController.h"
 
 @implementation VLCLibrarySearchOverviewController
 {
@@ -74,6 +75,7 @@
         if (_searchViewController == nil) {
             _searchViewController = [self newSearchViewController];
         }
+        self.libraryWindow.splitViewController.libraryContentUnderlapsNavigationSidebar = NO;
         [_searchViewController presentInContainer:self.libraryTargetView];
         _isShowingSearchOverlay = YES;
         [_searchViewController searchForString:query];


=====================================
modules/gui/macosx/tests/Makefile.am
=====================================
@@ -10,6 +10,7 @@ TESTS += $(macosx_gui_xctest_bundles)
 
 VLCMacOSXTests_SOURCES = \
 	gui/macosx/tests/VLCAppKitMockingTestCase.m \
+	gui/macosx/tests/VLCCarouselViewTest.m \
 	gui/macosx/tests/VLCHexNumberFormatterTest.m \
 	gui/macosx/tests/NSStringHelpersTest.m \
 	gui/macosx/tests/VLCLibraryDataTypesTest.m \


=====================================
modules/gui/macosx/tests/VLCCarouselViewTest.m
=====================================
@@ -0,0 +1,222 @@
+/*****************************************************************************
+ * VLCCarouselViewTest.m: tests for inset-aware native carousel navigation
+ *****************************************************************************
+ * Copyright (C) 2026 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+#import <XCTest/XCTest.h>
+
+#import "views/VLCCarouselView.h"
+
+ at interface VLCCarouselView (Testing)
+- (void)scrollToHorizontalOffset:(CGFloat)offset
+                        animated:(BOOL)animated
+                        duration:(NSTimeInterval)duration;
+ at end
+
+ at interface VLCCarouselViewTestNonanimatedView : VLCCarouselView
+ at end
+
+ at implementation VLCCarouselViewTestNonanimatedView
+
+- (void)scrollToHorizontalOffset:(CGFloat)offset
+                        animated:(__unused BOOL)animated
+                        duration:(__unused NSTimeInterval)duration
+{
+    // An unordered test window does not run implicit view animations. Exercise
+    // the real navigation and bounds helper synchronously without displaying UI.
+    [super scrollToHorizontalOffset:offset animated:NO duration:0.];
+}
+
+ at end
+
+ at interface VLCCarouselViewTestItem : NSCollectionViewItem
+ at end
+
+ at implementation VLCCarouselViewTestItem
+
+- (void)loadView
+{
+    self.view = [[NSView alloc] initWithFrame:NSMakeRect(0., 0., 180., 180.)];
+}
+
+ at end
+
+ at interface VLCCarouselViewTestDataSource : NSObject<NSCollectionViewDataSource>
+ at property (nonatomic) NSInteger itemCount;
+ at end
+
+ at implementation VLCCarouselViewTestDataSource
+
+- (NSInteger)collectionView:(__unused NSCollectionView *)collectionView
+     numberOfItemsInSection:(__unused NSInteger)section
+{
+    return self.itemCount;
+}
+
+- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
+     itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
+{
+    return [collectionView makeItemWithIdentifier:@"CarouselTestItem" forIndexPath:indexPath];
+}
+
+ at end
+
+ at interface VLCCarouselViewTest : XCTestCase
+ at property (nonatomic) NSWindow *window;
+ at property (nonatomic) NSScrollView *scrollView;
+ at property (nonatomic) VLCCarouselViewTestNonanimatedView *carouselView;
+ at property (nonatomic) NSCollectionViewFlowLayout *layout;
+ at property (nonatomic) VLCCarouselViewTestDataSource *dataSource;
+ at end
+
+ at implementation VLCCarouselViewTest
+
+- (void)setUp
+{
+    [super setUp];
+    [NSApplication sharedApplication];
+}
+
+- (void)tearDown
+{
+    [self.window close];
+    self.window = nil;
+    self.carouselView = nil;
+    self.scrollView = nil;
+    self.layout = nil;
+    self.dataSource = nil;
+    [super tearDown];
+}
+
+- (void)configureWithItemCount:(NSInteger)itemCount
+                  leadingInset:(CGFloat)leadingInset
+                 trailingInset:(CGFloat)trailingInset
+{
+    self.window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0., 0., 800., 180.)
+                                              styleMask:NSWindowStyleMaskBorderless
+                                                backing:NSBackingStoreBuffered
+                                                  defer:NO];
+    self.window.releasedWhenClosed = NO;
+    self.scrollView = [[NSScrollView alloc] initWithFrame:self.window.contentView.bounds];
+    self.scrollView.automaticallyAdjustsContentInsets = NO;
+    self.scrollView.contentInsets = NSEdgeInsetsMake(0., leadingInset, 0., trailingInset);
+    self.scrollView.hasVerticalScroller = NO;
+    self.scrollView.hasHorizontalScroller = NO;
+    [self.window.contentView addSubview:self.scrollView];
+
+    self.carouselView = [[VLCCarouselViewTestNonanimatedView alloc] initWithFrame:self.scrollView.bounds];
+    self.layout = [[NSCollectionViewFlowLayout alloc] init];
+    self.layout.scrollDirection = NSCollectionViewScrollDirectionHorizontal;
+    self.layout.itemSize = NSMakeSize(180., 180.);
+    self.layout.minimumLineSpacing = 8.;
+    self.layout.minimumInteritemSpacing = 8.;
+    self.layout.sectionInset = NSEdgeInsetsMake(0., 8., 0., 8.);
+    self.carouselView.collectionViewLayout = self.layout;
+    self.carouselView.leadingItemInset = 8.;
+    [self.carouselView registerClass:VLCCarouselViewTestItem.class forItemWithIdentifier:@"CarouselTestItem"];
+    self.dataSource = [[VLCCarouselViewTestDataSource alloc] init];
+    self.dataSource.itemCount = itemCount;
+    self.carouselView.dataSource = self.dataSource;
+    self.scrollView.documentView = self.carouselView;
+    [self.carouselView reloadData];
+    [self.window.contentView layoutSubtreeIfNeeded];
+    [self.layout prepareLayout];
+
+    const CGFloat contentWidth = MAX(0., NSWidth(self.scrollView.bounds) - leadingInset - trailingInset);
+    self.carouselView.frame = NSMakeRect(0., 0., MAX(contentWidth, self.layout.collectionViewContentSize.width), 180.);
+    [self.scrollView.contentView scrollToPoint:NSMakePoint(-leadingInset, 0.)];
+    [self.scrollView reflectScrolledClipView:self.scrollView.contentView];
+}
+
+- (void)testArrowNavigationKeepsNextCardOutsideLeadingSidebar
+{
+    [self configureWithItemCount:10 leadingInset:200. trailingInset:0.];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), -200., .01);
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+    XCTAssertTrue(self.carouselView.canScrollForward);
+
+    [self.carouselView scrollByOneItemForward:YES];
+    const CGFloat offset = NSMinX(self.scrollView.documentVisibleRect);
+    const NSRect firstFrame = [self.layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].frame;
+    const NSRect secondFrame = [self.layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]].frame;
+    XCTAssertEqualWithAccuracy(offset, -12., .01);
+    XCTAssertEqualWithAccuracy(NSMinX(secondFrame) - offset, 208., .01);
+    XCTAssertEqualWithAccuracy(NSMinX(firstFrame) - offset, 20., .01);
+    XCTAssertTrue(self.carouselView.canScrollBackward);
+
+    [self.carouselView scrollByOneItemForward:NO];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), -200., .01);
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+}
+
+- (void)testScrollingHonorsLeadingAndTrailingNativeBounds
+{
+    [self configureWithItemCount:10 leadingInset:200. trailingInset:120.];
+    [self.carouselView scrollToHorizontalOffset:100000. animated:NO duration:0.];
+    const CGFloat offset = NSMinX(self.scrollView.documentVisibleRect);
+    const NSRect lastFrame = [self.layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:9 inSection:0]].frame;
+    XCTAssertEqualWithAccuracy(offset, 1208., .01);
+    XCTAssertEqualWithAccuracy(NSMaxX(lastFrame) - offset, 672., .01);
+    XCTAssertTrue(self.carouselView.canScrollBackward);
+    XCTAssertFalse(self.carouselView.canScrollForward);
+
+    [self.carouselView scrollToHorizontalOffset:-100000. animated:NO duration:0.];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), -200., .01);
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+    XCTAssertTrue(self.carouselView.canScrollForward);
+}
+
+- (void)testArrowNavigationWithoutSidebarInsets
+{
+    [self configureWithItemCount:10 leadingInset:0. trailingInset:0.];
+    [self.carouselView scrollByOneItemForward:YES];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), 188., .01);
+    XCTAssertTrue(self.carouselView.canScrollBackward);
+    [self.carouselView scrollByOneItemForward:NO];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), 0., .01);
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+}
+
+- (void)testShortDocumentCannotScroll
+{
+    [self configureWithItemCount:1 leadingInset:200. trailingInset:120.];
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+    XCTAssertFalse(self.carouselView.canScrollForward);
+    [self.carouselView scrollByOneItemForward:YES];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), -200., .01);
+}
+
+- (void)testEmptyDocumentCannotScrollEvenWithStaleFrame
+{
+    [self configureWithItemCount:0 leadingInset:200. trailingInset:120.];
+    self.carouselView.frame = NSMakeRect(0., 0., 1888., 180.);
+    XCTAssertFalse(self.carouselView.canScrollBackward);
+    XCTAssertFalse(self.carouselView.canScrollForward);
+    [self.carouselView scrollByOneItemForward:YES];
+    XCTAssertEqualWithAccuracy(NSMinX(self.scrollView.documentVisibleRect), -200., .01);
+}
+
+- (void)testDetachedCarouselCannotScroll
+{
+    VLCCarouselView * const carouselView = [[VLCCarouselView alloc] initWithFrame:NSZeroRect];
+    XCTAssertFalse(carouselView.canScrollBackward);
+    XCTAssertFalse(carouselView.canScrollForward);
+}
+
+ at end


=====================================
modules/gui/macosx/tests/VLCLibraryHomeVideoCarouselLayoutTest.m
=====================================
@@ -264,15 +264,19 @@ static const CGFloat VLCHomeLayoutTestHeroWidth = 656.;
     XCTAssertTrue(_container.leftButton.hidden);
 }
 
-- (void)testHeroWithoutRecentVideosScrollsToBothEdgesInANarrowWindow
+- (void)assertHeroOnlyNavigationWithContentInsets:(NSEdgeInsets)insets
 {
     _itemCount = 0;
     [_window setContentSize:NSMakeSize(520., 450.)];
+    _container.scrollView.automaticallyAdjustsContentInsets = NO;
+    _container.scrollView.contentInsets = insets;
     [self configureTwoRowsWithHero:YES];
+    [_container.scrollView.contentView scrollToPoint:NSMakePoint(-insets.left, 0.)];
+    [_container.scrollView reflectScrolledClipView:_container.scrollView.contentView];
     [self disableNavigationAnimation];
     const CGFloat maximumOffset = NSMaxX(_container.collectionView.frame) -
-        NSWidth(_container.scrollView.documentVisibleRect);
-    XCTAssertGreaterThan(maximumOffset, 0.);
+        NSWidth(_container.scrollView.documentVisibleRect) + insets.right;
+    XCTAssertGreaterThan(maximumOffset, -insets.left);
     XCTAssertTrue(_container.leftButton.hidden);
     XCTAssertFalse(_container.rightButton.hidden);
 
@@ -281,9 +285,19 @@ static const CGFloat VLCHomeLayoutTestHeroWidth = 656.;
     XCTAssertFalse(_container.leftButton.hidden);
     XCTAssertTrue(_container.rightButton.hidden);
     [_container.collectionView scrollByOneItemForward:NO];
-    XCTAssertEqualWithAccuracy(NSMinX(_container.scrollView.documentVisibleRect), 0., .01);
+    XCTAssertEqualWithAccuracy(NSMinX(_container.scrollView.documentVisibleRect), -insets.left, .01);
     XCTAssertTrue(_container.leftButton.hidden);
     XCTAssertFalse(_container.rightButton.hidden);
 }
 
+- (void)testHeroWithoutRecentVideosScrollsToBothEdgesInANarrowWindow
+{
+    [self assertHeroOnlyNavigationWithContentInsets:NSEdgeInsetsMake(0., 0., 0., 0.)];
+}
+
+- (void)testHeroWithoutRecentVideosScrollsToBothEdgesWithHorizontalInsets
+{
+    [self assertHeroOnlyNavigationWithContentInsets:NSEdgeInsetsMake(0., 120., 0., 60.)];
+}
+
 @end


=====================================
modules/gui/macosx/views/VLCCarouselView.h
=====================================
@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
 @interface VLCCarouselView : NSCollectionView
 
 @property (nonatomic) CGFloat leadingItemInset;
+ at property (nonatomic, readonly) BOOL canScrollBackward;
+ at property (nonatomic, readonly) BOOL canScrollForward;
 
 - (void)scrollByOneItemForward:(BOOL)forward;
 // Tracks carousel dragging and inertia, returning the release event only for a click.


=====================================
modules/gui/macosx/views/VLCCarouselView.m
=====================================
@@ -45,10 +45,24 @@ static const CGFloat VLCCarouselDragVelocitySmoothingFactor = .75;
 static const CGFloat VLCCarouselMinimumScrollWheelDelta = .1;
 // Minimum vertical scroll delta forwarded to the enclosing scroll view.
 static const CGFloat VLCCarouselMinimumVerticalScrollDelta = .5;
-// Distance, in points, used when choosing the next item to navigate to.
-static const CGFloat VLCCarouselItemNavigationTolerance = 1.;
 // Minimum movement, in points, before deceleration stops at a content edge.
 static const CGFloat VLCCarouselDecelerationEdgeTolerance = .01;
+// Ignore sub-point differences when navigating or checking scrollability.
+static const CGFloat VLCCarouselScrollPositionTolerance = 1.;
+
+ at interface VLCCarouselView ()
+
+- (void)scrollByHorizontalDelta:(CGFloat)delta;
+- (void)scrollToHorizontalOffset:(CGFloat)offset
+                        animated:(BOOL)animated
+                        duration:(NSTimeInterval)duration;
+- (void)startDeceleratingWithVelocity:(CGFloat)velocity;
+- (void)decelerate;
+- (void)stopDecelerating;
+- (BOOL)canScrollInDirection:(BOOL)forward;
+- (NSArray<NSCollectionViewLayoutAttributes *> *)itemLayoutAttributes;
+
+ at end
 
 @implementation VLCCarouselView
 {
@@ -66,6 +80,16 @@ static const CGFloat VLCCarouselDecelerationEdgeTolerance = .01;
 
 #pragma mark - Public methods
 
+- (BOOL)canScrollBackward
+{
+    return [self canScrollInDirection:NO];
+}
+
+- (BOOL)canScrollForward
+{
+    return [self canScrollInDirection:YES];
+}
+
 - (void)scrollByOneItemForward:(BOOL)forward
 {
     [self stopDecelerating];
@@ -76,31 +100,27 @@ static const CGFloat VLCCarouselDecelerationEdgeTolerance = .01;
     }
 
     const CGFloat visibleOffset = NSMinX(scrollView.documentVisibleRect);
+    const CGFloat leadingInset = self.leadingItemInset + scrollView.contentInsets.left;
     NSArray<NSCollectionViewLayoutAttributes *> * const attributes = self.itemLayoutAttributes;
     NSCollectionViewLayoutAttributes *targetAttributes = nil;
     NSEnumerator * const enumerator = forward ? attributes.objectEnumerator : attributes.reverseObjectEnumerator;
     for (NSCollectionViewLayoutAttributes * const attributes in enumerator) {
-        const CGFloat itemOffset = MAX(NSMinX(attributes.frame) - self.leadingItemInset,
-                                       NSMinX(self.frame));
-        if ((forward && itemOffset > visibleOffset + VLCCarouselItemNavigationTolerance) ||
-            (!forward && itemOffset < visibleOffset - VLCCarouselItemNavigationTolerance)) {
+        const CGFloat itemOffset = NSMinX(attributes.frame) - leadingInset;
+        if ((forward && itemOffset > visibleOffset + VLCCarouselScrollPositionTolerance) || (!forward && itemOffset < visibleOffset - VLCCarouselScrollPositionTolerance)) {
             targetAttributes = attributes;
             break;
         }
     }
 
     if (targetAttributes != nil) {
-        const CGFloat targetOffset = MAX(NSMinX(targetAttributes.frame) - self.leadingItemInset,
-                                         NSMinX(self.frame));
+        const CGFloat targetOffset = NSMinX(targetAttributes.frame) - leadingInset;
         [self scrollToHorizontalOffset:targetOffset
                               animated:YES
                               duration:VLCCarouselItemScrollDuration];
-    } else {
+    } else if ([self canScrollInDirection:forward]) {
         // Supplementary views may extend beyond the first or last item, or be
         // the only content when there are no recent videos.
-        const CGFloat edgeOffset = forward
-            ? NSMaxX(self.frame) - NSWidth(scrollView.documentVisibleRect)
-            : NSMinX(self.frame);
+        const CGFloat edgeOffset = [self horizontalOffsetBeyondEdgeInScrollView:scrollView forward:forward];
         [self scrollToHorizontalOffset:edgeOffset
                               animated:YES
                               duration:VLCCarouselItemScrollDuration];
@@ -269,6 +289,54 @@ static const CGFloat VLCCarouselDecelerationEdgeTolerance = .01;
 
 #pragma mark - Scrolling helpers
 
+- (BOOL)canScrollInDirection:(BOOL)forward
+{
+    NSScrollView * const scrollView = self.enclosingScrollView;
+    if (scrollView == nil || self.collectionViewLayout == nil) {
+        return NO;
+    }
+
+    NSClipView * const clipView = scrollView.contentView;
+    const NSRect bounds = clipView.bounds;
+    if (NSWidth(bounds) <= 0.) {
+        return NO;
+    }
+
+    NSRect proposedBounds = bounds;
+    proposedBounds.origin.x = [self horizontalOffsetBeyondEdgeInScrollView:scrollView forward:forward];
+    const CGFloat endpoint = NSMinX([clipView constrainBoundsRect:proposedBounds]);
+    const CGFloat distance = forward ? endpoint - NSMinX(bounds) : NSMinX(bounds) - endpoint;
+    return distance > VLCCarouselScrollPositionTolerance && [self hasItemsOrSupplementaryViews];
+}
+
+- (CGFloat)horizontalOffsetBeyondEdgeInScrollView:(NSScrollView *)scrollView
+                                          forward:(BOOL)forward
+{
+    return forward
+        ? NSMaxX(self.frame) + fabs(scrollView.contentInsets.right)
+        : NSMinX(self.frame) - NSWidth(scrollView.contentView.bounds) - fabs(scrollView.contentInsets.left);
+}
+
+- (BOOL)hasItemsOrSupplementaryViews
+{
+    for (NSInteger section = 0; section < self.numberOfSections; ++section) {
+        if ([self numberOfItemsInSection:section] > 0) {
+            return YES;
+        }
+    }
+
+    NSArray<NSCollectionViewLayoutAttributes *> * const attributes =
+        [self.collectionViewLayout layoutAttributesForElementsInRect:self.bounds];
+    for (NSCollectionViewLayoutAttributes * const element in attributes) {
+        if (element.representedElementCategory == NSCollectionElementCategorySupplementaryView &&
+            !element.hidden &&
+            !NSIsEmptyRect(element.frame)) {
+            return YES;
+        }
+    }
+    return NO;
+}
+
 - (void)scrollByHorizontalDelta:(CGFloat)delta
 {
     NSScrollView * const scrollView = self.enclosingScrollView;
@@ -290,11 +358,9 @@ static const CGFloat VLCCarouselDecelerationEdgeTolerance = .01;
     }
 
     NSClipView * const clipView = scrollView.contentView;
-    const NSRect visibleRect = scrollView.documentVisibleRect;
-    const CGFloat minimumOffset = NSMinX(self.frame);
-    const CGFloat maximumOffset = MAX(NSMaxX(self.frame) - NSWidth(visibleRect), minimumOffset);
-    offset = MIN(MAX(offset, minimumOffset), maximumOffset);
-    const NSPoint point = NSMakePoint(offset, NSMinY(visibleRect));
+    NSRect proposedBounds = clipView.bounds;
+    proposedBounds.origin.x = offset;
+    const NSPoint point = [clipView constrainBoundsRect:proposedBounds].origin;
 
     if (!animated) {
         [clipView scrollToPoint:point];


=====================================
modules/gui/macosx/views/VLCLoadingOverlayView.m
=====================================
@@ -61,8 +61,12 @@
     self.indicator.indeterminate = YES;
     self.indicator.style = NSProgressIndicatorStyleSpinning;
     [self addSubview:self.indicator];
+    NSLayoutXAxisAnchor *centerXAnchor = self.centerXAnchor;
+    if (@available(macOS 26.0, *)) {
+        centerXAnchor = self.safeAreaLayoutGuide.centerXAnchor;
+    }
     [self addConstraints:@[
-        [self.indicator.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
+        [self.indicator.centerXAnchor constraintEqualToAnchor:centerXAnchor],
         [self.indicator.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
     ]];
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e788d3af35b8805be4b4f77eab0c1c709a6766f4...80aba2883f972debaf01452316103cb9d1f5bbbf

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e788d3af35b8805be4b4f77eab0c1c709a6766f4...80aba2883f972debaf01452316103cb9d1f5bbbf
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list