[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
cblu
cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:25:57 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit e3315f7f2844cc1aa0cef661ea270b1fdcfa26d7
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Feb 10 23:24:16 2004 +0000
Fixed: <rdar://problem/3552545>: Cut, Paste and Delete must support Undo and Redo
Reviewed by kocienda.
* khtml/editing/htmlediting.cpp:
(ModifyTextNodeStep::splitTextNode): ken's fix that fixes a problem with unapply
(ModifyTextNodeStep::joinTextNodes): my fix that fixes a problem with unapply
(PasteHTMLCommand::PasteHTMLCommand): new
(PasteHTMLCommand::apply): moved from dom_docimpl.cpp and improved
* khtml/editing/htmlediting.h:
(khtml::PasteHTMLCommand::~PasteHTMLCommand):
* khtml/khtml_part.cpp:
(KHTMLPart::deleteSelection): new, create and applies a DeleteTextCommand
(KHTMLPart::pasteHTMLString): new, create and applies a PasteHTMLCommand
* khtml/khtml_part.h:
* khtml/xml/dom_docimpl.cpp: moved paste code to htmlediting.cpp
* khtml/xml/dom_docimpl.h:
* kwq/WebCoreBridge.mm:
(-[WebCoreBridge pasteHTMLString:]): call pasteHTMLString on the part instead of the bridge
(-[WebCoreBridge deleteSelection]): call deleteSelection on the part instead of the bridge
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6059 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index f81ca76..abd986d 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,26 @@
+2004-02-10 Chris Blumenberg <cblu at apple.com>
+
+ Fixed: <rdar://problem/3552545>: Cut, Paste and Delete must support Undo and Redo
+
+ Reviewed by kocienda.
+
+ * khtml/editing/htmlediting.cpp:
+ (ModifyTextNodeStep::splitTextNode): ken's fix that fixes a problem with unapply
+ (ModifyTextNodeStep::joinTextNodes): my fix that fixes a problem with unapply
+ (PasteHTMLCommand::PasteHTMLCommand): new
+ (PasteHTMLCommand::apply): moved from dom_docimpl.cpp and improved
+ * khtml/editing/htmlediting.h:
+ (khtml::PasteHTMLCommand::~PasteHTMLCommand):
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::deleteSelection): new, create and applies a DeleteTextCommand
+ (KHTMLPart::pasteHTMLString): new, create and applies a PasteHTMLCommand
+ * khtml/khtml_part.h:
+ * khtml/xml/dom_docimpl.cpp: moved paste code to htmlediting.cpp
+ * khtml/xml/dom_docimpl.h:
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge pasteHTMLString:]): call pasteHTMLString on the part instead of the bridge
+ (-[WebCoreBridge deleteSelection]): call deleteSelection on the part instead of the bridge
+
2004-02-10 David Hyatt <hyatt at apple.com>
Fix crash on abcnews.com by adding isEmpty checks before dereferencing.
diff --git a/WebCore/khtml/editing/htmlediting.cpp b/WebCore/khtml/editing/htmlediting.cpp
index b2dc620..fe3345f 100644
--- a/WebCore/khtml/editing/htmlediting.cpp
+++ b/WebCore/khtml/editing/htmlediting.cpp
@@ -34,16 +34,20 @@
#include "khtml_part.h"
#include "khtml_selection.h"
#include "dom/dom_position.h"
+#include "html/html_elementimpl.h"
#include "rendering/render_object.h"
+#include "xml/dom_docimpl.h"
#include "xml/dom_elementimpl.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom2_rangeimpl.h"
#include "xml/dom_textimpl.h"
+using DOM::DocumentFragmentImpl;
using DOM::DocumentImpl;
using DOM::DOMPosition;
using DOM::DOMString;
using DOM::ElementImpl;
+using DOM::HTMLElementImpl;
using DOM::Node;
using DOM::NodeImpl;
using DOM::NodeListImpl;
@@ -60,13 +64,14 @@ using khtml::InsertNodeBeforeStep;
using khtml::InsertTextStep;
using khtml::JoinTextNodesStep;
using khtml::ModifyTextNodeStep;
-using khtml::RemoveNodeStep;
using khtml::MoveSelectionToStep;
+using khtml::RemoveNodeStep;
using khtml::SplitTextNodeStep;
using khtml::DeleteTextCommand;
using khtml::EditCommand;
using khtml::InputTextCommand;
+using khtml::PasteHTMLCommand;
#if !APPLE_CHANGES
#define ASSERT(assertion) ((void)0)
@@ -467,7 +472,7 @@ void ModifyTextNodeStep::splitTextNode()
ASSERT(m_offset >= m_text2->caretMinOffset() && m_offset <= m_text2->caretMaxOffset());
int exceptionCode;
- TextImpl *m_text1 = document()->createTextNode(m_text2->substringData(0, m_offset, exceptionCode));
+ m_text1 = document()->createTextNode(m_text2->substringData(0, m_offset, exceptionCode));
ASSERT(exceptionCode == 0);
ASSERT(m_text1);
m_text1->ref();
@@ -494,7 +499,7 @@ void ModifyTextNodeStep::joinTextNodes()
m_text2->insertData(0, m_text1->data(), exceptionCode);
ASSERT(exceptionCode == 0);
- m_text2->parent()->removeChild(m_text2, exceptionCode);
+ m_text2->parent()->removeChild(m_text1, exceptionCode);
ASSERT(exceptionCode == 0);
m_offset = m_text1->length();
@@ -982,3 +987,78 @@ void DeleteTextCommand::apply()
}
}
}
+
+PasteHTMLCommand::PasteHTMLCommand(DocumentImpl *document, const DOM::DOMString &HTMLString)
+: EditCommand(document)
+{
+ ASSERT(!HTMLString.isEmpty());
+ m_HTMLString = HTMLString;
+}
+
+void PasteHTMLCommand::apply()
+{
+ DOM::DocumentFragmentImpl *root = static_cast<HTMLElementImpl *>(document()->documentElement())->createContextualFragment(m_HTMLString);
+ ASSERT(root);
+
+ DOM::NodeImpl *firstChild = root->firstChild();
+ DOM::NodeImpl *lastChild = root->lastChild();
+ ASSERT(firstChild);
+ ASSERT(lastChild);
+
+ deleteSelection();
+
+ KHTMLPart *part = document()->part();
+ ASSERT(part);
+
+ KHTMLSelection selection = part->selection();
+ 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());
+ moveSelectionTo(textNode, startOffset + static_cast<TextImpl *>(firstChild)->length());
+ } else {
+ // HTML tree paste.
+ DOM::NodeImpl *child = firstChild;
+ DOM::NodeImpl *beforeNode = NULL;
+ if (startNode->caretMinOffset() == startOffset) {
+ // Caret is at the beginning of the node. Insert before it.
+ DOM::NodeImpl *nextSibling = child->nextSibling();
+ insertNodeBefore(child, startNode);
+ beforeNode = child;
+ child = nextSibling;
+ } else if (textNode && textNode->caretMaxOffset() != startOffset) {
+ // Caret is in middle of a text node. Split the text node and insert in between.
+ splitTextNode(textNode, startOffset);
+ beforeNode = textNode->previousSibling();
+ } else {
+ // Caret is at the end of the node. Insert after it.
+ beforeNode = startNode;
+ }
+
+ ASSERT(beforeNode);
+
+ // Insert the nodes from the clipping.
+ while (child) {
+ DOM::NodeImpl *nextSibling = child->nextSibling();
+ insertNodeAfter(child, beforeNode);
+ beforeNode = child;
+ child = nextSibling;
+ }
+
+ // Find the last leaf and place the caret after it.
+ child = lastChild;
+ while (1) {
+ DOM::NodeImpl *nextChild = child->lastChild();
+ if (!nextChild) {
+ break;
+ }
+ child = nextChild;
+ }
+ moveSelectionTo(child, child->caretMaxOffset());
+ }
+}
diff --git a/WebCore/khtml/editing/htmlediting.h b/WebCore/khtml/editing/htmlediting.h
index ffffd90..b146b00 100644
--- a/WebCore/khtml/editing/htmlediting.h
+++ b/WebCore/khtml/editing/htmlediting.h
@@ -35,6 +35,7 @@
class KHTMLSelection;
namespace DOM {
+ class DocumentFragmentImpl;
class DocumentImpl;
class DOMPosition;
class DOMString;
@@ -311,6 +312,17 @@ public:
virtual void apply();
};
+class PasteHTMLCommand : public EditCommand
+{
+public:
+ PasteHTMLCommand(DOM::DocumentImpl *document, const DOM::DOMString &HTMLString);
+ virtual ~PasteHTMLCommand() {};
+
+ virtual void apply();
+private:
+ DOM::DOMString m_HTMLString;
+};
+
}; // end namespace khtml
#endif
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 4c59078..8c23ced 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -99,8 +99,10 @@ using namespace DOM;
#endif
using khtml::Decoder;
+using khtml::DeleteTextCommand;
using khtml::EditCommand;
using khtml::InlineTextBox;
+using khtml::PasteHTMLCommand;
using khtml::RenderObject;
using khtml::RenderText;
using khtml::Tokenizer;
@@ -2470,6 +2472,12 @@ void KHTMLPart::clearSelection()
notifySelectionChanged();
}
+void KHTMLPart::deleteSelection()
+{
+ DeleteTextCommand *cmd = new DeleteTextCommand(d->m_doc);
+ applyCommand(cmd);
+}
+
void KHTMLPart::invalidateSelection()
{
d->m_selection.setNeedsLayout();
@@ -5115,6 +5123,11 @@ void KHTMLPart::redoEditing()
#endif
}
+void KHTMLPart::pasteHTMLString(const QString &HTMLString)
+{
+ PasteHTMLCommand *cmd = new PasteHTMLCommand(d->m_doc, DOMString(HTMLString));
+ applyCommand(cmd);
+}
#if !APPLE_CHANGES
diff --git a/WebCore/khtml/khtml_part.h b/WebCore/khtml/khtml_part.h
index 1d0531a..6346caf 100644
--- a/WebCore/khtml/khtml_part.h
+++ b/WebCore/khtml/khtml_part.h
@@ -579,6 +579,11 @@ public:
void clearSelection();
/**
+ * Deletes the nodes of the current selection.
+ */
+ void deleteSelection();
+
+ /**
* Invalidates the current selection.
*/
void invalidateSelection();
@@ -643,6 +648,11 @@ public:
* Performs a redo of the edit.
*/
void redoEditing();
+
+ /**
+ * Pastes an HTML string at the current caret position.
+ */
+ void pasteHTMLString(const QString &HTMLString);
/**
* Convenience method to show the document's view.
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index 0f27a97..6dc25f2 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -1215,87 +1215,6 @@ void DocumentImpl::updateSelection()
}
}
-void DocumentImpl::deleteSelection()
-{
- KHTMLSelection s = part()->selection();
- if (!s.isEmpty()) {
- Range range(s.startNode(), s.startOffset(), s.endNode(), s.endOffset());
- range.deleteContents();
- part()->clearSelection();
- }
-}
-
-void DocumentImpl::pasteHTMLString(const QString &HTMLString)
-{
- deleteSelection();
-
- KHTMLSelection selection = part()->selection();
- DOM::NodeImpl *startNode = selection.startNode();
- long startOffset = selection.startOffset();
- DOM::NodeImpl *endNode = selection.endNode();
-
- if (startNode == NULL || endNode == NULL) {
- return;
- }
-
- DOMString string = DOMString(HTMLString);
- DocumentFragmentImpl *root = static_cast<HTMLElementImpl *>(startNode)->createContextualFragment(string);
- if (root == NULL) {
- return;
- }
-
- TextImpl *textNode = startNode->isTextNode() ? static_cast<TextImpl *>(startNode) : NULL;
- DOM::NodeImpl *firstChild = root->firstChild();
- DOM::NodeImpl *lastChild = root->lastChild();
- if (firstChild == NULL || lastChild == NULL) {
- return;
- }
-
- int exceptionCode = 0;
- long finalOffset;
-
- if (textNode && firstChild == lastChild && firstChild->isTextNode()) {
- // Simple text paste. Add the text to the text node with the caret.
- textNode->insertData(startOffset, static_cast<TextImpl *>(firstChild)->data(), exceptionCode);
- finalOffset = startOffset + static_cast<TextImpl *>(firstChild)->length();
- selection.moveTo(textNode, finalOffset);
- } else {
- // HTML tree paste.
- DOM::NodeImpl *parent = startNode->parentNode();
- DOM::NodeImpl *afterNode = NULL;
- if (textNode) {
- // Split the text node.
- TextImpl *textBeforeNode = createTextNode(textNode->substringData(0, startOffset, exceptionCode));
- textNode->deleteData(0, selection.startOffset(), exceptionCode);
- parent->insertBefore(textBeforeNode, textNode, exceptionCode);
- afterNode = textNode;
- }
-
- // Add the children of the pasted root to the document.
- DOM::NodeImpl *child = lastChild;
- while (child) {
- DOM::NodeImpl *previousSibling = child->previousSibling();
- parent->insertBefore(child, afterNode, exceptionCode);
- afterNode = child;
- child = previousSibling;
- }
-
- // Find the last leaf and place the caret after it.
- child = lastChild;
- while (1) {
- DOM::NodeImpl *nextChild = child->lastChild();
- if (!nextChild) {
- break;
- }
- child = nextChild;
- }
- finalOffset = child->isTextNode() ? static_cast<TextImpl *>(child)->length() : 1;
- selection.moveTo(child, finalOffset);
- }
-
- part()->setSelection(selection);
-}
-
Tokenizer *DocumentImpl::createTokenizer()
{
return new XMLTokenizer(docPtr(),m_view);
diff --git a/WebCore/khtml/xml/dom_docimpl.h b/WebCore/khtml/xml/dom_docimpl.h
index 3d5b1bb..5579148 100644
--- a/WebCore/khtml/xml/dom_docimpl.h
+++ b/WebCore/khtml/xml/dom_docimpl.h
@@ -264,11 +264,8 @@ public:
// to get visually ordered hebrew and arabic pages right
void setVisuallyOrdered();
- void deleteSelection();
void updateSelection();
- void pasteHTMLString(const QString &HTMLString);
-
void open();
void close();
void closeInternal ( bool checkTokenizer );
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 5accdcc..c499ad3 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -396,18 +396,12 @@ static bool initializedKJS = FALSE;
- (void)pasteHTMLString:(NSString *)HTMLString
{
- DocumentImpl *doc = _part->xmlDocImpl();
- if (doc) {
- doc->pasteHTMLString(QString::fromNSString(HTMLString));
- }
+ _part->pasteHTMLString(QString::fromNSString(HTMLString));
}
- (void)deleteSelection
{
- DocumentImpl *doc = _part->xmlDocImpl();
- if (doc) {
- doc->deleteSelection();
- }
+ _part->deleteSelection();
}
- (BOOL)haveSelection
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list