LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2006 00:42:39 +0000 (00:42 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2006 00:42:39 +0000 (00:42 +0000)
        Reviewed by harrison

        * editing/style/non-inheritable-styles-expected.checksum: Added.
        * editing/style/non-inheritable-styles-expected.png: Added.
        * editing/style/non-inheritable-styles-expected.txt: Added.
        * editing/style/non-inheritable-styles.html: Added.

WebCore:

        Reviewed by harrison

        <rdar://problem/4641033/4515463/4052426/4046570/4053718/4053724/4060115/4062858>
        Copy/Paste fidelity was bad.

        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::applyInlineStyle):
        * editing/markup.cpp:
        (WebCore::startMarkup): We were not adding non-inheritable styles
        to the markup for an element unless they were in the elements inline
        style declaration.

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

LayoutTests/ChangeLog
LayoutTests/editing/style/non-inheritable-styles-expected.checksum [new file with mode: 0644]
LayoutTests/editing/style/non-inheritable-styles-expected.png [new file with mode: 0644]
LayoutTests/editing/style/non-inheritable-styles-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/non-inheritable-styles.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/ApplyStyleCommand.cpp
WebCore/editing/markup.cpp

index 03ab2c3..3d5bf11 100644 (file)
@@ -1,5 +1,14 @@
 2006-08-03  Justin Garcia  <justin.garcia@apple.com>
 
+        Reviewed by harrison
+        
+        * editing/style/non-inheritable-styles-expected.checksum: Added.
+        * editing/style/non-inheritable-styles-expected.png: Added.
+        * editing/style/non-inheritable-styles-expected.txt: Added.
+        * editing/style/non-inheritable-styles.html: Added.
+
+2006-08-03  Justin Garcia  <justin.garcia@apple.com>
+
         Reviewed by darin
 
         * fast/forms/plaintext-mode-1-expected.txt:
