Title: [109529] trunk
Revision
109529
Author
[email protected]
Date
2012-03-02 01:20:39 -0800 (Fri, 02 Mar 2012)

Log Message

Implement DefaultParagraphSeparator execCommand, to let authors choose the default block element
https://bugs.webkit.org/show_bug.cgi?id=59961

Patch by Pablo Flouret <[email protected]> on 2012-03-02
Reviewed by Ryosuke Niwa.

Source/WebCore:

http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#the-defaultparagraphseparator-command

Test: editing/execCommand/default-paragraph-separator.html

* editing/Editor.cpp:
(WebCore::Editor::Editor):
* editing/Editor.h:
(WebCore::Editor::defaultParagraphSeparator):
(WebCore::Editor::setDefaultParagraphSeparator):
(Editor):
* editing/EditorCommand.cpp:
(WebCore::executeDefaultParagraphSeparator):
(WebCore):
(WebCore::valueDefaultParagraphSeparator):
(WebCore::createCommandMap):
* editing/htmlediting.cpp:
(WebCore::createDefaultParagraphElement):

* html/HTMLParagraphElement.cpp:
(WebCore::HTMLParagraphElement::create):
(WebCore):
* html/HTMLParagraphElement.h:
(HTMLParagraphElement):
    Added create(Document*) method that defaults to pTag as the QualifiedName.

LayoutTests:

* editing/execCommand/default-paragraph-separator-expected.txt: Added.
* editing/execCommand/default-paragraph-separator.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (109528 => 109529)


--- trunk/LayoutTests/ChangeLog	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/LayoutTests/ChangeLog	2012-03-02 09:20:39 UTC (rev 109529)
@@ -1,3 +1,13 @@
+2012-03-02  Pablo Flouret  <[email protected]>
+
+        Implement DefaultParagraphSeparator execCommand, to let authors choose the default block element
+        https://bugs.webkit.org/show_bug.cgi?id=59961
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/execCommand/default-paragraph-separator-expected.txt: Added.
+        * editing/execCommand/default-paragraph-separator.html: Added.
+
 2012-03-02  Mike Lawther  <[email protected]>
 
         reflection computed style test for CSS3 calc

Added: trunk/LayoutTests/editing/execCommand/default-paragraph-separator-expected.txt (0 => 109529)


--- trunk/LayoutTests/editing/execCommand/default-paragraph-separator-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/default-paragraph-separator-expected.txt	2012-03-02 09:20:39 UTC (rev 109529)
@@ -0,0 +1,65 @@
+PASS document.queryCommandEnabled('DefaultParagraphSeparator') is true
+PASS document.queryCommandValue('DefaultParagraphSeparator') is "div"
+document.execCommand('DefaultParagraphSeparator', false, 'p')
+PASS document.queryCommandValue('DefaultParagraphSeparator') is "p"
+document.execCommand('DefaultParagraphSeparator', false, 'br')
+PASS document.queryCommandValue('DefaultParagraphSeparator') is "p"
+document.execCommand('DefaultParagraphSeparator', false, 'invalid')
+PASS document.queryCommandValue('DefaultParagraphSeparator') is "p"
+
+Creating paragraphs in the normal way.
+document.execCommand('InsertText', false, 'a')
+PASS div.innerHTML is "a"
+document.execCommand('InsertText', false, '\n')
+PASS div.innerHTML is "a<p><br></p>"
+document.execCommand('InsertText', false, 'b')
+PASS div.innerHTML is "a<p>b</p>"
+document.execCommand('InsertText', false, '\n')
+PASS div.innerHTML is "a<p>b</p><p><br></p>"
+document.execCommand('Delete')
+PASS div.innerHTML is "a<p>b</p>"
+document.execCommand('Delete')
+PASS div.innerHTML is "a<p><br></p>"
+document.execCommand('Delete')
+PASS div.innerHTML is "a"
+document.execCommand('DefaultParagraphSeparator', false, 'div')
+document.execCommand('InsertParagraph')
+PASS div.innerHTML is "a<div><br></div>"
+div.innerHTML = ''
+
+Using the previous block as template for the new one.
+document.execCommand('DefaultParagraphSeparator', false, 'p')
+document.execCommand("InsertHTML", false, "<pre>a</pre>");
+PASS div.innerHTML is "<pre>a</pre>"
+document.execCommand('InsertText', false, 'b')
+PASS div.innerHTML is "<pre>ab</pre>"
+document.execCommand('InsertText', false, '\n')
+PASS div.innerHTML is "<pre>ab</pre><pre><br></pre>"
+document.execCommand('InsertText', false, 'c')
+PASS div.innerHTML is "<pre>ab</pre><pre>c</pre>"
+document.execCommand('DefaultParagraphSeparator', false, 'div')
+document.execCommand('InsertText', false, '\n')
+PASS div.innerHTML is "<pre>ab</pre><pre>c</pre><pre><br></pre>"
+document.execCommand('Delete')
+document.execCommand('InsertParagraph')
+PASS div.innerHTML is "<pre>ab</pre><pre>c</pre><pre><br></pre>"
+
+Breaking out of lists.
+div.innerHTML = ''
+document.execCommand('DefaultParagraphSeparator', false, 'p')
+document.execCommand("InsertHTML", false, "<ul><li>a</li></ul>")
+PASS div.innerHTML is "<ul><li>a</li></ul>"
+document.execCommand('InsertParagraph')
+document.execCommand('InsertParagraph')
+PASS div.innerHTML is "<ul><li>a</li></ul><p><br></p>"
+
+Breaking up nested elements.
+div.innerHTML = ''
+document.execCommand("InsertHTML", false, "<cite>a<cite>bc</cite></cite>")
+window.getSelection().modify("move", "backward", "character")
+document.execCommand('InsertParagraph')
+PASS div.innerHTML is "<cite>a<cite>b</cite></cite><p><cite><cite>c</cite></cite></p>"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/execCommand/default-paragraph-separator.html (0 => 109529)


