WebKit/chromium/public/WebViewClient.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "WebFileChooserParams.h"
       
    38 #include "WebPopupType.h"
       
    39 #include "WebString.h"
       
    40 #include "WebTextAffinity.h"
       
    41 #include "WebTextDirection.h"
       
    42 #include "WebWidgetClient.h"
       
    43 
       
    44 namespace WebKit {
       
    45 
       
    46 class WebAccessibilityObject;
       
    47 class WebDragData;
       
    48 class WebElement;
       
    49 class WebFileChooserCompletion;
       
    50 class WebFrame;
       
    51 class WebGeolocationService;
       
    52 class WebImage;
       
    53 class WebInputElement;
       
    54 class WebKeyboardEvent;
       
    55 class WebNode;
       
    56 class WebNotificationPresenter;
       
    57 class WebRange;
       
    58 class WebStorageNamespace;
       
    59 class WebURL;
       
    60 class WebView;
       
    61 class WebWidget;
       
    62 struct WebConsoleMessage;
       
    63 struct WebContextMenuData;
       
    64 struct WebPoint;
       
    65 struct WebPopupMenuInfo;
       
    66 struct WebWindowFeatures;
       
    67 
       
    68 // Since a WebView is a WebWidget, a WebViewClient is a WebWidgetClient.
       
    69 // Virtual inheritance allows an implementation of WebWidgetClient to be
       
    70 // easily reused as part of an implementation of WebViewClient.
       
    71 class WebViewClient : virtual public WebWidgetClient {
       
    72 public:
       
    73     // Factory methods -----------------------------------------------------
       
    74 
       
    75     // Create a new related WebView.  This method must clone its session storage
       
    76     // so any subsequent calls to createSessionStorageNamespace conform to the
       
    77     // WebStorage specification.
       
    78     virtual WebView* createView(WebFrame* creator,
       
    79                                 const WebWindowFeatures& features,
       
    80                                 const WebString& name) { return 0; }
       
    81 
       
    82     // Create a new WebPopupMenu.  In the second form, the client is
       
    83     // responsible for rendering the contents of the popup menu.
       
    84     virtual WebWidget* createPopupMenu(WebPopupType) { return 0; }
       
    85     virtual WebWidget* createPopupMenu(const WebPopupMenuInfo&) { return 0; }
       
    86 
       
    87     // Create a session storage namespace object associated with this WebView.
       
    88     virtual WebStorageNamespace* createSessionStorageNamespace(unsigned quota) { return 0; }
       
    89 
       
    90     // Misc ----------------------------------------------------------------
       
    91 
       
    92     // A new message was added to the console.
       
    93     virtual void didAddMessageToConsole(
       
    94         const WebConsoleMessage&, const WebString& sourceName, unsigned sourceLine) { }
       
    95 
       
    96     // Called when script in the page calls window.print().  If frame is
       
    97     // non-null, then it selects a particular frame, including its
       
    98     // children, to print.  Otherwise, the main frame and its children
       
    99     // should be printed.
       
   100     virtual void printPage(WebFrame*) { }
       
   101 
       
   102     // Called to retrieve the provider of desktop notifications.
       
   103     virtual WebNotificationPresenter* notificationPresenter() { return 0; }
       
   104 
       
   105 
       
   106     // Navigational --------------------------------------------------------
       
   107 
       
   108     // These notifications bracket any loading that occurs in the WebView.
       
   109     virtual void didStartLoading() { }
       
   110     virtual void didStopLoading() { }
       
   111 
       
   112 
       
   113     // Editing -------------------------------------------------------------
       
   114 
       
   115     // These methods allow the client to intercept and overrule editing
       
   116     // operations.
       
   117     virtual bool shouldBeginEditing(const WebRange&) { return true; }
       
   118     virtual bool shouldEndEditing(const WebRange&) { return true; }
       
   119     virtual bool shouldInsertNode(
       
   120         const WebNode&, const WebRange&, WebEditingAction) { return true; }
       
   121     virtual bool shouldInsertText(
       
   122         const WebString&, const WebRange&, WebEditingAction) { return true; }
       
   123     virtual bool shouldChangeSelectedRange(
       
   124         const WebRange& from, const WebRange& to, WebTextAffinity,
       
   125         bool stillSelecting) { return true; }
       
   126     virtual bool shouldDeleteRange(const WebRange&) { return true; }
       
   127     virtual bool shouldApplyStyle(const WebString& style, const WebRange&) { return true; }
       
   128 
       
   129     virtual bool isSmartInsertDeleteEnabled() { return true; }
       
   130     virtual bool isSelectTrailingWhitespaceEnabled() { return true; }
       
   131 
       
   132     virtual void didBeginEditing() { }
       
   133     virtual void didChangeSelection(bool isSelectionEmpty) { }
       
   134     virtual void didChangeContents() { }
       
   135     virtual void didExecuteCommand(const WebString& commandName) { }
       
   136     virtual void didEndEditing() { }
       
   137 
       
   138     // These methods are called when the users edits a text-field.
       
   139     virtual void textFieldDidBeginEditing(const WebInputElement&) { }
       
   140     virtual void textFieldDidEndEditing(const WebInputElement&) { }
       
   141     virtual void textFieldDidChange(const WebInputElement&) { }
       
   142     virtual void textFieldDidReceiveKeyDown(const WebInputElement&, const WebKeyboardEvent&) { }
       
   143 
       
   144     // This method is called in response to WebView's handleInputEvent()
       
   145     // when the default action for the current keyboard event is not
       
   146     // suppressed by the page, to give the embedder a chance to handle
       
   147     // the keyboard event specially.
       
   148     //
       
   149     // Returns true if the keyboard event was handled by the embedder,
       
   150     // indicating that the default action should be suppressed.
       
   151     virtual bool handleCurrentKeyboardEvent() { return false; }
       
   152 
       
   153 
       
   154     // Spellchecker --------------------------------------------------------
       
   155 
       
   156     // The client should perform spell-checking on the given text.  If the
       
   157     // text contains a misspelled word, then upon return misspelledOffset
       
   158     // will point to the start of the misspelled word, and misspelledLength
       
   159     // will indicates its length.  Otherwise, if there was not a spelling
       
   160     // error, then upon return misspelledLength is 0.
       
   161     virtual void spellCheck(
       
   162         const WebString& text, int& misspelledOffset, int& misspelledLength) { }
       
   163 
       
   164     // Computes an auto-corrected replacement for a misspelled word.  If no
       
   165     // replacement is found, then an empty string is returned.
       
   166     virtual WebString autoCorrectWord(const WebString& misspelledWord) { return WebString(); }
       
   167 
       
   168     // Show or hide the spelling UI.
       
   169     virtual void showSpellingUI(bool show) { }
       
   170 
       
   171     // Returns true if the spelling UI is showing.
       
   172     virtual bool isShowingSpellingUI() { return false; }
       
   173 
       
   174     // Update the spelling UI with the given word.
       
   175     virtual void updateSpellingUIWithMisspelledWord(const WebString& word) { }
       
   176 
       
   177 
       
   178     // Dialogs -------------------------------------------------------------
       
   179 
       
   180     // This method returns immediately after showing the dialog. When the
       
   181     // dialog is closed, it should call the WebFileChooserCompletion to
       
   182     // pass the results of the dialog. Returns false if
       
   183     // WebFileChooseCompletion will never be called.
       
   184     virtual bool runFileChooser(const WebFileChooserParams&,
       
   185                                 WebFileChooserCompletion*) { return false; }
       
   186 
       
   187     // Displays a modal alert dialog containing the given message.  Returns
       
   188     // once the user dismisses the dialog.
       
   189     virtual void runModalAlertDialog(
       
   190         WebFrame*, const WebString& message) { }
       
   191 
       
   192     // Displays a modal confirmation dialog with the given message as
       
   193     // description and OK/Cancel choices.  Returns true if the user selects
       
   194     // 'OK' or false otherwise.
       
   195     virtual bool runModalConfirmDialog(
       
   196         WebFrame*, const WebString& message) { return false; }
       
   197 
       
   198     // Displays a modal input dialog with the given message as description
       
   199     // and OK/Cancel choices.  The input field is pre-filled with
       
   200     // defaultValue.  Returns true if the user selects 'OK' or false
       
   201     // otherwise.  Upon returning true, actualValue contains the value of
       
   202     // the input field.
       
   203     virtual bool runModalPromptDialog(
       
   204         WebFrame*, const WebString& message, const WebString& defaultValue,
       
   205         WebString* actualValue) { return false; }
       
   206 
       
   207     // Displays a modal confirmation dialog containing the given message as
       
   208     // description and OK/Cancel choices, where 'OK' means that it is okay
       
   209     // to proceed with closing the view.  Returns true if the user selects
       
   210     // 'OK' or false otherwise.
       
   211     virtual bool runModalBeforeUnloadDialog(
       
   212         WebFrame*, const WebString& message) { return true; }
       
   213 
       
   214     virtual bool supportsFullscreen() { return false; }
       
   215     virtual void enterFullscreenForNode(const WebNode&) { }
       
   216     virtual void exitFullscreenForNode(const WebNode&) { }
       
   217 
       
   218     // UI ------------------------------------------------------------------
       
   219 
       
   220     // Called when script modifies window.status
       
   221     virtual void setStatusText(const WebString&) { }
       
   222 
       
   223     // Called when hovering over an anchor with the given URL.
       
   224     virtual void setMouseOverURL(const WebURL&) { }
       
   225 
       
   226     // Called when keyboard focus switches to an anchor with the given URL.
       
   227     virtual void setKeyboardFocusURL(const WebURL&) { }
       
   228 
       
   229     // Called when a tooltip should be shown at the current cursor position.
       
   230     virtual void setToolTipText(const WebString&, WebTextDirection hint) { }
       
   231 
       
   232     // Shows a context menu with commands relevant to a specific element on
       
   233     // the given frame. Additional context data is supplied.
       
   234     virtual void showContextMenu(WebFrame*, const WebContextMenuData&) { }
       
   235 
       
   236     // Called when a drag-n-drop operation should begin.
       
   237     virtual void startDragging(
       
   238         const WebDragData&, WebDragOperationsMask, const WebImage&, const WebPoint&) { }
       
   239 
       
   240     // Called to determine if drag-n-drop operations may initiate a page
       
   241     // navigation.
       
   242     virtual bool acceptsLoadDrops() { return true; }
       
   243 
       
   244     // Take focus away from the WebView by focusing an adjacent UI element
       
   245     // in the containing window.
       
   246     virtual void focusNext() { }
       
   247     virtual void focusPrevious() { }
       
   248 
       
   249     // Called when a new node gets focused.
       
   250     virtual void focusedNodeChanged(const WebNode&) { }
       
   251 
       
   252 
       
   253     // Session history -----------------------------------------------------
       
   254 
       
   255     // Tells the embedder to navigate back or forward in session history by
       
   256     // the given offset (relative to the current position in session
       
   257     // history).
       
   258     virtual void navigateBackForwardSoon(int offset) { }
       
   259 
       
   260     // Returns the number of history items before/after the current
       
   261     // history item.
       
   262     virtual int historyBackListCount() { return 0; }
       
   263     virtual int historyForwardListCount() { return 0; }
       
   264 
       
   265     // Called to notify the embedder when a new history item is added.
       
   266     virtual void didAddHistoryItem() { }
       
   267 
       
   268 
       
   269     // Accessibility -------------------------------------------------------
       
   270 
       
   271     // Notifies embedder that the focus has changed to the given
       
   272     // accessibility object.
       
   273     virtual void focusAccessibilityObject(const WebAccessibilityObject&) { }
       
   274 
       
   275     // Notifies embedder that the state of an accessibility object has changed.
       
   276     virtual void didChangeAccessibilityObjectState(const WebAccessibilityObject&) { }
       
   277 
       
   278 
       
   279     // Developer tools -----------------------------------------------------
       
   280 
       
   281     // Called to notify the client that the inspector's settings were
       
   282     // changed and should be saved.  See WebView::inspectorSettings.
       
   283     virtual void didUpdateInspectorSettings() { }
       
   284 
       
   285     virtual void didUpdateInspectorSetting(const WebString& key, const WebString& value) { }
       
   286 
       
   287 
       
   288     // AutoFill ------------------------------------------------------------
       
   289 
       
   290     // Queries the browser for suggestions to be shown for the form text
       
   291     // field named |name|.  |value| is the text entered by the user so
       
   292     // far and the WebNode corresponds to the input field.
       
   293     virtual void queryAutofillSuggestions(const WebNode&,
       
   294                                           const WebString& name,
       
   295                                           const WebString& value) { }
       
   296 
       
   297     // Instructs the browser to remove the Autocomplete entry specified from
       
   298     // its DB.
       
   299     // FIXME: This method should be named removeAutocompleteSugestion.
       
   300     virtual void removeAutofillSuggestions(const WebString& name,
       
   301                                            const WebString& value) { }
       
   302 
       
   303     // Informs the browser that the user has accepted an AutoFill suggestion for
       
   304     // a WebNode.  |name| and |label| form a key into the set of AutoFill
       
   305     // profiles.  |index| is an index of the selected suggestion in the list of
       
   306     // suggestions provided by the client
       
   307     virtual void didAcceptAutoFillSuggestion(const WebNode&,
       
   308                                              const WebString& name,
       
   309                                              const WebString& label,
       
   310                                              int uniqueID,
       
   311                                              unsigned index) { }
       
   312 
       
   313     // Informs the browser that the user has selected an AutoFill suggestion for
       
   314     // a WebNode.  This happens when the user hovers over a suggestion or uses
       
   315     // the arrow keys to navigate to a suggestion.
       
   316     virtual void didSelectAutoFillSuggestion(const WebNode&,
       
   317                                              const WebString& name,
       
   318                                              const WebString& label,
       
   319                                              int uniqueID) { }
       
   320 
       
   321     // Informs the browser that the user has cleared the selection from the
       
   322     // AutoFill suggestions popup.  This happens when a user uses the arrow
       
   323     // keys to navigate outside the range of possible selections.
       
   324     virtual void didClearAutoFillSelection(const WebNode&) { }
       
   325 
       
   326     // Informs the browser that the user has selected an autocomplete (password
       
   327     // or field) suggestion from the drop-down.  The input element text has
       
   328     // already been set to the selected suggestion.
       
   329     virtual void didAcceptAutocompleteSuggestion(const WebInputElement&) { }
       
   330 
       
   331     // Geolocation ---------------------------------------------------------
       
   332 
       
   333     // Access the embedder API for geolocation services.
       
   334     virtual WebKit::WebGeolocationService* geolocationService() { return 0; }
       
   335 
       
   336 protected:
       
   337     ~WebViewClient() { }
       
   338 };
       
   339 
       
   340 } // namespace WebKit
       
   341 
       
   342 #endif