[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:32:37 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 058cd5352e112e45ea8d42c4de1d0e2635f70312
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Apr 7 17:55:08 2004 +0000

            Reviewed by John
    
            Make paste work again. It has been broken for some undetermined
            period of time.
    
            * khtml/editing/htmlediting_impl.cpp:
            (CompositeEditCommandImpl::insertNodeAt): Handle inserting a node when
            the reference node has children, or is an empty block.
            (CompositeEditCommandImpl::inputText): New convenience to create and
            apply an InputTextCommand.
            (InputTextCommandImpl::execute): Collapse whitespace when selection is
            not a range. Deleting the selection when it is a range already does that,
            so no need to make special accommodation for it.
            (PasteHTMLCommandImpl::PasteHTMLCommandImpl): Initialize m_HTMLString using
            an initialization list.
            (PasteHTMLCommandImpl::doApply): Collapse whitespace.... as above for
            InputTextCommandImpl::execute. Don't need to qualify NodeImpl's with DOM
            namespace. Clean up selection access; no need to grep around for it, the
            desired selection is returned by calling currentSelection(). Treat "simple
            text paste" like typing. Tighten up and simplify HTML fragment paste; no
            real change in algorithm.
            (SplitTextNodeCommandImpl::SplitTextNodeCommandImpl): m_text1 member variable
            not initialized. This bug was introduced by a recent change by me. Fixing now.
            * khtml/editing/htmlediting_impl.h: Add inputText() declaration.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6323 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index c20377b..f6ebd1e 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,30 @@
+2004-04-07  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by John
+        
+        Make paste work again. It has been broken for some undetermined
+        period of time.
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (CompositeEditCommandImpl::insertNodeAt): Handle inserting a node when
+        the reference node has children, or is an empty block.
+        (CompositeEditCommandImpl::inputText): New convenience to create and
+        apply an InputTextCommand.
+        (InputTextCommandImpl::execute): Collapse whitespace when selection is
+        not a range. Deleting the selection when it is a range already does that, 
+        so no need to make special accommodation for it.
+        (PasteHTMLCommandImpl::PasteHTMLCommandImpl): Initialize m_HTMLString using 
+        an initialization list.
+        (PasteHTMLCommandImpl::doApply): Collapse whitespace.... as above for 
+        InputTextCommandImpl::execute. Don't need to qualify NodeImpl's with DOM 
+        namespace. Clean up selection access; no need to grep around for it, the
+        desired selection is returned by calling currentSelection(). Treat "simple
+        text paste" like typing. Tighten up and simplify HTML fragment paste; no
+        real change in algorithm. 
+        (SplitTextNodeCommandImpl::SplitTextNodeCommandImpl): m_text1 member variable
+        not initialized. This bug was introduced by a recent change by me. Fixing now.
+        * khtml/editing/htmlediting_impl.h: Add inputText() declaration.
+
 2004-04-06  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Richard
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index a1f1930..ae93bcf 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -437,9 +437,18 @@ void CompositeEditCommandImpl::insertNodeAfter(DOM::NodeImpl *insertChild, DOM::
     }
 }
 