--- trunk/LayoutTests/editing/execCommand/default-paragraph-separator.html	                        (rev 0)
+++ trunk/LayoutTests/editing/execCommand/default-paragraph-separator.html	2012-03-02 09:20:39 UTC (rev 109529)
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id=editor contenteditable></div>
+<script>
+    shouldBeTrue("document.queryCommandEnabled('DefaultParagraphSeparator')");
+    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "div"); // Default is div.
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
+    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'br')");
+    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'invalid')");
+    shouldBeEqualToString("document.queryCommandValue('DefaultParagraphSeparator')", "p");
+
+    debug("\nCreating paragraphs in the normal way.");
+    var div = document.querySelector("#editor");
+    div.focus();
+    evalAndLog("document.execCommand('InsertText', false, 'a')");
+    shouldBeEqualToString("div.innerHTML", "a");
+    evalAndLog("document.execCommand('InsertText', false, '\\n')");
+    shouldBeEqualToString("div.innerHTML", "a<p><br></p>");
+    evalAndLog("document.execCommand('InsertText', false, 'b')");
+    shouldBeEqualToString("div.innerHTML", "a<p>b</p>");
+    evalAndLog("document.execCommand('InsertText', false, '\\n')");
+    shouldBeEqualToString("div.innerHTML", "a<p>b</p><p><br></p>");
+    evalAndLog("document.execCommand('Delete')");
+    shouldBeEqualToString("div.innerHTML", "a<p>b</p>");
+    evalAndLog("document.execCommand('Delete')");
+    shouldBeEqualToString("div.innerHTML", "a<p><br></p>");
+    evalAndLog("document.execCommand('Delete')");
+    shouldBeEqualToString("div.innerHTML", "a");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'div')");
+    evalAndLog("document.execCommand('InsertParagraph')");
+    shouldBeEqualToString("div.innerHTML", "a<div><br></div>");
+    evalAndLog("div.innerHTML = ''");
+
+    debug("\nUsing the previous block as template for the new one.");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
+    debug('document.execCommand("InsertHTML", false, "&lt;pre&gt;a&lt;/pre&gt;");');
+    document.execCommand("InsertHTML", false, "<pre>a</pre>");
+    shouldBeEqualToString("div.innerHTML", "<pre>a</pre>");
+    evalAndLog("document.execCommand('InsertText', false, 'b')");
+    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre>");
+    evalAndLog("document.execCommand('InsertText', false, '\\n')");
+    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre><br></pre>");
+    evalAndLog("document.execCommand('InsertText', false, 'c')");
+    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre>");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'div')");
+    evalAndLog("document.execCommand('InsertText', false, '\\n')");
+    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre><pre><br></pre>");
+    evalAndLog("document.execCommand('Delete')");
+    evalAndLog("document.execCommand('InsertParagraph')");
+    shouldBeEqualToString("div.innerHTML", "<pre>ab</pre><pre>c</pre><pre><br></pre>");
+
+    debug("\nBreaking out of lists.");
+    evalAndLog("div.innerHTML = ''");
+    evalAndLog("document.execCommand('DefaultParagraphSeparator', false, 'p')");
+    debug('document.execCommand("InsertHTML", false, "&lt;ul>&lt;li>a&lt;/li>&lt;/ul>")');
+    document.execCommand("InsertHTML", false, "<ul><li>a</li></ul>");
+    shouldBeEqualToString("div.innerHTML", "<ul><li>a</li></ul>");
+    evalAndLog("document.execCommand('InsertParagraph')");
+    evalAndLog("document.execCommand('InsertParagraph')");
+    shouldBeEqualToString("div.innerHTML", "<ul><li>a</li></ul><p><br></p>");
+
+    debug("\nBreaking up nested elements.");
+    evalAndLog("div.innerHTML = ''");
+    debug('document.execCommand("InsertHTML", false, "&lt;cite>a&lt;cite>bc&lt;/cite>&lt;/cite>")');
+    document.execCommand("InsertHTML", false, "<cite>a<cite>bc</cite></cite>");
+    evalAndLog('window.getSelection().modify("move", "backward", "character")');
+    evalAndLog("document.execCommand('InsertParagraph')");
+    shouldBeEqualToString("div.innerHTML", "<cite>a<cite>b</cite></cite><p><cite><cite>c</cite></cite></p>");
+
+    div.innerHTML = "";
+    document.execCommand("DefaultParagraphSeparator", false, "div");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (109528 => 109529)


