[macOS] Font formatting options don't work when composing a message in Yahoo mail
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 May 2019 16:52:05 +0000 (16:52 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 May 2019 16:52:05 +0000 (16:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197813
<rdar://problem/49382250>

Reviewed by Darin Adler.

Source/WebCore:

The bug happens because on mousedown, the "Aa Font" menu item's event handler hides itself before changing the
font at the text selection. This causes us to clear the selection in FocusController::setFocusedElement.

There is existing logic in clearSelectionIfNeeded that would normally prevent us from clearing the selection due
to the mousePressNode not being able to start a selection. However, since the clickable element in this case is
hidden during mousedown, it is missing a renderer, and we bail from the `mousePressNode->renderer() &&
!mousePressNode->canStartSelection()` check as a result.

This check was orginally added in https://trac.webkit.org/r24334 to avoid clearing the selection when clicking
a button; the intention appears to have been making it so that clicking on something that could not start a
selection (back then, synonymous with -webkit-user-select: ignore;) would not clear the current selection; to
this end, it seems odd to additionally require that the thing being clicked should still have a renderer, so
it seems safe to remove this requirement.

Test: editing/selection/preserve-selection-when-clicking-button.html

* page/FocusController.cpp:
(WebCore::clearSelectionIfNeeded):

LayoutTests:

Add a new layout test to verify that DOM selection is preserved after clicking a button that hides itself
upon mousedown.

* editing/selection/preserve-selection-when-clicking-button-expected.txt: Added.
* editing/selection/preserve-selection-when-clicking-button.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/preserve-selection-when-clicking-button-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/preserve-selection-when-clicking-button.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/FocusController.cpp

index eb098ea..36e3b4c 100644 (file)
@@ -1,3 +1,17 @@
+2019-05-13  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [macOS] Font formatting options don't work when composing a message in Yahoo mail
+        https://bugs.webkit.org/show_bug.cgi?id=197813
+        <rdar://problem/49382250>
+
+        Reviewed by Darin Adler.
+
+        Add a new layout test to verify that DOM selection is preserved after clicking a button that hides itself
+        upon mousedown.
+
+        * editing/selection/preserve-selection-when-clicking-button-expected.txt: Added.
+        * editing/selection/preserve-selection-when-clicking-button.html: Added.
+
 2019-05-13  Sihui Liu  <sihui_liu@apple.com>
 
         [ Mojave Debug ] REGRESSION (r242975) Layout Test imported/w3c/IndexedDB-private-browsing/idbobjectstore_createIndex7-event_order.html is a flaky failure
diff --git a/LayoutTests/editing/selection/preserve-selection-when-clicking-button-expected.txt b/LayoutTests/editing/selection/preserve-selection-when-clicking-button-expected.txt
new file mode 100644 (file)
index 0000000..14de6e5
--- /dev/null
@@ -0,0 +1,3 @@
+Hello world
+The selected text after clicking is: "Hello world"
+This test verifies that clicking a button which hides itself on mousedown does not clear the selection. To test manually, select "Hello world" above and click the button. The pre element above should indicate that "Hello world" was selected after clicking.
diff --git a/LayoutTests/editing/selection/preserve-selection-when-clicking-button.html b/LayoutTests/editing/selection/preserve-selection-when-clicking-button.html
new file mode 100644 (file)
index 0000000..8305b72
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <script src="../../resources/ui-helper.js"></script>
+</head>
+<body>
+    <div class="editor" contenteditable>Hello world</div>
+    <pre>The selected text after clicking is: "<span class="output"></span>"</pre>
+    <div>
+        <button>Click here</button>
+    </div>
+    <p>This test verifies that clicking a button which hides itself on mousedown does not clear the selection. To test manually, select "Hello world" above and click the button. The <code>pre</code> element above should indicate that "Hello world" was selected after clicking.</p>
+    <script>
+    if (window.testRunner) {
+        testRunner.waitUntilDone();
+        testRunner.dumpAsText();
+    }
+
+    const editor = document.querySelector(".editor");
+    const button = document.querySelector("button");
+    const output = document.querySelector(".output");
+
+    function checkDone() {
+        doneCount = window.doneCount ? doneCount : 0;
+        if (++doneCount == 2 && window.testRunner)
+            testRunner.notifyDone();
+    }
+
+    getSelection().selectAllChildren(editor);
+    button.addEventListener("mousedown", () => {
+        button.style.display = "none";
+        setTimeout(() => {
+            output.textContent = getSelection().toString();
+            checkDone();
+        });
+    });
+
+    addEventListener("load", () => {
+        if (window.testRunner)
+            UIHelper.activateElement(button).then(checkDone);
+    });
+    </script>
+</body>
+</html>
index c48fd75..e78779e 100644 (file)
@@ -1,3 +1,30 @@
+2019-05-13  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [macOS] Font formatting options don't work when composing a message in Yahoo mail
+        https://bugs.webkit.org/show_bug.cgi?id=197813
+        <rdar://problem/49382250>
+
+        Reviewed by Darin Adler.
+
+        The bug happens because on mousedown, the "Aa Font" menu item's event handler hides itself before changing the
+        font at the text selection. This causes us to clear the selection in FocusController::setFocusedElement.
+
+        There is existing logic in clearSelectionIfNeeded that would normally prevent us from clearing the selection due
+        to the mousePressNode not being able to start a selection. However, since the clickable element in this case is
+        hidden during mousedown, it is missing a renderer, and we bail from the `mousePressNode->renderer() &&
+        !mousePressNode->canStartSelection()` check as a result.
+
+        This check was orginally added in https://trac.webkit.org/r24334 to avoid clearing the selection when clicking
+        a button; the intention appears to have been making it so that clicking on something that could not start a
+        selection (back then, synonymous with -webkit-user-select: ignore;) would not clear the current selection; to
+        this end, it seems odd to additionally require that the thing being clicked should still have a renderer, so
+        it seems safe to remove this requirement.
+
+        Test: editing/selection/preserve-selection-when-clicking-button.html
+
+        * page/FocusController.cpp:
+        (WebCore::clearSelectionIfNeeded):
+
 2019-05-13  Eric Carlson  <eric.carlson@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=197793
index 75276b2..d29c78f 100644 (file)
@@ -774,7 +774,7 @@ static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFram
     }
 
     if (Node* mousePressNode = newFocusedFrame->eventHandler().mousePressNode()) {
-        if (mousePressNode->renderer() && !mousePressNode->canStartSelection()) {
+        if (!mousePressNode->canStartSelection()) {
             // Don't clear the selection for contentEditable elements, but do clear it for input and textarea. See bug 38696.
             auto* root = selection.rootEditableElement();
             if (!root)