-void CompositeEditCommandImpl::insertNodeAt(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild, long offset)
-{
-    if (refChild->caretMinOffset() >= offset) {
+void CompositeEditCommandImpl::insertNodeAt(NodeImpl *insertChild, NodeImpl *refChild, long offset)
+{
+    if (refChild->hasChildNodes() || (refChild->renderer() && refChild->renderer()->isBlockFlow())) {
+        NodeImpl *child = refChild->firstChild();
+        for (long i = 0; child && i < offset; i++)
+            child = child->nextSibling();
+        if (child)
+            insertNodeBefore(insertChild, child);
+        else
+            appendNode(refChild, insertChild);
+    } 
+    else if (refChild->caretMinOffset() >= offset) {
         insertNodeBefore(insertChild, refChild);
     } 
     else if (refChild->isTextNode() && refChild->caretMaxOffset() > offset) {
@@ -481,6 +490,13 @@ void CompositeEditCommandImpl::joinTextNodes(DOM::TextImpl *text1, DOM::TextImpl
     applyCommandToComposite(cmd);
 }
 
+void CompositeEditCommandImpl::inputText(const DOMString &text)
+{
+    InputTextCommand cmd(document());
+    applyCommandToComposite(cmd);
+    cmd.input(text);
+}
+
 void CompositeEditCommandImpl::insertText(DOM::TextImpl *node, long offset, const DOM::DOMString &text)
 {
     InsertTextCommand cmd(document(), node, offset, text);
@@ -1156,7 +1172,7 @@ void InputTextCommandImpl::execute(const DOMString &text)
 {
     KHTMLSelection selection = currentSelection();
 
-    // Delete the current selection
+    // Delete the current selection, or collapse whitespace, as needed
     if (selection.state() == KHTMLSelection::RANGE)
         deleteSelection();
     else
@@ -1384,10 +1400,9 @@ void JoinTextNodesCommandImpl::doUnapply()
 // PasteHTMLCommandImpl
 
 PasteHTMLCommandImpl::PasteHTMLCommandImpl(DocumentImpl *document, const DOMString &HTMLString) 
-    : CompositeEditCommandImpl(document)
+    : CompositeEditCommandImpl(document), m_HTMLString(HTMLString)
 {
-    ASSERT(!HTMLString.isEmpty());
-    m_HTMLString = HTMLString; 
+    ASSERT(!m_HTMLString.isEmpty());
 }
 
 PasteHTMLCommandImpl::~PasteHTMLCommandImpl()
@@ -1401,58 +1416,55 @@ int PasteHTMLCommandImpl::commandID() const
 
 void PasteHTMLCommandImpl::doApply()
 {
-    DOM::DocumentFragmentImpl *root = static_cast<HTMLElementImpl *>(document()->documentElement())->createContextualFragment(m_HTMLString);
+    DocumentFragmentImpl *root = static_cast<HTMLElementImpl *>(document()->documentElement())->createContextualFragment(m_HTMLString);
     ASSERT(root);
     
-    DOM::NodeImpl *firstChild = root->firstChild();
-    DOM::NodeImpl *lastChild = root->lastChild();
+    NodeImpl *firstChild = root->firstChild();
+    NodeImpl *lastChild = root->lastChild();
     ASSERT(firstChild);
     ASSERT(lastChild);
     
-    deleteSelection();
-    
-    KHTMLPart *part = document()->part();
-    ASSERT(part);
+    KHTMLSelection selection = currentSelection();
+
+    // Delete the current selection, or collapse whitespace, as needed
+    if (selection.state() == KHTMLSelection::RANGE)
+        deleteSelection();
+    else
+        deleteCollapsibleWhitespace();
     
-    KHTMLSelection selection = part->selection();
+    selection = endingSelection();
     ASSERT(!selection.isEmpty());
     
-    DOM::NodeImpl *startNode = selection.startNode();
-    long startOffset = selection.startOffset();
-    TextImpl *textNode = startNode->isTextNode() ? static_cast<TextImpl *>(startNode) : NULL;
-
-    if (textNode && firstChild == lastChild && firstChild->isTextNode()) {
-        // Simple text paste. Add the text to the text node with the caret.
-        insertText(textNode, startOffset, static_cast<TextImpl *>(firstChild)->data());
-        selection = KHTMLSelection(textNode, startOffset + static_cast<TextImpl *>(firstChild)->length());
-        setEndingSelection(selection);
+    if (firstChild == lastChild && firstChild->isTextNode()) {
+        // Simple text paste. Treat as if the text were typed.
+        inputText(static_cast<TextImpl *>(firstChild)->data());
     } 
     else {
-        // HTML tree paste.
-        insertNodeAt(firstChild, startNode, startOffset);
+        // HTML fragment paste.
+        NodeImpl *beforeNode = firstChild;
+        NodeImpl *node = firstChild->nextSibling();
+
+        insertNodeAt(firstChild, selection.startNode(), selection.startOffset());
         
-        DOM::NodeImpl *child = startNode->nextSibling();
-        DOM::NodeImpl *beforeNode = startNode;
-		
-        // Insert the nodes from the clipping.
-        while (child) {
-            DOM::NodeImpl *nextSibling = child->nextSibling();
-            insertNodeAfter(child, beforeNode);
-            beforeNode = child;
-            child = nextSibling;
+        // Insert the nodes from the fragment
+        while (node) {
+            NodeImpl *next = node->nextSibling();
+            insertNodeAfter(node, beforeNode);
+            beforeNode = node;
+            node = next;
         }
+        ASSERT(beforeNode);
 		
 		// Find the last leaf and place the caret after it.
-        child = lastChild;
+        NodeImpl *leaf = lastChild;
         while (1) {
-            DOM::NodeImpl *nextChild = child->lastChild();
-            if (!nextChild) {
+            NodeImpl *nextChild = leaf->lastChild();
+            if (!nextChild)
                 break;
-            }
-            child = nextChild;
+            leaf = nextChild;
         }
-        selection = KHTMLSelection(child, child->caretMaxOffset());
-        setEndingSelection(selection);
+        
+        setEndingSelection(DOMPosition(leaf, leaf->caretMaxOffset()));
     }
 }
 
@@ -1597,8 +1609,12 @@ void RemoveNodeAndPruneCommandImpl::doApply()
 // SplitTextNodeCommandImpl
 
 SplitTextNodeCommandImpl::SplitTextNodeCommandImpl(DocumentImpl *document, TextImpl *text, long offset)
-    : EditCommandImpl(document), m_text2(text), m_offset(offset)
+    : EditCommandImpl(document), m_text1(0), m_text2(text), m_offset(offset)
 {
+    ASSERT(m_text2);
+    ASSERT(m_text2->length() > 0);
+
+    m_text2->ref();
 }
 
 SplitTextNodeCommandImpl::~SplitTextNodeCommandImpl()
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index 39ef1c1..693d737 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -123,6 +123,7 @@ protected:
     void splitTextNode(DOM::TextImpl *text, long offset);
     void joinTextNodes(DOM::TextImpl *text1, DOM::TextImpl *text2);
     void insertText(DOM::TextImpl *node, long offset, const DOM::DOMString &text);
+    void inputText(const DOM::DOMString &text);
     void deleteText(DOM::TextImpl *node, long offset, long count);
     void replaceText(DOM::TextImpl *node, long offset, long count, const DOM::DOMString &replacementText);
     void deleteSelection();

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list