Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / web / WebView.h
blob1bce1b29c1c406d455ed3a94ebe57392d755d3cd
1 /*
2 * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef WebView_h
32 #define WebView_h
34 #include "../platform/WebColor.h"
35 #include "../platform/WebDisplayMode.h"
36 #include "../platform/WebPageVisibilityState.h"
37 #include "../platform/WebString.h"
38 #include "../platform/WebVector.h"
39 #include "WebDragOperation.h"
40 #include "WebHistoryCommitType.h"
41 #include "WebHistoryItem.h"
42 #include "WebWidget.h"
44 namespace blink {
46 class WebAXObject;
47 class WebAutofillClient;
48 class WebCompositedDisplayList;
49 class WebCredentialManagerClient;
50 class WebDragData;
51 class WebFrame;
52 class WebHitTestResult;
53 class WebPageImportanceSignals;
54 class WebPageOverlay;
55 class WebPrerendererClient;
56 class WebSettings;
57 class WebSpellCheckClient;
58 class WebString;
59 class WebViewClient;
60 struct WebActiveWheelFlingParameters;
61 struct WebDeviceEmulationParams;
62 struct WebFloatPoint;
63 struct WebMediaPlayerAction;
64 struct WebPluginAction;
65 struct WebPoint;
66 struct WebWindowFeatures;
68 class WebView : public WebWidget {
69 public:
70 BLINK_EXPORT static const double textSizeMultiplierRatio;
71 BLINK_EXPORT static const double minTextSizeMultiplier;
72 BLINK_EXPORT static const double maxTextSizeMultiplier;
74 enum StyleInjectionTarget {
75 InjectStyleInAllFrames,
76 InjectStyleInTopFrameOnly
80 // Initialization ------------------------------------------------------
82 // Creates a WebView that is NOT yet initialized. You will need to
83 // call setMainFrame to finish the initialization. It is valid
84 // to pass a null client pointer.
85 BLINK_EXPORT static WebView* create(WebViewClient*);
87 // After creating a WebView, you should immediately call this method.
88 // You can optionally modify the settings before calling this method.
89 // This WebFrame will receive events for the main frame and must not
90 // be null.
91 virtual void setMainFrame(WebFrame*) = 0;
93 // Initializes the various client interfaces.
94 virtual void setCredentialManagerClient(WebCredentialManagerClient*) = 0;
95 virtual void setPrerendererClient(WebPrerendererClient*) = 0;
96 virtual void setSpellCheckClient(WebSpellCheckClient*) = 0;
98 // Options -------------------------------------------------------------
100 // The returned pointer is valid for the lifetime of the WebView.
101 virtual WebSettings* settings() = 0;
103 // Corresponds to the encoding of the main frame. Setting the page
104 // encoding may cause the main frame to reload.
105 virtual WebString pageEncoding() const = 0;
106 virtual void setPageEncoding(const WebString&) = 0;
108 // Makes the WebView transparent. This is useful if you want to have
109 // some custom background rendered behind it.
110 virtual bool isTransparent() const = 0;
111 virtual void setIsTransparent(bool) = 0;
113 // Sets the base color used for this WebView's background. This is in effect
114 // the default background color used for pages with no background-color
115 // style in effect, or used as the alpha-blended basis for any pages with
116 // translucent background-color style. (For pages with opaque
117 // background-color style, this property is effectively ignored).
118 // Setting this takes effect for the currently loaded page, if any, and
119 // persists across subsequent navigations. Defaults to white prior to the
120 // first call to this method.
121 virtual void setBaseBackgroundColor(WebColor) = 0;
123 // Controls whether pressing Tab key advances focus to links.
124 virtual bool tabsToLinks() const = 0;
125 virtual void setTabsToLinks(bool) = 0;
127 // Method that controls whether pressing Tab key cycles through page
128 // elements or inserts a '\t' char in the focused text area.
129 virtual bool tabKeyCyclesThroughElements() const = 0;
130 virtual void setTabKeyCyclesThroughElements(bool) = 0;
132 // Controls the WebView's active state, which may affect the rendering
133 // of elements on the page (i.e., tinting of input elements).
134 virtual bool isActive() const = 0;
135 virtual void setIsActive(bool) = 0;
137 // Allows disabling domain relaxation.
138 virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) = 0;
140 // Allows setting the state of the various bars exposed via BarProp
141 // properties on the window object. The size related fields of
142 // WebWindowFeatures are ignored.
143 virtual void setWindowFeatures(const WebWindowFeatures&) = 0;
145 // Marks the WebView as being opened by a DOM call. This is relevant
146 // for whether window.close() may be called.
147 virtual void setOpenedByDOM() = 0;
150 // Frames --------------------------------------------------------------
152 virtual WebFrame* mainFrame() = 0;
154 // Returns the frame identified by the given name. This method
155 // supports pseudo-names like _self, _top, and _blank. It traverses
156 // the entire frame tree containing this tree looking for a frame that
157 // matches the given name. If the optional relativeToFrame parameter
158 // is specified, then the search begins with the given frame and its
159 // children.
160 virtual WebFrame* findFrameByName(
161 const WebString& name, WebFrame* relativeToFrame = 0) = 0;
164 // Focus ---------------------------------------------------------------
166 virtual WebFrame* focusedFrame() = 0;
167 virtual void setFocusedFrame(WebFrame*) = 0;
169 // Focus the first (last if reverse is true) focusable node.
170 virtual void setInitialFocus(bool reverse) = 0;
172 // Clears the focused element (and selection if a text field is focused)
173 // to ensure that a text field on the page is not eating keystrokes we
174 // send it.
175 virtual void clearFocusedElement() = 0;
177 // Scrolls the node currently in focus into |rect|, where |rect| is in
178 // viewport space. Returns true if an animation was started.
179 virtual bool scrollFocusedNodeIntoRect(const WebRect&) { return false; }
181 // Smooth scroll the root layer to |targetX|, |targetY| in |durationMs|.
182 virtual void smoothScroll(int targetX, int targetY, long durationMs) { }
184 // Advance the focus of the WebView forward to the next element or to the
185 // previous element in the tab sequence (if reverse is true).
186 virtual void advanceFocus(bool reverse) { }
188 // Animate a scale into the specified rect where multiple targets were
189 // found from previous tap gesture.
190 // Returns false if it doesn't do any zooming.
191 virtual bool zoomToMultipleTargetsRect(const WebRect&) = 0;
194 // Zoom ----------------------------------------------------------------
196 // Returns the current zoom level. 0 is "original size", and each increment
197 // above or below represents zooming 20% larger or smaller to default limits
198 // of 300% and 50% of original size, respectively. Only plugins use
199 // non whole-numbers, since they might choose to have specific zoom level so
200 // that fixed-width content is fit-to-page-width, for example.
201 virtual double zoomLevel() = 0;
203 // Changes the zoom level to the specified level, clamping at the limits
204 // noted above, and returns the current zoom level after applying the
205 // change.
206 virtual double setZoomLevel(double) = 0;
208 // Updates the zoom limits for this view.
209 virtual void zoomLimitsChanged(double minimumZoomLevel,
210 double maximumZoomLevel) = 0;
212 // Helper functions to convert between zoom level and zoom factor. zoom
213 // factor is zoom percent / 100, so 300% = 3.0.
214 BLINK_EXPORT static double zoomLevelToZoomFactor(double zoomLevel);
215 BLINK_EXPORT static double zoomFactorToZoomLevel(double factor);
217 // Returns the current text zoom factor, where 1.0 is the normal size, > 1.0
218 // is scaled up and < 1.0 is scaled down.
219 virtual float textZoomFactor() = 0;
221 // Scales the text in the page by a factor of textZoomFactor.
222 // Note: this has no effect on plugins.
223 virtual float setTextZoomFactor(float) = 0;
225 // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0
226 // is scaled up, < 1.0 is scaled down.
227 virtual float pageScaleFactor() const = 0;
229 // TODO: Obsolete, the origin parameter is ambiguous with two viewports. Remove
230 // once Chromium side users are removed.
231 // Scales a page by a factor of scaleFactor and then sets a scroll position to (x, y).
232 // setPageScaleFactor() magnifies and shrinks a page without affecting layout.
233 // On the other hand, zooming affects layout of the page.
234 virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) { setPageScaleFactor(scaleFactor); }
236 // Scales the page without affecting layout by using the visual viewport.
237 virtual void setPageScaleFactor(float) = 0;
239 // Sets the offset of the visual viewport within the main frame, in
240 // partial CSS pixels. The offset will be clamped so the visual viewport
241 // stays within the frame's bounds.
242 virtual void setVisualViewportOffset(const WebFloatPoint&) = 0;
244 // TODO(bokan): Renamed to VisualViewport above, remove once chromium
245 // side callers are renamed.
246 virtual void setPinchViewportOffset(const WebFloatPoint&) = 0;
248 // Gets the visual viewport's current offset within the page's main frame,
249 // in partial CSS pixels.
250 virtual WebFloatPoint visualViewportOffset() const = 0;
252 // TODO(bokan): Renamed to VisualViewport above, remove once chromium
253 // side callers are renamed.
254 virtual WebFloatPoint pinchViewportOffset() const = 0;
256 // Sets the default minimum, and maximum page scale. These will be overridden
257 // by the page or by the overrides below if they are set.
258 virtual void setDefaultPageScaleLimits(
259 float minScale,
260 float maxScale) = 0;
262 // Sets the initial page scale to the given factor. This scale setting overrides
263 // page scale set in the page's viewport meta tag.
264 virtual void setInitialPageScaleOverride(float) = 0;
266 // Sets the maximum page scale considered to be legible. Automatic zooms (e.g, double-tap
267 // or find in page) will have the page scale limited to this value times the font scale
268 // factor. Manual pinch zoom will not be affected by this limit.
269 virtual void setMaximumLegibleScale(float) = 0;
271 // Reset any saved values for the scroll and scale state.
272 virtual void resetScrollAndScaleState() = 0;
274 // Prevent the web page from setting min/max scale via the viewport meta
275 // tag. This is an accessibility feature that lets folks zoom in to web
276 // pages even if the web page tries to block scaling.
277 virtual void setIgnoreViewportTagScaleLimits(bool) = 0;
279 // Returns the "preferred" contents size, defined as the preferred minimum width of the main document's contents
280 // and the minimum height required to display the main document without scrollbars.
281 // The returned size has the page zoom factor applied.
282 virtual WebSize contentsPreferredMinimumSize() = 0;
284 // Sets the display mode of the web app.
285 virtual void setDisplayMode(WebDisplayMode) = 0;
287 // The ratio of the current device's screen DPI to the target device's screen DPI.
288 virtual float deviceScaleFactor() const = 0;
290 // Sets the ratio as computed by computePageScaleConstraints.
291 virtual void setDeviceScaleFactor(float) = 0;
293 // Set and reset the device color profile.
294 virtual void setDeviceColorProfile(const WebVector<char>&) = 0;
295 virtual void resetDeviceColorProfile() = 0;
297 // Auto-Resize -----------------------------------------------------------
299 // In auto-resize mode, the view is automatically adjusted to fit the html
300 // content within the given bounds.
301 virtual void enableAutoResizeMode(
302 const WebSize& minSize,
303 const WebSize& maxSize) = 0;
305 // Turn off auto-resize.
306 virtual void disableAutoResizeMode() = 0;
308 // Media ---------------------------------------------------------------
310 // Performs the specified media player action on the node at the given location.
311 virtual void performMediaPlayerAction(
312 const WebMediaPlayerAction&, const WebPoint& location) = 0;
314 // Performs the specified plugin action on the node at the given location.
315 virtual void performPluginAction(
316 const WebPluginAction&, const WebPoint& location) = 0;
319 // Data exchange -------------------------------------------------------
321 // Do a hit test at given point and return the HitTestResult.
322 virtual WebHitTestResult hitTestResultAt(const WebPoint&) = 0;
324 // Do a hit test equivalent to what would be done for a GestureTap event
325 // that has width/height corresponding to the supplied |tapArea|.
326 virtual WebHitTestResult hitTestResultForTap(const WebPoint& tapPoint,
327 const WebSize& tapArea) = 0;
329 // Copy to the clipboard the image located at a particular point in the
330 // WebView (if there is such an image)
331 virtual void copyImageAt(const WebPoint&) = 0;
333 // Save as the image located at a particular point in the
334 // WebView (if there is such an image)
335 virtual void saveImageAt(const WebPoint&) = 0;
337 // Notifies the WebView that a drag has terminated.
338 virtual void dragSourceEndedAt(
339 const WebPoint& clientPoint, const WebPoint& screenPoint,
340 WebDragOperation operation) = 0;
342 // Notfies the WebView that the system drag and drop operation has ended.
343 virtual void dragSourceSystemDragEnded() = 0;
345 // Callback methods when a drag-and-drop operation is trying to drop
346 // something on the WebView.
347 virtual WebDragOperation dragTargetDragEnter(
348 const WebDragData&,
349 const WebPoint& clientPoint, const WebPoint& screenPoint,
350 WebDragOperationsMask operationsAllowed,
351 int modifiers) = 0;
352 virtual WebDragOperation dragTargetDragOver(
353 const WebPoint& clientPoint, const WebPoint& screenPoint,
354 WebDragOperationsMask operationsAllowed,
355 int modifiers) = 0;
356 virtual void dragTargetDragLeave() = 0;
357 virtual void dragTargetDrop(
358 const WebPoint& clientPoint, const WebPoint& screenPoint,
359 int modifiers) = 0;
361 // Retrieves a list of spelling markers.
362 virtual void spellingMarkers(WebVector<uint32_t>* markers) = 0;
363 virtual void removeSpellingMarkersUnderWords(const WebVector<WebString>& words) = 0;
365 // Support for resource loading initiated by plugins -------------------
367 // Returns next unused request identifier which is unique within the
368 // parent Page.
369 virtual unsigned long createUniqueIdentifierForRequest() = 0;
372 // Developer tools -----------------------------------------------------
374 // Enables device emulation as specified in params.
375 virtual void enableDeviceEmulation(const WebDeviceEmulationParams&) = 0;
377 // Cancel emulation started via |enableDeviceEmulation| call.
378 virtual void disableDeviceEmulation() = 0;
381 // Accessibility -------------------------------------------------------
383 // Returns the accessibility object for this view.
384 virtual WebAXObject accessibilityObject() = 0;
387 // Context menu --------------------------------------------------------
389 virtual void performCustomContextMenuAction(unsigned action) = 0;
391 // Shows a context menu for the currently focused element.
392 virtual void showContextMenu() = 0;
395 // SmartClip support ---------------------------------------------------
396 virtual void extractSmartClipData(WebRect initRect, WebString& text, WebString& html, WebRect& resultRect) = 0;
399 // Popup menu ----------------------------------------------------------
401 // Sets whether select popup menus should be rendered by the browser.
402 BLINK_EXPORT static void setUseExternalPopupMenus(bool);
404 // Hides any popup (suggestions, selects...) that might be showing.
405 virtual void hidePopups() = 0;
408 // Visited link state --------------------------------------------------
410 // Tells all WebView instances to update the visited link state for the
411 // specified hash.
412 BLINK_EXPORT static void updateVisitedLinkState(unsigned long long hash);
414 // Tells all WebView instances to update the visited state for all
415 // their links.
416 BLINK_EXPORT static void resetVisitedLinkState();
419 // Custom colors -------------------------------------------------------
421 virtual void setSelectionColors(unsigned activeBackgroundColor,
422 unsigned activeForegroundColor,
423 unsigned inactiveBackgroundColor,
424 unsigned inactiveForegroundColor) = 0;
426 // Modal dialog support ------------------------------------------------
428 // Call these methods before and after running a nested, modal event loop
429 // to suspend script callbacks and resource loads.
430 BLINK_EXPORT static void willEnterModalLoop();
431 BLINK_EXPORT static void didExitModalLoop();
433 // Called to inform the WebView that a wheel fling animation was started externally (for instance
434 // by the compositor) but must be completed by the WebView.
435 virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) = 0;
437 // Cancels an active fling, returning true if a fling was active.
438 virtual bool endActiveFlingAnimation() = 0;
440 virtual void setShowPaintRects(bool) = 0;
441 virtual void setShowFPSCounter(bool) = 0;
442 virtual void setShowScrollBottleneckRects(bool) = 0;
444 // Visibility -----------------------------------------------------------
446 // Sets the visibility of the WebView.
447 virtual void setVisibilityState(WebPageVisibilityState visibilityState,
448 bool isInitialState) { }
450 // Graphics -------------------------------------------------------------
452 virtual WebCompositedDisplayList* compositedDisplayList() { return nullptr; }
454 // PageOverlay ----------------------------------------------------------
456 // Overlay this WebView with a solid color.
457 virtual void setPageOverlayColor(WebColor) = 0;
459 // Page Importance Signals ----------------------------------------------
461 virtual WebPageImportanceSignals* pageImportanceSignals() { return nullptr; }
463 // i18n -----------------------------------------------------------------
465 // Inform the WebView that the accept languages have changed.
466 // If the WebView wants to get the accept languages value, it will have
467 // to call the WebViewClient::acceptLanguages().
468 virtual void acceptLanguagesChanged() = 0;
470 // Testing functionality for TestRunner ---------------------------------
472 // Force the webgl context to fail so that webglcontextcreationerror
473 // event gets generated/tested.
474 virtual void forceNextWebGLContextCreationToFail() = 0;
476 // Force the drawing buffer used by webgl contexts to fail so that the webgl
477 // context's ability to deal with that failure gracefully can be tested.
478 virtual void forceNextDrawingBufferCreationToFail() = 0;
480 protected:
481 ~WebView() {}
484 } // namespace blink
486 #endif