Changeset 29456 in webkit


Ignore:
Timestamp:
Jan 13, 2008 5:35:00 PM (16 years ago)
Author:
eric@webkit.org
Message:

Reviewed by darin.

Range.insertNode does not update endContainer endIndex correctly
in the case where it had to split a text node.
http://bugs.webkit.org/show_bug.cgi?id=16765

Darin pointed out during review that we still don't handle the dynamic
range case (where the dom tree changes not using range methods)
Thus this code will get ripped out when we add that. The test cases
are still valid and useful however, so I'm landing this as-is.

Tests: fast/dom/Range/range-insertNode-separate-endContainer.html

fast/dom/Range/range-insertNode-splittext.html

  • dom/Range.cpp: (WebCore::Range::insertNode): handle the splitText case correctly.
Location:
trunk
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r29450 r29456  
     12008-01-13  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by darin.
     4       
     5        range-insertNode-separate-endContainer validates proper range behavior
     6        and does not change with this patch.
     7        range-insertNode-splittext demonstrates the issue fixed by this patch
     8        http://bugs.webkit.org/show_bug.cgi?id=16765
     9
     10        * fast/dom/Range/range-insertNode-separate-endContainer-expected.txt: Added.
     11        * fast/dom/Range/range-insertNode-separate-endContainer.html: Added.
     12        * fast/dom/Range/range-insertNode-splittext-expected.txt: Added.
     13        * fast/dom/Range/range-insertNode-splittext.html: Added.
     14        * fast/dom/Range/resources/range-insertNode-separate-endContainer.js: Added.
     15        * fast/dom/Range/resources/range-insertNode-splittext.js: Added.
     16
    1172008-01-13  Dan Bernstein  <mitz@apple.com>
    218
  • trunk/WebCore/ChangeLog

    r29452 r29456  
     12008-01-13  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by darin.
     4
     5        Range.insertNode does not update endContainer endIndex correctly
     6        in the case where it had to split a text node.
     7        http://bugs.webkit.org/show_bug.cgi?id=16765
     8       
     9        Darin pointed out during review that we still don't handle the dynamic
     10        range case (where the dom tree changes not using range methods)
     11        Thus this code will get ripped out when we add that.  The test cases
     12        are still valid and useful however, so I'm landing this as-is.
     13
     14        Tests: fast/dom/Range/range-insertNode-separate-endContainer.html
     15               fast/dom/Range/range-insertNode-splittext.html
     16
     17        * dom/Range.cpp:
     18        (WebCore::Range::insertNode): handle the splitText case correctly.
     19
    1202008-01-13  Darin Adler  <darin@apple.com>
    221
  • trunk/WebCore/dom/Range.cpp

    r29214 r29456  
    980980void Range::insertNode(PassRefPtr<Node> newNode, ExceptionCode& ec)
    981981{
     982    ec = 0;
     983
    982984    if (m_detached) {
    983985        ec = INVALID_STATE_ERR;
     
    10311033            }
    10321034        }
    1033     }
    1034     else {
     1035    } else {
    10351036        if (!checkAgainst->childTypeAllowed(newNode->nodeType())) {
    10361037            ec = HIERARCHY_REQUEST_ERR;
     
    10471048
    10481049    // INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or Document node.
    1049     if( newNode->nodeType() == Node::ATTRIBUTE_NODE ||
     1050    if (newNode->nodeType() == Node::ATTRIBUTE_NODE ||
    10501051        newNode->nodeType() == Node::ENTITY_NODE ||
    10511052        newNode->nodeType() == Node::NOTATION_NODE ||
     
    10551056    }
    10561057
    1057     unsigned offsetDelta = 0;
    1058     if (m_startContainer == m_endContainer) {
    1059         bool isFragment = newNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;
    1060         offsetDelta = isFragment ? newNode->childNodeCount() : 1;
    1061     }
    1062    
    1063     if(m_startContainer->nodeType() == Node::TEXT_NODE ||
    1064        m_startContainer->nodeType() == Node::CDATA_SECTION_NODE) {
    1065         ec = 0;
     1058    unsigned endOffsetDelta = 0;
     1059    if (m_startContainer->nodeType() == Node::TEXT_NODE ||
     1060        m_startContainer->nodeType() == Node::CDATA_SECTION_NODE) {
    10661061        RefPtr<Text> newText = static_cast<Text*>(m_startContainer.get())->splitText(m_startOffset, ec);
    10671062        if (ec)
    10681063            return;
     1064
     1065        if (m_startContainer == m_endContainer)
     1066            endOffsetDelta = -m_startOffset;
     1067
    10691068        m_startContainer->parentNode()->insertBefore(newNode, newText.get(), ec);
     1069        if (ec)
     1070            return;
     1071        m_endContainer = newText;
    10701072    } else {
     1073        if (m_startContainer == m_endContainer) {
     1074            bool isFragment = newNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;
     1075            endOffsetDelta = isFragment ? newNode->childNodeCount() : 1;
     1076        }
     1077
    10711078        m_startContainer->insertBefore(newNode, m_startContainer->childNode(m_startOffset), ec);
    1072     }
    1073    
    1074     m_endOffset += offsetDelta;
     1079        if (ec)
     1080            return;
     1081    }
     1082    m_endOffset += endOffsetDelta;
    10751083}
    10761084
Note: See TracChangeset for help on using the changeset viewer.