Changeset 83247 in webkit


Ignore:
Timestamp:
Apr 7, 2011 9:11:13 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-04-07 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

REGRESSION (r46914, r48764): When typing in Mail, line wrapping frequently occurs in the middle of words
https://bugs.webkit.org/show_bug.cgi?id=57872

Added tests to ensure WebKit inserts a paragraph separator properly around tab span.

  • editing/inserting/insert-div-021-expected.txt: No longer duplicates span[id="test"] incorrectly.
  • editing/inserting/insert-paragraph-after-tab-span-and-text-expected.txt: Added.
  • editing/inserting/insert-paragraph-after-tab-span-and-text.html: Added.
  • editing/inserting/insert-paragraph-separator-tab-span-expected.txt: Added.
  • editing/inserting/insert-paragraph-separator-tab-span.html: Added.
  • editing/inserting/insert-paragraph-at-end-of-line-expected.txt: No longer duplicates a[id="anchor"] incorrectly.

2011-04-07 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

REGRESSION (r46914, r48764): When typing in Mail, line wrapping frequently occurs in the middle of words
https://bugs.webkit.org/show_bug.cgi?id=57872

r46914 initially introduced a regression by replacing calls to styleAtPosition by editingStyleAtPosition
because editingStyleAtPosition did not avoid tab span to obtain the computed style unlike styleAtPosition.

r46914 also introduced a regression by cloning hierarchy under new block at the insertion position without
avoiding the tab span.

Fixed the both regressions by avoiding tab spans when computing the editing style and when cloning hierarchy.
Also reverted r46914 for the general code path because re-creating node hierarchy duplicates nodes when
we're moving nodes after the paragraph separator. Instead, we now split the tree up until the start block
before moving the nodes.

Tests: editing/inserting/insert-paragraph-after-tab-span-and-text.html

editing/inserting/insert-paragraph-separator-tab-span.html

  • editing/DeleteSelectionCommand.cpp: (WebCore::DeleteSelectionCommand::saveTypingStyleState): Since EditingStyle's constructor avoids a tab span, no longer calls positionBeforeTabSpan on the position passed to EditingStyle's constructor.
  • editing/EditingStyle.cpp: (WebCore::EditingStyle::init): Always avoid a tab span when computing the editing style.
  • editing/InsertParagraphSeparatorCommand.cpp: (WebCore::InsertParagraphSeparatorCommand::doApply): Avoid cloning tab spans and inserting a paragraph separator into a paragraph separator.
  • editing/htmlediting.cpp: (WebCore::positionOutsideTabSpan): Renamed from positionBeforeTabSpan. Also returns the position in the parent node after the tab span if the position was at the end of the tab span.
  • editing/htmlediting.h:
