Fixed: <rdar://problem/4023566> Stickies: Crash in ReplacementFragment::insertFragme...
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Feb 2005 19:34:52 +0000 (19:34 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Feb 2005 19:34:52 +0000 (19:34 +0000)
        Reviewed by darin.

        * khtml/editing/htmlediting.cpp:
        (khtml::ApplyStyleCommand::addInlineStyleIfNeeded):
        (khtml::ReplacementFragment::insertFragmentForTestRendering):
        (khtml::floatRefdElement):
        (khtml::createDefaultParagraphElement):
        (khtml::createBlockPlaceholderElement):
        (khtml::createFontElement):
        (khtml::createStyleSpanElement):
        * khtml/editing/htmlediting.h:

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

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

index f4446d98e4f0040ff4350d53031759e1f0840413..d9606be45146f358c8709cc7669fde11acc50323 100644 (file)
@@ -1,3 +1,19 @@
+2005-02-25  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/4023566> Stickies: Crash in ReplacementFragment::insertFragmentForTestRendering on paste
+
+        Reviewed by darin.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ApplyStyleCommand::addInlineStyleIfNeeded):
+        (khtml::ReplacementFragment::insertFragmentForTestRendering):
+        (khtml::floatRefdElement):
+        (khtml::createDefaultParagraphElement):
+        (khtml::createBlockPlaceholderElement):
+        (khtml::createFontElement):
+        (khtml::createStyleSpanElement):
+        * khtml/editing/htmlediting.h:
+
 2005-02-25  Darin Adler  <darin@apple.com>
 
         * kwq/character-sets.txt: Checked in updated file. This new file has no effect, because none of the
index 8b33a0bdfefbeb597282e7a62b99724752eb9389..a0fd077822c55fcb100c87eafd273b4410207cf1 100644 (file)
@@ -2176,8 +2176,10 @@ void ApplyStyleCommand::addInlineStyleIfNeeded(CSSMutableStyleDeclarationImpl *s
 
     if (styleChange.cssStyle().length() > 0) {
         ElementImpl *styleElement = createStyleSpanElement(document());
+        styleElement->ref();
         styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle());
         insertNodeBefore(styleElement, startNode);
+        styleElement->deref();
         surroundNodeRangeWithElement(startNode, endNode, styleElement);
     }
 
@@ -3106,6 +3108,7 @@ bool InsertParagraphSeparatorCommand::preservesTypingStyle() const
     return true;
 }
 
+// FIXME: callers of createParagraphElement are not properly deref'ing the returned ref'd element. 
 ElementImpl *InsertParagraphSeparatorCommand::createParagraphElement()
 {
     ElementImpl *element = createDefaultParagraphElement(document());
@@ -4247,6 +4250,7 @@ NodeImpl *ReplacementFragment::insertFragmentForTestRendering()
         return 0;
 
     ElementImpl *holder = createDefaultParagraphElement(m_document);
+    holder->ref();
     
     int exceptionCode = 0;
     holder->appendChild(m_fragment, exceptionCode);
@@ -4257,7 +4261,7 @@ NodeImpl *ReplacementFragment::insertFragmentForTestRendering()
     
     m_document->updateLayout();
     
-    return holder;
+    return floatRefdElement(holder);
 }
 
 void ReplacementFragment::restoreTestRenderingNodesToFragment(NodeImpl *holder)
@@ -5545,15 +5549,19 @@ bool TypingCommand::isTypingCommand() const
     return true;
 }
 
+ElementImpl *floatRefdElement(ElementImpl *node)
+{
+    node->setParent(node->getDocument());
+    node->deref();
+    node->setParent(0);
+    return node;
+}
+
 ElementImpl *createDefaultParagraphElement(DocumentImpl *document)
 {
-    // We would need this margin-zeroing and attribute-setter code back if we ever 
-    // return to using <p> elements for default paragraphs.
-    //static const DOMString defaultParagraphStyle("margin-top: 0; margin-bottom: 0");
     int exceptionCode = 0;
     ElementImpl *element = document->createHTMLElement("div", exceptionCode);
     ASSERT(exceptionCode == 0);
-    //element->setAttribute(ATTR_STYLE, defaultParagraphStyle);
     return element;
 }
 
@@ -5561,9 +5569,10 @@ ElementImpl *createBlockPlaceholderElement(DocumentImpl *document)
 {
     int exceptionCode = 0;
     ElementImpl *breakNode = document->createHTMLElement("br", exceptionCode);
+    breakNode->ref();
     ASSERT(exceptionCode == 0);
     breakNode->setAttribute(ATTR_CLASS, blockPlaceholderClassString());
-    return breakNode;
+    return floatRefdElement(breakNode);
 }
 
 ElementImpl *createBreakElement(DocumentImpl *document)
@@ -5578,18 +5587,20 @@ ElementImpl *createFontElement(DocumentImpl *document)
 {
     int exceptionCode = 0;
     ElementImpl *fontNode = document->createHTMLElement("font", exceptionCode);
+    fontNode->ref();
     ASSERT(exceptionCode == 0);
     fontNode->setAttribute(ATTR_CLASS, styleSpanClassString());
-    return fontNode;
+    return floatRefdElement(fontNode);
 }
 
 ElementImpl *createStyleSpanElement(DocumentImpl *document)
 {
     int exceptionCode = 0;
     ElementImpl *styleElement = document->createHTMLElement("SPAN", exceptionCode);
+    styleElement->ref();
     ASSERT(exceptionCode == 0);
     styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
-    return styleElement;
+    return floatRefdElement(styleElement);
 }
 
 bool isNodeRendered(const NodeImpl *node)
index 5bd86f794f88e827e4dbc39222ec649e2e263cba..23502c390abb8db17f9e140b58479f9cd288dded 100644 (file)
@@ -929,6 +929,7 @@ private:
 
 //------------------------------------------------------------------------------------------
 
+DOM::ElementImpl *floatRefdElement(DOM::ElementImpl *node);
 DOM::ElementImpl *createDefaultParagraphElement(DOM::DocumentImpl *document);
 DOM::ElementImpl *createBlockPlaceholderElement(DOM::DocumentImpl *document);
 DOM::ElementImpl *createBreakElement(DOM::DocumentImpl *document);