Title: [192811] trunk/Source/WebKit2
- Revision
- 192811
- Author
- timothy_hor...@apple.com
- Date
- 2015-11-30 11:52:46 -0800 (Mon, 30 Nov 2015)
Log Message
[iOS] Option-up and Option-down should scroll a little less than a full page
https://bugs.webkit.org/show_bug.cgi?id=151538
<rdar://problem/23642675>
Reviewed by Simon Fraser.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _scrollOffsetForEvent:]):
(-[WKContentView _interpretKeyEvent:isCharEvent:]):
Clean up the code a little, and adjust so that we *always* use pageStep
instead of just scrolling by the unobscured rect when scrolling by a page.
Previously, we did for the spacebar, but not for option-up and option-down.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (192810 => 192811)
--- trunk/Source/WebKit2/ChangeLog 2015-11-30 19:27:26 UTC (rev 192810)
+++ trunk/Source/WebKit2/ChangeLog 2015-11-30 19:52:46 UTC (rev 192811)
@@ -1,3 +1,18 @@
+2015-11-30 Tim Horton <timothy_hor...@apple.com>
+
+ [iOS] Option-up and Option-down should scroll a little less than a full page
+ https://bugs.webkit.org/show_bug.cgi?id=151538
+ <rdar://problem/23642675>
+
+ Reviewed by Simon Fraser.
+
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView _scrollOffsetForEvent:]):
+ (-[WKContentView _interpretKeyEvent:isCharEvent:]):
+ Clean up the code a little, and adjust so that we *always* use pageStep
+ instead of just scrolling by the unobscured rect when scrolling by a page.
+ Previously, we did for the spacebar, but not for option-up and option-down.
+
2015-11-30 Brian Burg <bb...@apple.com>
Web Inspector: using "Reload Web Inspector" when docked breaks dock-specific styles
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (192810 => 192811)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2015-11-30 19:27:26 UTC (rev 192810)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2015-11-30 19:52:46 UTC (rev 192811)
@@ -2865,6 +2865,70 @@
_uiEventBeingResent = nil;
}
+- (Optional<FloatPoint>)_scrollOffsetForEvent:(WebIOSEvent *)event
+{
+ static const unsigned kWebSpaceKey = 0x20;
+
+ if (_page->editorState().isContentEditable)
+ return Nullopt;
+
+ NSString *charactersIgnoringModifiers = event.charactersIgnoringModifiers;
+ if (!charactersIgnoringModifiers.length)
+ return Nullopt;
+
+ enum ScrollingIncrement { Document, Page, Line };
+ enum ScrollingDirection { Up, Down, Left, Right };
+
+ auto computeOffset = ^(ScrollingIncrement increment, ScrollingDirection direction) {
+ bool isHorizontal = (direction == Left || direction == Right);
+
+ CGFloat scrollDistance = ^ CGFloat {
+ switch (increment) {
+ case Document:
+ ASSERT(!isHorizontal);
+ return self.bounds.size.height;
+ case Page:
+ ASSERT(!isHorizontal);
+ return Scrollbar::pageStep(_page->unobscuredContentRect().height(), self.bounds.size.height);
+ case Line:
+ return Scrollbar::pixelsPerLineStep();
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+ }();
+
+ if (direction == Up || direction == Left)
+ scrollDistance = -scrollDistance;
+
+ return (isHorizontal ? FloatPoint(scrollDistance, 0) : FloatPoint(0, scrollDistance));
+ };
+
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputLeftArrow])
+ return computeOffset(Line, Left);
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputRightArrow])
+ return computeOffset(Line, Right);
+
+ ScrollingIncrement incrementForVerticalArrowKey = Line;
+ if (event.modifierFlags & WebEventFlagMaskAlternate)
+ incrementForVerticalArrowKey = Page;
+ else if (event.modifierFlags & WebEventFlagMaskCommand)
+ incrementForVerticalArrowKey = Document;
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputUpArrow])
+ return computeOffset(incrementForVerticalArrowKey, Up);
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputDownArrow])
+ return computeOffset(incrementForVerticalArrowKey, Down);
+
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputPageDown])
+ return computeOffset(Page, Down);
+ if ([charactersIgnoringModifiers isEqualToString:UIKeyInputPageUp])
+ return computeOffset(Page, Up);
+
+ if ([charactersIgnoringModifiers characterAtIndex:0] == kWebSpaceKey)
+ return computeOffset(Page, (event.modifierFlags & WebEventFlagMaskShift) ? Up : Down);
+
+ return Nullopt;
+}
+
- (BOOL)_interpretKeyEvent:(WebIOSEvent *)event isCharEvent:(BOOL)isCharEvent
{
static const unsigned kWebEnterKey = 0x0003;
@@ -2875,52 +2939,19 @@
static const unsigned kWebSpaceKey = 0x20;
BOOL contentEditable = _page->editorState().isContentEditable;
- WebCore::FloatRect unobscuredContentRect = _page->unobscuredContentRect();
if (!contentEditable && event.isTabKey)
return NO;
- BOOL shift = event.modifierFlags & WebEventFlagMaskShift;
- BOOL command = event.modifierFlags & WebEventFlagMaskCommand;
- BOOL option = event.modifierFlags & WebEventFlagMaskAlternate;
- NSString *charactersIgnoringModifiers = [event charactersIgnoringModifiers];
- BOOL shouldScroll = YES;
- FloatPoint scrollOffset;
-
- if ([charactersIgnoringModifiers isEqualToString:UIKeyInputLeftArrow])
- scrollOffset.setX(-Scrollbar::pixelsPerLineStep());
- else if ([charactersIgnoringModifiers isEqualToString:UIKeyInputUpArrow]) {
- if (option)
- scrollOffset.setY(-unobscuredContentRect.height());
- else if (command)
- scrollOffset.setY(-self.bounds.size.height);
- else
- scrollOffset.setY(-Scrollbar::pixelsPerLineStep());
- } else if ([charactersIgnoringModifiers isEqualToString:UIKeyInputRightArrow])
- scrollOffset.setX(Scrollbar::pixelsPerLineStep());
- else if ([charactersIgnoringModifiers isEqualToString:UIKeyInputDownArrow]) {
- if (option)
- scrollOffset.setY(unobscuredContentRect.height());
- else if (command)
- scrollOffset.setY(self.bounds.size.height);
- else
- scrollOffset.setY(Scrollbar::pixelsPerLineStep());
- } else if ([charactersIgnoringModifiers isEqualToString:UIKeyInputPageDown])
- scrollOffset.setY(unobscuredContentRect.height());
- else if ([charactersIgnoringModifiers isEqualToString:UIKeyInputPageUp])
- scrollOffset.setY(-unobscuredContentRect.height());
- else
- shouldScroll = NO;
-
- if (shouldScroll) {
- [_webView _scrollByContentOffset:scrollOffset];
+ if (Optional<FloatPoint> scrollOffset = [self _scrollOffsetForEvent:event]) {
+ [_webView _scrollByContentOffset:*scrollOffset];
return YES;
}
UIKeyboardImpl *keyboard = [UIKeyboardImpl sharedInstance];
- NSString *characters = [event characters];
+ NSString *characters = event.characters;
- if (![characters length])
+ if (!characters.length)
return NO;
switch ([characters characterAtIndex:0]) {
@@ -2937,12 +2968,7 @@
break;
case kWebSpaceKey:
- if (!contentEditable) {
- int pageStep = Scrollbar::pageStep(unobscuredContentRect.height(), self.bounds.size.height);
- [_webView _scrollByContentOffset:FloatPoint(0, shift ? -pageStep : pageStep)];
- return YES;
- }
- if (isCharEvent) {
+ if (contentEditable && isCharEvent) {
[keyboard addInputString:event.characters withFlags:event.keyboardFlags];
return YES;
}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes