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;
40 //------------------------------------------------------------------------------------------
43 class EditCommand : public Shared<EditCommand>
46 EditCommand(DOM::DocumentImpl *);
47 virtual ~EditCommand();
49 bool isCompositeStep() const { return m_parent != 0; }
50 EditCommand *parent() const { return m_parent; }
51 void setParent(EditCommand *parent) { m_parent = parent; }
53 enum ECommandState { NotApplied, Applied };
59 virtual void doApply() = 0;
60 virtual void doUnapply() = 0;
61 virtual void doReapply(); // calls doApply()
63 virtual EditAction editingAction() const;
65 virtual DOM::DocumentImpl * const document() const { return m_document; }
67 Selection startingSelection() const { return m_startingSelection; }
68 Selection endingSelection() const { return m_endingSelection; }
70 void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); }
72 ECommandState state() const { return m_state; }
73 void setState(ECommandState state) { m_state = state; }
75 void setStartingSelection(const Selection &s);
76 void setStartingSelection(const VisiblePosition &p);
77 void setStartingSelection(const DOM::Position &p, EAffinity affinity);
78 void setEndingSelection(const Selection &s);
79 void setEndingSelection(const VisiblePosition &p);
80 void setEndingSelection(const DOM::Position &p, EAffinity affinity);
82 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; };
83 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
85 DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos);
87 virtual bool isInsertTextCommand() const;
88 virtual bool isTypingCommand() const;
91 void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
93 virtual bool preservesTypingStyle() const;
95 DOM::DocumentImpl *m_document;
96 ECommandState m_state;
97 Selection m_startingSelection;
98 Selection m_endingSelection;
99 DOM::CSSMutableStyleDeclarationImpl *m_typingStyle;
100 EditCommand *m_parent;
103 class EditCommandPtr : public SharedPtr<EditCommand>
107 EditCommandPtr(EditCommand *);
108 EditCommandPtr(const EditCommandPtr &);
111 EditCommandPtr &operator=(const EditCommandPtr &);
113 bool isCompositeStep() const;
116 void unapply() const;
117 void reapply() const;
119 EditAction editingAction() const;
121 DOM::DocumentImpl * const document() const;
123 Selection startingSelection() const;
124 Selection endingSelection() const;
126 void setStartingSelection(const Selection &s) const;
127 void setStartingSelection(const VisiblePosition &p) const;
128 void setStartingSelection(const DOM::Position &p, EAffinity affinity) const;
129 void setEndingSelection(const Selection &s) const;
130 void setEndingSelection(const VisiblePosition &p) const;
131 void setEndingSelection(const DOM::Position &p, EAffinity affinity) const;
133 DOM::CSSMutableStyleDeclarationImpl *typingStyle() const;
134 void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *) const;
136 EditCommandPtr parent() const;
137 void setParent(const EditCommandPtr &) const;
139 bool isInsertTextCommand() const;
140 bool isInsertLineBreakCommand() const;
141 bool isTypingCommand() const;
143 static EditCommandPtr &emptyCommand();
148 #endif // __edit_command_h__