Using the touchbar, both align left and align justify send a beforeinput event with...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Aug 2017 19:04:23 +0000 (19:04 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Aug 2017 19:04:23 +0000 (19:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168669
<rdar://problem/30639155>

Reviewed by Beth Dakin.

Source/WebCore:

Small tweak to add a "formatJustifyFull" inputType when justifying text using the touch bar's rich text
formatting controls. Currently, the EditActionJustify edit command incorrectly maps to "formatJustifyLeft".

Test: fast/events/input-events-text-alignment.html

* editing/EditCommand.cpp:
(WebCore::inputTypeNameForEditingAction):

LayoutTests:

Adds a new LayoutTest checking that the text alignment editor commands, "Align{Right|Center|Left|Justify}",
correctly propagate input events and beforeinput events of inputType "formatJustify{Right|Center|Left|Justify}",
and that these text alignment style changes can be prevented by calling preventDefault() on the dispatched
beforeinput event.

* fast/events/input-events-text-alignment-expected.txt: Added.
* fast/events/input-events-text-alignment.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/input-events-text-alignment-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/input-events-text-alignment.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/EditCommand.cpp

index 17fd2506d8fe394ea21ad8d1b7ac6ccd02f01d3c..0508f5566bc715dd59481d0a6ddfb8bb0e7c83a6 100644 (file)
@@ -1,3 +1,19 @@
+2017-08-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Using the touchbar, both align left and align justify send a beforeinput event with the 'formatJustifyLeft' inputType.
+        https://bugs.webkit.org/show_bug.cgi?id=168669
+        <rdar://problem/30639155>
+
+        Reviewed by Beth Dakin.
+
+        Adds a new LayoutTest checking that the text alignment editor commands, "Align{Right|Center|Left|Justify}",
+        correctly propagate input events and beforeinput events of inputType "formatJustify{Right|Center|Left|Justify}",
+        and that these text alignment style changes can be prevented by calling preventDefault() on the dispatched
+        beforeinput event.
+
+        * fast/events/input-events-text-alignment-expected.txt: Added.
+        * fast/events/input-events-text-alignment.html: Added.
+
 2017-08-25  Brady Eidson  <beidson@apple.com>
 
         Introduce ServerWorkerRegistration task queues.
diff --git a/LayoutTests/fast/events/input-events-text-alignment-expected.txt b/LayoutTests/fast/events/input-events-text-alignment-expected.txt
new file mode 100644 (file)
index 0000000..3c88552
--- /dev/null
@@ -0,0 +1,33 @@
+To manually test this, change the text alignment and check the resulting debug messages.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+beforeinput (inputType = formatJustifyCenter)
+input (inputType = formatJustifyCenter)
+getComputedStyle(text).textAlign = 'center'
+beforeinput (inputType = formatJustifyRight)
+input (inputType = formatJustifyRight)
+getComputedStyle(text).textAlign = 'right'
+beforeinput (inputType = formatJustifyLeft)
+input (inputType = formatJustifyLeft)
+getComputedStyle(text).textAlign = 'left'
+beforeinput (inputType = formatJustifyFull)
+input (inputType = formatJustifyFull)
+getComputedStyle(text).textAlign = 'justify'
+beforeinput (inputType = formatJustifyCenter)
+Prevented default
+getComputedStyle(text).textAlign = 'justify'
+beforeinput (inputType = formatJustifyRight)
+Prevented default
+getComputedStyle(text).textAlign = 'justify'
+beforeinput (inputType = formatJustifyLeft)
+Prevented default
+getComputedStyle(text).textAlign = 'justify'
+beforeinput (inputType = formatJustifyFull)
+Prevented default
+getComputedStyle(text).textAlign = 'justify'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+WebKit
diff --git a/LayoutTests/fast/events/input-events-text-alignment.html b/LayoutTests/fast/events/input-events-text-alignment.html
new file mode 100644 (file)
index 0000000..738c827
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <div id="editable" contenteditable onbeforeinput=handleInput(event) oninput=handleInput(event)><div id="text">WebKit</div></div>
+    <script type="text/javascript">
+        description("To manually test this, change the text alignment and check the resulting debug messages.");
+
+        let range = document.createRange();
+        range.setStartBefore(text);
+        range.setEndAfter(text);
+        getSelection().addRange(range);
+
+        if (window.testRunner) {
+            preventDefaultForBeforeInputEvents = false;
+
+            execCommandAndLogComputedTextAlignmentStyle("AlignCenter");
+            execCommandAndLogComputedTextAlignmentStyle("AlignRight");
+            execCommandAndLogComputedTextAlignmentStyle("AlignLeft");
+            execCommandAndLogComputedTextAlignmentStyle("AlignJustified");
+
+            preventDefaultForBeforeInputEvents = true;
+
+            execCommandAndLogComputedTextAlignmentStyle("AlignCenter");
+            execCommandAndLogComputedTextAlignmentStyle("AlignRight");
+            execCommandAndLogComputedTextAlignmentStyle("AlignLeft");
+            execCommandAndLogComputedTextAlignmentStyle("AlignJustified");
+        }
+
+        function handleInput(event)
+        {
+            debug(`${event.type} (inputType = ${event.inputType})`);
+            if (window.preventDefaultForBeforeInputEvents && event.type === "beforeinput") {
+                event.preventDefault();
+                debug("Prevented default");
+            }
+        }
+
+        function execCommandAndLogComputedTextAlignmentStyle(command) {
+            testRunner.execCommand(command);
+            debug(`getComputedStyle(text).textAlign = '${getComputedStyle(text).textAlign}'`);
+        }
+    </script>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 9212c49dda17456515f69abad38fe8f125d345d1..ad0252269786b40a69483abf433352a8bb336925 100644 (file)
@@ -1,3 +1,19 @@
+2017-08-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Using the touchbar, both align left and align justify send a beforeinput event with the 'formatJustifyLeft' inputType.
+        https://bugs.webkit.org/show_bug.cgi?id=168669
+        <rdar://problem/30639155>
+
+        Reviewed by Beth Dakin.
+
+        Small tweak to add a "formatJustifyFull" inputType when justifying text using the touch bar's rich text
+        formatting controls. Currently, the EditActionJustify edit command incorrectly maps to "formatJustifyLeft".
+
+        Test: fast/events/input-events-text-alignment.html
+
+        * editing/EditCommand.cpp:
+        (WebCore::inputTypeNameForEditingAction):
+
 2017-08-25  Brady Eidson  <beidson@apple.com>
 
         Introduce ServerWorkerRegistration task queues.
index 8cc10c7cb3ad41fe85c6d2a7bbe9ca87984d46c3..2ce08c7f0c7285411ca515c2304468e0e9ce27e6 100644 (file)
@@ -43,6 +43,7 @@ String inputTypeNameForEditingAction(EditAction action)
 {
     switch (action) {
     case EditActionJustify:
+        return ASCIILiteral("formatJustifyFull");
     case EditActionAlignLeft:
         return ASCIILiteral("formatJustifyLeft");
     case EditActionAlignRight: