Bug 164241

Summary: Setting foreground color when text is selected should fire an input event with color data
Product: WebKit Reporter: Wenson Hsieh <wenson_hsieh>
Component: UI EventsAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, enrica, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 163112    
Attachments:
Description Flags
Patch
none
Rebased on ToT
none
Patch
darin: review+
Patch for landing none

Wenson Hsieh
Reported 2016-10-31 14:57:17 PDT
1. Go to whsieh.github.io/examples/input-events 2. Type some text and select it 3. Set foreground color - The data attribute of the input event should not be null, but it is!
Attachments
Patch (7.45 KB, patch)
2016-10-31 15:02 PDT, Wenson Hsieh
no flags
Rebased on ToT (7.23 KB, patch)
2016-10-31 16:08 PDT, Wenson Hsieh
no flags
Patch (12.12 KB, patch)
2016-10-31 18:32 PDT, Wenson Hsieh
darin: review+
Patch for landing (12.27 KB, patch)
2016-11-09 11:09 PST, Wenson Hsieh
no flags
Wenson Hsieh
Comment 1 2016-10-31 14:58:23 PDT
Wenson Hsieh
Comment 2 2016-10-31 15:02:38 PDT
Wenson Hsieh
Comment 3 2016-10-31 16:08:48 PDT
Created attachment 293485 [details] Rebased on ToT
Ryosuke Niwa
Comment 4 2016-10-31 16:59:50 PDT
Comment on attachment 293485 [details] Rebased on ToT View in context: https://bugs.webkit.org/attachment.cgi?id=293485&action=review > Source/WebCore/editing/ApplyStyleCommand.cpp:234 > +String ApplyStyleCommand::inputEventData() const > +{ > + if (editingAction() != EditActionSetColor) > + return CompositeEditCommand::inputEventData(); > + > + auto* styleProperties = m_style->style(); > + if (!styleProperties) > + return { }; > + > + return styleProperties->getPropertyValue(CSSPropertyColor); > +} This really needs to be done at the call site of ApplyStyleCommand. See how toggleStyle, etc... works in EditorCommands.cpp We need to set the input event's data there instead of trying to figure it out down in ApplyStyleCommand.
Wenson Hsieh
Comment 5 2016-10-31 18:32:14 PDT
Darin Adler
Comment 6 2016-11-05 22:58:13 PDT
Comment on attachment 293508 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=293508&action=review > Source/WebCore/editing/Editor.cpp:794 > + auto* element = m_frame.selection().selection().rootEditableElement(); I think that likely this needs to be a RefPtr because this pointer is used after calling applyCommand, which I assume can run arbitrary JavaScript. > Source/WebCore/editing/Editor.cpp:800 > + if (selectionType == VisibleSelection::CaretSelection) > + computeAndSetTypingStyle(*style, editingAction); > + > + if (selectionType == VisibleSelection::RangeSelection) > applyCommand(ApplyStyleCommand::create(document(), style.get(), editingAction)); I think a switch statement would be better than two if statements. > Source/WebCore/editing/Editor.cpp:803 > + dispatchInputEvent(*element, inputTypeName, inputEventData); Are we sure it’s OK to dispatch this event before calling didApplyStyle, given the event could do additional editing before returning? I think that generally events need to be dispatched after all other code runs and before returning to JavaScript. We may want to come up with a system similar to the one used for custom elements, or share its system. Not just for this event, but many others. > Source/WebCore/editing/Editor.cpp:824 > + auto* element = m_frame.selection().selection().rootEditableElement(); Ditto. > Source/WebCore/editing/Editor.cpp:828 > + dispatchInputEvent(*element, inputTypeName); Ditto.
Wenson Hsieh
Comment 7 2016-11-07 08:24:52 PST
Comment on attachment 293508 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=293508&action=review >> Source/WebCore/editing/Editor.cpp:794 >> + auto* element = m_frame.selection().selection().rootEditableElement(); > > I think that likely this needs to be a RefPtr because this pointer is used after calling applyCommand, which I assume can run arbitrary JavaScript. Good catch -- fixed. >> Source/WebCore/editing/Editor.cpp:800 >> applyCommand(ApplyStyleCommand::create(document(), style.get(), editingAction)); > > I think a switch statement would be better than two if statements. Ok! Done. >> Source/WebCore/editing/Editor.cpp:803 >> + dispatchInputEvent(*element, inputTypeName, inputEventData); > > Are we sure it’s OK to dispatch this event before calling didApplyStyle, given the event could do additional editing before returning? I think that generally events need to be dispatched after all other code runs and before returning to JavaScript. We may want to come up with a system similar to the one used for custom elements, or share its system. Not just for this event, but many others. I see. It looks like we've always dispatched the input event and then called didApplyStyle, so this patch maintains the current behavior. However, didApplyStyle is a no-op in WK2, and in WK1, it just updates the font selection panel by calling into -[WebHTMLView _updateFontPanel]. I'll move the input event dispatch to after we invoke didApplyStyle.
Wenson Hsieh
Comment 8 2016-11-09 11:09:39 PST
Created attachment 294246 [details] Patch for landing
WebKit Commit Bot
Comment 9 2016-11-09 12:07:56 PST
Comment on attachment 294246 [details] Patch for landing Clearing flags on attachment: 294246 Committed r208461: <http://trac.webkit.org/changeset/208461>
Note You need to log in before you can comment on or make changes to this bug.