--- trunk/Source/WebCore/ChangeLog	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/ChangeLog	2012-03-02 09:20:39 UTC (rev 109529)
@@ -1,3 +1,35 @@
+2012-03-02  Pablo Flouret  <[email protected]>
+
+        Implement DefaultParagraphSeparator execCommand, to let authors choose the default block element
+        https://bugs.webkit.org/show_bug.cgi?id=59961
+
+        Reviewed by Ryosuke Niwa.
+
+        http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#the-defaultparagraphseparator-command
+
+        Test: editing/execCommand/default-paragraph-separator.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::Editor):
+        * editing/Editor.h:
+        (WebCore::Editor::defaultParagraphSeparator):
+        (WebCore::Editor::setDefaultParagraphSeparator):
+        (Editor):
+        * editing/EditorCommand.cpp:
+        (WebCore::executeDefaultParagraphSeparator):
+        (WebCore):
+        (WebCore::valueDefaultParagraphSeparator):
+        (WebCore::createCommandMap):
+        * editing/htmlediting.cpp:
+        (WebCore::createDefaultParagraphElement):
+
+        * html/HTMLParagraphElement.cpp:
+        (WebCore::HTMLParagraphElement::create):
+        (WebCore):
+        * html/HTMLParagraphElement.h:
+        (HTMLParagraphElement):
+            Added create(Document*) method that defaults to pTag as the QualifiedName.
+
 2012-03-02  Kenneth Russell  <[email protected]>
 
         [chromium] Fix errors in LayerRendererChromium cleanup

Modified: trunk/Source/WebCore/editing/Editor.cpp (109528 => 109529)


--- trunk/Source/WebCore/editing/Editor.cpp	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/editing/Editor.cpp	2012-03-02 09:20:39 UTC (rev 109529)
@@ -846,6 +846,7 @@
     , m_spellChecker(adoptPtr(new SpellChecker(frame)))
     , m_spellingCorrector(adoptPtr(new SpellingCorrectionController(frame)))
     , m_areMarkedTextMatchesHighlighted(false)
+    , m_defaultParagraphSeparator(EditorParagraphSeparatorIsDiv)
 {
 }
 

Modified: trunk/Source/WebCore/editing/Editor.h (109528 => 109529)


--- trunk/Source/WebCore/editing/Editor.h	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/editing/Editor.h	2012-03-02 09:20:39 UTC (rev 109529)
@@ -80,6 +80,7 @@
 };
 
 enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
+enum EditorParagraphSeparator { EditorParagraphSeparatorIsDiv, EditorParagraphSeparatorIsP };
 
 class Editor {
 public:
@@ -383,6 +384,9 @@
 
     void deviceScaleFactorChanged();
 
+    EditorParagraphSeparator defaultParagraphSeparator() const { return m_defaultParagraphSeparator; }
+    void setDefaultParagraphSeparator(EditorParagraphSeparator separator) { m_defaultParagraphSeparator = separator; }
+
 private:
     Frame* m_frame;
     OwnPtr<DeleteButtonController> m_deleteButtonController;
@@ -400,6 +404,7 @@
     OwnPtr<SpellingCorrectionController> m_spellingCorrector;
     VisibleSelection m_mark;
     bool m_areMarkedTextMatchesHighlighted;
+    EditorParagraphSeparator m_defaultParagraphSeparator;
 
     bool canDeleteRange(Range*) const;
     bool canSmartReplaceWithPasteboard(Pasteboard*);

Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (109528 => 109529)


--- trunk/Source/WebCore/editing/EditorCommand.cpp	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp	2012-03-02 09:20:39 UTC (rev 109529)
@@ -307,6 +307,16 @@
     return true;
 }
 
