Reviewed by Hyatt
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Oct 2004 19:57:55 +0000 (19:57 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Oct 2004 19:57:55 +0000 (19:57 +0000)
        Fix for this bug::

        <rdar://problem/3851164> mail crashed when I pasted a large amount of text into a reply

        * khtml/editing/htmlediting.cpp:
        (khtml::CompositeEditCommand::removeBlockPlaceholderIfNeeded): This now returns bool to
        let the caller know if a placeholder was removed.
        (khtml::ReplaceSelectionCommand::doApply): Use the bool return value from the call to
        removeBlockPlaceholderIfNeeded. If true, shift the selection to the now-empty block. In
        some cases, the selection was still set on the removed BR, and this was the cause of the
        crash.
        * khtml/editing/htmlediting.h: Change removeBlockPlaceholderIfNeeded return type.

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

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

index 75ce2e84685d0454556bbef180622bd2b9ba542b..1d02af106cc2fa8fa4060b9635a247a3b7b50ef1 100644 (file)
@@ -1,3 +1,20 @@
+2004-10-26  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Hyatt
+        
+        Fix for this bug::
+        
+        <rdar://problem/3851164> mail crashed when I pasted a large amount of text into a reply
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::CompositeEditCommand::removeBlockPlaceholderIfNeeded): This now returns bool to
+        let the caller know if a placeholder was removed.
+        (khtml::ReplaceSelectionCommand::doApply): Use the bool return value from the call to
+        removeBlockPlaceholderIfNeeded. If true, shift the selection to the now-empty block. In
+        some cases, the selection was still set on the removed BR, and this was the cause of the
+        crash.
+        * khtml/editing/htmlediting.h: Change removeBlockPlaceholderIfNeeded return type.
+
 2004-10-26  Darin Adler  <darin@apple.com>
 
         Reviewed by Chris.
index 9a00c3e78db56d125a6e7864d8cb30365962bc52..01a678cb6f0d5aca5f3d91a94024912bb921959f 100644 (file)
@@ -875,13 +875,13 @@ void CompositeEditCommand::insertBlockPlaceholderIfNeeded(NodeImpl *node)
     appendNode(breakNode, node);
 }
 
-void CompositeEditCommand::removeBlockPlaceholderIfNeeded(NodeImpl *node)
+bool CompositeEditCommand::removeBlockPlaceholderIfNeeded(NodeImpl *node)
 {
     document()->updateLayout();
 
     RenderObject *renderer = node->renderer();
     if (!renderer->isBlockFlow())
-        return;
+        return false;
 
     // This code will remove a block placeholder if it still is at the end
     // of a block, where we placed it in insertBlockPlaceholderIfNeeded().
@@ -890,9 +890,12 @@ void CompositeEditCommand::removeBlockPlaceholderIfNeeded(NodeImpl *node)
     NodeImpl *last = node->lastChild();
     if (last && last->isHTMLElement()) {
         ElementImpl *element = static_cast<ElementImpl *>(last);
-        if (element->getAttribute(ATTR_CLASS) == blockPlaceholderClassString())
+        if (element->getAttribute(ATTR_CLASS) == blockPlaceholderClassString()) {
             removeNode(element);
+            return true;
+        }
     }
+    return false;
 }
 
 //==========================================================================================
@@ -2124,13 +2127,17 @@ void ReplaceSelectionCommand::doApply()
 
     // Now that we are about to add content, check to see if a placeholder element
     // can be removed.
-    removeBlockPlaceholderIfNeeded(selection.start().node()->enclosingBlockFlowElement());
+    Position pos = selection.start();
+    NodeImpl *block = pos.node()->enclosingBlockFlowElement();
+    if (removeBlockPlaceholderIfNeeded(block)) {
+        pos = Position(block, 0);
+    }
     
     bool addLeadingSpace = false;
     bool addTrailingSpace = false;
     if (m_smartReplace) {
-        addLeadingSpace = selection.start().leadingWhitespacePosition().isNull();
-        addTrailingSpace = selection.start().trailingWhitespacePosition().isNull();
+        addLeadingSpace = pos.leadingWhitespacePosition().isNull();
+        addTrailingSpace = pos.trailingWhitespacePosition().isNull();
     }
     
     if (!firstChild) {
@@ -2141,7 +2148,7 @@ void ReplaceSelectionCommand::doApply()
         // where we can remove this separate case.
         
         // Simple text paste. Treat as if the text were typed.
-        Position upstreamStart(selection.start().upstream(StayInBlock));
+        Position upstreamStart(pos.upstream(StayInBlock));
         DOMString text = static_cast<TextImpl *>(firstChild)->data();
         if (addLeadingSpace) {
             text = " " + text;
@@ -2160,7 +2167,7 @@ void ReplaceSelectionCommand::doApply()
         NodeImpl *beforeNode = firstChild;
         NodeImpl *node = firstChild->nextSibling();
         
-        insertNodeAt(firstChild, selection.start().node(), selection.start().offset());
+        insertNodeAt(firstChild, pos.node(), pos.offset());
         
         // Insert the nodes from the fragment
         while (node) {
index 5239e7935af16f32ffe9d8b140a888c28f55dbf1..09382594bc8024f77f643942d85df96f35ede8ec 100644 (file)
@@ -201,7 +201,7 @@ protected:
     void deleteInsignificantTextDownstream(const DOM::Position &);
 
     void insertBlockPlaceholderIfNeeded(DOM::NodeImpl *);
-    void removeBlockPlaceholderIfNeeded(DOM::NodeImpl *);
+    bool removeBlockPlaceholderIfNeeded(DOM::NodeImpl *);
 
     QValueList<EditCommandPtr> m_cmds;
 };