Reviewed by Kevin.
[WebKit-https.git] / WebCore / khtml / editing / htmlediting.cpp
index e8605da5b0ff7543f46494f1e61050f7f2eb1cbc..f3fafb83165686964e97e654cc45c531bd75f4f4 100644 (file)
@@ -88,9 +88,7 @@ using DOM::TreeWalkerImpl;
 #include "KWQAssertions.h"
 #include "KWQLogging.h"
 #include "KWQKHTMLPart.h"
-#endif
-
-#if !APPLE_CHANGES
+#else
 #define ASSERT(assertion) ((void)0)
 #define ASSERT_WITH_MESSAGE(assertion, formatAndArgs...) ((void)0)
 #define ASSERT_NOT_REACHED() ((void)0)
@@ -103,14 +101,6 @@ using DOM::TreeWalkerImpl;
 #endif
 #endif
 
-#define IF_IMPL_NULL_RETURN_ARG(arg) do { \
-        if (isNull()) { return arg; } \
-    } while (0)
-        
-#define IF_IMPL_NULL_RETURN do { \
-        if (isNull()) { return; } \
-    } while (0)
-
 namespace khtml {
 
 static inline bool isNBSP(const QChar &c)
@@ -247,159 +237,6 @@ static void debugNode(const char *prefix, const NodeImpl *node)
         LOG(Editing, "%s%s %p", prefix, node->nodeName().string().latin1(), node);
 }
 
-//------------------------------------------------------------------------------------------
-// EditCommandPtr
-
-EditCommandPtr::EditCommandPtr()
-{
-}
-
-EditCommandPtr::EditCommandPtr(EditCommand *impl) : SharedPtr<EditCommand>(impl)
-{
-}
-
-EditCommandPtr::EditCommandPtr(const EditCommandPtr &o) : SharedPtr<EditCommand>(o)
-{
-}
-
-EditCommandPtr::~EditCommandPtr()
-{
-}
-
-EditCommandPtr &EditCommandPtr::operator=(const EditCommandPtr &c)
-{
-    static_cast<SharedPtr<EditCommand> &>(*this) = c;
-    return *this;
-}
-
-bool EditCommandPtr::isCompositeStep() const
-{
-    IF_IMPL_NULL_RETURN_ARG(false);        
-    return get()->isCompositeStep();
-}
-
-bool EditCommandPtr::isInsertTextCommand() const
-{
-    IF_IMPL_NULL_RETURN_ARG(false);        
-    return get()->isInsertTextCommand();
-}
-
-bool EditCommandPtr::isTypingCommand() const
-{
-    IF_IMPL_NULL_RETURN_ARG(false);        
-    return get()->isTypingCommand();
-}
-
-void EditCommandPtr::apply() const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->apply();
-}
-
-void EditCommandPtr::unapply() const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->unapply();
-}
-
-void EditCommandPtr::reapply() const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->reapply();
-}
-
-EditAction EditCommandPtr::editingAction() const
-{
-    IF_IMPL_NULL_RETURN_ARG(EditActionUnspecified);
-    return get()->editingAction();
-}
-
-DocumentImpl * const EditCommandPtr::document() const
-{
-    IF_IMPL_NULL_RETURN_ARG(0);
-    return get()->document();
-}
-
-Selection EditCommandPtr::startingSelection() const
-{
-    IF_IMPL_NULL_RETURN_ARG(Selection());
-    return get()->startingSelection();
-}
-
-Selection EditCommandPtr::endingSelection() const
-{
-    IF_IMPL_NULL_RETURN_ARG(Selection());
-    return get()->endingSelection();
-}
-
-void EditCommandPtr::setStartingSelection(const Selection &s) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setStartingSelection(s);
-}
-
-void EditCommandPtr::setStartingSelection(const VisiblePosition &p) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setStartingSelection(p);
-}
-
-void EditCommandPtr::setStartingSelection(const Position &p, EAffinity affinity) const
-{
-    IF_IMPL_NULL_RETURN;
-    Selection s = Selection(p, affinity);
-    get()->setStartingSelection(s);
-}
-
-void EditCommandPtr::setEndingSelection(const Selection &s) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setEndingSelection(s);
-}
-
-void EditCommandPtr::setEndingSelection(const VisiblePosition &p) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setEndingSelection(p);
-}
-
-void EditCommandPtr::setEndingSelection(const Position &p, EAffinity affinity) const
-{
-    IF_IMPL_NULL_RETURN;
-    Selection s = Selection(p, affinity);
-    get()->setEndingSelection(s);
-}
-
-CSSMutableStyleDeclarationImpl *EditCommandPtr::typingStyle() const
-{
-    IF_IMPL_NULL_RETURN_ARG(0);
-    return get()->typingStyle();
-}
-
-void EditCommandPtr::setTypingStyle(CSSMutableStyleDeclarationImpl *style) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setTypingStyle(style);
-}
-
-EditCommandPtr EditCommandPtr::parent() const
-{
-    IF_IMPL_NULL_RETURN_ARG(0);
-    return get()->parent();
-}
-
-void EditCommandPtr::setParent(const EditCommandPtr &cmd) const
-{
-    IF_IMPL_NULL_RETURN;
-    get()->setParent(cmd.get());
-}
-
-EditCommandPtr &EditCommandPtr::emptyCommand()
-{
-    static EditCommandPtr m_emptyCommand;
-    return m_emptyCommand;
-}
-
 //------------------------------------------------------------------------------------------
 // StyleChange
 
