Bug 164241 - Setting foreground color when text is selected should fire an input event with color data
Summary: Setting foreground color when text is selected should fire an input event wit...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks: 163112
  Show dependency treegraph
 
Reported: 2016-10-31 14:57 PDT by Wenson Hsieh
Modified: 2016-11-09 13:15 PST (History)
4 users (show)

See Also:


Attachments
Patch (7.45 KB, patch)
2016-10-31 15:02 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Rebased on ToT (7.23 KB, patch)
2016-10-31 16:08 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (12.12 KB, patch)
2016-10-31 18:32 PDT, Wenson Hsieh
darin: review+
Details | Formatted Diff | Diff
Patch for landing (12.27 KB, patch)
2016-11-09 11:09 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 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!
Comment 1 Wenson Hsieh 2016-10-31 14:58:23 PDT
<rdar://problem/29032759>
Comment 2 Wenson Hsieh 2016-10-31 15:02:38 PDT
Created attachment 293472 [details]
Patch
Comment 3 Wenson Hsieh 2016-10-31 16:08:48 PDT
Created attachment 293485 [details]
Rebased on ToT
Comment 4 Ryosuke Niwa 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.
Comment 5 Wenson Hsieh 2016-10-31 18:32:14 PDT
Created attachment 293508 [details]
Patch
Comment 6 Darin Adler 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.
Comment 7 Wenson Hsieh 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.
Comment 8 Wenson Hsieh 2016-11-09 11:09:39 PST
Created attachment 294246 [details]
Patch for landing
Comment 9 WebKit Commit Bot 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>