Location:
trunk
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r83246 r83247  
     12011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        REGRESSION (r46914, r48764): When typing in Mail, line wrapping frequently occurs in the middle of words
     6        https://bugs.webkit.org/show_bug.cgi?id=57872
     7
     8        Added tests to ensure WebKit inserts a paragraph separator properly around tab span.
     9
     10        * editing/inserting/insert-div-021-expected.txt: No longer duplicates span[id="test"] incorrectly.
     11        * editing/inserting/insert-paragraph-after-tab-span-and-text-expected.txt: Added.
     12        * editing/inserting/insert-paragraph-after-tab-span-and-text.html: Added.
     13        * editing/inserting/insert-paragraph-separator-tab-span-expected.txt: Added.
     14        * editing/inserting/insert-paragraph-separator-tab-span.html: Added.
     15        * editing/inserting/insert-paragraph-at-end-of-line-expected.txt: No longer duplicates a[id="anchor"] incorrectly.
     16
    1172011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
    218
     
    408424        * platform/chromium-mac-leopard/fast/speech/input-appearance-searchandspeech-expected.png: Added.
    409425        * platform/chromium-mac/fast/speech/input-appearance-numberandspeech-expected.txt:
     426
     4272011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
     428
     429        Reviewed by Eric Seidel.
     430
     431        REGRESSION (r46914, r48764): When typing in Mail, line wrapping frequently occurs in the middle of words
     432        https://bugs.webkit.org/show_bug.cgi?id=57872
     433
     434        Added a test insert a paragraph separator and text around tab spans. WebKit should not apply the tab span's
     435        style to the paragraph separator or the text.
     436
     437        * editing/inserting/insert-paragraph-separator-tab-span-expected.txt: Added.
     438        * editing/inserting/insert-paragraph-separator-tab-span.html: Added.
    410439
    4114402011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
  • trunk/LayoutTests/editing/inserting/insert-div-021-expected.txt

    r83161 r83247  
    3333|   <br>
    3434| <div>
    35 |   <span>
    36 |     id="test"
    3735|   "<#selection-caret>bar
    3836"
  • trunk/LayoutTests/editing/inserting/insert-paragraph-at-end-of-line-expected.txt

    r83181 r83247  
    1919|   "1"
    2020| <div>
    21 |   <a>
    22 |     href="#"
    23 |     id="anchor"
    2421|   "2<#selection-caret>"
    2522|   <br>
  • trunk/Source/WebCore/ChangeLog

    r83245 r83247  
     12011-04-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        REGRESSION (r46914, r48764): When typing in Mail, line wrapping frequently occurs in the middle of words
     6        https://bugs.webkit.org/show_bug.cgi?id=57872
     7
     8        r46914 initially introduced a regression by replacing calls to styleAtPosition by editingStyleAtPosition
     9        because editingStyleAtPosition did not avoid tab span to obtain the computed style unlike styleAtPosition.
     10
     11        r46914 also introduced a regression by cloning hierarchy under new block at the insertion position without
     12        avoiding the tab span.
     13
     14        Fixed the both regressions by avoiding tab spans when computing the editing style and when cloning hierarchy.
     15        Also reverted r46914 for the general code path because re-creating node hierarchy duplicates nodes when
     16        we're moving nodes after the paragraph separator. Instead, we now split the tree up until the start block
     17        before moving the nodes.
     18
     19        Tests: editing/inserting/insert-paragraph-after-tab-span-and-text.html
     20               editing/inserting/insert-paragraph-separator-tab-span.html
     21
     22        * editing/DeleteSelectionCommand.cpp:
     23        (WebCore::DeleteSelectionCommand::saveTypingStyleState): Since EditingStyle's constructor avoids a tab span,
     24        no longer calls positionBeforeTabSpan on the position passed to EditingStyle's constructor.
     25        * editing/EditingStyle.cpp:
     26        (WebCore::EditingStyle::init): Always avoid a tab span when computing the editing style.
     27        * editing/InsertParagraphSeparatorCommand.cpp:
     28        (WebCore::InsertParagraphSeparatorCommand::doApply): Avoid cloning tab spans and inserting a paragraph
     29        separator into a paragraph separator.
     30        * editing/htmlediting.cpp:
     31        (WebCore::positionOutsideTabSpan): Renamed from positionBeforeTabSpan. Also returns the position in the parent
     32        node after the tab span if the position was at the end of the tab span.
     33        * editing/htmlediting.h:
     34
    1352011-04-07  Jia Pu  <jpu@apple.com>
    236
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r82550 r83247  
    282282
    283283    // Figure out the typing style in effect before the delete is done.
    284     m_typingStyle = EditingStyle::create(positionBeforeTabSpan(m_selectionToDelete.start()));
     284    m_typingStyle = EditingStyle::create(m_selectionToDelete.start());
    285285    m_typingStyle->removeStyleAddedByNode(enclosingAnchorElement(m_selectionToDelete.start()));
    286286
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r83097 r83247  
    301301void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude)
    302302{
     303    if (isTabSpanTextNode(node))
     304        node = tabSpanNode(node)->parentNode();
     305    else if (isTabSpanNode(node))
     306        node = node->parentNode();
     307
    303308    RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = computedStyle(node);
    304309    m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosition ? computedStyleAtPosition->copy() : editingStyleFromComputedStyle(computedStyleAtPosition);
  • trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp

    r83097 r83247  
    240240       
    241241        Vector<Element*> ancestors;
    242         getAncestorsInsideBlock(insertionPosition.deprecatedNode(), startBlock, ancestors);     
     242        getAncestorsInsideBlock(positionOutsideTabSpan(insertionPosition).deprecatedNode(), startBlock, ancestors);     
    243243        RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToInsert);
    244244       
     
    255255    if (isFirstInBlock || !inSameBlock(visiblePos, visiblePos.previous())) {
    256256        Node *refNode;
     257       
     258        insertionPosition = positionOutsideTabSpan(insertionPosition);
     259
    257260        if (isFirstInBlock && !nestNewBlock)
    258261            refNode = startBlock;
     
    271274
    272275        Vector<Element*> ancestors;
    273         getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(insertionPosition).deprecatedNode(), startBlock, ancestors);
     276        getAncestorsInsideBlock(positionAvoidingSpecialElementBoundary(positionOutsideTabSpan(insertionPosition)).deprecatedNode(), startBlock, ancestors);
    274277       
    275278        appendBlockPlaceholder(cloneHierarchyUnderNewBlock(ancestors, blockToInsert));
     
    300303    // all of the correct nodes when building the ancestor list.  So this needs to be the deepest representation of the position
    301304    // before we walk the DOM tree.
    302     insertionPosition = VisiblePosition(insertionPosition).deepEquivalent();
    303 
    304     // Build up list of ancestors in between the start node and the start block.
    305     Vector<Element*> ancestors;
    306     getAncestorsInsideBlock(insertionPosition.deprecatedNode(), startBlock, ancestors);
     305    insertionPosition = positionOutsideTabSpan(VisiblePosition(insertionPosition).deepEquivalent());
    307306
    308307    // Make sure we do not cause a rendered space to become unrendered.
     
    336335
    337336    updateLayout();
    338    
    339     // Make clones of ancestors in between the start node and the outer block.
    340     RefPtr<Element> parent = cloneHierarchyUnderNewBlock(ancestors, blockToInsert);
    341337
    342338    // If the paragraph separator was inserted at the end of a paragraph, an empty line must be
     
    345341    if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visiblePos))
    346342        appendNode(createBreakElement(document()).get(), blockToInsert.get());
    347        
     343
    348344    // Move the start node and the siblings of the start node.
    349     if (insertionPosition.deprecatedNode() != startBlock) {
    350         Node* n = insertionPosition.deprecatedNode();
    351         if (insertionPosition.deprecatedEditingOffset() >= caretMaxOffset(n))
    352             n = n->nextSibling();
     345    if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode(blockToInsert.get()))) {
     346        Node* n;
     347        if (insertionPosition.containerNode() == startBlock)
     348            n = insertionPosition.computeNodeAfterPosition();
     349        else {
     350            splitTreeToNode(insertionPosition.containerNode(), startBlock);
     351
     352            for (n = startBlock->firstChild(); n; n = n->nextSibling()) {
     353                if (comparePositions(VisiblePosition(insertionPosition), positionBeforeNode(n)) <= 0)
     354                    break;
     355            }
     356        }
    353357
    354358        while (n && n != blockToInsert) {
    355359            Node *next = n->nextSibling();
    356360            removeNode(n);
    357             appendNode(n, parent.get());
     361            appendNode(n, blockToInsert);
    358362            n = next;
    359363        }
    360364    }           
    361 
    362     // Move everything after the start node.
    363     if (!ancestors.isEmpty()) {
    364         Element* leftParent = ancestors.first();
    365         while (leftParent && leftParent != startBlock) {
    366             parent = parent->parentElement();
    367             if (!parent)
    368                 break;
    369             Node* n = leftParent->nextSibling();
    370             while (n && n != blockToInsert) {
    371                 Node* next = n->nextSibling();
    372                 removeNode(n);
    373                 appendNode(n, parent.get());
    374                 n = next;
    375             }
    376             leftParent = leftParent->parentElement();
    377         }
    378     }
    379365
    380366    // Handle whitespace that occurs after the split
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r82121 r83247  
    895895}
    896896   
    897 Position positionBeforeTabSpan(const Position& pos)
    898 {
    899     Node* node = pos.deprecatedNode();
     897Position positionOutsideTabSpan(const Position& pos)
     898{
     899    Node* node = pos.containerNode();
    900900    if (isTabSpanTextNode(node))
    901901        node = tabSpanNode(node);
    902902    else if (!isTabSpanNode(node))
    903903        return pos;
    904    
     904
     905    if (node && VisiblePosition(pos) == lastPositionInNode(node))
     906        return positionInParentAfterNode(node);
     907
    905908    return positionInParentBeforeNode(node);
    906909}
  • trunk/Source/WebCore/editing/htmlediting.h

    r82121 r83247  
    112112Position previousVisuallyDistinctCandidate(const Position&);
    113113
    114 Position positionBeforeTabSpan(const Position&);
     114Position positionOutsideTabSpan(const Position&);
    115115Position positionBeforeContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
    116116Position positionAfterContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
Note: See TracChangeset for help on using the changeset viewer.