Title: [125955] trunk
Revision
125955
Author
commit-qu...@webkit.org
Date
2012-08-17 17:31:00 -0700 (Fri, 17 Aug 2012)

Log Message

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

Patch by Alice Cheng <alice_ch...@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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (125954 => 125955)


--- trunk/LayoutTests/ChangeLog	2012-08-18 00:25:44 UTC (rev 125954)
+++ trunk/LayoutTests/ChangeLog	2012-08-18 00:31:00 UTC (rev 125955)
@@ -1,3 +1,18 @@
+2012-08-17  Alice Cheng  <alice_ch...@apple.com>
+
+        Preserve styling elements in DeleteSelectionCommand
+        <rdar://problem/12040676>
+        https://bugs.webkit.org/show_bug.cgi?id=93643
+
+        Reviewed by Ryosuke Niwa.
+
+        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.
+
 2012-08-17  Sukolsak Sakshuwong  <sukol...@google.com>
 
         Disconnect UndoManager when its undo scope host is destroyed

Added: trunk/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt (0 => 125955)


--- trunk/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt	2012-08-18 00:31:00 UTC (rev 125955)
@@ -0,0 +1,39 @@
+This tests deleting a selection that has a styling element in it. Should move styling elements to head to prevent style loss.
+
+styling elements have been moved:
+| "
+        "
+| <div>
+|   <#selection-caret>
+|   <br>
+| "
+    "
+| <style>
+|   " .text { color:red; } "
+| <link>
+|   href=""
+|   rel="stylesheet"
+|   type="text/css"
+
+styling elements are back to their original place:
+| "
+        "
+| <div>
+|   " <#selection-anchor>hide styling elements in --> "
+| "
+        "
+| <style>
+|   " .text { color:red; } "
+| "
+        "
+| <link>
+|   href=""
+|   rel="stylesheet"
+|   type="text/css"
+| "
+        "
+| <div>
+|   class="text"
+|   " between<#selection-focus> "
+| "
+    "

Added: trunk/LayoutTests/editing/execCommand/delete-selection-has-style.html (0 => 125955)


--- trunk/LayoutTests/editing/execCommand/delete-selection-has-style.html	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/delete-selection-has-style.html	2012-08-18 00:31:00 UTC (rev 125955)
@@ -0,0 +1,19 @@
+<!DOCTYPE html><body>
+    <div id="description">This tests deleting a selection that has a styling element in it. Should move styling elements to head to prevent style loss.</div>
+    <div id="rootEditableElement" contentEditable="true">
+        <div> hide styling elements in --> </div>
+        <style> .text { color:red; } </style>
+        <link rel="stylesheet" type="text/css" href="" />
+        <div class = "text"> between </div>
+    </div>
+<script src=""
+<script>
+Markup.description(document.getElementById('description').textContent);
+document.getElementById('rootEditableElement').focus();
+document.execCommand("SelectAll");
+document.execCommand("Delete");
+Markup.dump('rootEditableElement', 'styling elements have been moved');
+document.execCommand("Undo");
+Markup.dump('rootEditableElement', 'styling elements are back to their original place');
+</script>
+</body></html>

Modified: trunk/Source/WebCore/ChangeLog (125954 => 125955)


--- trunk/Source/WebCore/ChangeLog	2012-08-18 00:25:44 UTC (rev 125954)
+++ trunk/Source/WebCore/ChangeLog	2012-08-18 00:31:00 UTC (rev 125955)
@@ -1,3 +1,23 @@
+2012-08-17  Alice Cheng  <alice_ch...@apple.com>
+
+        Preserve styling elements in DeleteSelectionCommand
+        <rdar://problem/12040676>
+        https://bugs.webkit.org/show_bug.cgi?id=93643
+
+        Reviewed by Ryosuke Niwa.
+
+        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):
+
 2012-08-17  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r125940.

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp (125954 => 125955)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2012-08-18 00:25:44 UTC (rev 125954)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2012-08-18 00:31:00 UTC (rev 125955)
@@ -416,6 +416,22 @@
     CompositeEditCommand::deleteTextFromNode(node, offset, count);
 }
 
+void DeleteSelectionCommand::makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss()
+{
+    RefPtr<Range> range = m_selectionToDelete.toNormalizedRange();
+    RefPtr<Node> node = range->firstNode();
+    while (node && node != range->pastLastNode()) {
+        RefPtr<Node> nextNode = node->traverseNextNode();
+        if ((node->hasTagName(styleTag) && !(toElement(node.get())->hasAttribute(scopedAttr))) || node->hasTagName(linkTag)) {
+            nextNode = node->traverseNextSibling();
+            RefPtr<ContainerNode> rootEditableElement = node->rootEditableElement();
+            removeNode(node);
+            appendNode(node, rootEditableElement);
+        }
+        node = nextNode;
+    }
+}
+
 void DeleteSelectionCommand::handleGeneralDelete()
 {
     if (m_upstreamStart.isNull())
@@ -423,6 +439,8 @@
 
     int startOffset = m_upstreamStart.deprecatedEditingOffset();
     Node* startNode = m_upstreamStart.deprecatedNode();
+    
+    makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss();
 
     // Never remove the start block unless it's a table, in which case we won't merge content in.
     if (startNode == m_startBlock && startOffset == 0 && canHaveChildrenForEditing(startNode) && !startNode->hasTagName(tableTag)) {

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.h (125954 => 125955)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.h	2012-08-18 00:25:44 UTC (rev 125954)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.h	2012-08-18 00:31:00 UTC (rev 125955)
@@ -65,6 +65,7 @@
     void calculateEndingPosition();
     void calculateTypingStyleAfterDelete();
     void clearTransientState();
+    void makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss();
     virtual void removeNode(PassRefPtr<Node>);
     virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned, unsigned);
     void removeRedundantBlocks();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to