Changeset 209976 in webkit


Ignore:
Timestamp:
Dec 18, 2016 5:14:10 PM (7 years ago)
Author:
Wenson Hsieh
Message:

Changing text direction fires input events with null inputTypes and no data
https://bugs.webkit.org/show_bug.cgi?id=166007
<rdar://problem/29557205>

Reviewed by Sam Weinig.

Source/WebCore:

Adds support for the "formatSetInlineTextDirection" input type, triggered when using the context menu on Mac in
an editable area (for both plain and rich text cases) to change paragraph direction. To do this, we add cases
for EditActionSetWritingDirection in inputTypeNameForEditingAction and inputEventDataForEditingStyleAndAction.

When changing text direction for a plaintext editable element, we have logic in Editor::setBaseWritingDirection
that sets the focused element's dir attribute to the requested value (ltr or rtl). We add similar hooks here to
dispatch input events and handle preventing default.

Test: fast/events/before-input-events-prevent-text-direction.html

  • editing/EditCommand.cpp:

(WebCore::inputTypeNameForEditingAction):

Handle the EditActionSetWritingDirection case.

  • editing/Editor.cpp:

(WebCore::inputEventDataForEditingStyleAndAction):
(WebCore::Editor::applyParagraphStyle):

Include input event data when dispatching an input event here.

(WebCore::Editor::setBaseWritingDirection):

  • testing/Internals.cpp:

(WebCore::Internals::setBaseWritingDirection):

  • testing/Internals.h:
  • testing/Internals.idl:

Introduce an internal testing support hook for setting base writing direction (the same codepath taken when
using the context menu to change paragraph direction). Currently, using testRunner.execCommand creates and
applies style with an additional unicode-bidi attribute, and appears to also be intentionally disabled for
plaintext editable elements.

LayoutTests:

