OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef WebViewClient_h | |
32 #define WebViewClient_h | |
33 | |
34 #include "WebDragOperation.h" | |
35 #include "WebEditingAction.h" | |
36 #include "WebFileChooserCompletion.h" | |
37 #include "WebString.h" | |
38 #include "WebTextAffinity.h" | |
39 #include "WebTextDirection.h" | |
40 #include "WebWidgetClient.h" | |
41 | |
42 namespace WebKit { | |
43 | |
44 class WebAccessibilityObject; | |
45 class WebDragData; | |
46 class WebFileChooserCompletion; | |
47 class WebFrame; | |
48 class WebNode; | |
49 class WebNotificationPresenter; | |
50 class WebRange; | |
51 class WebURL; | |
52 class WebView; | |
53 class WebWidget; | |
54 struct WebConsoleMessage; | |
55 struct WebContextMenuData; | |
56 struct WebPoint; | |
57 struct WebPopupMenuInfo; | |
58 | |
59 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient. | |
60 // Virtual inheritance allows an implementation of WebWidgetClient to be | |
61 // easily reused as part of an implementation of WebViewClient. | |
62 class WebViewClient : virtual public WebWidgetClient { | |
63 public: | |
64 // Factory methods ----------------------------------------------------- | |
65 | |
66 // Create a new related WebView. | |
67 virtual WebView* createView(WebFrame* creator) { return 0; } | |
68 | |
69 // Create a new WebPopupMenu. In the second form, the client is | |
70 // responsible for rendering the contents of the popup menu. | |
71 virtual WebWidget* createPopupMenu(bool activatable) { return 0; } | |
72 virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; } | |
73 | |
74 | |
75 // Misc ---------------------------------------------------------------- | |
76 | |
77 // A new message was added to the console. | |
78 virtual void didAddMessageToConsole( | |
79 const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { } | |
80 | |
81 // Called when script in the page calls window.print(). If frame is | |
82 // non-null, then it selects a particular frame, including its | |
83 // children, to print. Otherwise, the main frame and its children | |
84 // should be printed. | |
85 virtual void printPage(WebFrame*) { } | |
86 | |
87 // Called to retrieve the provider of desktop notifications. | |
88 virtual WebNotificationPresenter* notificationPresenter() { return 0; } | |
89 | |
90 | |
91 // Navigational -------------------------------------------------------- | |
92 | |
93 // These notifications bracket any loading that occurs in the WebView. | |
94 virtual void didStartLoading() { } | |
95 virtual void didStopLoading() { } | |
96 | |
97 | |
98 // Editing ------------------------------------------------------------- | |
99 | |
100 // These methods allow the client to intercept and overrule editing | |
101 // operations. | |
102 virtual bool shouldBeginEditing(const WebRange&) { return true; } | |
103 virtual bool shouldEndEditing(const WebRange&) { return true; } | |
104 virtual bool shouldInsertNode( | |
105 const WebNode&, const WebRange&, WebEditingAction) { return true; } | |
106 virtual bool shouldInsertText( | |
107 const WebString&, const WebRange&, WebEditingAction) { return true; } | |
108 virtual bool shouldChangeSelectedRange( | |
109 const WebRange& from, const WebRange& to, WebTextAffinity, | |
110 bool stillSelecting) { return true; } | |
111 virtual bool shouldDeleteRange(const WebRange&) { return true; } | |
112 virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { return true; } | |
113 | |
114 virtual bool isSmartInsertDeleteEnabled() { return true; } | |
115 virtual bool isSelectTrailingWhitespaceEnabled() { return true; } | |
116 virtual void setInputMethodEnabled(bool enabled) { } | |
117 | |
118 virtual void didBeginEditing() { } | |
119 virtual void didChangeSelection(bool isSelectionEmpty) { } | |
120 virtual void didChangeContents() { } | |
121 virtual void didExecuteCommand(const WebString& commandName) { } | |
122 virtual void didEndEditing() { } | |
123 | |
124 // This method is called in response to WebView's handleInputEvent() | |
125 // when the default action for the current keyboard event is not | |
126 // suppressed by the page, to give the embedder a chance to handle | |
127 // the keyboard event specially. | |
128 // | |
129 // Returns true if the keyboard event was handled by the embedder, | |
130 // indicating that the default action should be suppressed. | |
131 virtual bool handleCurrentKeyboardEvent() { return false; } | |
132 | |
133 | |
134 // Spellchecker -------------------------------------------------------- | |
135 | |
136 // The client should perform spell-checking on the given text. If the | |
137 // text contains a misspelled word, then upon return misspelledOffset | |
138 // will point to the start of the misspelled word, and misspelledLength | |
139 // will indicates its length. Otherwise, if there was not a spelling | |
140 // error, then upon return misspelledLength is 0. | |
141 virtual void spellCheck( | |
142 const WebString& text, int& misspelledOffset, int& misspelledLength) { } | |
143 | |
144 // Computes an auto-corrected replacement for a misspelled word. If no | |
145 // replacement is found, then an empty string is returned. | |
146 virtual WebString autoCorrectWord(const WebString& misspelledWord) { return WebString(); } | |
147 | |
148 // Show or hide the spelling UI. | |
149 virtual void showSpellingUI(bool show) { } | |
150 | |
151 // Returns true if the spelling UI is showing. | |
152 virtual bool isShowingSpellingUI() { return false; } | |
153 | |
154 // Update the spelling UI with the given word. | |
155 virtual void updateSpellingUIWithMisspelledWord(const WebString& word) { } | |
156 | |
157 | |
158 // Dialogs ------------------------------------------------------------- | |
159 | |
160 // This method returns immediately after showing the dialog. When the | |
161 // dialog is closed, it should call the WebFileChooserCompletion to | |
162 // pass the results of the dialog. Returns false if | |
163 // WebFileChooseCompletion will never be called. | |
164 virtual bool runFileChooser( | |
165 bool multiSelect, const WebString& title, | |
166 const WebString& initialValue, WebFileChooserCompletion*) { return false; } | |
167 | |
168 // Displays a modal alert dialog containing the given message. Returns | |
169 // once the user dismisses the dialog. | |
170 virtual void runModalAlertDialog( | |
171 WebFrame*, const WebString& message) { } | |
172 | |
173 // Displays a modal confirmation dialog with the given message as | |
174 // description and OK/Cancel choices. Returns true if the user selects | |
175 // 'OK' or false otherwise. | |
176 virtual bool runModalConfirmDialog( | |
177 WebFrame*, const WebString& message) { return false; } | |
178 | |
179 // Displays a modal input dialog with the given message as description | |
180 // and OK/Cancel choices. The input field is pre-filled with | |
181 // defaultValue. Returns true if the user selects 'OK' or false | |
182 // otherwise. Upon returning true, actualValue contains the value of | |
183 // the input field. | |
184 virtual bool runModalPromptDialog( | |
185 WebFrame*, const WebString& message, const WebString& defaultValue, | |
186 WebString* actualValue) { return false; } | |
187 | |
188 // Displays a modal confirmation dialog containing the given message as | |
189 // description and OK/Cancel choices, where 'OK' means that it is okay | |
190 // to proceed with closing the view. Returns true if the user selects | |
191 // 'OK' or false otherwise. | |
192 virtual bool runModalBeforeUnloadDialog( | |
193 WebFrame*, const WebString& message) { return true; } | |
194 | |
195 | |
196 // UI ------------------------------------------------------------------ | |
197 | |
198 // Called when script modifies window.status | |
199 virtual void setStatusText(const WebString&) { } | |
200 | |
201 // Called when hovering over an anchor with the given URL. | |
202 virtual void setMouseOverURL(const WebURL&) { } | |
203 | |
204 // Called when keyboard focus switches to an anchor with the given URL. | |
205 virtual void setKeyboardFocusURL(const WebURL&) { } | |
206 | |
207 // Called when a tooltip should be shown at the current cursor position. | |
208 virtual void setToolTipText(const WebString&, WebTextDirection hint) { } | |
209 | |
210 // Shows a context menu with commands relevant to a specific element on | |
211 // the given frame. Additional context data is supplied. | |
212 virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { } | |
213 | |
214 // Called when a drag-n-drop operation should begin. | |
215 virtual void startDragging( | |
216 const WebPoint& from, const WebDragData&, WebDragOperationsMask) { } | |
217 | |
218 // Called to determine if drag-n-drop operations may initiate a page | |
219 // navigation. | |
220 virtual bool acceptsLoadDrops() { return true; } | |
221 | |
222 // Take focus away from the WebView by focusing an adjacent UI element | |
223 // in the containing window. | |
224 virtual void focusNext() { } | |
225 virtual void focusPrevious() { } | |
226 | |
227 | |
228 // Session history ----------------------------------------------------- | |
229 | |
230 // Tells the embedder to navigate back or forward in session history by | |
231 // the given offset (relative to the current position in session | |
232 // history). | |
233 virtual void navigateBackForwardSoon(int offset) { } | |
234 | |
235 // Returns the number of history items before/after the current | |
236 // history item. | |
237 virtual int historyBackListCount() { return 0; } | |
238 virtual int historyForwardListCount() { return 0; } | |
239 | |
240 // Called to notify the embedder when a new history item is added. | |
241 virtual void didAddHistoryItem() { } | |
242 | |
243 | |
244 // Accessibility ------------------------------------------------------- | |
245 | |
246 // Notifies embedder that the focus has changed to the given | |
247 // accessibility object. | |
248 virtual void focusAccessibilityObject(const WebAccessibilityObject&) { } | |
249 | |
250 | |
251 // Developer tools ----------------------------------------------------- | |
252 | |
253 // Called to notify the client that the inspector's settings were | |
254 // changed and should be saved. See WebView::inspectorSettings. | |
255 virtual void didUpdateInspectorSettings() { } | |
256 | |
257 | |
258 // Autofill ------------------------------------------------------------ | |
259 | |
260 // Queries the browser for suggestions to be shown for the form text | |
261 // field named |name|. |value| is the text entered by the user so | |
262 // far and the WebNode corresponds to the input field. | |
263 virtual void queryAutofillSuggestions(const WebNode&, | |
264 const WebString& name, | |
265 const WebString& value) { } | |
266 | |
267 // Instructs the browser to remove the autofill entry specified from | |
268 // its DB. | |
269 virtual void removeAutofillSuggestions(const WebString& name, | |
270 const WebString& value) { } | |
271 | |
272 protected: | |
273 ~WebViewClient() { } | |
274 }; | |
275 | |
276 } // namespace WebKit | |
277 | |
278 #endif | |
OLD | NEW |