Changeset 195281 in webkit


Ignore:
Timestamp:
Jan 19, 2016 2:47:11 AM (8 years ago)
Author:
rniwa@webkit.org
Message:

Text::splitText doesn't update Range end points anchored on parent nodes
https://bugs.webkit.org/show_bug.cgi?id=153227

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Rebaseline the test now that we're passing more test cases.

  • web-platform-tests/dom/ranges/Range-mutations-expected.txt:

Source/WebCore:

When a Text node is split into two and there is a Range whose boundary points' container node
is its parent and offset appears after the Text node, we must update the boundary points as specified
in step 7 of the concept "split" a Text node at https://dom.spec.whatwg.org/#concept-text-split

  1. Insert new node into parent before node’s next sibling.
  2. For each range whose start node is node and start offset is greater than offset, set its start node to new node and decrease its start offset by offset.
  3. For each range whose end node is node and end offset is greater than offset, set its end node to new node and decrease its end offset by offset.
  4. For each range whose start node is parent and start offset is equal to the index of node + 1, increase its start offset by one.
  5. For each range whose end node is parent and end offset is equal to the index of node + 1, increase its end offset by one.

Fixed the bug by implementing steps 4 and 5 in boundaryTextNodesSplit. New behavior matches the DOM spec
as well as the behavior of Firefox.

Test: fast/dom/Range/update-range-in-split-text.html

  • dom/Range.cpp:

(WebCore::boundaryTextNodesSplit): See above.

  • dom/RangeBoundaryPoint.h:

(WebCore::RangeBoundaryPoint::setToAfterChild): Added.

LayoutTests:

