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