]> git.saurik.com Git - iphone-api.git/blob - WebCore/Editor.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / Editor.h
1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 #ifndef Editor_h
27 #define Editor_h
28
29 #include "ClipboardAccessPolicy.h"
30 #include "Color.h"
31 #include "EditAction.h"
32 #include "EditorDeleteAction.h"
33 #include "EditorInsertAction.h"
34 #include "SelectionController.h"
35
36 namespace WebCore {
37
38 class CSSStyleDeclaration;
39 class Clipboard;
40 class DeleteButtonController;
41 class EditCommand;
42 class EditorClient;
43 class EditorInternalCommand;
44 class HTMLElement;
45 class HitTestResult;
46 class Pasteboard;
47 class SimpleFontData;
48 class Text;
49
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) { }
55 unsigned startOffset;
56 unsigned endOffset;
57 Color color;
58 bool thick;
59 };
60
61 enum TriState { FalseTriState, TrueTriState, MixedTriState };
62 enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
63 enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection };
64
65 class Editor {
66 public:
67 Editor(Frame*);
68 ~Editor();
69
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(); }
74
75 void handleKeyboardEvent(KeyboardEvent*);
76 void handleInputMethodKeydown(KeyboardEvent*);
77
78 bool canEdit() const;
79 bool canEditRichly() const;
80
81
82 bool canCut() const;
83 bool canCopy() const;
84 bool canPaste() const;
85 bool canDelete() const;
86 bool canSmartCopyOrDelete();
87
88 void cut();
89 void copy();
90 void paste();
91 void pasteAsPlainText();
92 void performDelete();
93
94
95 void indent();
96 void outdent();
97 void transpose();
98
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*);
104
105 void respondToChangedSelection(const Selection& oldSelection);
106 void respondToChangedContents(const Selection& endingSelection);
107
108 TriState selectionHasStyle(CSSStyleDeclaration*) const;
109 const SimpleFontData* fontForSelection(bool&) const;
110 WritingDirection textDirectionForSelection(bool&) const;
111 WritingDirection baseWritingDirectionForSelectionStart() const;
112
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();
123
124 void removeFormattingAndStyle();
125
126 void clearLastEditCommand();
127
128 bool deleteWithDirection(SelectionController::EDirection, TextGranularity, bool killRing, bool isTypingAction);
129 void deleteSelectionWithSmartDelete(bool smartDelete);
130 void clearText();
131
132
133 Node* removedAnchor() const { return m_removedAnchor.get(); }
134 void setRemovedAnchor(PassRefPtr<Node> n) { m_removedAnchor = n; }
135
136 void applyStyle(CSSStyleDeclaration*, EditAction = EditActionUnspecified);
137 void applyParagraphStyle(CSSStyleDeclaration*, EditAction = EditActionUnspecified);
138 void applyStyleToSelection(CSSStyleDeclaration*, EditAction);
139 void applyParagraphStyleToSelection(CSSStyleDeclaration*, EditAction);
140
141 void appliedEditing(PassRefPtr<EditCommand>);
142 void unappliedEditing(PassRefPtr<EditCommand>);
143 void reappliedEditing(PassRefPtr<EditCommand>);
144
145 bool selectionStartHasStyle(CSSStyleDeclaration*) const;
146
147 bool clientIsEditable() const;
148
149 class Command {
150 public:
151 Command();
152 Command(PassRefPtr<Frame>, const EditorInternalCommand*, EditorCommandSource);
153
154 bool execute(const String& parameter = String(), Event* triggeringEvent = 0) const;
155 bool execute(Event* triggeringEvent) const;
156
157 bool isSupported() const;
158 bool isEnabled(Event* triggeringEvent = 0) const;
159
160 TriState state(Event* triggeringEvent = 0) const;
161 String value(Event* triggeringEvent = 0) const;
162
163 bool isTextInsertion() const;
164
165 private:
166 RefPtr<Frame> m_frame;
167 const EditorInternalCommand* m_command;
168 EditorCommandSource m_source;
169 };
170 Command command(const String& commandName); // Default is CommandFromMenuOrKeyBinding.
171 Command command(const String& commandName, EditorCommandSource);
172
173 bool insertText(const String&, Event* triggeringEvent);
174 bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, Event* triggeringEvent);
175 bool insertLineBreak();
176 bool insertParagraphSeparator();
177
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();
194
195 bool shouldBeginEditing(Range*);
196 bool shouldEndEditing(Range*);
197
198 void clearUndoRedoOperations();
199 bool canUndo();
200 void undo();
201 bool canRedo();
202 void redo();
203
204 void didBeginEditing();
205 void didEndEditing();
206 void didWriteSelectionToPasteboard();
207
208 void showFontPanel();
209 void showStylesPanel();
210 void showColorPanel();
211 void toggleBold();
212 void toggleUnderline();
213 void setBaseWritingDirection(WritingDirection);
214
215 // smartInsertDeleteEnabled and selectTrailingWhitespaceEnabled are
216 // mutually exclusive, meaning that enabling one will disable the other.
217 bool smartInsertDeleteEnabled();
218 bool isSelectTrailingWhitespaceEnabled();
219
220 bool hasBidiSelection() const;
221
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;
230
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; }
237
238 bool ignoreCompositionSelectionChange() const { return m_ignoreCompositionSelectionChange; }
239
240 void setStartNewKillRingSequence(bool);
241
242 PassRefPtr<Range> rangeForPoint(const IntPoint& windowPoint);
243
244 void clear();
245
246 Selection selectionForCommand(Event*);
247
248 void appendToKillRing(const String&);
249 void prependToKillRing(const String&);
250 String yankFromKillRing();
251 void startNewKillRingSequence();
252 void setKillRingToYankedState();
253
254 PassRefPtr<Range> selectedRange();
255
256 void confirmMarkedText();
257 void setTextAsChildOfElement(const String&, Element*, bool);
258 void setTextAlignmentForChangedBaseWritingDirection(WritingDirection);
259
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);
264
265 void addToKillRing(Range*, bool prepend);
266 private:
267 Frame* m_frame;
268 OwnPtr<DeleteButtonController> m_deleteButtonController;
269 RefPtr<EditCommand> m_lastEditCommand;
270 RefPtr<Node> m_removedAnchor;
271
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;
278
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();
287
288 void selectComposition();
289 void confirmComposition(const String&, bool preserveSelection);
290 void setIgnoreCompositionSelectionChange(bool ignore);
291
292 PassRefPtr<Range> firstVisibleRange(const String&, bool caseFlag);
293 PassRefPtr<Range> lastVisibleRange(const String&, bool caseFlag);
294
295 void changeSelectionAfterCommand(const Selection& newSelection, bool closeTyping, bool clearTypingStyle, EditCommand*);
296 };
297
298 inline void Editor::setStartNewKillRingSequence(bool flag)
299 {
300 m_shouldStartNewKillRingSequence = flag;
301 }
302
303 } // namespace WebCore
304
305 #endif // Editor_h