Title: [209445] trunk
Revision
209445
Author
wenson_hs...@apple.com
Date
2016-12-06 20:36:55 -0800 (Tue, 06 Dec 2016)

Log Message

After preventing a beforeinput event, an input event is fired when formatting rich text
https://bugs.webkit.org/show_bug.cgi?id=165435
<rdar://problem/29522314>

Reviewed by Ryosuke Niwa.

Source/WebCore:

This regressed after I refactored some input event event dispatch logic when formatting text in r208461.
I moved the logic for dispatching input events when applying styles into Editor::applyStyle, but left out an
early return after firing the beforeinput event if the default behavior was prevented, which caused us to
continue on and dispatch an input event. The fix is to bail from applyStyle if default was prevented.

Augmented an existing layout test to cover this case.

* editing/Editor.cpp:
(WebCore::Editor::applyStyle):
(WebCore::Editor::applyParagraphStyle):

LayoutTests:

Augmented a layout test to verify that when preventing beforeinput events, a corresponding input event is not
fired in addition to the style not being applied to the text.

* fast/events/before-input-prevent-biu.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209444 => 209445)


--- trunk/LayoutTests/ChangeLog	2016-12-07 04:26:50 UTC (rev 209444)
+++ trunk/LayoutTests/ChangeLog	2016-12-07 04:36:55 UTC (rev 209445)
@@ -1,3 +1,16 @@
+2016-12-06  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        After preventing a beforeinput event, an input event is fired when formatting rich text
+        https://bugs.webkit.org/show_bug.cgi?id=165435
+        <rdar://problem/29522314>
+
+        Reviewed by Ryosuke Niwa.
+
+        Augmented a layout test to verify that when preventing beforeinput events, a corresponding input event is not
+        fired in addition to the style not being applied to the text.
+
+        * fast/events/before-input-prevent-biu.html:
+
 2016-12-06  Simon Fraser  <simon.fra...@apple.com>
 
         Fix behavior of background-attachment:fixed with visual viewports

Modified: trunk/LayoutTests/fast/events/before-input-prevent-biu.html (209444 => 209445)


--- trunk/LayoutTests/fast/events/before-input-prevent-biu.html	2016-12-07 04:26:50 UTC (rev 209444)
+++ trunk/LayoutTests/fast/events/before-input-prevent-biu.html	2016-12-07 04:36:55 UTC (rev 209445)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <body>
-    <div id="editable" contenteditable _onbeforeinput_=handleBeforeInput(event)></div>
+    <div id="editable" contenteditable _onbeforeinput_=handleBeforeInput(event) _oninput_=handleInput(event)></div>
     <script src=""
     <script type="text/_javascript_">
         Markup.description(`To manually test this, turn on bold, italic and underline via the context menu, and then type some text into the contenteditable. The text should be italicized and underlined, but not bold.`);
@@ -33,6 +33,12 @@
             if (event.inputType === "formatBold")
                 event.preventDefault();
         }
+
+        function handleInput(event)
+        {
+            if (event.inputType === "formatBold")
+                Markup.dump("editable", "FAILED: received input event");
+        }
     </script>
 </body>
 

Modified: trunk/Source/WebCore/ChangeLog (209444 => 209445)


--- trunk/Source/WebCore/ChangeLog	2016-12-07 04:26:50 UTC (rev 209444)
+++ trunk/Source/WebCore/ChangeLog	2016-12-07 04:36:55 UTC (rev 209445)
@@ -1,3 +1,22 @@
+2016-12-06  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        After preventing a beforeinput event, an input event is fired when formatting rich text
+        https://bugs.webkit.org/show_bug.cgi?id=165435
+        <rdar://problem/29522314>
+
+        Reviewed by Ryosuke Niwa.
+
+        This regressed after I refactored some input event event dispatch logic when formatting text in r208461.
+        I moved the logic for dispatching input events when applying styles into Editor::applyStyle, but left out an
+        early return after firing the beforeinput event if the default behavior was prevented, which caused us to
+        continue on and dispatch an input event. The fix is to bail from applyStyle if default was prevented.
+
+        Augmented an existing layout test to cover this case.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyStyle):
+        (WebCore::Editor::applyParagraphStyle):
+
 2016-12-06  Antoine Quint  <grao...@apple.com>
 
         [Modern Media Controls] Instantiate iOS media controls

Modified: trunk/Source/WebCore/editing/Editor.cpp (209444 => 209445)


--- trunk/Source/WebCore/editing/Editor.cpp	2016-12-07 04:26:50 UTC (rev 209444)
+++ trunk/Source/WebCore/editing/Editor.cpp	2016-12-07 04:36:55 UTC (rev 209445)
@@ -792,17 +792,18 @@
     String inputTypeName = inputTypeNameForEditingAction(editingAction);
     String inputEventData = inputEventDataForEditingStyleAndAction(*style, editingAction);
     RefPtr<Element> element = m_frame.selection().selection().rootEditableElement();
-    if (!element || dispatchBeforeInputEvent(*element, inputTypeName, inputEventData)) {
-        switch(selectionType) {
-        case VisibleSelection::CaretSelection:
-            computeAndSetTypingStyle(*style, editingAction);
-            break;
-        case VisibleSelection::RangeSelection:
-            applyCommand(ApplyStyleCommand::create(document(), style.get(), editingAction));
-            break;
-        default:
-            break;
-        }
+    if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData))
+        return;
+
+    switch (selectionType) {
+    case VisibleSelection::CaretSelection:
+        computeAndSetTypingStyle(*style, editingAction);
+        break;
+    case VisibleSelection::RangeSelection:
+        applyCommand(ApplyStyleCommand::create(document(), style.get(), editingAction));
+        break;
+    default:
+        break;
     }
 
     client()->didApplyStyle();
@@ -826,9 +827,10 @@
 
     String inputTypeName = inputTypeNameForEditingAction(editingAction);
     RefPtr<Element> element = m_frame.selection().selection().rootEditableElement();
-    if (!element || dispatchBeforeInputEvent(*element, inputTypeName))
-        applyCommand(ApplyStyleCommand::create(document(), EditingStyle::create(style).ptr(), editingAction, ApplyStyleCommand::ForceBlockProperties));
+    if (element && !dispatchBeforeInputEvent(*element, inputTypeName))
+        return;
 
+    applyCommand(ApplyStyleCommand::create(document(), EditingStyle::create(style).ptr(), editingAction, ApplyStyleCommand::ForceBlockProperties));
     client()->didApplyStyle();
     if (element)
         dispatchInputEvent(*element, inputTypeName);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to