Diff
Modified: trunk/LayoutTests/ChangeLog (208460 => 208461)
--- trunk/LayoutTests/ChangeLog 2016-11-09 19:56:17 UTC (rev 208460)
+++ trunk/LayoutTests/ChangeLog 2016-11-09 20:04:51 UTC (rev 208461)
@@ -1,3 +1,18 @@
+2016-11-09 Wenson Hsieh <[email protected]>
+
+ Setting foreground color when text is selected should fire an input event with color data
+ https://bugs.webkit.org/show_bug.cgi?id=164241
+ <rdar://problem/29032759>
+
+ Reviewed by Darin Adler.
+
+ Adds a new layout test verifying that selecting text and setting its foreground color will fire input events
+ with the correct RGB values in the data attribute.
+
+ * fast/events/input-events-selection-forecolor-data-expected.txt: Added.
+ * fast/events/input-events-selection-forecolor-data.html: Added.
+ * platform/ios-simulator/TestExpectations:
+
2016-11-08 Dean Jackson <[email protected]>
Rendering support for ExtendedColors
Added: trunk/LayoutTests/fast/events/input-events-selection-forecolor-data-expected.txt (0 => 208461)
--- trunk/LayoutTests/fast/events/input-events-selection-forecolor-data-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/input-events-selection-forecolor-data-expected.txt 2016-11-09 20:04:51 UTC (rev 208461)
@@ -0,0 +1,14 @@
+To manually test this, select the text and change the foreground color.
+
+The resulting debug message should show the input color.
+
+This is some text
+Received beforeinput event with data: "rgb(255, 255, 255)"
+Received input event with data: "rgb(255, 255, 255)"
+Received beforeinput event with data: "rgb(100, 255, 0)"
+Received input event with data: "rgb(100, 255, 0)"
+Received beforeinput event with data: "rgb(0, 0, 0)"
+Received input event with data: "rgb(0, 0, 0)"
+Received beforeinput event with data: "rgb(255, 0, 0)"
+Received input event with data: "rgb(255, 0, 0)"
+
Added: trunk/LayoutTests/fast/events/input-events-selection-forecolor-data.html (0 => 208461)
--- trunk/LayoutTests/fast/events/input-events-selection-forecolor-data.html (rev 0)
+++ trunk/LayoutTests/fast/events/input-events-selection-forecolor-data.html 2016-11-09 20:04:51 UTC (rev 208461)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+ <p>To manually test this, select the text and change the foreground color.</p>
+ <p>The resulting debug message should show the input color.</p>
+ <div id="editable" contenteditable _onbeforeinput_=handleInput(event) _oninput_=handleInput(event)>This is some text</div>
+ <div id="output"></div>
+ <script type="text/_javascript_">
+ let write = s => output.innerHTML += s + "<br>";
+ if (window.internals) {
+ testRunner.dumpAsText();
+ internals.settings.setInputEventsEnabled(true);
+ }
+
+ document.getElementById("editable").focus();
+
+ if (window.testRunner) {
+ document.execCommand("SelectAll");
+ setForeColor("rgb(255, 255, 255)");
+ setForeColor("rgb(100, 255, 0)");
+ setForeColor("rgb(0, 0, 0)");
+ setForeColor("rgb(255, 0, 0)");
+ }
+
+ function setForeColor(color) {
+ // FIXME: Color is passed twice here for compatibility with both DumpRenderTree and WebKitTestRunner.
+ testRunner.execCommand("ForeColor", color, color);
+ }
+
+ function handleInput(event)
+ {
+ if (event.inputType === "formatForeColor")
+ write(`Received ${event.type} event with data: "${event.data}"`);
+ }
+ </script>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (208460 => 208461)
--- trunk/LayoutTests/platform/ios-simulator/TestExpectations 2016-11-09 19:56:17 UTC (rev 208460)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations 2016-11-09 20:04:51 UTC (rev 208461)
@@ -1212,6 +1212,7 @@
fast/events/input-events-ime-composition.html [ Failure ]
fast/events/input-events-paste-rich-datatransfer.html [ Failure ]
fast/events/input-events-spell-checking-datatransfer.html [ Failure ]
+fast/events/input-events-selection-forecolor-data.html [ Failure ]
fast/events/before-input-events-prevent-default.html [ Failure ]
fast/events/before-input-events-prevent-default-in-textfield.html [ Failure ]
fast/events/before-input-events-different-start-end-elements.html [ Failure ]
Modified: trunk/Source/WebCore/ChangeLog (208460 => 208461)
--- trunk/Source/WebCore/ChangeLog 2016-11-09 19:56:17 UTC (rev 208460)
+++ trunk/Source/WebCore/ChangeLog 2016-11-09 20:04:51 UTC (rev 208461)
@@ -1,3 +1,25 @@
+2016-11-09 Wenson Hsieh <[email protected]>
+
+ Setting foreground color when text is selected should fire an input event with color data
+ https://bugs.webkit.org/show_bug.cgi?id=164241
+ <rdar://problem/29032759>
+
+ Reviewed by Darin Adler.
+
+ Refactors Editor::applyStyle and Editor::applyParagraphStyle to handle beforeinput and input event dispatch.
+ Instead of going through the ApplyStyleCommand to dispatch input events, override shouldDispatchInputEvents to
+ return false. This strategy also has the effect of unifying the way input events are dispatched in applyStyle,
+ in both codepaths where we computeAndSetTypingStyle and where we create and then apply a style command.
+
+ Test: fast/events/input-events-selection-forecolor-data.html
+
+ * editing/ApplyStyleCommand.h:
+ * editing/Editor.cpp:
+ (WebCore::inputEventDataForEditingStyleAndAction):
+ (WebCore::Editor::applyStyle):
+ (WebCore::Editor::applyParagraphStyle):
+ (WebCore::Editor::computeAndSetTypingStyle):
+
2016-11-08 Dean Jackson <[email protected]>
Rendering support for ExtendedColors
Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.h (208460 => 208461)
--- trunk/Source/WebCore/editing/ApplyStyleCommand.h 2016-11-09 19:56:17 UTC (rev 208460)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.h 2016-11-09 20:04:51 UTC (rev 208461)
@@ -72,6 +72,7 @@
ApplyStyleCommand(Document&, const EditingStyle*, bool (*isInlineElementToRemove)(const Element*), EditAction);
void doApply() override;
+ bool shouldDispatchInputEvents() const final { return false; }
// style-removal helpers
bool isStyledInlineElementToRemove(Element*) const;
Modified: trunk/Source/WebCore/editing/Editor.cpp (208460 => 208461)
--- trunk/Source/WebCore/editing/Editor.cpp 2016-11-09 19:56:17 UTC (rev 208460)
+++ trunk/Source/WebCore/editing/Editor.cpp 2016-11-09 20:04:51 UTC (rev 208461)
@@ -122,20 +122,24 @@
element.dispatchInputEvent();
}
-static String inputEventDataForEditingStyleAndAction(EditingStyle& style, EditAction action)
+static String inputEventDataForEditingStyleAndAction(const StyleProperties* style, EditAction action)
{
- auto* properties = style.style();
- if (!properties)
+ if (!style)
return { };
switch (action) {
case EditActionSetColor:
- return properties->getPropertyValue(CSSPropertyColor);
+ return style->getPropertyValue(CSSPropertyColor);
default:
return { };
}
}
+static String inputEventDataForEditingStyleAndAction(EditingStyle& style, EditAction action)
+{
+ return inputEventDataForEditingStyleAndAction(style.style(), action);
+}
+
class ClearTextCommand : public DeleteSelectionCommand {
public:
ClearTextCommand(Document& document);
@@ -772,34 +776,38 @@
void Editor::applyStyle(StyleProperties* style, EditAction editingAction)
{
- switch (m_frame.selection().selection().selectionType()) {
- case VisibleSelection::NoSelection:
- return;
- case VisibleSelection::CaretSelection:
- computeAndSetTypingStyle(EditingStyle::create(style), editingAction);
- break;
- case VisibleSelection::RangeSelection:
- if (style)
- applyCommand(ApplyStyleCommand::create(document(), EditingStyle::create(style).ptr(), editingAction));
- break;
- }
- client()->didApplyStyle();
+ if (style)
+ applyStyle(EditingStyle::create(style), editingAction);
}
void Editor::applyStyle(RefPtr<EditingStyle>&& style, EditAction editingAction)
{
- switch (m_frame.selection().selection().selectionType()) {
- case VisibleSelection::NoSelection:
+ if (!style)
return;
- case VisibleSelection::CaretSelection:
- computeAndSetTypingStyle(*style, editingAction);
- break;
- case VisibleSelection::RangeSelection:
- if (style)
+
+ auto selectionType = m_frame.selection().selection().selectionType();
+ if (selectionType == VisibleSelection::NoSelection)
+ return;
+
+ 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;
+ break;
+ default:
+ break;
+ }
}
+
client()->didApplyStyle();
+ if (element)
+ dispatchInputEvent(*element, inputTypeName, inputEventData);
}
bool Editor::shouldApplyStyle(StyleProperties* style, Range* range)
@@ -809,16 +817,21 @@
void Editor::applyParagraphStyle(StyleProperties* style, EditAction editingAction)
{
- switch (m_frame.selection().selection().selectionType()) {
- case VisibleSelection::NoSelection:
+ if (!style)
return;
- case VisibleSelection::CaretSelection:
- case VisibleSelection::RangeSelection:
- if (style)
- applyCommand(ApplyStyleCommand::create(document(), EditingStyle::create(style).ptr(), editingAction, ApplyStyleCommand::ForceBlockProperties));
- break;
- }
+
+ auto selectionType = m_frame.selection().selection().selectionType();
+ if (selectionType == VisibleSelection::NoSelection)
+ return;
+
+ 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));
+
client()->didApplyStyle();
+ if (element)
+ dispatchInputEvent(*element, inputTypeName);
}
void Editor::applyStyleToSelection(StyleProperties* style, EditAction editingAction)
@@ -2985,12 +2998,6 @@
return;
}
- String inputTypeName = inputTypeNameForEditingAction(editingAction);
- String inputEventData = inputEventDataForEditingStyleAndAction(style, editingAction);
- auto* element = m_frame.selection().selection().rootEditableElement();
- if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData))
- return;
-
// Calculate the current typing style.
RefPtr<EditingStyle> typingStyle;
if (auto existingTypingStyle = m_frame.selection().typingStyle())
@@ -3004,9 +3011,6 @@
if (!blockStyle->isEmpty())
applyCommand(ApplyStyleCommand::create(document(), blockStyle.get(), editingAction));
- if (element)
- dispatchInputEvent(*element, inputTypeName, inputEventData);
-
// Set the remaining style as the typing style.
m_frame.selection().setTypingStyle(typingStyle);
}