From 7dcd8829f6899c0ac08bb9352534fb24a3eec1e2 Mon Sep 17 00:00:00 2001 From: mjs Date: Wed, 11 May 2005 06:04:24 +0000 Subject: [PATCH] Reviewed by Kevin. - start on splitting htmlediting.cpp into smaller files - pull EditCommand and EditCommandPtr out. * WebCore.pbproj/project.pbxproj: * khtml/editing/edit_command.cpp: Added. * khtml/editing/edit_command.h: Added. * khtml/editing/htmlediting.cpp: Took EditCommand and EditCommandPtr out. * khtml/editing/htmlediting.h: Ditto. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9160 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog-2005-08-23 | 13 + WebCore/WebCore.pbproj/project.pbxproj | 34 ++ WebCore/khtml/editing/edit_command.cpp | 421 +++++++++++++++++++++++++ WebCore/khtml/editing/edit_command.h | 152 +++++++++ WebCore/khtml/editing/htmlediting.cpp | 369 +--------------------- WebCore/khtml/editing/htmlediting.h | 110 +------ WebCore/khtml/khtml_part.cpp | 1 + WebCore/khtml/khtmlpart_p.h | 2 +- 8 files changed, 624 insertions(+), 478 deletions(-) create mode 100644 WebCore/khtml/editing/edit_command.cpp create mode 100644 WebCore/khtml/editing/edit_command.h diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23 index 5c3a10a87bbe..7aebab6e6b5a 100644 --- a/WebCore/ChangeLog-2005-08-23 +++ b/WebCore/ChangeLog-2005-08-23 @@ -1,3 +1,16 @@ +2005-05-10 Maciej Stachowiak + + Reviewed by Kevin. + + - start on splitting htmlediting.cpp into smaller files - pull + EditCommand and EditCommandPtr out. + + * WebCore.pbproj/project.pbxproj: + * khtml/editing/edit_command.cpp: Added. + * khtml/editing/edit_command.h: Added. + * khtml/editing/htmlediting.cpp: Took EditCommand and EditCommandPtr out. + * khtml/editing/htmlediting.h: Ditto. + 2005-05-10 David Hyatt Refactor the DOM so that the concept of class/style/id is no longer unique to HTML elements. This paves the way diff --git a/WebCore/WebCore.pbproj/project.pbxproj b/WebCore/WebCore.pbproj/project.pbxproj index 7ff18667b84a..482f04bdbdaf 100644 --- a/WebCore/WebCore.pbproj/project.pbxproj +++ b/WebCore/WebCore.pbproj/project.pbxproj @@ -325,6 +325,36 @@ //652 //653 //654 + 654D87B50831973B0082DCA1 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.cpp.cpp; + name = edit_command.cpp; + path = editing/edit_command.cpp; + refType = 4; + sourceTree = ""; + }; + 654D87B60831973B0082DCA1 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = edit_command.h; + path = editing/edit_command.h; + refType = 4; + sourceTree = ""; + }; + 654D87B70831973B0082DCA1 = { + fileRef = 654D87B50831973B0082DCA1; + isa = PBXBuildFile; + settings = { + }; + }; + 654D87B80831973B0082DCA1 = { + fileRef = 654D87B60831973B0082DCA1; + isa = PBXBuildFile; + settings = { + }; + }; 654E7EE00569FD4600358BD2 = { fileEncoding = 30; isa = PBXFileReference; @@ -1808,6 +1838,7 @@ 93F199FA08245E59001E9ABC, 93F199FB08245E59001E9ABC, 93F199FC08245E59001E9ABC, + 654D87B80831973B0082DCA1, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -4231,6 +4262,7 @@ 93F19B1008245E59001E9ABC, 93F19B1108245E59001E9ABC, 93276B4F0826F80F002E46CE, + 654D87B70831973B0082DCA1, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -6522,6 +6554,8 @@ BEB1DD0805C197DF00DD1F43 = { children = ( EDA4AC97076FB89100DD23EC, + 654D87B50831973B0082DCA1, + 654D87B60831973B0082DCA1, BE9185DD05EE59B80081354D, BE9185E005EE59B80081354D, BEA5DBDA075CEDA00098A432, diff --git a/WebCore/khtml/editing/edit_command.cpp b/WebCore/khtml/editing/edit_command.cpp new file mode 100644 index 000000000000..cca3005e8c48 --- /dev/null +++ b/WebCore/khtml/editing/edit_command.cpp @@ -0,0 +1,421 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "edit_command.h" + +#include "xml/dom_position.h" +#include "xml/dom_docimpl.h" +#include "css/css_valueimpl.h" +#include "css/css_computedstyle.h" + +#if APPLE_CHANGES +#include "KWQAssertions.h" +#include "KWQLogging.h" +#include "KWQKHTMLPart.h" +#else +#define ASSERT(assertion) ((void)0) +#define ASSERT_WITH_MESSAGE(assertion, formatAndArgs...) ((void)0) +#define ASSERT_NOT_REACHED() ((void)0) +#define LOG(channel, formatAndArgs...) ((void)0) +#define ERROR(formatAndArgs...) ((void)0) +#define ASSERT(assertion) assert(assertion) +#if LOG_DISABLED +#define debugPosition(a,b) ((void)0) +#define debugNode(a,b) ((void)0) +#endif +#endif + +using DOM::DocumentImpl; +using DOM::Position; +using DOM::CSSMutableStyleDeclarationImpl; +using DOM::CSSComputedStyleDeclarationImpl; + +#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 { + +//------------------------------------------------------------------------------------------ +// EditCommandPtr + +EditCommandPtr::EditCommandPtr() +{ +} + +EditCommandPtr::EditCommandPtr(EditCommand *impl) : SharedPtr(impl) +{ +} + +EditCommandPtr::EditCommandPtr(const EditCommandPtr &o) : SharedPtr(o) +{ +} + +EditCommandPtr::~EditCommandPtr() +{ +} + +EditCommandPtr &EditCommandPtr::operator=(const EditCommandPtr &c) +{ + static_cast &>(*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; +} + +//------------------------------------------------------------------------------------------ +// 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: 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: 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: Implementation of typing style needs improvement + CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle(); + if (typingStyle) + style->merge(typingStyle); + + return style; +} + +} // namespace khtml diff --git a/WebCore/khtml/editing/edit_command.h b/WebCore/khtml/editing/edit_command.h new file mode 100644 index 000000000000..d066f3b9eaad --- /dev/null +++ b/WebCore/khtml/editing/edit_command.h @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __edit_command_h__ +#define __edit_command_h__ + +#include "misc/shared.h" +#include "edit_actions.h" +#include "selection.h" + +namespace DOM { + class CSSMutableStyleDeclarationImpl; + class DocumentImpl; +} + +namespace khtml { + +class EditCommand; +//------------------------------------------------------------------------------------------ +// EditCommandPtr + +class EditCommandPtr : public SharedPtr +{ +public: + EditCommandPtr(); + EditCommandPtr(EditCommand *); + EditCommandPtr(const EditCommandPtr &); + ~EditCommandPtr(); + + EditCommandPtr &operator=(const EditCommandPtr &); + + bool isCompositeStep() const; + + void apply() const; + void unapply() const; + void reapply() const; + + EditAction editingAction() const; + + DOM::DocumentImpl * const document() const; + + Selection startingSelection() const; + Selection endingSelection() const; + + void setStartingSelection(const Selection &s) const; + void setStartingSelection(const VisiblePosition &p) const; + void setStartingSelection(const DOM::Position &p, EAffinity affinity) const; + void setEndingSelection(const Selection &s) const; + void setEndingSelection(const VisiblePosition &p) const; + void setEndingSelection(const DOM::Position &p, EAffinity affinity) const; + + DOM::CSSMutableStyleDeclarationImpl *typingStyle() const; + void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *) const; + + EditCommandPtr parent() const; + void setParent(const EditCommandPtr &) const; + + bool isInsertTextCommand() const; + bool isInsertLineBreakCommand() const; + bool isTypingCommand() const; + + static EditCommandPtr &emptyCommand(); +}; + +//------------------------------------------------------------------------------------------ +// EditCommand + +class EditCommand : public Shared +{ +public: + EditCommand(DOM::DocumentImpl *); + virtual ~EditCommand(); + + bool isCompositeStep() const { return m_parent != 0; } + EditCommand *parent() const { return m_parent; } + void setParent(EditCommand *parent) { m_parent = parent; } + + enum ECommandState { NotApplied, Applied }; + + void apply(); + void unapply(); + void reapply(); + + virtual void doApply() = 0; + virtual void doUnapply() = 0; + virtual void doReapply(); // calls doApply() + + virtual EditAction editingAction() const; + + virtual DOM::DocumentImpl * const document() const { return m_document; } + + Selection startingSelection() const { return m_startingSelection; } + Selection endingSelection() const { return m_endingSelection; } + + void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); } + + ECommandState state() const { return m_state; } + void setState(ECommandState state) { m_state = state; } + + void setStartingSelection(const Selection &s); + void setStartingSelection(const VisiblePosition &p); + void setStartingSelection(const DOM::Position &p, EAffinity affinity); + void setEndingSelection(const Selection &s); + void setEndingSelection(const VisiblePosition &p); + void setEndingSelection(const DOM::Position &p, EAffinity affinity); + + DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; }; + void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); + + DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos); + + virtual bool isInsertTextCommand() const; + virtual bool isTypingCommand() const; + +private: + void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); + + virtual bool preservesTypingStyle() const; + + DOM::DocumentImpl *m_document; + ECommandState m_state; + Selection m_startingSelection; + Selection m_endingSelection; + DOM::CSSMutableStyleDeclarationImpl *m_typingStyle; + EditCommand *m_parent; +}; + +} // namespace khtml + +#endif // __edit_command_h__ diff --git a/WebCore/khtml/editing/htmlediting.cpp b/WebCore/khtml/editing/htmlediting.cpp index e8605da5b0ff..f3fafb831656 100644 --- a/WebCore/khtml/editing/htmlediting.cpp +++ b/WebCore/khtml/editing/htmlediting.cpp @@ -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(impl) -{ -} - -EditCommandPtr::EditCommandPtr(const EditCommandPtr &o) : SharedPtr(o) -{ -} - -EditCommandPtr::~EditCommandPtr() -{ -} - -EditCommandPtr &EditCommandPtr::operator=(const EditCommandPtr &c) -{ - static_cast &>(*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: 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: 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: Implementation of typing style needs improvement - CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle(); - if (typingStyle) - style->merge(typingStyle); - - return style; -} - - //------------------------------------------------------------------------------------------ // CompositeEditCommand diff --git a/WebCore/khtml/editing/htmlediting.h b/WebCore/khtml/editing/htmlediting.h index 8e135857d73e..f0a6410127c1 100644 --- a/WebCore/khtml/editing/htmlediting.h +++ b/WebCore/khtml/editing/htmlediting.h @@ -26,6 +26,7 @@ #ifndef __htmlediting_h__ #define __htmlediting_h__ +#include "edit_command.h" #include "dom_nodeimpl.h" #include "editing/edit_actions.h" #include "qmap.h" @@ -49,52 +50,6 @@ class EditCommand; class Selection; class VisiblePosition; -//------------------------------------------------------------------------------------------ -// EditCommandPtr - -class EditCommandPtr : public SharedPtr -{ -public: - EditCommandPtr(); - EditCommandPtr(EditCommand *); - EditCommandPtr(const EditCommandPtr &); - ~EditCommandPtr(); - - EditCommandPtr &operator=(const EditCommandPtr &); - - bool isCompositeStep() const; - - void apply() const; - void unapply() const; - void reapply() const; - - EditAction editingAction() const; - - DOM::DocumentImpl * const document() const; - - Selection startingSelection() const; - Selection endingSelection() const; - - void setStartingSelection(const Selection &s) const; - void setStartingSelection(const VisiblePosition &p) const; - void setStartingSelection(const DOM::Position &p, EAffinity affinity) const; - void setEndingSelection(const Selection &s) const; - void setEndingSelection(const VisiblePosition &p) const; - void setEndingSelection(const DOM::Position &p, EAffinity affinity) const; - - DOM::CSSMutableStyleDeclarationImpl *typingStyle() const; - void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *) const; - - EditCommandPtr parent() const; - void setParent(const EditCommandPtr &) const; - - bool isInsertTextCommand() const; - bool isInsertLineBreakCommand() const; - bool isTypingCommand() const; - - static EditCommandPtr &emptyCommand(); -}; - //------------------------------------------------------------------------------------------ // StyleChange @@ -134,69 +89,6 @@ private: bool m_usesLegacyStyles; }; -//------------------------------------------------------------------------------------------ -// EditCommand - -class EditCommand : public Shared -{ -public: - EditCommand(DOM::DocumentImpl *); - virtual ~EditCommand(); - - bool isCompositeStep() const { return m_parent != 0; } - EditCommand *parent() const { return m_parent; } - void setParent(EditCommand *parent) { m_parent = parent; } - - enum ECommandState { NotApplied, Applied }; - - void apply(); - void unapply(); - void reapply(); - - virtual void doApply() = 0; - virtual void doUnapply() = 0; - virtual void doReapply(); // calls doApply() - - virtual EditAction editingAction() const; - - virtual DOM::DocumentImpl * const document() const { return m_document; } - - Selection startingSelection() const { return m_startingSelection; } - Selection endingSelection() const { return m_endingSelection; } - - void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); } - - ECommandState state() const { return m_state; } - void setState(ECommandState state) { m_state = state; } - - void setStartingSelection(const Selection &s); - void setStartingSelection(const VisiblePosition &p); - void setStartingSelection(const DOM::Position &p, EAffinity affinity); - void setEndingSelection(const Selection &s); - void setEndingSelection(const VisiblePosition &p); - void setEndingSelection(const DOM::Position &p, EAffinity affinity); - - DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; }; - void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); - - DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos); - - virtual bool isInsertTextCommand() const; - virtual bool isTypingCommand() const; - -private: - void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); - - virtual bool preservesTypingStyle() const; - - DOM::DocumentImpl *m_document; - ECommandState m_state; - Selection m_startingSelection; - Selection m_endingSelection; - DOM::CSSMutableStyleDeclarationImpl *m_typingStyle; - EditCommand *m_parent; -}; - //------------------------------------------------------------------------------------------ // CompositeEditCommand diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp index afe21140c57a..0234e50c748f 100644 --- a/WebCore/khtml/khtml_part.cpp +++ b/WebCore/khtml/khtml_part.cpp @@ -44,6 +44,7 @@ #include "dom/dom_element.h" #include "dom/html_document.h" #include "editing/markup.h" +#include "editing/htmlediting.h" #include "editing/selection.h" #include "editing/visible_position.h" #include "editing/visible_text.h" diff --git a/WebCore/khtml/khtmlpart_p.h b/WebCore/khtml/khtmlpart_p.h index cfa06eda45eb..8a0bb606ce80 100644 --- a/WebCore/khtml/khtmlpart_p.h +++ b/WebCore/khtml/khtmlpart_p.h @@ -46,7 +46,7 @@ #include "ecma/kjs_proxy.h" #include "css/css_valueimpl.h" #include "dom/dom_misc.h" -#include "editing/htmlediting.h" +#include "editing/edit_command.h" #include "editing/selection.h" namespace KIO -- 2.36.0