Reviewed by me
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Dec 2004 21:59:51 +0000 (21:59 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Dec 2004 21:59:51 +0000 (21:59 +0000)
        Moving code only.

        * khtml/editing/htmlediting.cpp: Move ReplaceSelectionCommand into alphabetical order with
        regard to other editing commands. The class had a name change ages ago, and it was never
        moved.
        * khtml/editing/htmlediting.h: Ditto.

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

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

index 986aa325664111b9b0c2d22fa874f9312be3c53f..2a944b31dfa7e75ccc7ca621c375e661f36b29b9 100644 (file)
@@ -1,3 +1,14 @@
+2004-12-01  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by me
+
+        Moving code only.
+
+        * khtml/editing/htmlediting.cpp: Move ReplaceSelectionCommand into alphabetical order with
+        regard to other editing commands. The class had a name change ages ago, and it was never
+        moved.
+        * khtml/editing/htmlediting.h: Ditto.
+
 2004-12-01  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Hyatt
index 6c366b62c63ebc1bc0522fdef41c5133a7fab981..d35bf4f452253c1fcc5be68d0926dd7543fd2804 100644 (file)
@@ -2670,6 +2670,195 @@ void JoinTextNodesCommand::doUnapply()
     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
 
@@ -3157,195 +3346,6 @@ void ReplaceSelectionCommand::completeHTMLReplacement(NodeImpl *firstNodeInserte
     }
 }
 
-//------------------------------------------------------------------------------------------
-// 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
 
index fd0b89cc6da7b2dc280f033a7c36a0f159a5017b..e2d150c851aca3cb78c2e5927851044c55cea83b 100644 (file)
@@ -478,75 +478,6 @@ private:
     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
 
@@ -644,6 +575,75 @@ private:
     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