Added a regression test since the rebaselined W3C test is incomprehensible.

  • fast/dom/Range/update-range-in-split-text-expected.txt: Added.
  • fast/dom/Range/update-range-in-split-text.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r195263 r195281  
     12016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Text::splitText doesn't update Range end points anchored on parent nodes
     4        https://bugs.webkit.org/show_bug.cgi?id=153227
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Added a regression test since the rebaselined W3C test is incomprehensible.
     9
     10        * fast/dom/Range/update-range-in-split-text-expected.txt: Added.
     11        * fast/dom/Range/update-range-in-split-text.html: Added.
     12
    1132016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r195263 r195281  
     12016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Text::splitText doesn't update Range end points anchored on parent nodes
     4        https://bugs.webkit.org/show_bug.cgi?id=153227
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Rebaseline the test now that we're passing more test cases.
     9
     10        * web-platform-tests/dom/ranges/Range-mutations-expected.txt:
     11
    1122016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-mutations-expected.txt

    r189471 r195281  
    100100PASS paras[0].firstChild.splitText(1), with unselected range collapsed at (paras[0], 0)
    101101FAIL paras[0].firstChild.splitText(1), with selected range collapsed at (paras[0], 0) assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "" but got object ""
    102 FAIL paras[0].firstChild.splitText(1), with unselected range on paras[0] from 0 to 1 assert_equals: Wrong end offset expected 2 but got 1
     102PASS paras[0].firstChild.splitText(1), with unselected range on paras[0] from 0 to 1
    103103FAIL paras[0].firstChild.splitText(1), with selected range on paras[0] from 0 to 1 assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "Äb̈c̈d̈ëf̈g̈ḧ
    104104" but got object "Äb̈c̈d̈ëf̈g̈ḧ"
    105 FAIL paras[0].firstChild.splitText(1), with unselected range collapsed at (paras[0], 1) assert_equals: Wrong start offset expected 2 but got 1
     105PASS paras[0].firstChild.splitText(1), with unselected range collapsed at (paras[0], 1)
    106106FAIL paras[0].firstChild.splitText(1), with selected range collapsed at (paras[0], 1) assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "" but got object ""
    107 FAIL paras[0].firstChild.splitText(1), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Wrong end offset expected 2 but got 1
     107PASS paras[0].firstChild.splitText(1), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1)
    108108FAIL paras[0].firstChild.splitText(1), with selected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "̈b̈c̈d̈ëf̈g̈ḧ
    109109" but got object "b̈c̈d̈ëf̈g̈ḧ"
    110 FAIL paras[0].firstChild.splitText(2), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Wrong end offset expected 2 but got 1
     110PASS paras[0].firstChild.splitText(2), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1)
    111111FAIL paras[0].firstChild.splitText(2), with selected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "̈b̈c̈d̈ëf̈g̈ḧ
    112112" but got object "b̈c̈d̈ëf̈g̈ḧ"
    113 FAIL paras[0].firstChild.splitText(3), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Wrong end offset expected 2 but got 1
     113PASS paras[0].firstChild.splitText(3), with unselected range from (paras[0].firstChild, 1) to (paras[0], 1)
    114114FAIL paras[0].firstChild.splitText(3), with selected range from (paras[0].firstChild, 1) to (paras[0], 1) assert_equals: Sanity check: selection's range must initially be the same as the range we added expected object "̈b̈c̈d̈ëf̈g̈ḧ
    115115" but got object "b̈c̈d̈ëf̈g̈ḧ"
  • trunk/Source/WebCore/ChangeLog

    r195264 r195281  
     12016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Text::splitText doesn't update Range end points anchored on parent nodes
     4        https://bugs.webkit.org/show_bug.cgi?id=153227
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When a Text node is split into two and there is a Range whose boundary points' container node
     9        is its parent and offset appears after the Text node, we must update the boundary points as specified
     10        in step 7 of the concept "split" a Text node at https://dom.spec.whatwg.org/#concept-text-split
     11
     12        1. Insert new node into parent before node’s next sibling.
     13        2. For each range whose start node is node and start offset is greater than offset, set its start node
     14           to new node and decrease its start offset by offset.
     15        3. For each range whose end node is node and end offset is greater than offset, set its end node to
     16           new node and decrease its end offset by offset.
     17        4. For each range whose start node is parent and start offset is equal to the index of node + 1,
     18           increase its start offset by one.
     19        5. For each range whose end node is parent and end offset is equal to the index of node + 1, increase
     20           its end offset by one.
     21
     22        Fixed the bug by implementing steps 4 and 5 in boundaryTextNodesSplit. New behavior matches the DOM spec
     23        as well as the behavior of Firefox.
     24
     25        Test: fast/dom/Range/update-range-in-split-text.html
     26
     27        * dom/Range.cpp:
     28        (WebCore::boundaryTextNodesSplit): See above.
     29        * dom/RangeBoundaryPoint.h:
     30        (WebCore::RangeBoundaryPoint::setToAfterChild): Added.
     31
    1322016-01-19  Ryosuke Niwa  <rniwa@webkit.org>
    233
  • trunk/Source/WebCore/dom/Range.cpp

    r195264 r195281  
    17131713static inline void boundaryTextNodesSplit(RangeBoundaryPoint& boundary, Text* oldNode)
    17141714{
    1715     if (boundary.container() != oldNode)
    1716         return;
    1717     unsigned boundaryOffset = boundary.offset();
    1718     if (boundaryOffset <= oldNode->length())
    1719         return;
    1720     boundary.set(oldNode->nextSibling(), boundaryOffset - oldNode->length(), 0);
     1715    if (boundary.container() == oldNode) {
     1716        unsigned splitOffset = oldNode->length();
     1717        unsigned boundaryOffset = boundary.offset();
     1718        if (boundaryOffset > splitOffset)
     1719            boundary.set(oldNode->nextSibling(), boundaryOffset - splitOffset, 0);
     1720        return;
     1721    }
     1722    auto* parent = oldNode->parentNode();
     1723    if (boundary.container() == parent && boundary.childBefore() == oldNode) {
     1724        auto* newChild = oldNode->nextSibling();
     1725        ASSERT(newChild);
     1726        boundary.setToAfterChild(*newChild);
     1727    }
    17211728}
    17221729
  • trunk/Source/WebCore/dom/RangeBoundaryPoint.h

    r191955 r195281  
    5050
    5151    void setToBeforeChild(Node&);
     52    void setToAfterChild(Node&);
    5253    void setToStartOfNode(PassRefPtr<Node>);
    5354    void setToEndOfNode(PassRefPtr<Node>);
     
    139140    ASSERT(child.parentNode());
    140141    m_childBeforeBoundary = child.previousSibling();
     142    m_containerNode = child.parentNode();
     143    m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
     144}
     145
     146inline void RangeBoundaryPoint::setToAfterChild(Node& child)
     147{
     148    ASSERT(child.parentNode());
     149    m_childBeforeBoundary = &child;
    141150    m_containerNode = child.parentNode();
    142151    m_offsetInContainer = m_childBeforeBoundary ? invalidOffset : 0;
Note: See TracChangeset for help on using the changeset viewer.