Title: [148544] branches/safari-536.30-branch

Diff

Modified: branches/safari-536.30-branch/LayoutTests/ChangeLog (148543 => 148544)


--- branches/safari-536.30-branch/LayoutTests/ChangeLog	2013-04-16 21:22:17 UTC (rev 148543)
+++ branches/safari-536.30-branch/LayoutTests/ChangeLog	2013-04-16 21:35:00 UTC (rev 148544)
@@ -1,3 +1,23 @@
+2013-04-16  Ryosuke Niwa  <[email protected]>
+
+        Merge r125955.
+
+    2012-08-17  Alice Cheng  <[email protected]>
+
+            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.
+
+
 2013-04-16  Lucas Forschler  <[email protected]>
 
         Merge r130313

Copied: branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt (from rev 125955, trunk/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt) (0 => 148544)


--- branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt	                        (rev 0)
+++ branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style-expected.txt	2013-04-16 21:35:00 UTC (rev 148544)
@@ -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> "
+| "
+    "

Copied: branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style.html (from rev 125955, trunk/LayoutTests/editing/execCommand/delete-selection-has-style.html) (0 => 148544)


--- branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style.html	                        (rev 0)
+++ branches/safari-536.30-branch/LayoutTests/editing/execCommand/delete-selection-has-style.html	2013-04-16 21:35:00 UTC (rev 148544)
@@ -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: branches/safari-536.30-branch/Source/WebCore/ChangeLog (148543 => 148544)


--- branches/safari-536.30-branch/Source/WebCore/ChangeLog	2013-04-16 21:22:17 UTC (rev 148543)
+++ branches/safari-536.30-branch/Source/WebCore/ChangeLog	2013-04-16 21:35:00 UTC (rev 148544)
@@ -1,3 +1,27 @@
+2013-04-16  Ryosuke Niwa  <[email protected]>
+
+        Merge r125955.
+
+    2012-08-17  Alice Cheng  <[email protected]>
+
+            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):
+
 2013-04-16  Lucas Forschler  <[email protected]>
 
         Merge r130313

Modified: branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.cpp (148543 => 148544)


--- branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.cpp	2013-04-16 21:22:17 UTC (rev 148543)
+++ branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.cpp	2013-04-16 21:35:00 UTC (rev 148544)
@@ -408,6 +408,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())
@@ -415,6 +431,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: branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.h (148543 => 148544)


--- branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.h	2013-04-16 21:22:17 UTC (rev 148543)
+++ branches/safari-536.30-branch/Source/WebCore/editing/DeleteSelectionCommand.h	2013-04-16 21:35:00 UTC (rev 148544)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to