⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 294753 in webkit


Ignore:
Timestamp:
May 24, 2022, 10:28:58 AM (4 years ago)
Author:
timothy_horton@apple.com
Message:

isContentEditable returns false for display:none contenteditable elements, but true for children
https://bugs.webkit.org/show_bug.cgi?id=240834

Reviewed by Ryosuke Niwa.

  • Source/WebCore/dom/Node.cpp:

(WebCore::computeEditabilityFromComputedStyle):
Remove a display: none check. This check is wrong for two reasons:

1) It only consults the style of the immediate element, not whether or not

that element is in a display: none subtree. This regressed in r160966.
This causes a confusing situation where display: none affects the editability
of only the element it is directly applied to.

2) isContentEditable is not specified to be affected by display: none.

  • LayoutTests/editing/editability/isContentEditable-in-display-none-expected.txt: Added.
  • LayoutTests/editing/editability/isContentEditable-in-display-none.html: Added.

Add a test that dumps the editability of a variety of different configurations of
contenteditable elements and their children.

Before this change, this test would have said that #nonVisible (the display: none
contenteditable element) was read-only, but its child <p> was editable. Now we
agree with Gecko and Blink who both say that both are editable.

  • LayoutTests/fast/events/event-input-contentEditable-expected.txt:
  • LayoutTests/fast/events/event-input-contentEditable.html:

Adjust this test to expect an input event to be dispatched for programmatic
editing in display: none elements. Also add a sub-test that checks the same,
but in a child element.

Before this change, we would not dispatch an input event to the display: none
contenteditable itself, but *would* dispatch an input event for input into a child element.
Now we agree with Gecko, who dispatch events in both cases.

Canonical link: https://commits.webkit.org/250921@main

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/fast/events/event-input-contentEditable-expected.txt

    r68830 r294753  
    1212PASS event.target.id is 'target4'
    1313PASS event.target.innerHTML is '<a href="http://www.example.com/">This text should be a link.</a>'
     14PASS event.target.id is 'target5A'
     15PASS event.target.innerHTML is 'Text'
     16PASS event.target.id is 'target5B'
     17PASS event.target.innerHTML is 'This <span id="target5BDestination">text</span> will not be rendered.'
    1418PASS event.target.id is 'target6parent'
    1519PASS event.target.innerHTML is '<a href="http://www.example.com/"><span id="target6start">Start,</span><span id="target6middle">Middle,</span><span id="target6end">End.</span></a>'
  • trunk/LayoutTests/fast/events/event-input-contentEditable.html

    r217390 r294753  
    6868document.execCommand("createLink", false, "http://www.example.com/");
    6969
    70 // An event shouldn't be dispatched to a 'display:none' node.
    71 var target5 = makeTestTarget('<p id="target5" contentEditable>This will not be rendered.</p>');
    72 target5.addEventListener("input", function(evt) { testFailed("should not be reached"); });
    73 sel.selectAllChildren(target5);
    74 target5.style.display = "none";
     70// An event should be dispatched to a 'display:none' node.
     71var target5A = setupForFiringTest('<p id="target5A" contentEditable>This will not be rendered.</p>', 'Text');
     72sel.selectAllChildren(target5A);
     73target5A.style.display = "none";
    7574document.execCommand("insertText", false, "Text");
     75
     76// An event should be dispatched to a child of a 'display:none' node.
     77var target5B = setupForFiringTest('<p id="target5B" contentEditable>This <span id="target5BDestination">replace</span> will not be rendered.</p>', 'This <span id="target5BDestination">text</span> will not be rendered.');
     78var target5BDestination = document.getElementById("target5BDestination");
     79sel.selectAllChildren(target5BDestination);
     80target5B.style.display = "none";
     81document.execCommand("insertText", false, "text");
    7682
    7783// The event should be dispatched from the editable root.
  • trunk/Source/WebCore/dom/Node.cpp

    r294605 r294753  
    765765        if (!style)
    766766            continue;
    767         if (style->display() == DisplayType::None)
    768             continue;
     767
    769768        // Elements with user-select: all style are considered atomic
    770769        // therefore non editable.
Note: See TracChangeset for help on using the changeset viewer.