LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 22:06:53 +0000 (22:06 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 22:06:53 +0000 (22:06 +0000)
        Reviewed by hyatt

        <rdar://problem/4888891>
        Docs & Spreadsheets: Comment fails to insert if text is selected in the document

        * fast/dom/Range/surroundContents-1-expected.checksum: Added.
        * fast/dom/Range/surroundContents-1-expected.png: Added.
        * fast/dom/Range/surroundContents-1-expected.txt: Added.
        * fast/dom/Range/surroundContents-1.html: Added.

WebCore:

        Reviewed by hyatt

        <rdar://problem/4888891>
        Docs & Spreadsheets: Comment fails to insert if text is selected in the document

        * dom/Range.cpp:
        (WebCore::Range::surroundContents): If startContainer is a text node,
        it will be split when the range is extracted, and it will be its parent
        that will have to accept newParent.  Also cleaned up some code with
        isDescendantOf.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18325 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/Range/surroundContents-1-expected.checksum [new file with mode: 0644]
LayoutTests/fast/dom/Range/surroundContents-1-expected.png [new file with mode: 0644]
LayoutTests/fast/dom/Range/surroundContents-1-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Range/surroundContents-1.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Range.cpp

index b0a6bea..e0142c9 100644 (file)
@@ -1,3 +1,15 @@
+2006-12-19  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by hyatt
+        
+        <rdar://problem/4888891>
+        Docs & Spreadsheets: Comment fails to insert if text is selected in the document
+        
+        * fast/dom/Range/surroundContents-1-expected.checksum: Added.
+        * fast/dom/Range/surroundContents-1-expected.png: Added.
+        * fast/dom/Range/surroundContents-1-expected.txt: Added.
+        * fast/dom/Range/surroundContents-1.html: Added.
+
 2006-12-19  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Oliver.
diff --git a/LayoutTests/fast/dom/Range/surroundContents-1-expected.checksum b/LayoutTests/fast/dom/Range/surroundContents-1-expected.checksum
new file mode 100644 (file)
index 0000000..af1c6f9
--- /dev/null
@@ -0,0 +1 @@
+0cd5915a6799238dcad7f1a00939ff64
\ No newline at end of file
diff --git a/LayoutTests/fast/dom/Range/surroundContents-1-expected.png b/LayoutTests/fast/dom/Range/surroundContents-1-expected.png
new file mode 100644 (file)
index 0000000..220638e
Binary files /dev/null and b/LayoutTests/fast/dom/Range/surroundContents-1-expected.png differ
diff --git a/LayoutTests/fast/dom/Range/surroundContents-1-expected.txt b/LayoutTests/fast/dom/Range/surroundContents-1-expected.txt
new file mode 100644 (file)
index 0000000..e4c52ef
--- /dev/null
@@ -0,0 +1,15 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x576
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 563x18
+          text run at (0,0) width 563: "This tests for HIERARCHY_REQUEST_ERRs when calling Range::surroundContents."
+      RenderBlock {DIV} at (0,34) size 784x22 [border: (1px solid #0000FF)]
+        RenderBlock (anonymous) at (1,1) size 782x0
+          RenderText {#text} at (0,0) size 0x0
+        RenderBlock {DIV} at (1,1) size 782x20 [border: (1px solid #FF0000)]
+          RenderText {#text} at (1,1) size 80x18
+            text run at (1,1) width 80: "Hello world."
+      RenderBlock {UL} at (0,72) size 784x0
diff --git a/LayoutTests/fast/dom/Range/surroundContents-1.html b/LayoutTests/fast/dom/Range/surroundContents-1.html
new file mode 100644 (file)
index 0000000..1169c9a
--- /dev/null
@@ -0,0 +1,35 @@
+<p>This tests for HIERARCHY_REQUEST_ERRs when calling Range::surroundContents.</p>
+<div id="select" style="border: 1px solid blue;">Hello world.</div>
+<div id="insert" style="border: 1px solid red;"></div>
+<ul id="console"></ul>
+<script>
+function log(str) {
+    var li = document.createElement("li");
+    li.appendChild(document.createTextNode(str));
+    var console = document.getElementById("console");
+    console.appendChild(li);
+}
+
+var range = document.createRange();
+var select = document.getElementById("select");
+var text = select.firstChild;
+
+var insert = document.getElementById("insert");
+
+range.setStart(text, 0);
+range.setEnd(text, text.length);
+
+try {
+    range.surroundContents(select);    
+} catch (e) {
+    var error = "Error: HIERARCHY_REQUEST_ERR: DOM Exception 3";
+    if (e != error)
+        log ("Failure, expected: " + error);
+}
+
+try {
+    range.surroundContents(insert); 
+} catch (e) {
+    log ("Failure: " + error);
+}
+</script>
index 19630d3..3056650 100644 (file)
@@ -1,3 +1,16 @@
+2006-12-19  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by hyatt
+        
+        <rdar://problem/4888891>
+        Docs & Spreadsheets: Comment fails to insert if text is selected in the document
+        
+        * dom/Range.cpp:
+        (WebCore::Range::surroundContents): If startContainer is a text node,
+        it will be split when the range is extracted, and it will be its parent
+        that will have to accept newParent.  Also cleaned up some code with 
+        isDescendantOf.
+
 2006-12-19  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Darin.
index 8b7661d..4998960 100644 (file)
@@ -1340,19 +1340,20 @@ void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec)
         return;
     }
 
-    // HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that
-    // does not allow children of the type of newParent or if newParent is an ancestor of the container
-    // or if node would end up with a child node of a type not allowed by the type of node.
-    if (!m_startContainer->childTypeAllowed(newParent->nodeType())) {
+    // Raise a HIERARCHY_REQUEST_ERR if m_startContainer doesn't accept children like newParent.
+    Node* parentOfNewParent = m_startContainer.get();
+    // If m_startContainer is a textNode, it will be split and it will be its parent that will 
+    // need to accept newParent.
+    if (parentOfNewParent->isTextNode())
+        parentOfNewParent = parentOfNewParent->parentNode();
+    if (!parentOfNewParent->childTypeAllowed(newParent->nodeType())) {
         ec = HIERARCHY_REQUEST_ERR;
         return;
     }
-
-    for (Node *n = m_startContainer.get(); n; n = n->parentNode()) {
-        if (n == newParent) {
-            ec = HIERARCHY_REQUEST_ERR;
-            return;
-        }
+    
+    if (m_startContainer == newParent || m_startContainer->isDescendantOf(newParent.get())) {
+        ec = HIERARCHY_REQUEST_ERR;
+        return;
     }
 
     // ### check if node would end up with a child node of a type not allowed by the type of node