Title: [255442] branches/safari-609-branch
Revision
255442
Author
[email protected]
Date
2020-01-30 11:58:54 -0800 (Thu, 30 Jan 2020)

Log Message

Cherry-pick r255337. rdar://problem/58936679

    macCatalyst: Right clicking on a link follows it immediately
    https://bugs.webkit.org/show_bug.cgi?id=206919
    <rdar://problem/58936679>

    Reviewed by Wenson Hsieh.

    Source/WebKit:

    * UIProcess/ios/WKMouseGestureRecognizer.mm:
    (-[WKMouseGestureRecognizer createMouseEventWithType:forEvent:]):
    (-[WKMouseGestureRecognizer touchesBegan:withEvent:]):
    (-[WKMouseGestureRecognizer touchesEnded:withEvent:]):
    UIKit's _buttonMask does not include the currently-released button,
    so in order to correctly identify the released button in touchesEnded,
    store the mask for the length of the click.

    Tools:

    * TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm:
    (TEST):
    Add a test ensuring that mouseup is still called with the secondary button,
    even if the event's buttonmask is 0.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255337 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-609-branch/Source/WebKit/ChangeLog (255441 => 255442)


--- branches/safari-609-branch/Source/WebKit/ChangeLog	2020-01-30 19:28:02 UTC (rev 255441)
+++ branches/safari-609-branch/Source/WebKit/ChangeLog	2020-01-30 19:58:54 UTC (rev 255442)
@@ -1,3 +1,48 @@
+2020-01-30  Alan Coon  <[email protected]>
+
+        Cherry-pick r255337. rdar://problem/58936679
+
+    macCatalyst: Right clicking on a link follows it immediately
+    https://bugs.webkit.org/show_bug.cgi?id=206919
+    <rdar://problem/58936679>
+    
+    Reviewed by Wenson Hsieh.
+    
+    Source/WebKit:
+    
+    * UIProcess/ios/WKMouseGestureRecognizer.mm:
+    (-[WKMouseGestureRecognizer createMouseEventWithType:forEvent:]):
+    (-[WKMouseGestureRecognizer touchesBegan:withEvent:]):
+    (-[WKMouseGestureRecognizer touchesEnded:withEvent:]):
+    UIKit's _buttonMask does not include the currently-released button,
+    so in order to correctly identify the released button in touchesEnded,
+    store the mask for the length of the click.
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm:
+    (TEST):
+    Add a test ensuring that mouseup is still called with the secondary button,
+    even if the event's buttonmask is 0.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255337 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-01-28  Tim Horton  <[email protected]>
+
+            macCatalyst: Right clicking on a link follows it immediately
+            https://bugs.webkit.org/show_bug.cgi?id=206919
+            <rdar://problem/58936679>
+
+            Reviewed by Wenson Hsieh.
+
+            * UIProcess/ios/WKMouseGestureRecognizer.mm:
+            (-[WKMouseGestureRecognizer createMouseEventWithType:forEvent:]):
+            (-[WKMouseGestureRecognizer touchesBegan:withEvent:]):
+            (-[WKMouseGestureRecognizer touchesEnded:withEvent:]):
+            UIKit's _buttonMask does not include the currently-released button,
+            so in order to correctly identify the released button in touchesEnded,
+            store the mask for the length of the click.
+
 2020-01-27  Russell Epstein  <[email protected]>
 
         Cherry-pick r255114. rdar://problem/58920176

Modified: branches/safari-609-branch/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm (255441 => 255442)


--- branches/safari-609-branch/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm	2020-01-30 19:28:02 UTC (rev 255441)
+++ branches/safari-609-branch/Source/WebKit/UIProcess/ios/WKMouseGestureRecognizer.mm	2020-01-30 19:58:54 UTC (rev 255442)
@@ -56,6 +56,7 @@
 
     std::unique_ptr<WebKit::NativeWebMouseEvent> _lastEvent;
     Optional<CGPoint> _lastLocation;
+    Optional<UIEventButtonMask> _pressedButtonMask;
 }
 
 - (instancetype)initWithTarget:(id)target action:(SEL)action
@@ -119,10 +120,10 @@
     return NO;
 }
 
