summaryrefslogtreecommitdiffstats
path: root/WebKit/mac/WebView/WebDynamicScrollBarsView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/mac/WebView/WebDynamicScrollBarsView.mm')
-rw-r--r--WebKit/mac/WebView/WebDynamicScrollBarsView.mm73
1 files changed, 73 insertions, 0 deletions
diff --git a/WebKit/mac/WebView/WebDynamicScrollBarsView.mm b/WebKit/mac/WebView/WebDynamicScrollBarsView.mm
index 74439dd..1c6980f 100644
--- a/WebKit/mac/WebView/WebDynamicScrollBarsView.mm
+++ b/WebKit/mac/WebView/WebDynamicScrollBarsView.mm
@@ -62,6 +62,17 @@ struct WebDynamicScrollBarsViewPrivate {
bool alwaysHideVerticalScroller;
bool horizontalScrollingAllowedButScrollerHidden;
bool verticalScrollingAllowedButScrollerHidden;
+
+ // scrollOrigin is set for various combinations of writing mode and direction.
+ // See the comment next to the corresponding member in ScrollView.h.
+ NSPoint scrollOrigin;
+
+ // Flag to indicate that the scrollbar thumb's initial position needs to
+ // be manually set.
+ bool scrollOriginChanged;
+ NSPoint scrollPositionExcludingOrigin;
+
+ bool inProgrammaticScroll;
};
@implementation WebDynamicScrollBarsView
@@ -149,6 +160,11 @@ struct WebDynamicScrollBarsViewPrivate {
return _private->verticalScrollingAllowedButScrollerHidden || [self hasVerticalScroller];
}
+- (BOOL)inProgramaticScroll
+{
+ return _private->inProgrammaticScroll;
+}
+
@end
@implementation WebDynamicScrollBarsView (WebInternal)
@@ -201,6 +217,24 @@ struct WebDynamicScrollBarsViewPrivate {
#endif
}
+- (void)adjustForScrollOriginChange
+{
+ if (!_private->scrollOriginChanged)
+ return;
+
+ _private->scrollOriginChanged = false;
+
+ NSView *documentView = [self documentView];
+ NSRect documentRect = [documentView bounds];
+
+ // The call to [NSView scrollPoint:] fires off notification the handler for which needs to know that
+ // we're setting the initial scroll position so it doesn't interpret this as a user action and
+ // fire off a JS event.
+ _private->inProgrammaticScroll = true;
+ [documentView scrollPoint:NSMakePoint(_private->scrollPositionExcludingOrigin.x + documentRect.origin.x, _private->scrollPositionExcludingOrigin.y + documentRect.origin.y)];
+ _private->inProgrammaticScroll = false;
+}
+
static const unsigned cMaxUpdateScrollbarsPass = 2;
- (void)updateScrollers
@@ -304,6 +338,10 @@ static const unsigned cMaxUpdateScrollbarsPass = 2;
[self setHasHorizontalScroller:newHasHorizontalScroller];
_private->inUpdateScrollers = NO;
needsLayout = YES;
+ NSView *documentView = [self documentView];
+ NSRect documentRect = [documentView bounds];
+ if (documentRect.origin.y < 0 && !newHasHorizontalScroller)
+ [documentView setBoundsOrigin:NSMakePoint(documentRect.origin.x, documentRect.origin.y + 15)];
}
if (hasVerticalScroller != newHasVerticalScroller) {
@@ -311,6 +349,10 @@ static const unsigned cMaxUpdateScrollbarsPass = 2;
[self setHasVerticalScroller:newHasVerticalScroller];
_private->inUpdateScrollers = NO;
needsLayout = YES;
+ NSView *documentView = [self documentView];
+ NSRect documentRect = [documentView bounds];
+ if (documentRect.origin.x < 0 && !newHasVerticalScroller)
+ [documentView setBoundsOrigin:NSMakePoint(documentRect.origin.x + 15, documentRect.origin.y)];
}
if (needsLayout && _private->inUpdateScrollersLayoutPass < cMaxUpdateScrollbarsPass &&
@@ -364,6 +406,11 @@ static const unsigned cMaxUpdateScrollbarsPass = 2;
}
#endif
+ // The call to [NSView reflectScrolledClipView] sets the scrollbar thumb
+ // position to 0 (the left) when the view is initially displayed.
+ // This call updates the initial position correctly.
+ [self adjustForScrollOriginChange];
+
#if USE(ACCELERATED_COMPOSITING) && defined(BUILDING_ON_LEOPARD)
NSView *documentView = [self documentView];
if ([documentView isKindOfClass:[WebHTMLView class]]) {
@@ -525,4 +572,30 @@ static const unsigned cMaxUpdateScrollbarsPass = 2;
return [super accessibilityIsIgnored];
}
+- (void)setScrollOrigin:(NSPoint)scrollOrigin updatePosition:(BOOL)updatePosition
+{
+ // The cross-platform ScrollView call already checked to see if the old/new scroll origins were the same or not
+ // so we don't have to check for equivalence here.
+ _private->scrollOrigin = scrollOrigin;
+ id docView = [self documentView];
+ NSPoint docOrigin = [docView bounds].origin;
+
+ NSRect visibleRect = [self documentVisibleRect];
+
+ [docView setBoundsOrigin:NSMakePoint(-scrollOrigin.x, -scrollOrigin.y)];
+
+ _private->scrollOriginChanged = true;
+
+ // Maintain our original position in the presence of the new scroll origin.
+ _private->scrollPositionExcludingOrigin = NSMakePoint(visibleRect.origin.x + scrollOrigin.x, visibleRect.origin.y + scrollOrigin.y);
+
+ if (updatePosition) // Otherwise we'll just let the snap happen when we update for the resize.
+ [self adjustForScrollOriginChange];
+}
+
+- (NSPoint)scrollOrigin
+{
+ return _private->scrollOrigin;
+}
+
@end