2 * Copyright (C) 2006, 2007, 2008 Apple 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.
29 #include "ClipboardAccessPolicy.h"
31 #include "EditAction.h"
32 #include "EditorDeleteAction.h"
33 #include "EditorInsertAction.h"
34 #include "SelectionController.h"
38 class CSSStyleDeclaration
;
40 class DeleteButtonController
;
43 class EditorInternalCommand
;
50 struct CompositionUnderline
{
51 CompositionUnderline()
52 : startOffset(0), endOffset(0), thick(false) { }
53 CompositionUnderline(unsigned s
, unsigned e
, const Color
& c
, bool t
)
54 : startOffset(s
), endOffset(e
), color(c
), thick(t
) { }
61 enum TriState
{ FalseTriState
, TrueTriState
, MixedTriState
};
62 enum EditorCommandSource
{ CommandFromMenuOrKeyBinding
, CommandFromDOM
, CommandFromDOMWithUserInterface
};
63 enum WritingDirection
{ NaturalWritingDirection
, LeftToRightWritingDirection
, RightToLeftWritingDirection
};
70 EditorClient
* client() const;
71 Frame
* frame() const { return m_frame
; }
72 DeleteButtonController
* deleteButtonController() const { return m_deleteButtonController
.get(); }
73 EditCommand
* lastEditCommand() { return m_lastEditCommand
.get(); }
75 void handleKeyboardEvent(KeyboardEvent
*);
76 void handleInputMethodKeydown(KeyboardEvent
*);
79 bool canEditRichly() const;
84 bool canPaste() const;
85 bool canDelete() const;
86 bool canSmartCopyOrDelete();
91 void pasteAsPlainText();
99 bool shouldInsertFragment(PassRefPtr
<DocumentFragment
>, PassRefPtr
<Range
>, EditorInsertAction
);
100 bool shouldInsertText(const String
&, Range
*, EditorInsertAction
) const;
101 bool shouldShowDeleteInterface(HTMLElement
*) const;
102 bool shouldDeleteRange(Range
*) const;
103 bool shouldApplyStyle(CSSStyleDeclaration
*, Range
*);
105 void respondToChangedSelection(const Selection
& oldSelection
);
106 void respondToChangedContents(const Selection
& endingSelection
);
108 TriState
selectionHasStyle(CSSStyleDeclaration
*) const;
109 const SimpleFontData
* fontForSelection(bool&) const;
110 WritingDirection
textDirectionForSelection(bool&) const;
111 WritingDirection
baseWritingDirectionForSelectionStart() const;
113 TriState
selectionUnorderedListState() const;
114 TriState
selectionOrderedListState() const;
115 PassRefPtr
<Node
> insertOrderedList();
116 PassRefPtr
<Node
> insertUnorderedList();
117 bool canIncreaseSelectionListLevel();
118 bool canDecreaseSelectionListLevel();
119 PassRefPtr
<Node
> increaseSelectionListLevel();
120 PassRefPtr
<Node
> increaseSelectionListLevelOrdered();
121 PassRefPtr
<Node
> increaseSelectionListLevelUnordered();
122 void decreaseSelectionListLevel();
124 void removeFormattingAndStyle();
126 void clearLastEditCommand();
128 bool deleteWithDirection(SelectionController::EDirection
, TextGranularity
, bool killRing
, bool isTypingAction
);
129 void deleteSelectionWithSmartDelete(bool smartDelete
);
133 Node
* removedAnchor() const { return m_removedAnchor
.get(); }
134 void setRemovedAnchor(PassRefPtr
<Node
> n
) { m_removedAnchor
= n
; }
136 void applyStyle(CSSStyleDeclaration
*, EditAction
= EditActionUnspecified
);
137 void applyParagraphStyle(CSSStyleDeclaration
*, EditAction
= EditActionUnspecified
);
138 void applyStyleToSelection(CSSStyleDeclaration
*, EditAction
);
139 void applyParagraphStyleToSelection(CSSStyleDeclaration
*, EditAction
);
141 void appliedEditing(PassRefPtr
<EditCommand
>);
142 void unappliedEditing(PassRefPtr
<EditCommand
>);
143 void reappliedEditing(PassRefPtr
<EditCommand
>);
145 bool selectionStartHasStyle(CSSStyleDeclaration
*) const;
147 bool clientIsEditable() const;
152 Command(PassRefPtr
<Frame
>, const EditorInternalCommand
*, EditorCommandSource
);
154 bool execute(const String
& parameter
= String(), Event
* triggeringEvent
= 0) const;
155 bool execute(Event
* triggeringEvent
) const;
157 bool isSupported() const;
158 bool isEnabled(Event
* triggeringEvent
= 0) const;
160 TriState
state(Event
* triggeringEvent
= 0) const;
161 String
value(Event
* triggeringEvent
= 0) const;
163 bool isTextInsertion() const;
166 RefPtr
<Frame
> m_frame
;
167 const EditorInternalCommand
* m_command
;
168 EditorCommandSource m_source
;
170 Command
command(const String
& commandName
); // Default is CommandFromMenuOrKeyBinding.
171 Command
command(const String
& commandName
, EditorCommandSource
);
173 bool insertText(const String
&, Event
* triggeringEvent
);
174 bool insertTextWithoutSendingTextEvent(const String
&, bool selectInsertedText
, Event
* triggeringEvent
);
175 bool insertLineBreak();
176 bool insertParagraphSeparator();
178 bool isContinuousSpellCheckingEnabled();
179 void toggleContinuousSpellChecking();
180 bool isGrammarCheckingEnabled();
181 void toggleGrammarChecking();
182 void ignoreSpelling();
183 void learnSpelling();
184 int spellCheckerDocumentTag();
185 bool isSelectionUngrammatical();
186 bool isSelectionMisspelled();
187 Vector
<String
> guessesForMisspelledSelection();
188 Vector
<String
> guessesForUngrammaticalSelection();
189 void markMisspellingsAfterTypingToPosition(const VisiblePosition
&);
190 void markMisspellings(const Selection
&);
191 void markBadGrammar(const Selection
&);
192 void showSpellingGuessPanel();
193 bool spellingPanelIsShowing();
195 bool shouldBeginEditing(Range
*);
196 bool shouldEndEditing(Range
*);
198 void clearUndoRedoOperations();
204 void didBeginEditing();
205 void didEndEditing();
206 void didWriteSelectionToPasteboard();
208 void showFontPanel();
209 void showStylesPanel();
210 void showColorPanel();
212 void toggleUnderline();
213 void setBaseWritingDirection(WritingDirection
);
215 // smartInsertDeleteEnabled and selectTrailingWhitespaceEnabled are
216 // mutually exclusive, meaning that enabling one will disable the other.
217 bool smartInsertDeleteEnabled();
218 bool isSelectTrailingWhitespaceEnabled();
220 bool hasBidiSelection() const;
222 // international text input composition
223 bool hasComposition() const { return m_compositionNode
; }
224 void setComposition(const String
&, const Vector
<CompositionUnderline
>&, unsigned selectionStart
, unsigned selectionEnd
);
225 void confirmComposition();
226 void confirmComposition(const String
&); // if no existing composition, replaces selection
227 void confirmCompositionWithoutDisturbingSelection();
228 PassRefPtr
<Range
> compositionRange() const;
229 bool getCompositionSelection(unsigned& selectionStart
, unsigned& selectionEnd
) const;
231 // getting international text input composition state (for use by InlineTextBox)
232 Text
* compositionNode() const { return m_compositionNode
.get(); }
233 unsigned compositionStart() const { return m_compositionStart
; }
234 unsigned compositionEnd() const { return m_compositionEnd
; }
235 bool compositionUsesCustomUnderlines() const { return !m_customCompositionUnderlines
.isEmpty(); }
236 const Vector
<CompositionUnderline
>& customCompositionUnderlines() const { return m_customCompositionUnderlines
; }
238 bool ignoreCompositionSelectionChange() const { return m_ignoreCompositionSelectionChange
; }
240 void setStartNewKillRingSequence(bool);
242 PassRefPtr
<Range
> rangeForPoint(const IntPoint
& windowPoint
);
246 Selection
selectionForCommand(Event
*);
248 void appendToKillRing(const String
&);
249 void prependToKillRing(const String
&);
250 String
yankFromKillRing();
251 void startNewKillRingSequence();
252 void setKillRingToYankedState();
254 PassRefPtr
<Range
> selectedRange();
256 void confirmMarkedText();
257 void setTextAsChildOfElement(const String
&, Element
*, bool);
258 void setTextAlignmentForChangedBaseWritingDirection(WritingDirection
);
260 // We should make these functions private when their callers in Frame are moved over here to Editor
261 bool insideVisibleArea(const IntPoint
&) const;
262 bool insideVisibleArea(Range
*) const;
263 PassRefPtr
<Range
> nextVisibleRange(Range
*, const String
&, bool forward
, bool caseFlag
, bool wrapFlag
);
265 void addToKillRing(Range
*, bool prepend
);
268 OwnPtr
<DeleteButtonController
> m_deleteButtonController
;
269 RefPtr
<EditCommand
> m_lastEditCommand
;
270 RefPtr
<Node
> m_removedAnchor
;
272 RefPtr
<Text
> m_compositionNode
;
273 unsigned m_compositionStart
;
274 unsigned m_compositionEnd
;
275 Vector
<CompositionUnderline
> m_customCompositionUnderlines
;
276 bool m_ignoreCompositionSelectionChange
;
277 bool m_shouldStartNewKillRingSequence
;
279 bool canDeleteRange(Range
*) const;
280 bool canSmartReplaceWithPasteboard(Pasteboard
*);
281 void pasteAsPlainTextWithPasteboard(Pasteboard
*);
282 void pasteWithPasteboard(Pasteboard
*, bool allowPlainText
);
283 void replaceSelectionWithFragment(PassRefPtr
<DocumentFragment
>, bool selectReplacement
, bool smartReplace
, bool matchStyle
);
284 void replaceSelectionWithText(const String
&, bool selectReplacement
, bool smartReplace
);
285 void writeSelectionToPasteboard(Pasteboard
*);
286 void revealSelectionAfterEditingOperation();
288 void selectComposition();
289 void confirmComposition(const String
&, bool preserveSelection
);
290 void setIgnoreCompositionSelectionChange(bool ignore
);
292 PassRefPtr
<Range
> firstVisibleRange(const String
&, bool caseFlag
);
293 PassRefPtr
<Range
> lastVisibleRange(const String
&, bool caseFlag
);
295 void changeSelectionAfterCommand(const Selection
& newSelection
, bool closeTyping
, bool clearTypingStyle
, EditCommand
*);
298 inline void Editor::setStartNewKillRingSequence(bool flag
)
300 m_shouldStartNewKillRingSequence
= flag
;
303 } // namespace WebCore