Verifies that changing text direction causes beforeinput and input events with appropriate inputType and data to
be dispatched, and that preventing this beforeinput event causes no change in text direction.

  • fast/events/before-input-events-prevent-text-direction-expected.txt: Added.
  • fast/events/before-input-events-prevent-text-direction.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r209973 r209976  
     12016-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Changing text direction fires input events with null inputTypes and no data
     4        https://bugs.webkit.org/show_bug.cgi?id=166007
     5        <rdar://problem/29557205>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Verifies that changing text direction causes beforeinput and input events with appropriate inputType and data to
     10        be dispatched, and that preventing this beforeinput event causes no change in text direction.
     11
     12        * fast/events/before-input-events-prevent-text-direction-expected.txt: Added.
     13        * fast/events/before-input-events-prevent-text-direction.html: Added.
     14
    1152016-12-18  Simon Fraser  <simon.fraser@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r209971 r209976  
     12016-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Changing text direction fires input events with null inputTypes and no data
     4        https://bugs.webkit.org/show_bug.cgi?id=166007
     5        <rdar://problem/29557205>
     6
     7        Reviewed by Sam Weinig.
     8
     9        Adds support for the "formatSetInlineTextDirection" input type, triggered when using the context menu on Mac in
     10        an editable area (for both plain and rich text cases) to change paragraph direction. To do this, we add cases
     11        for EditActionSetWritingDirection in inputTypeNameForEditingAction and inputEventDataForEditingStyleAndAction.
     12
     13        When changing text direction for a plaintext editable element, we have logic in Editor::setBaseWritingDirection
     14        that sets the focused element's dir attribute to the requested value (ltr or rtl). We add similar hooks here to
     15        dispatch input events and handle preventing default.
     16
     17        Test: fast/events/before-input-events-prevent-text-direction.html
     18
     19        * editing/EditCommand.cpp:
     20        (WebCore::inputTypeNameForEditingAction):
     21
     22        Handle the EditActionSetWritingDirection case.
     23
     24        * editing/Editor.cpp:
     25        (WebCore::inputEventDataForEditingStyleAndAction):
     26        (WebCore::Editor::applyParagraphStyle):
     27
     28        Include input event data when dispatching an input event here.
     29
     30        (WebCore::Editor::setBaseWritingDirection):
     31        * testing/Internals.cpp:
     32        (WebCore::Internals::setBaseWritingDirection):
     33        * testing/Internals.h:
     34        * testing/Internals.idl:
     35
     36        Introduce an internal testing support hook for setting base writing direction (the same codepath taken when
     37        using the context menu to change paragraph direction). Currently, using testRunner.execCommand creates and
     38        applies style with an additional `unicode-bidi` attribute, and appears to also be intentionally disabled for
     39        plaintext editable elements.
     40
    1412016-12-17  Simon Fraser  <simon.fraser@apple.com>
    242
  • trunk/Source/WebCore/editing/EditCommand.cpp

    r208014 r209976  
    111111    case EditActionOutdent:
    112112        return ASCIILiteral("formatOutdent");
     113    case EditActionSetWritingDirection:
     114        return ASCIILiteral("formatSetInlineTextDirection");
    113115    default:
    114116        return emptyString();
  • trunk/Source/WebCore/editing/Editor.cpp

    r209943 r209976  
    131131    case EditActionSetColor:
    132132        return style->getPropertyValue(CSSPropertyColor);
     133    case EditActionSetWritingDirection:
     134        return style->getPropertyValue(CSSPropertyDirection);
    133135    default:
    134136        return { };
     
    830832
    831833    String inputTypeName = inputTypeNameForEditingAction(editingAction);
     834    String inputEventData = inputEventDataForEditingStyleAndAction(style, editingAction);
    832835    RefPtr<Element> element = m_frame.selection().selection().rootEditableElement();
    833     if (element && !dispatchBeforeInputEvent(*element, inputTypeName))
     836    if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData))
    834837        return;
    835838
     
    837840    client()->didApplyStyle();
    838841    if (element)
    839         dispatchInputEvent(*element, inputTypeName);
     842        dispatchInputEvent(*element, inputTypeName, inputEventData);
    840843}
    841844
     
    15871590        if (direction == NaturalWritingDirection)
    15881591            return;
    1589         downcast<HTMLTextFormControlElement>(*focusedElement).setAttributeWithoutSynchronization(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl");
    1590         focusedElement->dispatchInputEvent();
     1592
     1593        auto& focusedFormElement = downcast<HTMLTextFormControlElement>(*focusedElement);
     1594        auto directionValue = direction == LeftToRightWritingDirection ? "ltr" : "rtl";
     1595        auto writingDirectionInputTypeName = inputTypeNameForEditingAction(EditActionSetWritingDirection);
     1596        if (!dispatchBeforeInputEvent(focusedFormElement, writingDirectionInputTypeName, directionValue))
     1597            return;
     1598
     1599        focusedFormElement.setAttributeWithoutSynchronization(dirAttr, directionValue);
     1600        dispatchInputEvent(focusedFormElement, writingDirectionInputTypeName, directionValue);
    15911601        document().updateStyleIfNeeded();
    15921602        return;
  • trunk/Source/WebCore/testing/Internals.cpp

    r209964 r209976  
    135135#include "WebCoreJSClientData.h"
    136136#include "WorkerThread.h"
     137#include "WritingDirection.h"
    137138#include "XMLHttpRequest.h"
    138139#include <bytecode/CodeBlock.h>
     
    35183519}
    35193520
     3521void Internals::setBaseWritingDirection(BaseWritingDirection direction)
     3522{
     3523    if (auto* document = contextDocument()) {
     3524        if (auto* frame = document->frame()) {
     3525            switch (direction) {
     3526            case BaseWritingDirection::Ltr:
     3527                frame->editor().setBaseWritingDirection(LeftToRightWritingDirection);
     3528                break;
     3529            case BaseWritingDirection::Rtl:
     3530                frame->editor().setBaseWritingDirection(RightToLeftWritingDirection);
     3531                break;
     3532            case BaseWritingDirection::Natural:
     3533                frame->editor().setBaseWritingDirection(NaturalWritingDirection);
     3534                break;
     3535            }
     3536        }
     3537    }
     3538}
     3539
    35203540#if ENABLE(POINTER_LOCK)
    35213541bool Internals::pageHasPendingPointerLock() const
  • trunk/Source/WebCore/testing/Internals.h

    r209964 r209976  
    520520    void reportBacktrace();
    521521
     522    enum class BaseWritingDirection { Natural, Ltr, Rtl };
     523    void setBaseWritingDirection(BaseWritingDirection);
     524
    522525#if ENABLE(POINTER_LOCK)
    523526    bool pageHasPendingPointerLock() const;
  • trunk/Source/WebCore/testing/Internals.idl

    r209964 r209976  
    7171};
    7272
     73enum BaseWritingDirection {
     74    "Natural",
     75    "Ltr",
     76    "Rtl"
     77};
     78
    7379enum EventThrottlingBehavior {
    7480    "responsive",
     
    486492
    487493    void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection userInterfaceLayoutDirection);
     494    void setBaseWritingDirection(BaseWritingDirection direction);
    488495
    489496    boolean userPrefersReducedMotion();
Note: See TracChangeset for help on using the changeset viewer.