OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_EDITOR_CLIENT_IMPL_H__ | |
6 #define WEBKIT_GLUE_EDITOR_CLIENT_IMPL_H__ | |
7 | |
8 #include "DOMWindow.h" | |
9 #include "EditorClient.h" | |
10 #include "Timer.h" | |
11 #include <wtf/Deque.h> | |
12 | |
13 namespace WebCore { | |
14 class Frame; | |
15 class HTMLInputElement; | |
16 class Node; | |
17 class PlatformKeyboardEvent; | |
18 } | |
19 | |
20 class WebViewImpl; | |
21 | |
22 class EditorClientImpl : public WebCore::EditorClient { | |
23 public: | |
24 EditorClientImpl(WebViewImpl* webview); | |
25 | |
26 virtual ~EditorClientImpl(); | |
27 virtual void pageDestroyed(); | |
28 | |
29 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*); | |
30 virtual bool smartInsertDeleteEnabled(); | |
31 virtual bool isSelectTrailingWhitespaceEnabled(); | |
32 virtual bool isContinuousSpellCheckingEnabled(); | |
33 virtual void toggleContinuousSpellChecking(); | |
34 virtual bool isGrammarCheckingEnabled(); | |
35 virtual void toggleGrammarChecking(); | |
36 virtual int spellCheckerDocumentTag(); | |
37 | |
38 virtual bool isEditable(); | |
39 | |
40 virtual bool shouldBeginEditing(WebCore::Range* range); | |
41 virtual bool shouldEndEditing(WebCore::Range* range); | |
42 virtual bool shouldInsertNode(WebCore::Node* node, WebCore::Range* range, | |
43 WebCore::EditorInsertAction action); | |
44 virtual bool shouldInsertText(const WebCore::String& text, WebCore::Range* ran
ge, | |
45 WebCore::EditorInsertAction action); | |
46 virtual bool shouldDeleteRange(WebCore::Range* range); | |
47 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, | |
48 WebCore::Range* toRange, | |
49 WebCore::EAffinity affinity, | |
50 bool stillSelecting); | |
51 virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration* style, | |
52 WebCore::Range* range); | |
53 virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*); | |
54 | |
55 virtual void didBeginEditing(); | |
56 virtual void respondToChangedContents(); | |
57 virtual void respondToChangedSelection(); | |
58 virtual void didEndEditing(); | |
59 virtual void didWriteSelectionToPasteboard(); | |
60 virtual void didSetSelectionTypesForPasteboard(); | |
61 | |
62 virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>); | |
63 virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>); | |
64 virtual void clearUndoRedoOperations(); | |
65 | |
66 virtual bool canUndo() const; | |
67 virtual bool canRedo() const; | |
68 | |
69 virtual void undo(); | |
70 virtual void redo(); | |
71 | |
72 virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*); | |
73 virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*); | |
74 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*); | |
75 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*); | |
76 | |
77 virtual void textFieldDidBeginEditing(WebCore::Element*); | |
78 virtual void textFieldDidEndEditing(WebCore::Element* element); | |
79 virtual void textDidChangeInTextField(WebCore::Element*); | |
80 virtual bool doTextFieldCommandFromEvent(WebCore::Element*,WebCore::KeyboardEv
ent*); | |
81 virtual void textWillBeDeletedInTextField(WebCore::Element*); | |
82 virtual void textDidChangeInTextArea(WebCore::Element*); | |
83 | |
84 virtual void ignoreWordInSpellDocument(const WebCore::String&); | |
85 virtual void learnWord(const WebCore::String&); | |
86 virtual void checkSpellingOfString(const UChar*, int length, | |
87 int* misspellingLocation, | |
88 int* misspellingLength); | |
89 virtual void checkGrammarOfString(const UChar*, int length, | |
90 WTF::Vector<WebCore::GrammarDetail>&, | |
91 int* badGrammarLocation, | |
92 int* badGrammarLength); | |
93 virtual WebCore::String getAutoCorrectSuggestionForMisspelledWord( | |
94 const WebCore::String& misspelledWord); | |
95 virtual void updateSpellingUIWithGrammarString(const WebCore::String&, | |
96 const WebCore::GrammarDetail& d
etail); | |
97 virtual void updateSpellingUIWithMisspelledWord(const WebCore::String&); | |
98 virtual void showSpellingUI(bool show); | |
99 virtual bool spellingUIIsShowing(); | |
100 virtual void getGuessesForWord(const WebCore::String&, | |
101 WTF::Vector<WebCore::String>& guesses); | |
102 virtual void setInputMethodState(bool enabled); | |
103 | |
104 // Shows the form autofill popup for |node| if it is an HTMLInputElement and | |
105 // it is empty. This is called when you press the up or down arrow in a | |
106 // text-field or when clicking an already focused text-field. | |
107 // Returns true if the autofill popup has been scheduled to be shown, false | |
108 // otherwise. | |
109 virtual bool ShowFormAutofillForNode(WebCore::Node* node); | |
110 | |
111 // Notification that the text changed in |text_field| due to acceptance of | |
112 // a suggestion provided by an autofill popup. Having a separate callback | |
113 // in this case is a simple way to break the cycle that would otherwise occur | |
114 // if textDidChangeInTextField was called. | |
115 virtual void OnAutofillSuggestionAccepted( | |
116 WebCore::HTMLInputElement* text_field); | |
117 | |
118 private: | |
119 void ModifySelection(WebCore::Frame* frame, | |
120 WebCore::KeyboardEvent* event); | |
121 | |
122 // Triggers autofill for |input_element| if applicable. This can be form | |
123 // autofill (via a popup-menu) or password autofill depending on | |
124 // |input_element|. If |form_autofill_only| is true, password autofill is not | |
125 // triggered. | |
126 // |autofill_on_empty_value| indicates whether the autofill should be shown | |
127 // when the text-field is empty. | |
128 // If |requires_caret_at_end| is true, the autofill popup is only shown if the | |
129 // caret is located at the end of the entered text in |input_element|. | |
130 // Returns true if the autofill popup has been scheduled to be shown, false | |
131 // otherwise. | |
132 bool Autofill(WebCore::HTMLInputElement* input_element, | |
133 bool form_autofill_only, | |
134 bool autofill_on_empty_value, | |
135 bool requires_caret_at_end); | |
136 | |
137 private: | |
138 // Called to process the autofill described by autofill_args_. | |
139 // This method is invoked asynchronously if the caret position is not | |
140 // reflecting the last text change yet, and we need it to decide whether or | |
141 // not to show the autofill popup. | |
142 void DoAutofill(WebCore::Timer<EditorClientImpl>*); | |
143 | |
144 void CancelPendingAutofill(); | |
145 | |
146 // Returns whether or not the focused control needs spell-checking. | |
147 // Currently, this function just retrieves the focused node and determines | |
148 // whether or not it is a <textarea> element or an element whose | |
149 // contenteditable attribute is true. | |
150 // TODO(hbono): Bug 740540: This code just implements the default behavior | |
151 // proposed in this issue. We should also retrieve "spellcheck" attributes | |
152 // for text fields and create a flag to over-write the default behavior. | |
153 bool ShouldSpellcheckByDefault(); | |
154 | |
155 WebViewImpl* webview_; | |
156 bool in_redo_; | |
157 | |
158 typedef Deque< RefPtr<WebCore::EditCommand> > EditCommandStack; | |
159 EditCommandStack undo_stack_; | |
160 EditCommandStack redo_stack_; | |
161 | |
162 // Whether the last entered key was a backspace. | |
163 bool backspace_or_delete_pressed_; | |
164 | |
165 // This flag is set to false if spell check for this editor is manually | |
166 // turned off. The default setting is SPELLCHECK_AUTOMATIC. | |
167 enum { | |
168 SPELLCHECK_AUTOMATIC, | |
169 SPELLCHECK_FORCED_ON, | |
170 SPELLCHECK_FORCED_OFF | |
171 }; | |
172 int spell_check_this_field_status_; | |
173 | |
174 // Used to delay autofill processing. | |
175 WebCore::Timer<EditorClientImpl> autofill_timer_; | |
176 | |
177 struct AutofillArgs { | |
178 RefPtr<WebCore::HTMLInputElement> input_element; | |
179 bool autofill_form_only; | |
180 bool autofill_on_empty_value; | |
181 bool require_caret_at_end; | |
182 bool backspace_or_delete_pressed; | |
183 }; | |
184 OwnPtr<AutofillArgs> autofill_args_; | |
185 }; | |
186 | |
187 #endif // WEBKIT_GLUE_EDITOR_CLIENT_IMPL_H__ | |
OLD | NEW |