Source/WebKit2: <rdar://problem/9557598> REGRESSION (WebKit2): Non-activating links...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Feb 2012 18:00:23 +0000 (18:00 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Feb 2012 18:00:23 +0000 (18:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79607

Reviewed by Adele Peterson.

Test: TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm

This was caused by not mapping the mouse event coordinates from window coordinates to
document coordinates.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDictionaryLookupAtLocation): Convert the point to main frame
coordinates when performing the hit test.
(WebKit::WebPage::shouldDelayWindowOrderingEvent): Convert the point to the main or focused
frame coordinates when perfomring the hit test.
(WebKit::WebPage::acceptsFirstMouse): Ditto.

Tools: Added a test for <rdar://problem/9557598> REGRESSION (WebKit2): Non-activating links sometimes don’t work
https://bugs.webkit.org/show_bug.cgi?id=79607

Reviewed by Adele Peterson.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
* TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm: Added.
(TestWebKitAPI::AcceptsFirstMouse::url):
(TestWebKitAPI::AcceptsFirstMouse::didLoadURL):
(TestWebKitAPI::AcceptsFirstMouse::runTest):
(TestWebKitAPI::TEST_F):
* TestWebKitAPI/Tests/mac/acceptsFirstMouse.html: Added.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/acceptsFirstMouse.html [new file with mode: 0644]

index 42029175c72065edd923b863933688707bc03843..261405715d21e9b8d14bcc62d1b35b353087b925 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-27  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/9557598> REGRESSION (WebKit2): Non-activating links sometimes don’t work
+        https://bugs.webkit.org/show_bug.cgi?id=79607
+
+        Reviewed by Adele Peterson.
+
+        Test: TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm
+
+        This was caused by not mapping the mouse event coordinates from window coordinates to
+        document coordinates.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDictionaryLookupAtLocation): Convert the point to main frame
+        coordinates when performing the hit test.
+        (WebKit::WebPage::shouldDelayWindowOrderingEvent): Convert the point to the main or focused
+        frame coordinates when perfomring the hit test.
+        (WebKit::WebPage::acceptsFirstMouse): Ditto.
+
 2012-02-27  Timothy Hatcher  <timothy@apple.com>
 
         Add WKInspector API to know when the Web Inspector is the frontmost window.
index bfee902078ecbc246a441fd2fac19fb6dc307be3..e4535dce14b2c38cc0317effd6dee5dda27568ea 100644 (file)
@@ -440,7 +440,7 @@ void WebPage::performDictionaryLookupAtLocation(const FloatPoint& floatPoint)
 
     // Find the frame the point is over.
     IntPoint point = roundedIntPoint(floatPoint);
-    HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, false);
+    HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(frame->view()->windowToContents(point), false);
     frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame();
 
     IntPoint translatedPoint = frame->view()->windowToContents(point);
@@ -687,7 +687,7 @@ void WebPage::shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent& event,
     if (!frame)
         return;
 
-    HitTestResult hitResult = frame->eventHandler()->hitTestResultAtPoint(event.position(), true);
+    HitTestResult hitResult = frame->eventHandler()->hitTestResultAtPoint(frame->view()->windowToContents(event.position()), true);
     if (hitResult.isSelected())
         result = frame->eventHandler()->eventMayStartDrag(platform(event));
 }
@@ -699,7 +699,7 @@ void WebPage::acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent& ev
     if (!frame)
         return;
     
-    HitTestResult hitResult = frame->eventHandler()->hitTestResultAtPoint(event.position(), true);
+    HitTestResult hitResult = frame->eventHandler()->hitTestResultAtPoint(frame->view()->windowToContents(event.position()), true);
     frame->eventHandler()->setActivationEventNumber(eventNumber);
     if (hitResult.isSelected())
         result = frame->eventHandler()->eventMayStartDrag(platform(event));
index e53aaecb55d1ee514876499cdbb7b0e8786982f7..758dcb606f983a0dc61a120cc64781923eed0150 100644 (file)
@@ -1,3 +1,18 @@
+2012-02-27  Dan Bernstein  <mitz@apple.com>
+
+        Added a test for <rdar://problem/9557598> REGRESSION (WebKit2): Non-activating links sometimes don’t work
+        https://bugs.webkit.org/show_bug.cgi?id=79607
+
+        Reviewed by Adele Peterson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
+        * TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm: Added.
+        (TestWebKitAPI::AcceptsFirstMouse::url):
+        (TestWebKitAPI::AcceptsFirstMouse::didLoadURL):
+        (TestWebKitAPI::AcceptsFirstMouse::runTest):
+        (TestWebKitAPI::TEST_F):
+        * TestWebKitAPI/Tests/mac/acceptsFirstMouse.html: Added.
+
 2012-02-27  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix make distcheck.
index ea44c5e38fcb8b2654f7038358026b7b5c5f0a24..379b26859d9868dcee6f53d2beb3cfc9d1925bf2 100644 (file)
@@ -28,6 +28,8 @@
                33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
                37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37200B9113A16230007A4FAD /* VectorReverse.cpp */; };
                3722C8691461E03E00C45D00 /* RenderedImageFromDOMRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */; };
