Changeset 125955 in webkit


Ignore:
Timestamp:
Aug 17, 2012 5:31:00 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Preserve styling elements in DeleteSelectionCommand
<rdar://problem/12040676>
https://bugs.webkit.org/show_bug.cgi?id=93643

Patch by Alice Cheng <alice_cheng@apple.com> on 2012-08-17
Reviewed by Ryosuke Niwa.

Source/WebCore:

Styling elements (<link> and <style>) can appear inside editable content. To
prevent accidental deletion, we move styling elements to rootEditableElement in
DeleteSelectionCommand undoably.

Test: editing/execCommand/delete-selection-has-style.html

  • editing/DeleteSelectionCommand.cpp:

(WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss): Added to preserve styling elements during the command
(WebCore::DeleteSelectionCommand::handleGeneralDelete): Modified to preserve styling elements during the command

  • editing/DeleteSelectionCommand.h:

(DeleteSelectionCommand):

LayoutTests:

Test if delete selection command does move styling elements to
rootEditableElement, when the selection contains some. Also test command's
undoness.

  • editing/execCommand/delete-selection-has-style-expected.txt: Added.
  • editing/execCommand/delete-selection-has-style.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r125951 r125955  
     12012-08-17  Alice Cheng  <alice_cheng@apple.com>
     2
     3        Preserve styling elements in DeleteSelectionCommand
     4        <rdar://problem/12040676>
     5        https://bugs.webkit.org/show_bug.cgi?id=93643
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Test if delete selection command does move styling elements to
     10        rootEditableElement, when the selection contains some. Also test command's
     11        undoness.
     12
     13        * editing/execCommand/delete-selection-has-style-expected.txt: Added.
     14        * editing/execCommand/delete-selection-has-style.html: Added.
     15
    1162012-08-17  Sukolsak Sakshuwong  <sukolsak@google.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r125953 r125955  
     12012-08-17  Alice Cheng  <alice_cheng@apple.com>
     2
     3        Preserve styling elements in DeleteSelectionCommand
     4        <rdar://problem/12040676>
     5        https://bugs.webkit.org/show_bug.cgi?id=93643
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Styling elements (<link> and <style>) can appear inside editable content. To
     10        prevent accidental deletion, we move styling elements to rootEditableElement in
     11        DeleteSelectionCommand undoably.
     12
     13        Test: editing/execCommand/delete-selection-has-style.html
     14
     15        * editing/DeleteSelectionCommand.cpp:
     16        (WebCore::DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss): Added to preserve styling elements during the command
     17        (WebCore::DeleteSelectionCommand::handleGeneralDelete):  Modified to preserve styling elements during the command
     18        * editing/DeleteSelectionCommand.h:
     19        (DeleteSelectionCommand):
     20
    1212012-08-17  Sheriff Bot  <webkit.review.bot@gmail.com>
    222
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r121303 r125955  
    417417}
    418418
     419void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss()
     420{
     421    RefPtr<Range> range = m_selectionToDelete.toNormalizedRange();
     422    RefPtr<Node> node = range->firstNode();
     423    while (node && node != range->pastLastNode()) {
     424        RefPtr<Node> nextNode = node->traverseNextNode();
     425        if ((node->hasTagName(styleTag) && !(toElement(node.get())->hasAttribute(scopedAttr))) || node->hasTagName(linkTag)) {
     426            nextNode = node->traverseNextSibling();
     427            RefPtr<ContainerNode> rootEditableElement = node->rootEditableElement();
     428            removeNode(node);
     429            appendNode(node, rootEditableElement);
     430        }
     431        node = nextNode;
     432    }
     433}
     434
    419435void DeleteSelectionCommand::handleGeneralDelete()
    420436{
     
    424440    int startOffset = m_upstreamStart.deprecatedEditingOffset();
    425441    Node* startNode = m_upstreamStart.deprecatedNode();
     442   
     443    makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss();
    426444
    427445    // Never remove the start block unless it's a table, in which case we won't merge content in.
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.h

    r116368 r125955  
    6666    void calculateTypingStyleAfterDelete();
    6767    void clearTransientState();
     68    void makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss();
    6869    virtual void removeNode(PassRefPtr<Node>);
    6970    virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned, unsigned);
Note: See TracChangeset for help on using the changeset viewer.