Changeset 54413 in webkit


Ignore:
Timestamp:
Feb 5, 2010 1:23:06 AM (14 years ago)
Author:
tony@chromium.org
Message:

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

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=24872
Add a test to make sure copying from a list and pasting into a list
keeps the list at the same indention level rather than nesting.

  • editing/pasteboard/paste-list-002-expected.txt: Added.
  • editing/pasteboard/paste-list-002.html: Added.

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

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=24872
When pasting a list into another list should not indent another level.
If the cursor is at the beginning of the line, it should insert the
list items before the current list item. If the cursor is at the end
of the line, it should insert the list items after the current list item.

This matches Firefox and IE and makes the common activity of reordering a list
work as expected.

This also adds a small helper method (isListItem) to htmlediting.h.

Test: editing/pasteboard/paste-list-002.html

  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::doApply): (WebCore::ReplaceSelectionCommand::insertAsListItems):
  • editing/ReplaceSelectionCommand.h:
  • editing/htmlediting.cpp: (WebCore::isListItem): (WebCore::appendedSublist):
  • editing/htmlediting.h:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r54406 r54413  
     12010-02-05  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=24872
     6        Add a test to make sure copying from a list and pasting into a list
     7        keeps the list at the same indention level rather than nesting.
     8
     9        * editing/pasteboard/paste-list-002-expected.txt: Added.
     10        * editing/pasteboard/paste-list-002.html: Added.
     11
    1122010-02-04  Fumitoshi Ukai  <ukai@chromium.org>
    213
  • trunk/WebCore/ChangeLog

    r54405 r54413  
     12010-02-05  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=24872
     6        When pasting a list into another list should not indent another level.
     7        If the cursor is at the beginning of the line, it should insert the
     8        list items before the current list item.  If the cursor is at the end
     9        of the line, it should insert the list items after the current list item.
     10
     11        This matches Firefox and IE and makes the common activity of reordering a list
     12        work as expected.
     13
     14        This also adds a small helper method (isListItem) to htmlediting.h.
     15
     16        Test: editing/pasteboard/paste-list-002.html
     17
     18        * editing/ReplaceSelectionCommand.cpp:
     19        (WebCore::ReplaceSelectionCommand::doApply):
     20        (WebCore::ReplaceSelectionCommand::insertAsListItems):
     21        * editing/ReplaceSelectionCommand.h:
     22        * editing/htmlediting.cpp:
     23        (WebCore::isListItem):
     24        (WebCore::appendedSublist):
     25        * editing/htmlediting.h:
     26
    1272010-02-04  Mark Rowe  <mrowe@apple.com>
    228
  • trunk/WebCore/editing/ReplaceSelectionCommand.cpp

    r54036 r54413  
    753753   
    754754    if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph && !startIsInsideMailBlockquote) ||
    755         startBlock == currentRoot ||
    756         (startBlock && startBlock->renderer() && startBlock->renderer()->isListItem()) ||
    757         selectionIsPlainText)
     755        startBlock == currentRoot || isListItem(startBlock) || selectionIsPlainText)
    758756        m_preventNesting = false;
    759757   
     
    872870   
    873871    fragment.removeNode(refNode);
    874     insertNodeAtAndUpdateNodesInserted(refNode, insertionPos);
     872
     873    Node* blockStart = enclosingBlock(insertionPos.node());
     874    if (isListElement(refNode.get()) && blockStart->renderer()->isListItem())
     875        refNode = insertAsListItems(refNode, blockStart, insertionPos);
     876    else
     877        insertNodeAtAndUpdateNodesInserted(refNode, insertionPos);
    875878
    876879    // Mutation events (bug 22634) may have already removed the inserted content
     
    961964            if (!isStartOfParagraph(endOfInsertedContent)) {
    962965                setEndingSelection(endOfInsertedContent);
    963                 // Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph
    964                 // block's style seems to annoy users.
    965                 insertParagraphSeparator(true);
     966                Node* enclosingNode = enclosingBlock(endOfInsertedContent.deepEquivalent().node());
     967                if (isListItem(enclosingNode)) {
     968                    RefPtr<Node> newListItem = createListItemElement(document());
     969                    insertNodeAfter(newListItem, enclosingNode);
     970                    setEndingSelection(VisiblePosition(Position(newListItem, 0)));
     971                } else
     972                    // Use a default paragraph element (a plain div) for the empty paragraph, using the last paragraph
     973                    // block's style seems to annoy users.
     974                    insertParagraphSeparator(true);
    966975
    967976                // Select up to the paragraph separator that was added.
     
    11121121}
    11131122
     1123// If the user is inserting a list into an existing list, instead of nesting the list,
     1124// we put the list items into the existing list.
     1125Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtr<Node> listElement, Node* insertionNode, const Position& p)
     1126{
     1127    while (listElement->hasChildNodes() && isListElement(listElement->firstChild()) && listElement->childNodeCount() == 1)
     1128        listElement = listElement->firstChild();
     1129
     1130    bool isStart = isStartOfParagraph(p);
     1131    bool isEnd = isEndOfParagraph(p);
     1132
     1133    Node* lastNode = insertionNode;
     1134    while (RefPtr<Node> listItem = listElement->firstChild()) {
     1135        ExceptionCode ec = 0;
     1136        listElement->removeChild(listItem.get(), ec);
     1137        ASSERT(!ec);
     1138        if (isStart)
     1139            insertNodeBefore(listItem, lastNode);
     1140        else if (isEnd) {
     1141            insertNodeAfter(listItem, lastNode);
     1142            lastNode = listItem.get();
     1143        } else {
     1144            // FIXME: If we're in the middle of a list item, we should split it into two separate
     1145            // list items and insert these nodes between them.  For now, just append the nodes.
     1146            insertNodeAfter(listItem, lastNode);
     1147            lastNode = listItem.get();
     1148        }
     1149    }
     1150    if (isStart)
     1151        lastNode = lastNode->previousSibling();
     1152    updateNodesInserted(lastNode);
     1153    return lastNode;
     1154}
     1155
    11141156void ReplaceSelectionCommand::updateNodesInserted(Node *node)
    11151157{
  • trunk/WebCore/editing/ReplaceSelectionCommand.h

    r42821 r54413  
    5555    void insertNodeAtAndUpdateNodesInserted(PassRefPtr<Node>, const Position&);
    5656    void insertNodeBeforeAndUpdateNodesInserted(PassRefPtr<Node> insertChild, Node* refChild);
     57    Node* insertAsListItems(PassRefPtr<Node>, Node* insertionNode, const Position&);
    5758
    5859    void updateNodesInserted(Node*);
  • trunk/WebCore/editing/htmlediting.cpp

    r54368 r54413  
    659659}
    660660
     661bool isListItem(Node *n)
     662{
     663    return n && n->renderer() && n->renderer()->isListItem();
     664}
     665
    661666Node* enclosingNodeWithTag(const Position& p, const QualifiedName& tagName)
    662667{
     
    780785        if (isListElement(n))
    781786            return static_cast<HTMLElement*>(n);
    782         if (n->renderer() && n->renderer()->isListItem())
     787        if (isListItem(listItem))
    783788            return 0;
    784789    }
  • trunk/WebCore/editing/htmlediting.h

    r54368 r54413  
    9191bool isTableStructureNode(const Node*);
    9292bool isListElement(Node*);
     93bool isListItem(Node*);
    9394bool isNodeRendered(const Node*);
    9495bool isNodeVisiblyContainedWithin(Node*, const Range*);
Note: See TracChangeset for help on using the changeset viewer.