1 /* 2 * Copyright (C) 2009, 2010, 2011, 2012 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 WebView_h 32 #define WebView_h 33 34 #include "../platform/WebColor.h" 35 #include "../platform/WebString.h" 36 #include "../platform/WebVector.h" 37 #include "WebDragOperation.h" 38 #include "WebPageVisibilityState.h" 39 #include "WebWidget.h" 40 41 namespace blink { 42 43 class WebAXObject; 44 class WebAutofillClient; 45 class WebDevToolsAgent; 46 class WebDevToolsAgentClient; 47 class WebDragData; 48 class WebFrame; 49 class WebFrameClient; 50 class WebGraphicsContext3D; 51 class WebHitTestResult; 52 class WebNode; 53 class WebPageOverlay; 54 class WebPermissionClient; 55 class WebPrerendererClient; 56 class WebRange; 57 class WebSettings; 58 class WebSpellCheckClient; 59 class WebString; 60 class WebPasswordGeneratorClient; 61 class WebSharedWorkerRepositoryClient; 62 class WebValidationMessageClient; 63 class WebViewClient; 64 struct WebActiveWheelFlingParameters; 65 struct WebMediaPlayerAction; 66 struct WebPluginAction; 67 struct WebPoint; 68 struct WebWindowFeatures; 69 70 class WebView : public WebWidget { 71 public: 72 BLINK_EXPORT static const double textSizeMultiplierRatio; 73 BLINK_EXPORT static const double minTextSizeMultiplier; 74 BLINK_EXPORT static const double maxTextSizeMultiplier; 75 BLINK_EXPORT static const float minPageScaleFactor; 76 BLINK_EXPORT static const float maxPageScaleFactor; 77 78 enum StyleInjectionTarget { 79 InjectStyleInAllFrames, 80 InjectStyleInTopFrameOnly 81 }; 82 83 84 // Initialization ------------------------------------------------------ 85 86 // Creates a WebView that is NOT yet initialized. You will need to 87 // call setMainFrame to finish the initialization. It is valid 88 // to pass a null client pointer. 89 BLINK_EXPORT static WebView* create(WebViewClient*); 90 91 // After creating a WebView, you should immediately call this method. 92 // You can optionally modify the settings before calling this method. 93 // This WebFrame will receive events for the main frame and must not 94 // be null. 95 virtual void setMainFrame(WebFrame*) = 0; 96 // FIXME: Remove initializeMainFrame() after clients have migrated to 97 // setMainFrame(). 98 virtual void initializeMainFrame(WebFrameClient*) = 0; 99 100 // Initializes the various client interfaces. 101 virtual void setAutofillClient(WebAutofillClient*) = 0; 102 virtual void setDevToolsAgentClient(WebDevToolsAgentClient*) = 0; 103 virtual void setPermissionClient(WebPermissionClient*) = 0; 104 virtual void setPrerendererClient(WebPrerendererClient*) = 0; 105 virtual void setSpellCheckClient(WebSpellCheckClient*) = 0; 106 virtual void setValidationMessageClient(WebValidationMessageClient*) = 0; 107 virtual void setPasswordGeneratorClient(WebPasswordGeneratorClient*) = 0; 108 virtual void setSharedWorkerRepositoryClient(WebSharedWorkerRepositoryClient*) = 0; 109 110 // Options ------------------------------------------------------------- 111 112 // The returned pointer is valid for the lifetime of the WebView. 113 virtual WebSettings* settings() = 0; 114 115 // Corresponds to the encoding of the main frame. Setting the page 116 // encoding may cause the main frame to reload. 117 virtual WebString pageEncoding() const = 0; 118 virtual void setPageEncoding(const WebString&) = 0; 119 120 // Makes the WebView transparent. This is useful if you want to have 121 // some custom background rendered behind it. 122 virtual bool isTransparent() const = 0; 123 virtual void setIsTransparent(bool) = 0; 124 125 // Sets the base color used for this WebView's background. This is in effect 126 // the default background color used for pages with no background-color 127 // style in effect, or used as the alpha-blended basis for any pages with 128 // translucent background-color style. (For pages with opaque 129 // background-color style, this property is effectively ignored). 130 // Setting this takes effect for the currently loaded page, if any, and 131 // persists across subsequent navigations. Defaults to white prior to the 132 // first call to this method. 133 virtual void setBaseBackgroundColor(WebColor) = 0; 134 135 // Controls whether pressing Tab key advances focus to links. 136 virtual bool tabsToLinks() const = 0; 137 virtual void setTabsToLinks(bool) = 0; 138 139 // Method that controls whether pressing Tab key cycles through page 140 // elements or inserts a '\t' char in the focused text area. 141 virtual bool tabKeyCyclesThroughElements() const = 0; 142 virtual void setTabKeyCyclesThroughElements(bool) = 0; 143 144 // Controls the WebView's active state, which may affect the rendering 145 // of elements on the page (i.e., tinting of input elements). 146 virtual bool isActive() const = 0; 147 virtual void setIsActive(bool) = 0; 148 149 // Allows disabling domain relaxation. 150 virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) = 0; 151 152 // Allows setting the state of the various bars exposed via BarProp 153 // properties on the window object. The size related fields of 154 // WebWindowFeatures are ignored. 155 virtual void setWindowFeatures(const WebWindowFeatures&) = 0; 156 157 158 // Closing ------------------------------------------------------------- 159 160 // Runs beforeunload handlers for the current page, returning false if 161 // any handler suppressed unloading. 162 virtual bool dispatchBeforeUnloadEvent() = 0; 163 164 // Runs unload handlers for the current page. 165 virtual void dispatchUnloadEvent() = 0; 166 167 168 // Frames -------------------------------------------------------------- 169 170 virtual WebFrame* mainFrame() = 0; 171 172 // Returns the frame identified by the given name. This method 173 // supports pseudo-names like _self, _top, and _blank. It traverses 174 // the entire frame tree containing this tree looking for a frame that 175 // matches the given name. If the optional relativeToFrame parameter 176 // is specified, then the search begins with the given frame and its 177 // children. 178 virtual WebFrame* findFrameByName( 179 const WebString& name, WebFrame* relativeToFrame = 0) = 0; 180 181 182 // Focus --------------------------------------------------------------- 183 184 virtual WebFrame* focusedFrame() = 0; 185 virtual void setFocusedFrame(WebFrame*) = 0; 186 187 // Focus the first (last if reverse is true) focusable node. 188 virtual void setInitialFocus(bool reverse) = 0; 189 190 // Clears the focused node (and selection if a text field is focused) 191 // to ensure that a text field on the page is not eating keystrokes we 192 // send it. 193 virtual void clearFocusedNode() = 0; 194 195 // Scrolls the node currently in focus into view. 196 virtual void scrollFocusedNodeIntoView() = 0; 197 198 // Scrolls the node currently in focus into |rect|, where |rect| is in 199 // window space. 200 virtual void scrollFocusedNodeIntoRect(const WebRect&) { } 201 202 // Advance the focus of the WebView forward to the next element or to the 203 // previous element in the tab sequence (if reverse is true). 204 virtual void advanceFocus(bool reverse) { } 205 206 // Animate a scale into the specified find-in-page rect. 207 virtual void zoomToFindInPageRect(const WebRect&) = 0; 208 209 // Animate a scale into the specified rect where multiple targets were 210 // found from previous tap gesture. 211 // Returns false if it doesn't do any zooming. 212 virtual bool zoomToMultipleTargetsRect(const WebRect&) = 0; 213 214 215 // Zoom ---------------------------------------------------------------- 216 217 // Returns the current zoom level. 0 is "original size", and each increment 218 // above or below represents zooming 20% larger or smaller to default limits 219 // of 300% and 50% of original size, respectively. Only plugins use 220 // non whole-numbers, since they might choose to have specific zoom level so 221 // that fixed-width content is fit-to-page-width, for example. 222 virtual double zoomLevel() = 0; 223 224 // Changes the zoom level to the specified level, clamping at the limits 225 // noted above, and returns the current zoom level after applying the 226 // change. 227 virtual double setZoomLevel(double) = 0; 228 229 // Updates the zoom limits for this view. 230 virtual void zoomLimitsChanged(double minimumZoomLevel, 231 double maximumZoomLevel) = 0; 232 233 // Helper functions to convert between zoom level and zoom factor. zoom 234 // factor is zoom percent / 100, so 300% = 3.0. 235 BLINK_EXPORT static double zoomLevelToZoomFactor(double zoomLevel); 236 BLINK_EXPORT static double zoomFactorToZoomLevel(double factor); 237 238 // Returns the current text zoom factor, where 1.0 is the normal size, > 1.0 239 // is scaled up and < 1.0 is scaled down. 240 virtual float textZoomFactor() = 0; 241 242 // Scales the text in the page by a factor of textZoomFactor. 243 // Note: this has no effect on plugins. 244 virtual float setTextZoomFactor(float) = 0; 245 246 // Sets the initial page scale to the given factor. This scale setting overrides 247 // page scale set in the page's viewport meta tag. 248 virtual void setInitialPageScaleOverride(float) = 0; 249 250 // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0 251 // is scaled up, < 1.0 is scaled down. 252 virtual float pageScaleFactor() const = 0; 253 254 // Scales the page and the scroll offset by a given factor, while ensuring 255 // that the new scroll position does not go beyond the edge of the page. 256 virtual void setPageScaleFactorPreservingScrollOffset(float) = 0; 257 258 // Scales a page by a factor of scaleFactor and then sets a scroll position to (x, y). 259 // setPageScaleFactor() magnifies and shrinks a page without affecting layout. 260 // On the other hand, zooming affects layout of the page. 261 virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) = 0; 262 263 // PageScaleFactor will be force-clamped between minPageScale and maxPageScale 264 // (and these values will persist until setPageScaleFactorLimits is called 265 // again). 266 virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale) = 0; 267 268 virtual float minimumPageScaleFactor() const = 0; 269 virtual float maximumPageScaleFactor() const = 0; 270 271 // Save the WebView's current scroll and scale state. Each call to this function 272 // overwrites the previously saved scroll and scale state. 273 virtual void saveScrollAndScaleState() = 0; 274 275 // Restore the previously saved scroll and scale state. After restoring the 276 // state, this function deletes any saved scroll and scale state. 277 virtual void restoreScrollAndScaleState() = 0; 278 279 // Reset any saved values for the scroll and scale state. 280 virtual void resetScrollAndScaleState() = 0; 281 282 // Prevent the web page from setting min/max scale via the viewport meta 283 // tag. This is an accessibility feature that lets folks zoom in to web 284 // pages even if the web page tries to block scaling. 285 virtual void setIgnoreViewportTagScaleLimits(bool) = 0; 286 287 // Returns the "preferred" contents size, defined as the preferred minimum width of the main document's contents 288 // and the minimum height required to display the main document without scrollbars. 289 // The returned size has the page zoom factor applied. 290 virtual WebSize contentsPreferredMinimumSize() = 0; 291 292 // The ratio of the current device's screen DPI to the target device's screen DPI. 293 virtual float deviceScaleFactor() const = 0; 294 295 // Sets the ratio as computed by computePageScaleConstraints. 296 virtual void setDeviceScaleFactor(float) = 0; 297 298 299 // Fixed Layout -------------------------------------------------------- 300 301 // Locks main frame's layout size to specified size. Passing WebSize(0, 0) 302 // removes the lock. 303 virtual void setFixedLayoutSize(const WebSize&) = 0; 304 305 306 // Auto-Resize ----------------------------------------------------------- 307 308 // In auto-resize mode, the view is automatically adjusted to fit the html 309 // content within the given bounds. 310 virtual void enableAutoResizeMode( 311 const WebSize& minSize, 312 const WebSize& maxSize) = 0; 313 314 // Turn off auto-resize. 315 virtual void disableAutoResizeMode() = 0; 316 317 // Media --------------------------------------------------------------- 318 319 // Performs the specified media player action on the node at the given location. 320 virtual void performMediaPlayerAction( 321 const WebMediaPlayerAction&, const WebPoint& location) = 0; 322 323 // Performs the specified plugin action on the node at the given location. 324 virtual void performPluginAction( 325 const WebPluginAction&, const WebPoint& location) = 0; 326 327 328 // Data exchange ------------------------------------------------------- 329 330 // Do a hit test at given point and return the HitTestResult. 331 virtual WebHitTestResult hitTestResultAt(const WebPoint&) = 0; 332 333 // Copy to the clipboard the image located at a particular point in the 334 // WebView (if there is such an image) 335 virtual void copyImageAt(const WebPoint&) = 0; 336 337 // Notifies the WebView that a drag has terminated. 338 virtual void dragSourceEndedAt( 339 const WebPoint& clientPoint, const WebPoint& screenPoint, 340 WebDragOperation operation) = 0; 341 342 // Notifies the WebView that a drag is going on. 343 virtual void dragSourceMovedTo( 344 const WebPoint& clientPoint, const WebPoint& screenPoint, 345 WebDragOperation operation) = 0; 346 347 // Notfies the WebView that the system drag and drop operation has ended. 348 virtual void dragSourceSystemDragEnded() = 0; 349 350 // Callback methods when a drag-and-drop operation is trying to drop 351 // something on the WebView. 352 virtual WebDragOperation dragTargetDragEnter( 353 const WebDragData&, 354 const WebPoint& clientPoint, const WebPoint& screenPoint, 355 WebDragOperationsMask operationsAllowed, 356 int keyModifiers) = 0; 357 virtual WebDragOperation dragTargetDragOver( 358 const WebPoint& clientPoint, const WebPoint& screenPoint, 359 WebDragOperationsMask operationsAllowed, 360 int keyModifiers) = 0; 361 virtual void dragTargetDragLeave() = 0; 362 virtual void dragTargetDrop( 363 const WebPoint& clientPoint, const WebPoint& screenPoint, 364 int keyModifiers) = 0; 365 366 // Retrieves a list of spelling markers. 367 virtual void spellingMarkers(WebVector<uint32_t>* markers) = 0; 368 369 370 // Support for resource loading initiated by plugins ------------------- 371 372 // Returns next unused request identifier which is unique within the 373 // parent Page. 374 virtual unsigned long createUniqueIdentifierForRequest() = 0; 375 376 377 // Developer tools ----------------------------------------------------- 378 379 // Inspect a particular point in the WebView. (x = -1 || y = -1) is a 380 // special case, meaning inspect the current page and not a specific 381 // point. 382 virtual void inspectElementAt(const WebPoint&) = 0; 383 384 // Settings used by the inspector. 385 virtual WebString inspectorSettings() const = 0; 386 virtual void setInspectorSettings(const WebString&) = 0; 387 virtual bool inspectorSetting(const WebString& key, 388 WebString* value) const = 0; 389 virtual void setInspectorSetting(const WebString& key, 390 const WebString& value) = 0; 391 392 // Set an override of device scale factor passed from WebView to 393 // compositor. Pass zero to cancel override. This is used to implement 394 // device metrics emulation. 395 virtual void setCompositorDeviceScaleFactorOverride(float) = 0; 396 397 // Set offset and scale on the root composited layer. This is used 398 // to implement device metrics emulation. 399 virtual void setRootLayerTransform(const WebSize& offset, float scale) = 0; 400 401 // The embedder may optionally engage a WebDevToolsAgent. This may only 402 // be set once per WebView. 403 virtual WebDevToolsAgent* devToolsAgent() = 0; 404 405 406 // Accessibility ------------------------------------------------------- 407 408 // Returns the accessibility object for this view. 409 virtual WebAXObject accessibilityObject() = 0; 410 411 412 // Autofill ----------------------------------------------------------- 413 414 // Notifies the WebView that Autofill suggestions are available for a node. 415 // |itemIDs| is a vector of IDs for the menu items. A positive itemID is a 416 // unique ID for the Autofill entries. Other MenuItemIDs are defined in 417 // WebAutofillClient.h 418 virtual void applyAutofillSuggestions( 419 const WebNode&, 420 const WebVector<WebString>& names, 421 const WebVector<WebString>& labels, 422 const WebVector<WebString>& icons, 423 const WebVector<int>& itemIDs, 424 int separatorIndex = -1) = 0; 425 426 // Hides any popup (suggestions, selects...) that might be showing. 427 virtual void hidePopups() = 0; 428 429 virtual void selectAutofillSuggestionAtIndex(unsigned listIndex) = 0; 430 431 432 // Context menu -------------------------------------------------------- 433 434 virtual void performCustomContextMenuAction(unsigned action) = 0; 435 436 // Shows a context menu for the currently focused element. 437 virtual void showContextMenu() = 0; 438 439 440 // SmartClip support --------------------------------------------------- 441 442 virtual WebString getSmartClipData(WebRect) = 0; 443 444 445 // Popup menu ---------------------------------------------------------- 446 447 // Sets whether select popup menus should be rendered by the browser. 448 BLINK_EXPORT static void setUseExternalPopupMenus(bool); 449 450 451 // Visited link state -------------------------------------------------- 452 453 // Tells all WebView instances to update the visited link state for the 454 // specified hash. 455 BLINK_EXPORT static void updateVisitedLinkState(unsigned long long hash); 456 457 // Tells all WebView instances to update the visited state for all 458 // their links. 459 BLINK_EXPORT static void resetVisitedLinkState(); 460 461 462 // Custom colors ------------------------------------------------------- 463 464 virtual void setSelectionColors(unsigned activeBackgroundColor, 465 unsigned activeForegroundColor, 466 unsigned inactiveBackgroundColor, 467 unsigned inactiveForegroundColor) = 0; 468 469 // Injected style ------------------------------------------------------ 470 471 // Treats |sourceCode| as a CSS author style sheet and injects it into all Documents whose URLs match |patterns|, 472 // in the frames specified by the last argument. 473 BLINK_EXPORT static void injectStyleSheet(const WebString& sourceCode, const WebVector<WebString>& patterns, StyleInjectionTarget); 474 BLINK_EXPORT static void removeInjectedStyleSheets(); 475 476 // Modal dialog support ------------------------------------------------ 477 478 // Call these methods before and after running a nested, modal event loop 479 // to suspend script callbacks and resource loads. 480 BLINK_EXPORT static void willEnterModalLoop(); 481 BLINK_EXPORT static void didExitModalLoop(); 482 483 // Called to inform the WebView that a wheel fling animation was started externally (for instance 484 // by the compositor) but must be completed by the WebView. 485 virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) = 0; 486 487 // Cancels an active fling, returning true if a fling was active. 488 virtual bool endActiveFlingAnimation() = 0; 489 490 virtual bool setEditableSelectionOffsets(int start, int end) = 0; 491 virtual bool setCompositionFromExistingText(int compositionStart, int compositionEnd, const WebVector<WebCompositionUnderline>& underlines) = 0; 492 virtual void extendSelectionAndDelete(int before, int after) = 0; 493 494 virtual bool isSelectionEditable() const = 0; 495 496 virtual void setShowPaintRects(bool) = 0; 497 virtual void setShowFPSCounter(bool) = 0; 498 virtual void setContinuousPaintingEnabled(bool) = 0; 499 virtual void setShowScrollBottleneckRects(bool) = 0; 500 501 // Visibility ----------------------------------------------------------- 502 503 // Sets the visibility of the WebView. 504 virtual void setVisibilityState(WebPageVisibilityState visibilityState, 505 bool isInitialState) { } 506 507 // PageOverlay ---------------------------------------------------------- 508 509 // Adds/removes page overlay to this WebView. These functions change the 510 // graphical appearance of the WebView. WebPageOverlay paints the 511 // contents of the page overlay. It also provides an z-order number for 512 // the page overlay. The z-order number defines the paint order the page 513 // overlays. Page overlays with larger z-order number will be painted after 514 // page overlays with smaller z-order number. That is, they appear above 515 // the page overlays with smaller z-order number. If two page overlays have 516 // the same z-order number, the later added one will be on top. 517 virtual void addPageOverlay(WebPageOverlay*, int /*z-order*/) = 0; 518 virtual void removePageOverlay(WebPageOverlay*) = 0; 519 520 // Testing functionality for TestRunner --------------------------------- 521 522 protected: 523 ~WebView() {} 524 }; 525 526 } // namespace blink 527 528 #endif 529