LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 19:44:24 +0000 (19:44 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Oct 2006 19:44:24 +0000 (19:44 +0000)
        Reviewed by john

        <http://bugs.webkit.org/show_bug.cgi?id=11329>
        Gmail Editor: Can't remove styling applied to selection after clicking "Remove Formatting" toolbar icon.

        * editing/execCommand/remove-formatting-2-expected.checksum: Added.
        * editing/execCommand/remove-formatting-2-expected.png: Added.
        * editing/execCommand/remove-formatting-2-expected.txt: Added.
        * editing/execCommand/remove-formatting-2.html: Added.
        * editing/execCommand/remove-formatting-expected.txt:

WebCore:

        Reviewed by john

        <http://bugs.webkit.org/show_bug.cgi?id=11329>
        Gmail Editor: Can't remove styling applied to selection after clicking "Remove Formatting" toolbar icon.

        * editing/Editor.cpp:
        (WebCore::Editor::removeFormattingAndStyle): Moved from JSEditor.
        Wrapped the plain text fragment in a style span with the document
        default style so that it will appear unstyled regardless of where
        it is inserted.  Could have also inserted the plain text fragment
        and then applied the document default style to it, but there is not
        yet any redundant style prevention in ApplyStyleCommand, so this
        is cleaner.
        * editing/Editor.h:
        * editing/JSEditor.cpp:

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

LayoutTests/ChangeLog
LayoutTests/editing/execCommand/remove-formatting-2-expected.checksum [new file with mode: 0644]
LayoutTests/editing/execCommand/remove-formatting-2-expected.png [new file with mode: 0644]
LayoutTests/editing/execCommand/remove-formatting-2-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/remove-formatting-2.html [new file with mode: 0644]
LayoutTests/editing/execCommand/remove-formatting-expected.txt
WebCore/ChangeLog
WebCore/editing/Editor.cpp
WebCore/editing/Editor.h
WebCore/editing/JSEditor.cpp

index d59a4e43e485b1681135551f58ad2f92592cbd6c..a9a447362cce153caf7120ff94640178ff5e77b2 100644 (file)
@@ -1,3 +1,16 @@
+2006-10-26  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by john
+        
+        <http://bugs.webkit.org/show_bug.cgi?id=11329>
+        Gmail Editor: Can't remove styling applied to selection after clicking "Remove Formatting" toolbar icon.
+
+        * editing/execCommand/remove-formatting-2-expected.checksum: Added.
+        * editing/execCommand/remove-formatting-2-expected.png: Added.
+        * editing/execCommand/remove-formatting-2-expected.txt: Added.
+        * editing/execCommand/remove-formatting-2.html: Added.
+        * editing/execCommand/remove-formatting-expected.txt:
+
 2006-10-26  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Anders.
diff --git a/LayoutTests/editing/execCommand/remove-formatting-2-expected.checksum b/LayoutTests/editing/execCommand/remove-formatting-2-expected.checksum
new file mode 100644 (file)
index 0000000..4c18cfd
--- /dev/null
@@ -0,0 +1 @@
+d7ae305d9b161eed95c6b7a643adce6c
\ No newline at end of file
diff --git a/LayoutTests/editing/execCommand/remove-formatting-2-expected.png b/LayoutTests/editing/execCommand/remove-formatting-2-expected.png
new file mode 100644 (file)
index 0000000..9120216
Binary files /dev/null and b/LayoutTests/editing/execCommand/remove-formatting-2-expected.png differ
diff --git a/LayoutTests/editing/execCommand/remove-formatting-2-expected.txt b/LayoutTests/editing/execCommand/remove-formatting-2-expected.txt
new file mode 100644 (file)
index 0000000..ef7a2e7
--- /dev/null
@@ -0,0 +1,23 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 4 of #text > DIV > BODY > HTML > #document to 4 of #text > DIV > 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 784x36
+        RenderText {#text} at (0,0) size 722x36
+          text run at (0,0) width 722: "This tests that RemoveFormat not only removes style from the selected part of the DOM, but that it also applies the"
+          text run at (0,18) width 625: "document default style to the selection if that's necessary in order to leave the selected text unstyled."
+      RenderBlock {DIV} at (0,52) size 784x18
+        RenderText {#text} at (0,0) size 28x18
+          text run at (0,0) width 28: "This"
+        RenderText {#text} at (28,0) size 277x18
+          text run at (28,0) width 277: " text should look the same as the text above."
+caret: position 4 of child 0 {#text} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/execCommand/remove-formatting-2.html b/LayoutTests/editing/execCommand/remove-formatting-2.html
new file mode 100644 (file)
index 0000000..734db64
--- /dev/null
@@ -0,0 +1,12 @@
+<p>This tests that RemoveFormat not only removes style from the selected part of the DOM, but that it also applies the document default style to the selection if that's necessary in order to leave the selected text unstyled.</p>
+<div id="div" contenteditable="true"><b>This</b> text should look the same as the text above.</div>
+
+<script>
+var sel = window.getSelection();
+var div = document.getElementById("div");
+
+sel.setPosition(div, 0);
+
+sel.modify("extend", "forward", "word");
+document.execCommand("RemoveFormat");
+</script>
\ No newline at end of file
index fabb9f101269be8b810e490ca29448a0a321fad7..e4ec83aa05998648b4121edb1a1ed02f40bb9e7a 100644 (file)
@@ -19,6 +19,7 @@ layer at (0,0) size 800x600
         RenderBlock {DIV} at (0,0) size 784x18
           RenderText {#text} at (0,0) size 63x18
             text run at (0,0) width 63: "foobarbaz"
+        RenderBlock (anonymous) at (0,18) size 784x0
         RenderBlock {DIV} at (0,18) size 784x18
           RenderText {#text} at (0,0) size 21x18
             text run at (0,0) width 21: "foo"
index 74789dde55207b8c8f0bf0670113cc83c56d43f4..3690474cfd79d1c4e87417e739dceac9a624b410 100644 (file)
@@ -1,3 +1,21 @@
+2006-10-26  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by john
+
+        <http://bugs.webkit.org/show_bug.cgi?id=11329>
+        Gmail Editor: Can't remove styling applied to selection after clicking "Remove Formatting" toolbar icon.
+        
+        * editing/Editor.cpp:
+        (WebCore::Editor::removeFormattingAndStyle): Moved from JSEditor.
+        Wrapped the plain text fragment in a style span with the document 
+        default style so that it will appear unstyled regardless of where
+        it is inserted.  Could have also inserted the plain text fragment 
+        and then applied the document default style to it, but there is not 
+        yet any redundant style prevention in ApplyStyleCommand, so this
+        is cleaner.
+        * editing/Editor.h:
+        * editing/JSEditor.cpp:
+
 2006-10-26  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Anders.
index d13a58963cfdb8f139ea10760b41acc3fc7b0a77..d2cbe5803893bd09e0351575db4d04bf595c6e26 100644 (file)
 #include "config.h"
 #include "Editor.h"
 
+#include "ApplyStyleCommand.h"
+#include "CSSComputedStyleDeclaration.h"
 #include "DeleteButtonController.h"
+#include "Document.h"
+#include "DocumentFragment.h"
 #include "EditorClient.h"
+#include "EditCommand.h"
 #include "htmlediting.h"
 #include "HTMLElement.h"
 #include "HTMLNames.h"
+#include "markup.h"
 #include "Range.h"
+#include "ReplaceSelectionCommand.h"
 #include "SelectionController.h"
 #include "Sound.h"
 
@@ -198,6 +205,33 @@ Frame::TriState Editor::selectionOrderedListState() const
     return Frame::falseTriState;
 }
 
+void Editor::removeFormattingAndStyle()
+{
+    Document* document = frame()->document();
+    
+    // Make a plain text string from the selection to remove formatting like tables and lists.
+    RefPtr<DocumentFragment> text = createFragmentFromText(frame()->selectionController()->toRange().get(), frame()->selectionController()->toString());
+    
+    // Put the fragment made from that string into a style span with the document's
+    // default style to make sure that it is unstyled regardless of where it is inserted.
+    Position pos(document->documentElement(), 0);
+    RefPtr<CSSComputedStyleDeclaration> computedStyle = pos.computedStyle();
+    RefPtr<CSSMutableStyleDeclaration> defaultStyle = computedStyle->copyInheritableProperties();
+    
+    RefPtr<Element> span = createStyleSpanElement(document);
+    span->setAttribute(styleAttr, defaultStyle->cssText());
+    
+    ExceptionCode ec;
+    
+    while (text->lastChild())
+        span->appendChild(text->lastChild(), ec);
+    
+    RefPtr<DocumentFragment> fragment = new DocumentFragment(document);
+    fragment->appendChild(span, ec);
+    
+    applyCommand(new ReplaceSelectionCommand(document, fragment, false, false, false, true, EditActionUnspecified));
+}
+
 // =============================================================================
 //
 // public editing commands
index 838091639e17339d40fb9694e8f2a868d210dc17..4a99e659fff5ac0ffbd6704e552a75c290d05650 100644 (file)
@@ -61,6 +61,8 @@ public:
     
     Frame::TriState selectionUnorderedListState() const;
     Frame::TriState selectionOrderedListState() const;
+    
+    void removeFormattingAndStyle();
 
     Frame* frame() const { return m_frame; }
     DeleteButtonController* deleteButtonController() const { return m_deleteButtonController.get(); }
index a4e91d1659656fb7357df08ba983d07420771b12..424d31bd9a983d045bc5826e20dba2f20b4809b1 100644 (file)
@@ -413,9 +413,7 @@ bool execRedo(Frame* frame, bool, const String&)
 
 bool execRemoveFormat(Frame* frame, bool userInterface, const String& value)
 {
-    applyCommand(new ReplaceSelectionCommand(frame->document(),
-        createFragmentFromText(frame->selectionController()->toRange().get(), frame->selectionController()->toString()),
-        false, false, false, true, EditActionUnspecified));
+    frame->editor()->removeFormattingAndStyle();
     return true;
 }