diff --git a/LayoutTests/editing/style/non-inheritable-styles-expected.checksum b/LayoutTests/editing/style/non-inheritable-styles-expected.checksum
new file mode 100644 (file)
index 0000000..535893d
--- /dev/null
@@ -0,0 +1 @@
+90362ed413c7ab542a3b1c78fd6bca1a
\ No newline at end of file
diff --git a/LayoutTests/editing/style/non-inheritable-styles-expected.png b/LayoutTests/editing/style/non-inheritable-styles-expected.png
new file mode 100644 (file)
index 0000000..9d672b4
Binary files /dev/null and b/LayoutTests/editing/style/non-inheritable-styles-expected.png differ
diff --git a/LayoutTests/editing/style/non-inheritable-styles-expected.txt b/LayoutTests/editing/style/non-inheritable-styles-expected.txt
new file mode 100644 (file)
index 0000000..cedd838
--- /dev/null
@@ -0,0 +1,44 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of SPAN > BODY > HTML > #document to 3 of SPAN > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of SPAN > BODY > HTML > #document to 0 of SPAN > BODY > HTML > #document toDOMRange:range from 1 of #text > SPAN > BODY > HTML > #document to 30 of #text > SPAN > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldEndEditingInDOMRange:range from 0 of SPAN > BODY > HTML > #document to 3 of SPAN > BODY > HTML > #document
+EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of SPAN > BODY > HTML > #document to 0 of SPAN > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of SPAN > BODY > HTML > #document to 0 of SPAN > BODY > HTML > #document givenAction:WebViewInsertActionPasted
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of SPAN > BODY > HTML > #document to 0 of SPAN > BODY > HTML > #document toDOMRange:range from 29 of #text > SPAN > BODY > HTML > #document to 29 of #text > SPAN > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 507x18
+          text run at (0,0) width 102: "This tests copy. "
+          text run at (102,0) width 405: "Non-inheritable styles should be brought down from stylesheets."
+      RenderBlock {SPAN} at (0,34) size 784x54
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 183x18
+            text run at (0,0) width 183: "This shouldn't have a border."
+        RenderBlock {DIV} at (0,18) size 784x18
+          RenderText {#text} at (0,0) size 289x18
+            text run at (0,0) width 289: "This should have blue border when its pasted."
+        RenderBlock (anonymous) at (0,36) size 784x18
+          RenderText {#text} at (0,0) size 183x18
+            text run at (0,0) width 183: "This shouldn't have a border."
+      RenderBlock {SPAN} at (0,88) size 784x56
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 183x18
+            text run at (0,0) width 183: "This shouldn't have a border."
+        RenderBlock {DIV} at (0,18) size 784x20 [border: (1px solid #0000FF)]
+          RenderText {#text} at (1,1) size 289x18
+            text run at (1,1) width 289: "This should have blue border when its pasted."
+        RenderBlock (anonymous) at (0,38) size 784x18
+          RenderText {#text} at (0,0) size 183x18
+            text run at (0,0) width 183: "This shouldn't have a border."
+caret: position 29 of child 2 {#text} of child 5 {SPAN} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/style/non-inheritable-styles.html b/LayoutTests/editing/style/non-inheritable-styles.html
new file mode 100644 (file)
index 0000000..b38cf32
--- /dev/null
@@ -0,0 +1,37 @@
+<style>
+div {
+    border: 1px solid red;
+}
+#id {
+    border: 1px solid blue;
+}
+.class {
+    border: 1px solid black;
+}
+</style>
+
+<body>
+<p>This tests copy.  Non-inheritable styles should be brought down from stylesheets.</p>
+<span id="copy" style="display:block" contenteditable="true">
+This shouldn't have a border.
+<div class="class" id="id">This should have blue border when its pasted.</div>
+This shouldn't have a border.</span>
+<span id="paste" style="display:block" contenteditable="true"></span>
+
+</body>
+<script>
+var sel = window.getSelection();
+var copy = document.getElementById("copy");
+var paste = document.getElementById("paste");
+
+sel.setPosition(copy, 0);
+document.execCommand("SelectAll");
+document.execCommand("Copy");
+var len = document.styleSheets[0].cssRules.length;
+for (var i = 0; i < len; i++)
+    document.styleSheets[0].deleteRule(0);
+
+sel.setPosition(paste, 0);
+document.execCommand("Paste");
+</script>
+</body>
\ No newline at end of file
index 5c076f1..582b6cf 100644 (file)
@@ -1,3 +1,17 @@
+2006-08-03  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <rdar://problem/4641033/4515463/4052426/4046570/4053718/4053724/4060115/4062858>
+        Copy/Paste fidelity was bad.
+
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::applyInlineStyle):
+        * editing/markup.cpp:
+        (WebCore::startMarkup): We were not adding non-inheritable styles
+        to the markup for an element unless they were in the elements inline
+        style declaration.
+
 2006-08-03  Sam Weinig  <sam.weinig@gmail.com>
 
         Reviewed by Darin.
index bef2ce3..6839f41 100644 (file)
@@ -595,17 +595,18 @@ void ApplyStyleCommand::applyInlineStyle(CSSMutableStyleDeclaration *style)
             rangeIsEmpty = true;
     }
 
+    // If end is [table, maxDeepOffset(table)], that means that the table is selected, and we want to visit
+    // contents of the table, instead of stopping at it.
     if (end.node()->renderer() && end.node()->renderer()->isTable() && end.offset() == maxDeepOffset(end.node()))
         endNode = end.node()->lastDescendant();
+    // If the end node is an ancestor of the start node then a pre-order
+    // traversal will never reach it.  Adjust it so that this won't happen.
+    if (node->isAncestor(endNode))
+        endNode = endNode->lastDescendant();
     
     if (node == endNode) {
         addInlineStyleIfNeeded(style, node, node);
     } else if (!rangeIsEmpty) {
-        // If the end node is an ancestor of the start node then we need
-        // to replace endNode with its next sibling to ensure that the
-        // exit condition node == endNode is reached
-        if (node->isAncestor(endNode))
-            endNode = endNode->traverseNextSibling();
     
         while (1) {
             if (node->childNodeCount() == 0 && node->renderer() && node->renderer()->isInline() && node->isContentRichlyEditable()) {
index 92844ab..a6a9672 100644 (file)
 #include "markup.h"
 
 #include "CSSComputedStyleDeclaration.h"
+#include "CSSRule.h"
+#include "CSSRuleList.h"
+#include "CSSStyleRule.h"
+#include "cssstyleselector.h"
 #include "Comment.h"
 #include "Document.h"
 #include "DocumentFragment.h"
@@ -161,6 +165,15 @@ static DeprecatedString startMarkup(const Node *node, const Range *range, EAnnot
             if (defaultStyle && el->isHTMLElement()) {
                 RefPtr<CSSComputedStyleDeclaration> computedStyle = Position(const_cast<Element*>(el), 0).computedStyle();
                 RefPtr<CSSMutableStyleDeclaration> style = computedStyle->copyInheritableProperties();
+                RefPtr<CSSRuleList> matchedRules = node->document()->styleSelector()->styleRulesForElement(const_cast<Element*>(el), true);
+                if (matchedRules) {
+                    for (unsigned i = 0; i < matchedRules->length(); i++) {
+                        if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE) {
+                            RefPtr<CSSMutableStyleDeclaration> s = static_cast<CSSStyleRule*>(matchedRules->item(i))->style();
+                            style->merge(s.get(), true);
+                        }
+                    }
+                }
                 defaultStyle->diff(style.get());
                 if (style->length() > 0) {
                     CSSMutableStyleDeclaration *inlineStyleDecl = static_cast<const HTMLElement*>(el)->inlineStyleDecl();