@@ -534,210 +371,6 @@ bool StyleChange::currentlyHasStyle(const Position &pos, const CSSProperty *prop
     return result;
 }
 
-//------------------------------------------------------------------------------------------
-// EditCommand
-
-EditCommand::EditCommand(DocumentImpl *document) 
-    : m_document(document), m_state(NotApplied), m_typingStyle(0), m_parent(0)
-{
-    ASSERT(m_document);
-    ASSERT(m_document->part());
-    m_document->ref();
-    m_startingSelection = m_document->part()->selection();
-    m_endingSelection = m_startingSelection;
-
-    m_document->part()->setSelection(Selection(), false, true);
-}
-
-EditCommand::~EditCommand()
-{
-    ASSERT(m_document);
-    m_document->deref();
-    if (m_typingStyle)
-        m_typingStyle->deref();
-}
-
-void EditCommand::apply()
-{
-    ASSERT(m_document);
-    ASSERT(m_document->part());
-    ASSERT(state() == NotApplied);
-    KHTMLPart *part = m_document->part();
-
-    ASSERT(part->selection().isNone());
-
-    doApply();
-    
-    m_state = Applied;
-
-    // FIXME: Improve typing style.
-    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
-    if (!preservesTypingStyle())
-        setTypingStyle(0);
-
-    if (!isCompositeStep()) {
-        document()->updateLayout();
-        EditCommandPtr cmd(this);
-        part->appliedEditing(cmd);
-    }
-}
-
-void EditCommand::unapply()
-{
-    ASSERT(m_document);
-    ASSERT(m_document->part());
-    ASSERT(state() == Applied);
-
-    bool topLevel = !isCompositeStep();
-    KHTMLPart *part = m_document->part();
-
-    if (topLevel) {
-        part->setSelection(Selection(), false, true);
-    }
-    ASSERT(part->selection().isNone());
-    
-    doUnapply();
-    
-    m_state = NotApplied;
-
-    if (topLevel) {
-        document()->updateLayout();
-        EditCommandPtr cmd(this);
-        part->unappliedEditing(cmd);
-    }
-}
-
-void EditCommand::reapply()
-{
-    ASSERT(m_document);
-    ASSERT(m_document->part());
-    ASSERT(state() == NotApplied);
-    
-    bool topLevel = !isCompositeStep();
-    KHTMLPart *part = m_document->part();
-
-    if (topLevel) {
-        part->setSelection(Selection(), false, true);
-    }
-    ASSERT(part->selection().isNone());
-    
-    doReapply();
-    
-    m_state = Applied;
-
-    if (topLevel) {
-        document()->updateLayout();
-        EditCommandPtr cmd(this);
-        part->reappliedEditing(cmd);
-    }
-}
-
-void EditCommand::doReapply()
-{
-    doApply();
-}
-
-EditAction EditCommand::editingAction() const
-{
-    return EditActionUnspecified;
-}
-
-void EditCommand::setStartingSelection(const Selection &s)
-{
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_startingSelection = s;
-}
-
-void EditCommand::setStartingSelection(const VisiblePosition &p)
-{
-    Selection s = Selection(p);
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_startingSelection = s;
-}
-
-void EditCommand::setStartingSelection(const Position &p, EAffinity affinity)
-{
-    Selection s = Selection(p, affinity);
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_startingSelection = s;
-}
-
-void EditCommand::setEndingSelection(const Selection &s)
-{
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_endingSelection = s;
-}
-
-void EditCommand::setEndingSelection(const VisiblePosition &p)
-{
-    Selection s = Selection(p);
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_endingSelection = s;
-}
-
-void EditCommand::setEndingSelection(const Position &p, EAffinity affinity)
-{
-    Selection s = Selection(p, affinity);
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->m_endingSelection = s;
-}
-
-void EditCommand::assignTypingStyle(CSSMutableStyleDeclarationImpl *style)
-{
-    if (m_typingStyle == style)
-        return;
-        
-    CSSMutableStyleDeclarationImpl *old = m_typingStyle;
-    m_typingStyle = style;
-    if (m_typingStyle)
-        m_typingStyle->ref();
-    if (old)
-        old->deref();
-}
-
-void EditCommand::setTypingStyle(CSSMutableStyleDeclarationImpl *style)
-{
-    // FIXME: Improve typing style.
-    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
-    for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
-        cmd->assignTypingStyle(style);
-}
-
-bool EditCommand::preservesTypingStyle() const
-{
-    return false;
-}
-
-bool EditCommand::isInsertTextCommand() const
-{
-    return false;
-}
-
-bool EditCommand::isTypingCommand() const
-{
-    return false;
-}
-
-CSSMutableStyleDeclarationImpl *EditCommand::styleAtPosition(const Position &pos)
-{
-    CSSComputedStyleDeclarationImpl *computedStyle = pos.computedStyle();
-    computedStyle->ref();
-    CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties();
-    computedStyle->deref();
-    // FIXME: Improve typing style.
-    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
-    CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
-    if (typingStyle)
-        style->merge(typingStyle);
-    
-    return style;
-}
-
-
 //------------------------------------------------------------------------------------------
 // CompositeEditCommand