-- (std::unique_ptr<WebKit::NativeWebMouseEvent>)createMouseEventWithType:(WebKit::WebEvent::Type)type forEvent:(UIEvent *)uiEvent
+- (std::unique_ptr<WebKit::NativeWebMouseEvent>)createMouseEventWithType:(WebKit::WebEvent::Type)type
 {
     auto modifiers = webEventModifiersForUIKeyModifierFlags(self.modifierFlags);
-    BOOL isRightButton = modifiers.contains(WebKit::WebEvent::Modifier::ControlKey) || ([uiEvent _buttonMask] & UIEventButtonMaskSecondary);
+    BOOL isRightButton = modifiers.contains(WebKit::WebEvent::Modifier::ControlKey) || (_pressedButtonMask && (*_pressedButtonMask & UIEventButtonMaskSecondary));
 
     auto button = [&] {
         if (!_touching)
@@ -151,8 +152,9 @@
 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 {
     _touching = YES;
+    _pressedButtonMask = [event _buttonMask];
 
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseDown forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseDown];
     _lastLocation = [self locationInView:self.view];
 
     self.state = UIGestureRecognizerStateChanged;
@@ -160,7 +162,7 @@
 
 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 {
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove];
     _lastLocation = [self locationInView:self.view];
 
     self.state = UIGestureRecognizerStateChanged;
@@ -168,10 +170,11 @@
 
 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 {
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseUp forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseU];
     _lastLocation = [self locationInView:self.view];
 
     _touching = NO;
+    _pressedButtonMask = WTF::nullopt;
 
     self.state = UIGestureRecognizerStateChanged;
 }
@@ -183,7 +186,7 @@
 
 - (void)_hoverEntered:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 {
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove];
 
     if (_currentHoverEvent == nil && touches.count == 1 && [event isKindOfClass:NSClassFromString(@"UIHoverEvent")]) {
         _currentHoverEvent = (UIHoverEvent *)event;
@@ -202,7 +205,7 @@
         return;
     }
 
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove];
     _lastLocation = [self locationInView:self.view];
 
     if (_currentHoverEvent == event && [touches containsObject:_currentTouch.get()])
