An element with -webkit-user-select: all should be selected on single click
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Jun 2013 00:09:09 +0000 (00:09 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Jun 2013 00:09:09 +0000 (00:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=117864

Reviewed by Darin Adler.

Source/WebCore:

Set m_mouseDownMayStartSelect true even when the node cannot start selection
if the node was inside an element with -webkit-user-select: all.

Test: editing/selection/user-select-all-with-single-click.html

* page/EventHandler.cpp:
(WebCore::canMouseDownStartSelect):

LayoutTests:

Add tests for single clicking on an element with user-select: all.
We select the entire element regardless of whether the user had clicked on text or an image
to be consistent even though Firefox requires a double click on the latter case.

* editing/selection/user-select-all-with-image-single-click-expected.txt: Added.
* editing/selection/user-select-all-with-image-single-click.html: Added.
* editing/selection/user-select-all-with-single-click-expected.txt: Added.
* editing/selection/user-select-all-with-single-click.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/user-select-all-image-with-single-click-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/user-select-all-image-with-single-click.html [new file with mode: 0644]
LayoutTests/editing/selection/user-select-all-with-single-click-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/user-select-all-with-single-click.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Position.h
Source/WebCore/page/EventHandler.cpp

index 58431bea919126638a8cad0746585ae6c7c43c98..7ec1fc96fec90f39c20c8242c8b1f7520845226b 100644 (file)
@@ -1,3 +1,19 @@
+2013-06-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        An element with -webkit-user-select: all should be selected on single click
+        https://bugs.webkit.org/show_bug.cgi?id=117864
+
+        Reviewed by Darin Adler.
+
+        Add tests for single clicking on an element with user-select: all.
+        We select the entire element regardless of whether the user had clicked on text or an image
+        to be consistent even though Firefox requires a double click on the latter case.
+
+        * editing/selection/user-select-all-with-image-single-click-expected.txt: Added.
+        * editing/selection/user-select-all-with-image-single-click.html: Added.
+        * editing/selection/user-select-all-with-single-click-expected.txt: Added.
+        * editing/selection/user-select-all-with-single-click.html: Added.
+
 2013-06-28  Ryosuke Niwa  <rniwa@webkit.org>
 
         -webkit-line-break: after-white-space sometimes truncates DOM on copy & paste
diff --git a/LayoutTests/editing/selection/user-select-all-image-with-single-click-expected.txt b/LayoutTests/editing/selection/user-select-all-image-with-single-click-expected.txt
new file mode 100644 (file)
index 0000000..d7c8c64
--- /dev/null
@@ -0,0 +1,9 @@
+This tests single-clicking on an image inside user-select: all. WebKit should select the entire element.
+Firefox doesn't do this but I'm not sure it makes sense for us to be inconsistent since Firefox DOES allow text with user-select: all to be selected by a single click.
+To manually test, single click on the image below. WebKit should select the entire bordered region.
+| <div>
+|   class="select-all"
+|   <#selection-anchor>
+|   <img>
+|     src="../resources/abe.png"
+|   <#selection-focus>
diff --git a/LayoutTests/editing/selection/user-select-all-image-with-single-click.html b/LayoutTests/editing/selection/user-select-all-image-with-single-click.html
new file mode 100644 (file)
index 0000000..070f40b
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<body onload="runTest()">
+<p id="description">This tests single-clicking on an image inside user-select: all. WebKit should select the entire element.
+Firefox doesn't do this but I'm not sure it makes sense for us to be inconsistent since Firefox DOES allow text with user-select: all to be selected by a single click.<br>
+To manually test, single click on the image below. WebKit should select the entire bordered region.</p>
+<div id="container"><div class="select-all"><img src="../resources/abe.png"></div></div>
+<script src="../../resources/dump-as-markup.js"></script>
+<style>
+.select-all {
+    border: 1px solid black;
+    height: 200px;
+    width: 200px;
+    -webkit-user-select: all;
+    -moz-user-select: all;
+}
+</style>
+<script>
+
+Markup.description(document.getElementById('description').textContent);
+Markup.waitUntilDone();
+
+function runTest() {
+    function clickOnElement(element) {
+        eventSender.mouseMoveTo(element.offsetLeft + 10, element.offsetTop + 10);
+        eventSender.mouseDown(0);
+        eventSender.mouseUp(0);
+    }
+
+    if (window.eventSender) {
+        clickOnElement(document.querySelector('.select-all'));
+        Markup.dump('container');
+        Markup.notifyDone();
+    }
+}
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/editing/selection/user-select-all-with-single-click-expected.txt b/LayoutTests/editing/selection/user-select-all-with-single-click-expected.txt
new file mode 100644 (file)
index 0000000..7041a39
--- /dev/null
@@ -0,0 +1,5 @@
+This tests single-clicking on text inside user-select: all. WebKit should select the entire element.
+To manually test, single click on "click here" below. WebKit should select the entire bordered region.
+| <div>
+|   class="select-all"
+|   "<#selection-anchor>Click here<#selection-focus>"
diff --git a/LayoutTests/editing/selection/user-select-all-with-single-click.html b/LayoutTests/editing/selection/user-select-all-with-single-click.html
new file mode 100644 (file)
index 0000000..e0ae70b
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p id="description">This tests single-clicking on text inside user-select: all. WebKit should select the entire element.
+To manually test, single click on "click here" below. WebKit should select the entire bordered region.</p>
+<div id="container"><div class="select-all">Click here</div></div>
+<script src="../../resources/dump-as-markup.js"></script>
+<style>
+.select-all {
+    border: 1px solid black;
+    height: 100px;
+    width: 100px;
+    -webkit-user-select: all;
+    -moz-user-select: all;
+}
+</style>
+<script>
+
+Markup.description(document.getElementById('description').textContent);
+
+function clickOnElement(element) {
+    eventSender.mouseMoveTo(element.offsetLeft + 10, element.offsetTop + 10);
+    eventSender.mouseDown(0);
+    eventSender.mouseUp(0);
+}
+
+if (window.eventSender) {
+    clickOnElement(document.querySelector('.select-all'));
+    Markup.dump('container');
+} else
+    Markup.noAutoDump();
+
+</script>
+</body>
+</html>
index a8666fb56d0d230219028e133101089d023d889b..92257fd19844e69b1ebff13b60d1f2c78c73f776 100644 (file)
@@ -1,3 +1,18 @@
+2013-06-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        An element with -webkit-user-select: all should be selected on single click
+        https://bugs.webkit.org/show_bug.cgi?id=117864
+
+        Reviewed by Darin Adler.
+
+        Set m_mouseDownMayStartSelect true even when the node cannot start selection
+        if the node was inside an element with -webkit-user-select: all.
+
+        Test: editing/selection/user-select-all-with-single-click.html
+
+        * page/EventHandler.cpp:
+        (WebCore::canMouseDownStartSelect):
+
 2013-06-28  Ryosuke Niwa  <rniwa@webkit.org>
 
         Remove unused attachChildrenLazily method and make attach/detachChildren private
index d8ecd985699a952c59a61ee08ba629597fa2e3da..3d9e76cc38b8d36603ed0ec2f1638eb5ef25cfbb 100644 (file)
@@ -191,6 +191,9 @@ public:
 #if ENABLE(USERSELECT_ALL)
     static bool nodeIsUserSelectAll(const Node*);
     static Node* rootUserSelectAllForNode(Node*);
+#else
+    static bool nodeIsUserSelectAll(const Node*) { return false; }
+    static Node* rootUserSelectAllForNode(Node*) { return 0; }
 #endif
     static ContainerNode* findParent(const Node*);
     
index 9c6067aa4e17580f4341b1bf7b1f5e92a4b0fc8b..2ffdb1b0e23f4a2f3fa6fe1b453df5f8742f67d3 100644 (file)
@@ -640,10 +640,7 @@ static inline bool canMouseDownStartSelect(Node* node)
     if (!node || !node->renderer())
         return true;
 
-    if (!node->canStartSelection())
-        return false;
-
-    return true;
+    return node->canStartSelection() || Position::nodeIsUserSelectAll(node);
 }
 
 bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& event)