ASSERT(m_text2->previousSibling() == m_text1);
}
+//------------------------------------------------------------------------------------------
+// MoveSelectionCommand
+
+MoveSelectionCommand::MoveSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, Position &position, bool smartMove)
+ : CompositeEditCommand(document), m_fragment(fragment), m_position(position), m_smartMove(smartMove)
+{
+ ASSERT(m_fragment);
+ m_fragment->ref();
+}
+
+MoveSelectionCommand::~MoveSelectionCommand()
+{
+ ASSERT(m_fragment);
+ m_fragment->deref();
+}
+
+void MoveSelectionCommand::doApply()
+{
+ Selection selection = endingSelection();
+ ASSERT(selection.isRange());
+
+ // Update the position otherwise it may become invalid after the selection is deleted.
+ NodeImpl *positionNode = m_position.node();
+ long positionOffset = m_position.offset();
+ Position selectionEnd = selection.end();
+ long selectionEndOffset = selectionEnd.offset();
+ if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) {
+ positionOffset -= selectionEndOffset;
+ Position selectionStart = selection.start();
+ if (selectionStart.node() == positionNode) {
+ positionOffset += selectionStart.offset();
+ }
+ }
+
+ deleteSelection(m_smartMove);
+
+ setEndingSelection(Position(positionNode, positionOffset));
+ EditCommandPtr cmd(new ReplaceSelectionCommand(document(), m_fragment, true, m_smartMove));
+ applyCommandToComposite(cmd);
+}
+
+//------------------------------------------------------------------------------------------
+// RemoveCSSPropertyCommand
+
+RemoveCSSPropertyCommand::RemoveCSSPropertyCommand(DocumentImpl *document, CSSStyleDeclarationImpl *decl, int property)
+ : EditCommand(document), m_decl(decl->makeMutable()), m_property(property), m_important(false)
+{
+ ASSERT(m_decl);
+ m_decl->ref();
+}
+
+RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand()
+{
+ ASSERT(m_decl);
+ m_decl->deref();
+}
+
+void RemoveCSSPropertyCommand::doApply()
+{
+ ASSERT(m_decl);
+
+ m_oldValue = m_decl->getPropertyValue(m_property);
+ ASSERT(!m_oldValue.isNull());
+
+ m_important = m_decl->getPropertyPriority(m_property);
+ m_decl->removeProperty(m_property);
+}
+
+void RemoveCSSPropertyCommand::doUnapply()
+{
+ ASSERT(m_decl);
+ ASSERT(!m_oldValue.isNull());
+
+ m_decl->setProperty(m_property, m_oldValue, m_important);
+}
+
+//------------------------------------------------------------------------------------------
+// RemoveNodeAttributeCommand
+
+RemoveNodeAttributeCommand::RemoveNodeAttributeCommand(DocumentImpl *document, ElementImpl *element, NodeImpl::Id attribute)
+ : EditCommand(document), m_element(element), m_attribute(attribute)
+{
+ ASSERT(m_element);
+ m_element->ref();
+}
+
+RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand()
+{
+ ASSERT(m_element);
+ m_element->deref();
+}
+
+void RemoveNodeAttributeCommand::doApply()
+{
+ ASSERT(m_element);
+
+ m_oldValue = m_element->getAttribute(m_attribute);
+ ASSERT(!m_oldValue.isNull());
+
+ int exceptionCode = 0;
+ m_element->removeAttribute(m_attribute, exceptionCode);
+ ASSERT(exceptionCode == 0);
+}
+
+void RemoveNodeAttributeCommand::doUnapply()
+{
+ ASSERT(m_element);
+ ASSERT(!m_oldValue.isNull());
+
+ int exceptionCode = 0;
+ m_element->setAttribute(m_attribute, m_oldValue.implementation(), exceptionCode);
+ ASSERT(exceptionCode == 0);
+}
+
+//------------------------------------------------------------------------------------------
+// RemoveNodeCommand
+
+RemoveNodeCommand::RemoveNodeCommand(DocumentImpl *document, NodeImpl *removeChild)
+ : EditCommand(document), m_parent(0), m_removeChild(removeChild), m_refChild(0)
+{
+ ASSERT(m_removeChild);
+ m_removeChild->ref();
+
+ m_parent = m_removeChild->parentNode();
+ ASSERT(m_parent);
+ m_parent->ref();
+
+ m_refChild = m_removeChild->nextSibling();
+ if (m_refChild)
+ m_refChild->ref();
+}
+
+RemoveNodeCommand::~RemoveNodeCommand()
+{
+ ASSERT(m_parent);
+ m_parent->deref();
+
+ ASSERT(m_removeChild);
+ m_removeChild->deref();
+
+ if (m_refChild)
+ m_refChild->deref();
+}
+
+void RemoveNodeCommand::doApply()
+{
+ ASSERT(m_parent);
+ ASSERT(m_removeChild);
+
+ int exceptionCode = 0;
+ m_parent->removeChild(m_removeChild, exceptionCode);
+ ASSERT(exceptionCode == 0);
+}
+
+void RemoveNodeCommand::doUnapply()
+{
+ ASSERT(m_parent);
+ ASSERT(m_removeChild);
+
+ int exceptionCode = 0;
+ m_parent->insertBefore(m_removeChild, m_refChild, exceptionCode);
+ ASSERT(exceptionCode == 0);
+}
+
+//------------------------------------------------------------------------------------------
+// RemoveNodePreservingChildrenCommand
+
+RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand(DocumentImpl *document, NodeImpl *node)
+ : CompositeEditCommand(document), m_node(node)
+{
+ ASSERT(m_node);
+ m_node->ref();
+}
+
+RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand()
+{
+ ASSERT(m_node);
+ m_node->deref();
+}
+
+void RemoveNodePreservingChildrenCommand::doApply()
+{
+ while (NodeImpl* curr = node()->firstChild()) {
+ removeNode(curr);
+ insertNodeBefore(curr, node());
+ }
+ removeNode(node());
+}
+
//------------------------------------------------------------------------------------------
// ReplaceSelectionCommand
}
}
-//------------------------------------------------------------------------------------------
-// MoveSelectionCommand
-
-MoveSelectionCommand::MoveSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, Position &position, bool smartMove)
- : CompositeEditCommand(document), m_fragment(fragment), m_position(position), m_smartMove(smartMove)
-{
- ASSERT(m_fragment);
- m_fragment->ref();
-}
-
-MoveSelectionCommand::~MoveSelectionCommand()
-{
- ASSERT(m_fragment);
- m_fragment->deref();
-}
-
-void MoveSelectionCommand::doApply()
-{
- Selection selection = endingSelection();
- ASSERT(selection.isRange());
-
- // Update the position otherwise it may become invalid after the selection is deleted.
- NodeImpl *positionNode = m_position.node();
- long positionOffset = m_position.offset();
- Position selectionEnd = selection.end();
- long selectionEndOffset = selectionEnd.offset();
- if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) {
- positionOffset -= selectionEndOffset;
- Position selectionStart = selection.start();
- if (selectionStart.node() == positionNode) {
- positionOffset += selectionStart.offset();
- }
- }
-
- deleteSelection(m_smartMove);
-
- setEndingSelection(Position(positionNode, positionOffset));
- EditCommandPtr cmd(new ReplaceSelectionCommand(document(), m_fragment, true, m_smartMove));
- applyCommandToComposite(cmd);
-}
-
-//------------------------------------------------------------------------------------------
-// RemoveCSSPropertyCommand
-
-RemoveCSSPropertyCommand::RemoveCSSPropertyCommand(DocumentImpl *document, CSSStyleDeclarationImpl *decl, int property)
- : EditCommand(document), m_decl(decl->makeMutable()), m_property(property), m_important(false)
-{
- ASSERT(m_decl);
- m_decl->ref();
-}
-
-RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand()
-{
- ASSERT(m_decl);
- m_decl->deref();
-}
-
-void RemoveCSSPropertyCommand::doApply()
-{
- ASSERT(m_decl);
-
- m_oldValue = m_decl->getPropertyValue(m_property);
- ASSERT(!m_oldValue.isNull());
-
- m_important = m_decl->getPropertyPriority(m_property);
- m_decl->removeProperty(m_property);
-}
-
-void RemoveCSSPropertyCommand::doUnapply()
-{
- ASSERT(m_decl);
- ASSERT(!m_oldValue.isNull());
-
- m_decl->setProperty(m_property, m_oldValue, m_important);
-}
-
-//------------------------------------------------------------------------------------------
-// RemoveNodeAttributeCommand
-
-RemoveNodeAttributeCommand::RemoveNodeAttributeCommand(DocumentImpl *document, ElementImpl *element, NodeImpl::Id attribute)
- : EditCommand(document), m_element(element), m_attribute(attribute)
-{
- ASSERT(m_element);
- m_element->ref();
-}
-
-RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand()
-{
- ASSERT(m_element);
- m_element->deref();
-}
-
-void RemoveNodeAttributeCommand::doApply()
-{
- ASSERT(m_element);
-
- m_oldValue = m_element->getAttribute(m_attribute);
- ASSERT(!m_oldValue.isNull());
-
- int exceptionCode = 0;
- m_element->removeAttribute(m_attribute, exceptionCode);
- ASSERT(exceptionCode == 0);
-}
-
-void RemoveNodeAttributeCommand::doUnapply()
-{
- ASSERT(m_element);
- ASSERT(!m_oldValue.isNull());
-
- int exceptionCode = 0;
- m_element->setAttribute(m_attribute, m_oldValue.implementation(), exceptionCode);
- ASSERT(exceptionCode == 0);
-}
-
-//------------------------------------------------------------------------------------------
-// RemoveNodeCommand
-
-RemoveNodeCommand::RemoveNodeCommand(DocumentImpl *document, NodeImpl *removeChild)
- : EditCommand(document), m_parent(0), m_removeChild(removeChild), m_refChild(0)
-{
- ASSERT(m_removeChild);
- m_removeChild->ref();
-
- m_parent = m_removeChild->parentNode();
- ASSERT(m_parent);
- m_parent->ref();
-
- m_refChild = m_removeChild->nextSibling();
- if (m_refChild)
- m_refChild->ref();
-}
-
-RemoveNodeCommand::~RemoveNodeCommand()
-{
- ASSERT(m_parent);
- m_parent->deref();
-
- ASSERT(m_removeChild);
- m_removeChild->deref();
-
- if (m_refChild)
- m_refChild->deref();
-}
-
-void RemoveNodeCommand::doApply()
-{
- ASSERT(m_parent);
- ASSERT(m_removeChild);
-
- int exceptionCode = 0;
- m_parent->removeChild(m_removeChild, exceptionCode);
- ASSERT(exceptionCode == 0);
-}
-
-void RemoveNodeCommand::doUnapply()
-{
- ASSERT(m_parent);
- ASSERT(m_removeChild);
-
- int exceptionCode = 0;
- m_parent->insertBefore(m_removeChild, m_refChild, exceptionCode);
- ASSERT(exceptionCode == 0);
-}
-
-//------------------------------------------------------------------------------------------
-// RemoveNodePreservingChildrenCommand
-
-RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand(DocumentImpl *document, NodeImpl *node)
- : CompositeEditCommand(document), m_node(node)
-{
- ASSERT(m_node);
- m_node->ref();
-}
-
-RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand()
-{
- ASSERT(m_node);
- m_node->deref();
-}
-
-void RemoveNodePreservingChildrenCommand::doApply()
-{
- while (NodeImpl* curr = node()->firstChild()) {
- removeNode(curr);
- insertNodeBefore(curr, node());
- }
- removeNode(node());
-}
-
//------------------------------------------------------------------------------------------
// SetNodeAttributeCommand
unsigned long m_offset;
};
-//------------------------------------------------------------------------------------------
-// ReplaceSelectionCommand
-
-// --- ReplacementFragment helper class
-
-class ReplacementFragment
-{
-public:
- ReplacementFragment(DOM::DocumentFragmentImpl *fragment);
- ~ReplacementFragment();
-
- enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
-
- DOM::DocumentFragmentImpl *root() const { return m_fragment; }
- DOM::NodeImpl *firstChild() const;
- DOM::NodeImpl *lastChild() const;
-
- DOM::NodeImpl *mergeStartNode() const;
- DOM::NodeImpl *mergeEndNode() const;
-
- void pruneEmptyNodes();
-
- EFragmentType type() const { return m_type; }
- bool isEmpty() const { return m_type == EmptyFragment; }
- bool isSingleTextNode() const { return m_type == SingleTextNodeFragment; }
- bool isTreeFragment() const { return m_type == TreeFragment; }
-
- bool hasMoreThanOneBlock() const { return m_hasMoreThanOneBlock; }
- bool hasInterchangeNewlineComment() const { return m_hasInterchangeNewlineComment; }
-
-private:
- // no copy construction or assignment
- ReplacementFragment(const ReplacementFragment &);
- ReplacementFragment &operator=(const ReplacementFragment &);
-
- static bool isInterchangeNewlineComment(const DOM::NodeImpl *);
- static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);
-
- // A couple simple DOM helpers
- void removeNode(DOM::NodeImpl *);
- void insertNodeBefore(DOM::NodeImpl *node, DOM::NodeImpl *refNode);
-
- EFragmentType m_type;
- DOM::DocumentFragmentImpl *m_fragment;
- bool m_hasInterchangeNewlineComment;
- bool m_hasMoreThanOneBlock;
-};
-
-// free-floating helper functions
-bool isProbablyBlock(const DOM::NodeImpl *);
-bool isComment(const DOM::NodeImpl *);
-
-class ReplaceSelectionCommand : public CompositeEditCommand
-{
-public:
- ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false);
- virtual ~ReplaceSelectionCommand();
-
- virtual void doApply();
-
-private:
- void completeHTMLReplacement(const DOM::Position &, const DOM::Position &);
- void completeHTMLReplacement(DOM::NodeImpl *, DOM::NodeImpl *);
-
- ReplacementFragment m_fragment;
- bool m_selectReplacement;
- bool m_smartReplace;
-};
-
//------------------------------------------------------------------------------------------
// MoveSelectionCommand
DOM::NodeImpl *m_node;
};
+//------------------------------------------------------------------------------------------
+// ReplaceSelectionCommand
+
+// --- ReplacementFragment helper class
+
+class ReplacementFragment
+{
+public:
+ ReplacementFragment(DOM::DocumentFragmentImpl *fragment);
+ ~ReplacementFragment();
+
+ enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
+
+ DOM::DocumentFragmentImpl *root() const { return m_fragment; }
+ DOM::NodeImpl *firstChild() const;
+ DOM::NodeImpl *lastChild() const;
+
+ DOM::NodeImpl *mergeStartNode() const;
+ DOM::NodeImpl *mergeEndNode() const;
+
+ void pruneEmptyNodes();
+
+ EFragmentType type() const { return m_type; }
+ bool isEmpty() const { return m_type == EmptyFragment; }
+ bool isSingleTextNode() const { return m_type == SingleTextNodeFragment; }
+ bool isTreeFragment() const { return m_type == TreeFragment; }
+
+ bool hasMoreThanOneBlock() const { return m_hasMoreThanOneBlock; }
+ bool hasInterchangeNewlineComment() const { return m_hasInterchangeNewlineComment; }
+
+private:
+ // no copy construction or assignment
+ ReplacementFragment(const ReplacementFragment &);
+ ReplacementFragment &operator=(const ReplacementFragment &);
+
+ static bool isInterchangeNewlineComment(const DOM::NodeImpl *);
+ static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);
+
+ // A couple simple DOM helpers
+ void removeNode(DOM::NodeImpl *);
+ void insertNodeBefore(DOM::NodeImpl *node, DOM::NodeImpl *refNode);
+
+ EFragmentType m_type;
+ DOM::DocumentFragmentImpl *m_fragment;
+ bool m_hasInterchangeNewlineComment;
+ bool m_hasMoreThanOneBlock;
+};
+
+// free-floating helper functions
+bool isProbablyBlock(const DOM::NodeImpl *);
+bool isComment(const DOM::NodeImpl *);
+
+class ReplaceSelectionCommand : public CompositeEditCommand
+{
+public:
+ ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false);
+ virtual ~ReplaceSelectionCommand();
+
+ virtual void doApply();
+
+private:
+ void completeHTMLReplacement(const DOM::Position &, const DOM::Position &);
+ void completeHTMLReplacement(DOM::NodeImpl *, DOM::NodeImpl *);
+
+ ReplacementFragment m_fragment;
+ bool m_selectReplacement;
+ bool m_smartReplace;
+};
+
//------------------------------------------------------------------------------------------
// SetNodeAttributeCommand