+               379028B614FABD92007E6B43 /* AcceptsFirstMouse.mm in Sources */ = {isa = PBXBuildFile; fileRef = 379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */; };
+               379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */; };
                3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */; };
                37A6895F148A9B50005100FA /* SubresourceErrorCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */; };
                37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
                                33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                                C07E6CB213FD73930038B22B /* devicePixelRatio.html in Copy Resources */,
                33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
                37200B9113A16230007A4FAD /* VectorReverse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VectorReverse.cpp; path = WTF/VectorReverse.cpp; sourceTree = "<group>"; };
                3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMRange.mm; sourceTree = "<group>"; };
+               379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AcceptsFirstMouse.mm; sourceTree = "<group>"; };
+               379028B814FABE49007E6B43 /* acceptsFirstMouse.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = acceptsFirstMouse.html; sourceTree = "<group>"; };
                3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringByEvaluatingJavaScriptFromString.mm; sourceTree = "<group>"; };
                37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SubresourceErrorCrash.mm; sourceTree = "<group>"; };
                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMRangeOfString.mm; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                C07E6CB013FD737C0038B22B /* Resources */,
+                               379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */,
                                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */,
                                C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
                                939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
                C07E6CB013FD737C0038B22B /* Resources */ = {
                        isa = PBXGroup;
                        children = (
-                               37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */,
+                               379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
                                C07E6CB113FD738A0038B22B /* devicePixelRatio.html */,
+                               37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */,
                        );
                        name = Resources;
                        sourceTree = "<group>";
                                93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
                                BC22D31514DC689800FFB1DD /* UserMessage.cpp in Sources */,
                                E490296814E2E3A4002BEDD1 /* TypingStyleCrash.mm in Sources */,
+                               379028B614FABD92007E6B43 /* AcceptsFirstMouse.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm b/Tools/TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm
new file mode 100644 (file)
index 0000000..2c3fe28
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+#include "WebKitAgnosticTest.h"
+
+#include <wtf/RetainPtr.h>
+
+@interface NSApplication (TestWebKitAPINSApplicationDetails)
+- (void)_setCurrentEvent:(NSEvent *)event;
+@end
+
+namespace TestWebKitAPI {
+
+class AcceptsFirstMouse : public WebKitAgnosticTest {
+public:
+    template <typename View> void runTest(View);
+
+    // WebKitAgnosticTest
+    virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"acceptsFirstMouse" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; }
+    virtual void didLoadURL(WebView *webView) { runTest(webView); }
+    virtual void didLoadURL(WKView *wkView) { runTest(wkView); }
+};
+
+template <typename View>
+void AcceptsFirstMouse::runTest(View view)
+{
+    RetainPtr<NSWindow> window(AdoptNS, [[NSWindow alloc] initWithContentRect:view.frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [window.get().contentView addSubview:view];
+
+    CGFloat viewHeight = view.bounds.size.height;
+
+    NSPoint pointInsideSelection = NSMakePoint(50, viewHeight - 50);
+    NSEvent *mouseEventInsideSelection = [NSEvent mouseEventWithType:NSLeftMouseDown location:pointInsideSelection modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:nil eventNumber:0 clickCount:1 pressure:1];
+    EXPECT_TRUE([[view hitTest:pointInsideSelection] acceptsFirstMouse:mouseEventInsideSelection]);
+
+    NSPoint pointOutsideSelection = NSMakePoint(50, viewHeight - 150);
+    NSEvent *mouseEventOutsideSelection = [NSEvent mouseEventWithType:NSLeftMouseDown location:pointOutsideSelection modifierFlags:0 timestamp:0 windowNumber:window.get().windowNumber context:nil eventNumber:0 clickCount:1 pressure:1];
+    EXPECT_FALSE([[view hitTest:pointInsideSelection] acceptsFirstMouse:mouseEventOutsideSelection]);
+}
+
+TEST_F(AcceptsFirstMouse, WebKit)
+{
+    // Ensure that [NSApp currentEvent] is not a previously-simulated spacebar key press, since this
+    // causes the scrollBy() in the test to perform a smooth scroll.
+    [NSApp _setCurrentEvent:nil];
+    runWebKit1Test();
+}
+
+TEST_F(AcceptsFirstMouse, WebKit2)
+{
+    runWebKit2Test();
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/mac/acceptsFirstMouse.html b/Tools/TestWebKitAPI/Tests/mac/acceptsFirstMouse.html
new file mode 100644 (file)
index 0000000..3de413a
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html style="height: 200%;">
+<head>
+    <style>
+        img.selectable {
+            width: 100px;
+            height: 100px;
+            display: block;
+            background-color: gray;
+        }
+    </style>
+</head>
+<body style="margin: 0;">
+    <img class="selectable">
+    <img class="selectable" id="target">
+    <img class="selectable">
+    <script>
+        var target = document.getElementById("target");
+        getSelection().setBaseAndExtent(target, 0, target, 1);
+        scrollBy(0, 100);
+    </script>
+</body>
+</html>