2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef __edit_command_h__
27 #define __edit_command_h__
29 #include "misc/shared.h"
30 #include "edit_actions.h"
31 #include "selection.h"
34 class CSSMutableStyleDeclarationImpl;
41 //------------------------------------------------------------------------------------------
44 class EditCommandPtr : public SharedPtr<EditCommand>
48 EditCommandPtr(EditCommand *);
49 EditCommandPtr(const EditCommandPtr &);
52 EditCommandPtr &operator=(const EditCommandPtr &);
54 bool isCompositeStep() const;
60 EditAction editingAction() const;
62 DOM::DocumentImpl * const document() const;
64 Selection startingSelection() const;
65 Selection endingSelection() const;
67 void setStartingSelection(const Selection &s) const;
68 void setStartingSelection(const VisiblePosition &p) const;
69 void setStartingSelection(const DOM::Position &p, EAffinity affinity) const;
70 void setEndingSelection(const Selection &s) const;
71 void setEndingSelection(const VisiblePosition &p) const;
72 void setEndingSelection(const DOM::Position &p, EAffinity affinity) const;
74 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const;
75 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *) const;
77 EditCommandPtr parent() const;
78 void setParent(const EditCommandPtr &) const;
80 bool isInsertTextCommand() const;
81 bool isInsertLineBreakCommand() const;
82 bool isTypingCommand() const;
84 static EditCommandPtr &emptyCommand();
87 //------------------------------------------------------------------------------------------
90 class EditCommand : public Shared<EditCommand>
93 EditCommand(DOM::DocumentImpl *);
94 virtual ~EditCommand();
96 bool isCompositeStep() const { return m_parent != 0; }
97 EditCommand *parent() const { return m_parent; }
98 void setParent(EditCommand *parent) { m_parent = parent; }
100 enum ECommandState { NotApplied, Applied };
106 virtual void doApply() = 0;
107 virtual void doUnapply() = 0;
108 virtual void doReapply(); // calls doApply()
110 virtual EditAction editingAction() const;
112 virtual DOM::DocumentImpl * const document() const { return m_document; }
114 Selection startingSelection() const { return m_startingSelection; }
115 Selection endingSelection() const { return m_endingSelection; }
117 void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); }
119 ECommandState state() const { return m_state; }
120 void setState(ECommandState state) { m_state = state; }
122 void setStartingSelection(const Selection &s);
123 void setStartingSelection(const VisiblePosition &p);
124 void setStartingSelection(const DOM::Position &p, EAffinity affinity);
125 void setEndingSelection(const Selection &s);
126 void setEndingSelection(const VisiblePosition &p);
127 void setEndingSelection(const DOM::Position &p, EAffinity affinity);
129 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; };
130 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
132 DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos);
134 virtual bool isInsertTextCommand() const;
135 virtual bool isTypingCommand() const;
138 void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
140 virtual bool preservesTypingStyle() const;
142 DOM::DocumentImpl *m_document;
143 ECommandState m_state;
144 Selection m_startingSelection;
145 Selection m_endingSelection;
146 DOM::CSSMutableStyleDeclarationImpl *m_typingStyle;
147 EditCommand *m_parent;
152 #endif // __edit_command_h__