+static bool executeDefaultParagraphSeparator(Frame* frame, Event*, EditorCommandSource, const String& value)
+{
+    if (equalIgnoringCase(value, "div"))
+        frame->editor()->setDefaultParagraphSeparator(EditorParagraphSeparatorIsDiv);
+    else if (equalIgnoringCase(value, "p"))
+        frame->editor()->setDefaultParagraphSeparator(EditorParagraphSeparatorIsP);
+
+    return true;
+}
+
 static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, const String&)
 {
     switch (source) {
@@ -1378,6 +1388,19 @@
     return valueStyle(frame, CSSPropertyBackgroundColor);
 }
 
+static String valueDefaultParagraphSeparator(Frame* frame, Event*)
+{
+    switch (frame->editor()->defaultParagraphSeparator()) {
+    case EditorParagraphSeparatorIsDiv:
+        return divTag.localName();
+    case EditorParagraphSeparatorIsP:
+        return pTag.localName();
+    }
+
+    ASSERT_NOT_REACHED();
+    return String();
+}
+
 static String valueFontName(Frame* frame, Event*)
 {
     return valueStyle(frame, CSSPropertyFontFamily);
@@ -1429,6 +1452,7 @@
         { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
         { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+        { "DefaultParagraphSeparator", { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
         { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
         { "DeleteBackwardByDecomposingPreviousCharacter", { executeDeleteBackwardByDecomposingPreviousCharacter, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (109528 => 109529)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2012-03-02 09:20:39 UTC (rev 109529)
@@ -29,6 +29,8 @@
 #include "AXObjectCache.h"
 #include "Document.h"
 #include "EditingText.h"
+#include "Editor.h"
+#include "Frame.h"
 #include "HTMLBRElement.h"
 #include "HTMLDivElement.h"
 #include "HTMLElementFactory.h"
@@ -38,6 +40,7 @@
 #include "HTMLNames.h"
 #include "HTMLObjectElement.h"
 #include "HTMLOListElement.h"
+#include "HTMLParagraphElement.h"
 #include "HTMLUListElement.h"
 #include "PositionIterator.h"
 #include "RenderObject.h"
@@ -844,7 +847,15 @@
 
 PassRefPtr<HTMLElement> createDefaultParagraphElement(Document* document)
 {
-    return HTMLDivElement::create(document);
+    switch (document->frame()->editor()->defaultParagraphSeparator()) {
+    case EditorParagraphSeparatorIsDiv:
+        return HTMLDivElement::create(document);
+    case EditorParagraphSeparatorIsP:
+        return HTMLParagraphElement::create(document);
+    }
+
+    ASSERT_NOT_REACHED();
+    return 0;
 }
 
 PassRefPtr<HTMLElement> createBreakElement(Document* document)

Modified: trunk/Source/WebCore/html/HTMLParagraphElement.cpp (109528 => 109529)


--- trunk/Source/WebCore/html/HTMLParagraphElement.cpp	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/html/HTMLParagraphElement.cpp	2012-03-02 09:20:39 UTC (rev 109529)
@@ -39,6 +39,11 @@
     ASSERT(hasTagName(pTag));
 }
 
+PassRefPtr<HTMLParagraphElement> HTMLParagraphElement::create(Document* document)
+{
+    return adoptRef(new HTMLParagraphElement(pTag, document));
+}
+
 PassRefPtr<HTMLParagraphElement> HTMLParagraphElement::create(const QualifiedName& tagName, Document* document)
 {
     return adoptRef(new HTMLParagraphElement(tagName, document));

Modified: trunk/Source/WebCore/html/HTMLParagraphElement.h (109528 => 109529)


--- trunk/Source/WebCore/html/HTMLParagraphElement.h	2012-03-02 09:12:43 UTC (rev 109528)
+++ trunk/Source/WebCore/html/HTMLParagraphElement.h	2012-03-02 09:20:39 UTC (rev 109529)
@@ -29,6 +29,7 @@
 
 class HTMLParagraphElement : public HTMLElement {
 public:
+    static PassRefPtr<HTMLParagraphElement> create(Document*);
     static PassRefPtr<HTMLParagraphElement> create(const QualifiedName&, Document*);
 
 private:
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to