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
+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.
--- /dev/null
+d7ae305d9b161eed95c6b7a643adce6c
\ No newline at end of file
--- /dev/null
+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
--- /dev/null
+<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
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"
+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.
#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"
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
Frame::TriState selectionUnorderedListState() const;
Frame::TriState selectionOrderedListState() const;
+
+ void removeFormattingAndStyle();
Frame* frame() const { return m_frame; }
DeleteButtonController* deleteButtonController() const { return m_deleteButtonController.get(); }
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;
}