2010-11-23 Avi Drissman <avi@google.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Nov 2010 19:33:57 +0000 (19:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Nov 2010 19:33:57 +0000 (19:33 +0000)
        Reviewed by Antonio Gomes.

        Add preference to not select when right-clicked
        https://bugs.webkit.org/show_bug.cgi?id=23351

        * editing/selection/context-menu-text-selection-expected.txt: Added.
        * editing/selection/context-menu-text-selection.html: Added.
2010-11-23  Avi Drissman  <avi@google.com>

        Reviewed by Antonio Gomes.

        Add preference to not select when right-clicked
        https://bugs.webkit.org/show_bug.cgi?id=23351

        Test: editing/selection/context-menu-text-selection.html

        * editing/EditingBehavior.h:
        (WebCore::EditingBehavior::shouldSelectOnContextualMenuClick):
        * page/EventHandler.cpp:
        (WebCore::EventHandler::sendContextMenuEvent):

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/context-menu-text-selection-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/context-menu-text-selection.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/EditingBehavior.h
WebCore/page/EventHandler.cpp

index 3ad582c..101dfef 100644 (file)
@@ -1,3 +1,13 @@
+2010-11-23  Avi Drissman  <avi@google.com>
+
+        Reviewed by Antonio Gomes.
+
+        Add preference to not select when right-clicked
+        https://bugs.webkit.org/show_bug.cgi?id=23351
+
+        * editing/selection/context-menu-text-selection-expected.txt: Added.
+        * editing/selection/context-menu-text-selection.html: Added.
+
 2010-11-23  Alexander Pavlov  <apavlov@chromium.org>
 
         Reviewed by Pavel Feldman.
diff --git a/LayoutTests/editing/selection/context-menu-text-selection-expected.txt b/LayoutTests/editing/selection/context-menu-text-selection-expected.txt
new file mode 100644 (file)
index 0000000..3caf907
--- /dev/null
@@ -0,0 +1,6 @@
+This test checks that triggering the context menu selects/doesn't select as platform-appropriate.
+
+Lorem ipsum
+SUCCESS
+SUCCESS
+SUCCESS
diff --git a/LayoutTests/editing/selection/context-menu-text-selection.html b/LayoutTests/editing/selection/context-menu-text-selection.html
new file mode 100644 (file)
index 0000000..69c470d
--- /dev/null
@@ -0,0 +1,58 @@
+<body onload="load()">
+<p>This test checks that triggering the context menu selects/doesn't select as platform-appropriate.</p>
+<div id="text">Lorem ipsum</div>
+<div id="resultmac">RUNNING</div>
+<div id="resultwin">RUNNING</div>
+<div id="resultunix">RUNNING</div>
+</body>
+<script>
+function test(platform, selectionExpected, result)
+{
+    // clear selection
+    window.getSelection().removeAllRanges();
+
+    layoutTestController.setEditingBehavior(platform);
+
+    var text = document.getElementById("text");
+    var resultElement = document.getElementById(result);
+
+    var x = text.offsetParent.offsetLeft + text.offsetLeft + 4;
+    var y = text.offsetParent.offsetTop + text.offsetTop + text.offsetHeight / 2;
+
+    eventSender.mouseMoveTo(x, y);
+
+    var items = eventSender.contextClick();
+    if (items.length == 0) {
+        resultElement.innerHTML = 'FAILURE: No context menu';
+        return;
+    }
+
+    // esc key to kill the context menu
+    eventSender.keyDown(String.fromCharCode(0x001B), null);
+
+    var selectionType = window.getSelection().type;
+    if (selectionExpected) {
+        if (selectionType == "Range")
+            resultElement.innerHTML = "SUCCESS";
+        else
+            resultElement.innerHTML = "FAILURE: There should be a selection.";
+    } else {
+        if (selectionType == "Range")
+            resultElement.innerHTML = "FAILURE: There shouldn't be a selection.";
+        else
+            resultElement.innerHTML = "SUCCESS";
+    }
+}
+
+function load()
+{
+    if (!window.eventSender || !window.layoutTestController)
+        return;
+
+    layoutTestController.dumpAsText();
+
+    test('mac', true, 'resultmac');
+    test('win', false, 'resultwin');
+    test('unix', false, 'resultunix');
+}
+</script>
index 492d872..fdb3461 100644 (file)
@@ -1,3 +1,17 @@
+2010-11-23  Avi Drissman  <avi@google.com>
+
+        Reviewed by Antonio Gomes.
+
+        Add preference to not select when right-clicked
+        https://bugs.webkit.org/show_bug.cgi?id=23351
+
+        Test: editing/selection/context-menu-text-selection.html
+
+        * editing/EditingBehavior.h:
+        (WebCore::EditingBehavior::shouldSelectOnContextualMenuClick):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::sendContextMenuEvent):
+
 2010-11-23  Alexander Pavlov  <apavlov@chromium.org>
 
         Reviewed by Pavel Feldman.
index 842d3f2..a367c52 100644 (file)
@@ -57,6 +57,9 @@ public:
     // in place and moving the extent. Matches NSTextView.
     bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior; }
 
+    // On Mac, when processing a contextual click, the object being clicked upon should be selected.
+    bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
+
 private:
     EditingBehaviorType m_type;
 };
index f6a2353..e095136 100644 (file)
@@ -2007,11 +2007,8 @@ bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
     HitTestRequest request(HitTestRequest::Active);
     MouseEventWithHitTestResults mev = doc->prepareMouseEvent(request, viewportPos, event);
 
-    // Context menu events shouldn't select text in GTK+ applications or in Chromium.
-    // FIXME: This should probably be configurable by embedders. Consider making it a WebPreferences setting.
-    // See: https://bugs.webkit.org/show_bug.cgi?id=15279
-#if !PLATFORM(GTK) && !PLATFORM(CHROMIUM)
-    if (!m_frame->selection()->contains(viewportPos)
+    if (m_frame->editor()->behavior().shouldSelectOnContextualMenuClick()
+        && !m_frame->selection()->contains(viewportPos)
         // FIXME: In the editable case, word selection sometimes selects content that isn't underneath the mouse.
         // If the selection is non-editable, we do word selection to make it easier to use the contextual menu items
         // available for text selections.  But only if we're above text.
@@ -2019,7 +2016,6 @@ bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
         m_mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
         selectClosestWordOrLinkFromMouseEvent(mev);
     }
-#endif
 
     swallowEvent = dispatchMouseEvent(eventNames().contextmenuEvent, mev.targetNode(), true, 0, event, false);