2
* Copyright (C) 2005, 2006 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.
27
#include "EditCommand.h"
29
#include "CompositeEditCommand.h"
30
#include "CSSComputedStyleDeclaration.h"
31
#include "CSSMutableStyleDeclaration.h"
32
#include "DeleteButtonController.h"
36
#include "EventNames.h"
38
#include "SelectionController.h"
39
#include "VisiblePosition.h"
40
#include "htmlediting.h"
44
using namespace EventNames;
46
EditCommand::EditCommand(Document* document)
47
: m_document(document)
48
, m_startingSelection(document->frame()->selectionController()->selection())
49
, m_endingSelection(m_startingSelection)
50
, m_startingRootEditableElement(m_startingSelection.rootEditableElement())
51
, m_endingRootEditableElement(m_startingRootEditableElement)
55
ASSERT(m_document->frame());
56
setStartingSelection(m_document->frame()->selectionController()->selection());
57
setEndingSelection(m_startingSelection);
60
EditCommand::~EditCommand()
64
void EditCommand::apply()
67
ASSERT(m_document->frame());
69
Frame* frame = m_document->frame();
72
if (!endingSelection().isContentRichlyEditable()) {
73
switch (editingAction()) {
74
case EditActionTyping:
77
case EditActionSetWritingDirection:
79
case EditActionUnspecified:
90
// FIXME: Improve typing style.
91
// See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
92
if (!preservesTypingStyle()) {
95
frame->editor()->setRemovedAnchor(0);
100
frame->editor()->appliedEditing(this);
104
void EditCommand::unapply()
107
ASSERT(m_document->frame());
109
Frame* frame = m_document->frame();
115
frame->editor()->unappliedEditing(this);
119
void EditCommand::reapply()
122
ASSERT(m_document->frame());
124
Frame* frame = m_document->frame();
130
frame->editor()->reappliedEditing(this);
134
void EditCommand::doReapply()
139
EditAction EditCommand::editingAction() const
141
return EditActionUnspecified;
144
void EditCommand::setStartingSelection(const Selection& s)
146
Element* root = s.rootEditableElement();
147
for (EditCommand* cmd = this; cmd; cmd = cmd->m_parent) {
148
cmd->m_startingSelection = s;
149
cmd->m_startingRootEditableElement = root;
150
if (!cmd->m_parent || cmd->m_parent->isFirstCommand(cmd))
155
void EditCommand::setEndingSelection(const Selection &s)
157
Element* root = s.rootEditableElement();
158
for (EditCommand* cmd = this; cmd; cmd = cmd->m_parent) {
159
cmd->m_endingSelection = s;
160
cmd->m_endingRootEditableElement = root;
164
void EditCommand::setTypingStyle(PassRefPtr<CSSMutableStyleDeclaration> style)
166
// FIXME: Improve typing style.
167
// See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
169
// Special more-efficient case for where there's only one command that
170
// takes advantage of the ability of PassRefPtr to pass its ref to a RefPtr.
171
m_typingStyle = style;
174
for (EditCommand* cmd = this; cmd; cmd = cmd->m_parent)
175
cmd->m_typingStyle = style.get(); // must use get() to avoid setting parent styles to 0
178
bool EditCommand::preservesTypingStyle() const
183
bool EditCommand::isInsertTextCommand() const
188
bool EditCommand::isTypingCommand() const
193
PassRefPtr<CSSMutableStyleDeclaration> EditCommand::styleAtPosition(const Position &pos)
195
RefPtr<CSSMutableStyleDeclaration> style = positionBeforeTabSpan(pos).computedStyle()->copyInheritableProperties();
197
// FIXME: Improve typing style.
198
// See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
199
CSSMutableStyleDeclaration* typingStyle = document()->frame()->typingStyle();
201
style->merge(typingStyle);
203
return style.release();
206
void EditCommand::updateLayout() const
208
document()->updateLayoutIgnorePendingStylesheets();
211
void EditCommand::setParent(CompositeEditCommand* parent)
216
m_startingSelection = parent->m_endingSelection;
217
m_endingSelection = parent->m_endingSelection;
218
m_startingRootEditableElement = parent->m_endingRootEditableElement;
219
m_endingRootEditableElement = parent->m_endingRootEditableElement;
222
void applyCommand(PassRefPtr<EditCommand> command)
224
DeleteButtonController *deleteButtonController = command->document()->frame()->editor()->deleteButtonController();
225
deleteButtonController->disable();
227
deleteButtonController->enable();
230
} // namespace WebCore