Reviewed by Chris
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2004 00:57:30 +0000 (00:57 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Dec 2004 00:57:30 +0000 (00:57 +0000)
        Added new createBreakElement() function that makes creating a <br> element a one-liner.
        Converted all the code that used to call the DocumentImpl, and dealt with the exceptionCode,
        over to this new helper.

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::moveNodesAfterNode): Now uses new helper function.
        (khtml::InsertLineBreakCommand::doApply): Ditto.
        (khtml::InsertParagraphSeparatorCommand::doApply): Ditto.
        (khtml::InsertParagraphSeparatorInQuotedContentCommand::doApply): Ditto.
        (khtml::ReplaceSelectionCommand::doApply): Ditto.
        (khtml::createBreakElement): New helper.
        * khtml/editing/htmlediting.h: Ditto.

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h

index 343cfeb..6c191bc 100644 (file)
@@ -1,3 +1,20 @@
+2004-12-16  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Chris
+
+        Added new createBreakElement() function that makes creating a <br> element a one-liner.
+        Converted all the code that used to call the DocumentImpl, and dealt with the exceptionCode,
+        over to this new helper.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::moveNodesAfterNode): Now uses new helper function.
+        (khtml::InsertLineBreakCommand::doApply): Ditto.
+        (khtml::InsertParagraphSeparatorCommand::doApply): Ditto.
+        (khtml::InsertParagraphSeparatorInQuotedContentCommand::doApply): Ditto.
+        (khtml::ReplaceSelectionCommand::doApply): Ditto.
+        (khtml::createBreakElement): New helper.
+        * khtml/editing/htmlediting.h: Ditto.
+
 2004-12-16  David Hyatt  <hyatt@apple.com>
 
        Fix a bug where vertical-align values that depended on their parent's value went crazy if the parent was
index 5d5ac7e..d9bb8a8 100644 (file)
@@ -1810,10 +1810,7 @@ void DeleteSelectionCommand::moveNodesAfterNode()
     if (!startBlock->renderer() || !startBlock->renderer()->firstChild()) {
         removeNode(startBlock);
         if (refNode->renderer() && refNode->renderer()->inlineBox() && refNode->renderer()->inlineBox()->nextOnLineExists()) {
-            int exceptionCode = 0;
-            ElementImpl *breakNode = document()->createHTMLElement("BR", exceptionCode);
-            ASSERT(exceptionCode == 0);
-            insertNodeAfter(breakNode, refNode);
+            insertNodeAfter(createBreakElement(document()), refNode);
         }
     }
 }
@@ -2035,10 +2032,7 @@ void InsertLineBreakCommand::doApply()
     deleteSelection();
     Selection selection = endingSelection();
 
-    int exceptionCode = 0;
-    ElementImpl *breakNode = document()->createHTMLElement("BR", exceptionCode);
-    ASSERT(exceptionCode == 0);
-
+    ElementImpl *breakNode = createBreakElement(document());
     NodeImpl *nodeToInsert = breakNode;
     
     // Handle the case where there is a typing style.
@@ -2072,8 +2066,7 @@ void InsertLineBreakCommand::doApply()
             }
             else if (!document()->inStrictMode()) {
                 // Insert an "extra" BR at the end of the block. 
-                ElementImpl *extraBreakNode = document()->createHTMLElement("br", exceptionCode);
-                ASSERT(exceptionCode == 0);
+                ElementImpl *extraBreakNode = createBreakElement(document());
                 insertNodeAfter(extraBreakNode, nodeToInsert);
                 setEndingSelection(Position(extraBreakNode, 0));
             }
@@ -2100,6 +2093,7 @@ void InsertLineBreakCommand::doApply()
         ASSERT(pos.node()->isTextNode());
         
         // Do the split
+        int exceptionCode = 0;
         TextImpl *textNode = static_cast<TextImpl *>(pos.node());
         TextImpl *textBeforeNode = document()->createTextNode(textNode->substringData(0, selection.start().offset(), exceptionCode));
         deleteTextFromNode(textNode, 0, pos.offset());
@@ -2276,20 +2270,15 @@ void InsertParagraphSeparatorCommand::doApply()
     // Check if pos.node() is a <br>. If it is, and the document is in quirks mode, 
     // then this <br> will collapse away when we add a block after it. Add an extra <br>.
     if (!document()->inStrictMode()) {
-        int exceptionCode = 0;
         if (pos.node()->id() == ID_BR) {
-            NodeImpl *extraBreak = document()->createHTMLElement("br", exceptionCode);
-            ASSERT(exceptionCode == 0);
+            NodeImpl *extraBreak = createBreakElement(document());
             insertNodeAfter(extraBreak, pos.node());
             pos = Position(extraBreak, 0);
         }
         else {
             Position upstreamPos = pos.upstream(StayInBlock);
-            if (upstreamPos.node()->id() == ID_BR) {
-                NodeImpl *extraBreak = document()->createHTMLElement("br", exceptionCode);
-                ASSERT(exceptionCode == 0);
-                insertNodeAfter(extraBreak, upstreamPos.node());
-            }
+            if (upstreamPos.node()->id() == ID_BR)
+                insertNodeAfter(createBreakElement(document()), upstreamPos.node());
             // leave pos where it is
         }
     }
@@ -2427,7 +2416,7 @@ void InsertParagraphSeparatorInQuotedContentCommand::doApply()
 
     // Insert a break after the top blockquote.
     int exceptionCode = 0;
-    m_breakNode = document()->createHTMLElement("BR", exceptionCode);
+    m_breakNode = createBreakElement(document());
     m_breakNode->ref();
     ASSERT(exceptionCode == 0);
     insertNodeAfter(m_breakNode, topBlockquote);
@@ -2492,7 +2481,7 @@ void InsertParagraphSeparatorInQuotedContentCommand::doApply()
         if (!startIsBR) {
             if (!leftParent)
                 leftParent = topBlockquote;
-            ElementImpl *b = document()->createHTMLElement("BR", exceptionCode);
+            ElementImpl *b = createBreakElement(document());
             b->ref();
             clonedNodes.append(b);
             ASSERT(exceptionCode == 0);
@@ -3563,10 +3552,7 @@ void ReplaceSelectionCommand::doApply()
                 bool hasTrailingBR = next && next->id() == ID_BR && lastNodeInserted->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
                 if (!hasTrailingBR) {
                     // Insert an "extra" BR at the end of the block. 
-                    int exceptionCode = 0;
-                    ElementImpl *extraBreakNode = document()->createHTMLElement("br", exceptionCode);
-                    ASSERT(exceptionCode == 0);
-                    insertNodeBefore(extraBreakNode, lastNodeInserted);
+                    insertNodeBefore(createBreakElement(document()), lastNodeInserted);
                 }
             }
         }
@@ -4062,4 +4048,12 @@ ElementImpl *createBlockPlaceholderElement(DocumentImpl *document)
     return breakNode;
 }
 
+ElementImpl *createBreakElement(DocumentImpl *document)
+{
+    int exceptionCode = 0;
+    ElementImpl *breakNode = document->createHTMLElement("br", exceptionCode);
+    ASSERT(exceptionCode == 0);
+    return breakNode;
+}
+
 } // namespace khtml
index e08c7a8..a6aecb6 100644 (file)
@@ -782,6 +782,7 @@ private:
 
 DOM::ElementImpl *createDefaultParagraphElement(DOM::DocumentImpl *document);
 DOM::ElementImpl *createBlockPlaceholderElement(DOM::DocumentImpl *document);
+DOM::ElementImpl *createBreakElement(DOM::DocumentImpl *document);
 
 //------------------------------------------------------------------------------------------