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