Changeset 54395 in webkit


Ignore:
Timestamp:
Feb 4, 2010 6:38:21 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-02-04 Tony Chang <tony@chromium.org>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=25002
When inserting a new paragraph, avoid nesting empty divs. When
pasting near the end of a paragraph, this prevents each paste
command for getting nested one level deeper.

Three paste tests have been rebaselined since this causes the pasted
content to be outside the last div instead of inside. E.g.,
<div>foo<div>bar</div>[pasted content]</div> is now
<div>foo<div>bar</div></div><div>[pasted content]</div>

The new test verifies this behavior.

  • editing/inserting/paragraph-outside-nested-divs-expected.txt: Added.
  • editing/inserting/paragraph-outside-nested-divs.html: Added.
  • platform/mac/editing/pasteboard/paste-text-012-expected.txt:
  • platform/mac/editing/pasteboard/paste-text-013-expected.txt:
  • platform/mac/editing/pasteboard/paste-text-017-expected.txt:

2010-02-04 Tony Chang <tony@chromium.org>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=25002
When inserting a new paragraph, avoid nesting empty divs. When
pasting near the end of a paragraph, this prevents each paste
command for getting nested one level deeper.

Test: editing/inserting/paragraph-outside-nested-divs.html

  • editing/InsertParagraphSeparatorCommand.cpp: (WebCore::highestVisuallyEquivalentDiv): (WebCore::InsertParagraphSeparatorCommand::doApply):
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r54393 r54395  
     12010-02-04  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25002
     6        When inserting a new paragraph, avoid nesting empty divs.  When
     7        pasting near the end of a paragraph, this prevents each paste
     8        command for getting nested one level deeper.
     9
     10        Three paste tests have been rebaselined since this causes the pasted
     11        content to be outside the last div instead of inside.  E.g.,
     12        <div>foo<div>bar</div>[pasted content]</div> is now
     13        <div>foo<div>bar</div></div><div>[pasted content]</div>
     14
     15        The new test verifies this behavior.
     16
     17        * editing/inserting/paragraph-outside-nested-divs-expected.txt: Added.
     18        * editing/inserting/paragraph-outside-nested-divs.html: Added.
     19        * platform/mac/editing/pasteboard/paste-text-012-expected.txt:
     20        * platform/mac/editing/pasteboard/paste-text-013-expected.txt:
     21        * platform/mac/editing/pasteboard/paste-text-017-expected.txt:
     22
    1232010-02-04  Dumitru Daniliuc  <dumi@chromium.org>
    224
  • trunk/LayoutTests/platform/mac/editing/pasteboard/paste-text-012-expected.txt

    r41569 r54395  
    88EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    99EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
    10 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > DIV > DIV > SPAN > DIV > BODY > HTML > #document to 0 of DIV > DIV > DIV > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     10EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > DIV > SPAN > DIV > BODY > HTML > #document to 0 of DIV > DIV > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    1111EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    1212EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    3737        RenderBlock (anonymous) at (14,14) size 756x132
    3838          RenderBlock {DIV} at (0,0) size 756x132 [border: (2px solid #FF0000)]
    39             RenderBlock {DIV} at (14,38) size 728x80
     39            RenderBlock {DIV} at (14,38) size 728x28
    4040              RenderBlock {BLOCKQUOTE} at (40,0) size 648x28
    4141                RenderText {#text} at (0,0) size 32x28
    4242                  text run at (0,0) width 32: "foo"
    43               RenderBlock {DIV} at (0,52) size 728x28
    44                 RenderBR {BR} at (0,0) size 0x28
     43            RenderBlock {DIV} at (14,90) size 728x28
     44              RenderBR {BR} at (0,0) size 0x28
    4545        RenderBlock (anonymous) at (14,146) size 756x0
    4646          RenderInline {SPAN} at (0,0) size 0x0
    47 caret: position 0 of child 0 {BR} of child 1 {DIV} of child 0 {DIV} of child 0 {DIV} of child 0 {SPAN} of child 7 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     47caret: position 0 of child 0 {BR} of child 1 {DIV} of child 0 {DIV} of child 0 {SPAN} of child 7 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/platform/mac/editing/pasteboard/paste-text-013-expected.txt

    r41569 r54395  
    1111EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
    1212EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
    13 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     13EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    1414EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    1515EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    4141          text run at (14,14) width 12: "x"
    4242      RenderBlock {DIV} at (0,238) size 784x132 [border: (2px solid #FF0000)]
    43         RenderBlock {DIV} at (14,38) size 756x80
     43        RenderBlock {DIV} at (14,38) size 756x28
    4444          RenderBlock {BLOCKQUOTE} at (40,0) size 676x28
    4545            RenderText {#text} at (0,0) size 32x28
    4646              text run at (0,0) width 32: "foo"
    47           RenderBlock {DIV} at (0,52) size 756x28
    48             RenderBR {BR} at (0,0) size 0x28
    49 caret: position 0 of child 0 {BR} of child 1 {DIV} of child 0 {DIV} of child 8 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     47        RenderBlock {DIV} at (14,90) size 756x28
     48          RenderBR {BR} at (0,0) size 0x28
     49caret: position 0 of child 0 {BR} of child 1 {DIV} of child 8 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/LayoutTests/platform/mac/editing/pasteboard/paste-text-017-expected.txt

    r25970 r54395  
    77EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 5 of #text > DIV > DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
    88EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    9 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > DIV > DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     9EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
    1010EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    1111EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     
    4141          RenderBlock {DIV} at (2,30) size 780x28
    4242            RenderBR {BR} at (0,0) size 0x28
    43           RenderBlock {DIV} at (2,58) size 780x56
     43          RenderBlock {DIV} at (2,58) size 780x28
    4444            RenderBlock {DIV} at (0,0) size 780x28
    4545              RenderText {#text} at (0,0) size 36x28
    4646                text run at (0,0) width 36: "two"
    4747            RenderBlock (anonymous) at (0,28) size 780x0
    48             RenderBlock {DIV} at (0,28) size 780x28
    49               RenderBR {BR} at (0,0) size 0x28
     48          RenderBlock {DIV} at (2,86) size 780x28
     49            RenderBR {BR} at (0,0) size 0x28
    5050          RenderBlock {DIV} at (2,114) size 780x28
    5151            RenderText {#text} at (0,0) size 49x28
    5252              text run at (0,0) width 49: "three"
    53 caret: position 0 of child 0 {BR} of child 1 {DIV} of child 5 {DIV} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
     53caret: position 0 of child 0 {BR} of child 6 {DIV} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
  • trunk/WebCore/ChangeLog

    r54393 r54395  
     12010-02-04  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=25002
     6        When inserting a new paragraph, avoid nesting empty divs.  When
     7        pasting near the end of a paragraph, this prevents each paste
     8        command for getting nested one level deeper.
     9
     10        Test: editing/inserting/paragraph-outside-nested-divs.html
     11
     12        * editing/InsertParagraphSeparatorCommand.cpp:
     13        (WebCore::highestVisuallyEquivalentDiv):
     14        (WebCore::InsertParagraphSeparatorCommand::doApply):
     15
    1162010-02-04  Dumitru Daniliuc  <dumi@chromium.org>
    217
  • trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp

    r48764 r54395  
    4545using namespace HTMLNames;
    4646
     47// When inserting a new line, we want to avoid nesting empty divs if we can.  Otherwise, when
     48// pasting, it's easy to have each new line be a div deeper than the previous.  E.g., in the case
     49// below, we want to insert at ^ instead of |.
     50// <div>foo<div>bar</div>|</div>^
     51static Element* highestVisuallyEquivalentDiv(Element* startBlock)
     52{
     53    Element* curBlock = startBlock;
     54    while (!curBlock->nextSibling() && curBlock->parentElement()->hasTagName(divTag)) {
     55        NamedNodeMap* attributes = curBlock->parentElement()->attributes(true);
     56        if (attributes && !attributes->isEmpty())
     57            break;
     58        curBlock = curBlock->parentElement();
     59    }
     60    return curBlock;
     61}
     62
    4763InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document *document, bool mustUseDefaultParagraphElement)
    4864    : CompositeEditCommand(document)
     
    215231                shouldApplyStyleAfterInsertion = false;
    216232            }
    217             insertNodeAfter(blockToInsert, startBlock);
     233
     234            // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists).  However,
     235            // for div nodes, this can result in nested div tags that are hard to break out of.
     236            Element* siblingNode = startBlock;
     237            if (blockToInsert->hasTagName(divTag))
     238                siblingNode = highestVisuallyEquivalentDiv(startBlock);
     239            insertNodeAfter(blockToInsert, siblingNode);
    218240        }
    219241
Note: See TracChangeset for help on using the changeset viewer.