@@ -213,7 +216,7 @@
 
 - (void)_hoverExited:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 {
-    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove forEvent:event];
+    _lastEvent = [self createMouseEventWithType:WebKit::WebEvent::MouseMove];
     _lastLocation = [self locationInView:self.view];
 
     if (_currentHoverEvent == event) {

Modified: branches/safari-609-branch/Tools/ChangeLog (255441 => 255442)


--- branches/safari-609-branch/Tools/ChangeLog	2020-01-30 19:28:02 UTC (rev 255441)
+++ branches/safari-609-branch/Tools/ChangeLog	2020-01-30 19:58:54 UTC (rev 255442)
@@ -1,3 +1,45 @@
+2020-01-30  Alan Coon  <[email protected]>
+
+        Cherry-pick r255337. rdar://problem/58936679
+
+    macCatalyst: Right clicking on a link follows it immediately
+    https://bugs.webkit.org/show_bug.cgi?id=206919
+    <rdar://problem/58936679>
+    
+    Reviewed by Wenson Hsieh.
+    
+    Source/WebKit:
+    
+    * UIProcess/ios/WKMouseGestureRecognizer.mm:
+    (-[WKMouseGestureRecognizer createMouseEventWithType:forEvent:]):
+    (-[WKMouseGestureRecognizer touchesBegan:withEvent:]):
+    (-[WKMouseGestureRecognizer touchesEnded:withEvent:]):
+    UIKit's _buttonMask does not include the currently-released button,
+    so in order to correctly identify the released button in touchesEnded,
+    store the mask for the length of the click.
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm:
+    (TEST):
+    Add a test ensuring that mouseup is still called with the secondary button,
+    even if the event's buttonmask is 0.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255337 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-01-28  Tim Horton  <[email protected]>
+
+            macCatalyst: Right clicking on a link follows it immediately
+            https://bugs.webkit.org/show_bug.cgi?id=206919
+            <rdar://problem/58936679>
+
+            Reviewed by Wenson Hsieh.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm:
+            (TEST):
+            Add a test ensuring that mouseup is still called with the secondary button,
+            even if the event's buttonmask is 0.
+
 2020-01-28  Russell Epstein  <[email protected]>
 
         Cherry-pick r254708. rdar://problem/58945571

Added: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm (0 => 255442)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm	                        (rev 0)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/MacCatalystMouseSupport.mm	2020-01-30 19:58:54 UTC (rev 255442)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MACCATALYST)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+@interface WKMouseGestureRecognizer : UIGestureRecognizer
+- (void)_hoverEntered:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
+- (void)_hoverExited:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
+- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
+- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
+@end
+
+@interface WKContentView ()
+- (void)_mouseGestureRecognizerChanged:(WKMouseGestureRecognizer *)gestureRecognizer;
+@end
+
+@interface WKTestingEvent : UIEvent
+@end
+
+@implementation WKTestingEvent {
+    UIEventButtonMask _buttonMask;
+}
+
+- (CGPoint)locationInView:(UIView *)view
+{
+    return CGPointMake(10, 10);
+}
+
+- (void)_setButtonMask:(UIEventButtonMask)buttonMask
+{
+    _buttonMask = buttonMask;
+}
+
+- (UIEventButtonMask)_buttonMask
+{
+    return _buttonMask;
+}
+
+@end
+
+@interface WKTestingTouch : UITouch
+@end
+
+@implementation WKTestingTouch {
+    NSUInteger _tapCount;
+}
+
+- (CGPoint)locationInView:(UIView *)view
+{
+    return CGPointMake(10, 10);
+}
+
+- (void)setTapCount:(NSUInteger)tapCount
+{
+    _tapCount = tapCount;
+}
+
+- (NSUInteger)tapCount
+{
+    return _tapCount;
+}
+
+@end
+
+static WKMouseGestureRecognizer *mouseGesture(UIView *view)
+{
+    for (UIGestureRecognizer *recognizer in view.gestureRecognizers) {
+        if ([recognizer isKindOfClass:NSClassFromString(@"WKMouseGestureRecognizer")])
+            return (WKMouseGestureRecognizer *)recognizer;
+    }
+
+    return nil;
+}
+
+TEST(MacCatalystMouseSupport, DoNotChangeSelectionWithRightClick)
+{
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView objectByEvaluatingJavaScript:@"document.body.setAttribute('contenteditable','');"];
+
+    auto contentView = [webView wkContentView];
+    auto gesture = mouseGesture(contentView);
+
+    RetainPtr<WKTestingTouch> touch = adoptNS([[WKTestingTouch alloc] init]);
+    RetainPtr<NSSet> touchSet = [NSSet setWithObject:touch.get()];
+
+    RetainPtr<WKTestingEvent> event = adoptNS([[WKTestingEvent alloc] init]);
+
+    [gesture _hoverEntered:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+    [touch setTapCount:1];
+    [event _setButtonMask:UIEventButtonMaskSecondary];
+    [gesture touchesBegan:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+    [gesture touchesEnded:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+
+    __block bool done = false;
+
+    [webView _doAfterProcessingAllPendingMouseEvents:^{
+        NSNumber *result = [webView objectByEvaluatingJavaScript:@"window.getSelection().isCollapsed"];
+        EXPECT_TRUE([result boolValue]);
+        done = true;
+    }];
+
+    TestWebKitAPI::Util::run(&done);
+}
+
+TEST(MacCatalystMouseSupport, TrackButtonMaskFromTouchStart)
+{
+    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    [webView synchronouslyLoadHTMLString:@"<script>"
+    "window.didReleaseRightButton = false;"
+    "document.documentElement.addEventListener('mouseup', function (e) {"
+    "    if (e.button == 2)"
+    "        window.didReleaseRightButton = true;"
+    "});"
+    "</script>"];
+
+    auto contentView = [webView wkContentView];
+    auto gesture = mouseGesture(contentView);
+
+    RetainPtr<WKTestingTouch> touch = adoptNS([[WKTestingTouch alloc] init]);
+    RetainPtr<NSSet> touchSet = [NSSet setWithObject:touch.get()];
+
+    RetainPtr<WKTestingEvent> event = adoptNS([[WKTestingEvent alloc] init]);
+
+    [gesture _hoverEntered:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+    [touch setTapCount:1];
+    [event _setButtonMask:UIEventButtonMaskSecondary];
+    [gesture touchesBegan:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+    [event _setButtonMask:0];
+    [gesture touchesEnded:touchSet.get() withEvent:event.get()];
+    [contentView _mouseGestureRecognizerChanged:gesture];
+
+    __block bool done = false;
+
+    [webView _doAfterProcessingAllPendingMouseEvents:^{
+        NSNumber *result = [webView objectByEvaluatingJavaScript:@"window.didReleaseRightButton"];
+        EXPECT_TRUE([result boolValue]);
+        done = true;
+    }];
+
+    TestWebKitAPI::Util::run(&done);
+}
+
+
+#endif // PLATFORM(MACCATALYST)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to