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
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
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.
34 #include "WebDragOperation.h"
35 #include "WebPageVisibilityState.h"
36 #include "WebWidget.h"
37 #include "platform/WebString.h"
38 #include "platform/WebVector.h"
42 class WebAccessibilityObject;
43 class WebAutofillClient;
44 class WebBatteryStatus;
45 class WebDevToolsAgent;
46 class WebDevToolsAgentClient;
50 class WebGraphicsContext3D;
53 class WebPermissionClient;
55 class WebSpellCheckClient;
57 class WebTextFieldDecoratorClient;
59 struct WebActiveWheelFlingParameters;
60 struct WebMediaPlayerAction;
61 struct WebPluginAction;
64 class WebView : public WebWidget {
66 WEBKIT_EXPORT static const double textSizeMultiplierRatio;
67 WEBKIT_EXPORT static const double minTextSizeMultiplier;
68 WEBKIT_EXPORT static const double maxTextSizeMultiplier;
69 WEBKIT_EXPORT static const float minPageScaleFactor;
70 WEBKIT_EXPORT static const float maxPageScaleFactor;
72 // Controls the time that user scripts injected into the document run.
73 enum UserScriptInjectAt {
74 UserScriptInjectAtDocumentStart,
75 UserScriptInjectAtDocumentEnd
78 // Controls which frames user content is injected into.
79 enum UserContentInjectIn {
80 UserContentInjectInAllFrames,
81 UserContentInjectInTopFrameOnly
84 // Controls which documents user styles are injected into.
85 enum UserStyleInjectionTime {
86 UserStyleInjectInExistingDocuments,
87 UserStyleInjectInSubsequentDocuments
91 // Initialization ------------------------------------------------------
93 // Creates a WebView that is NOT yet initialized. You will need to
94 // call initializeMainFrame to finish the initialization. It is valid
95 // to pass null client pointers.
96 WEBKIT_EXPORT static WebView* create(WebViewClient*);
98 // After creating a WebView, you should immediately call this method.
99 // You can optionally modify the settings before calling this method.
100 // The WebFrameClient will receive events for the main frame and any
101 // child frames. It is valid to pass a null WebFrameClient pointer.
102 virtual void initializeMainFrame(WebFrameClient*) = 0;
104 // Initializes the various client interfaces.
105 virtual void setAutofillClient(WebAutofillClient*) = 0;
106 virtual void setDevToolsAgentClient(WebDevToolsAgentClient*) = 0;
107 virtual void setPermissionClient(WebPermissionClient*) = 0;
108 virtual void setSpellCheckClient(WebSpellCheckClient*) = 0;
109 virtual void addTextFieldDecoratorClient(WebTextFieldDecoratorClient*) = 0;
112 // Options -------------------------------------------------------------
114 // The returned pointer is valid for the lifetime of the WebView.
115 virtual WebSettings* settings() = 0;
117 // Corresponds to the encoding of the main frame. Setting the page
118 // encoding may cause the main frame to reload.
119 virtual WebString pageEncoding() const = 0;
120 virtual void setPageEncoding(const WebString&) = 0;
122 // Makes the WebView transparent. This is useful if you want to have
123 // some custom background rendered behind it.
124 virtual bool isTransparent() const = 0;
125 virtual void setIsTransparent(bool) = 0;
127 // Controls whether pressing Tab key advances focus to links.
128 virtual bool tabsToLinks() const = 0;
129 virtual void setTabsToLinks(bool) = 0;
131 // Method that controls whether pressing Tab key cycles through page
132 // elements or inserts a '\t' char in the focused text area.
133 virtual bool tabKeyCyclesThroughElements() const = 0;
134 virtual void setTabKeyCyclesThroughElements(bool) = 0;
136 // Controls the WebView's active state, which may affect the rendering
137 // of elements on the page (i.e., tinting of input elements).
138 virtual bool isActive() const = 0;
139 virtual void setIsActive(bool) = 0;
141 // Allows disabling domain relaxation.
142 virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) = 0;
145 // Closing -------------------------------------------------------------
147 // Runs beforeunload handlers for the current page, returning false if
148 // any handler suppressed unloading.
149 virtual bool dispatchBeforeUnloadEvent() = 0;
151 // Runs unload handlers for the current page.
152 virtual void dispatchUnloadEvent() = 0;
155 // Frames --------------------------------------------------------------
157 virtual WebFrame* mainFrame() = 0;
159 // Returns the frame identified by the given name. This method
160 // supports pseudo-names like _self, _top, and _blank. It traverses
161 // the entire frame tree containing this tree looking for a frame that
162 // matches the given name. If the optional relativeToFrame parameter
163 // is specified, then the search begins with the given frame and its
165 virtual WebFrame* findFrameByName(
166 const WebString& name, WebFrame* relativeToFrame = 0) = 0;
169 // Focus ---------------------------------------------------------------
171 virtual WebFrame* focusedFrame() = 0;
172 virtual void setFocusedFrame(WebFrame*) = 0;
174 // Focus the first (last if reverse is true) focusable node.
175 virtual void setInitialFocus(bool reverse) = 0;
177 // Clears the focused node (and selection if a text field is focused)
178 // to ensure that a text field on the page is not eating keystrokes we
180 virtual void clearFocusedNode() = 0;
182 // Scrolls the node currently in focus into view.
183 virtual void scrollFocusedNodeIntoView() = 0;
185 // Scrolls the node currently in focus into |rect|, where |rect| is in
187 virtual void scrollFocusedNodeIntoRect(const WebRect&) { }
190 // Zoom ----------------------------------------------------------------
192 // Returns the current zoom level. 0 is "original size", and each increment
193 // above or below represents zooming 20% larger or smaller to default limits
194 // of 300% and 50% of original size, respectively. Only plugins use
195 // non whole-numbers, since they might choose to have specific zoom level so
196 // that fixed-width content is fit-to-page-width, for example.
197 virtual double zoomLevel() = 0;
199 // Changes the zoom level to the specified level, clamping at the limits
200 // noted above, and returns the current zoom level after applying the
203 // If |textOnly| is set, only the text will be zoomed; otherwise the entire
204 // page will be zoomed. You can only have either text zoom or full page zoom
205 // at one time. Changing the mode while the page is zoomed will have odd
207 virtual double setZoomLevel(bool textOnly, double zoomLevel) = 0;
209 // Updates the zoom limits for this view.
210 virtual void zoomLimitsChanged(double minimumZoomLevel,
211 double maximumZoomLevel) = 0;
213 // Helper functions to convert between zoom level and zoom factor. zoom
214 // factor is zoom percent / 100, so 300% = 3.0.
215 WEBKIT_EXPORT static double zoomLevelToZoomFactor(double zoomLevel);
216 WEBKIT_EXPORT static double zoomFactorToZoomLevel(double factor);
218 // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0
219 // is scaled up, < 1.0 is scaled down.
220 virtual float pageScaleFactor() const = 0;
222 // Indicates whether the page scale factor has been set since navigating
224 virtual bool isPageScaleFactorSet() const = 0;
226 // Scales the page and the scroll offset by a given factor, while ensuring
227 // that the new scroll position does not go beyond the edge of the page.
228 virtual void setPageScaleFactorPreservingScrollOffset(float) = 0;
230 // Scales a page by a factor of scaleFactor and then sets a scroll position to (x, y).
231 // setPageScaleFactor() magnifies and shrinks a page without affecting layout.
232 // On the other hand, zooming affects layout of the page.
233 virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) = 0;
235 // PageScaleFactor will be force-clamped between minPageScale and maxPageScale
236 // (and these values will persist until setPageScaleFactorLimits is called
238 virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale) = 0;
240 virtual float minimumPageScaleFactor() const = 0;
241 virtual float maximumPageScaleFactor() const = 0;
243 // The ratio of the current device's screen DPI to the target device's screen DPI.
244 virtual float deviceScaleFactor() const = 0;
246 // Sets the ratio as computed by computeViewportAttributes.
247 virtual void setDeviceScaleFactor(float) = 0;
250 // Fixed Layout --------------------------------------------------------
252 // In fixed layout mode, the layout of the page is independent of the
253 // view port size, given by WebWidget::size().
255 virtual bool isFixedLayoutModeEnabled() const = 0;
256 virtual void enableFixedLayoutMode(bool enable) = 0;
258 virtual WebSize fixedLayoutSize() const = 0;
259 virtual void setFixedLayoutSize(const WebSize&) = 0;
262 // Auto-Resize -----------------------------------------------------------
264 // In auto-resize mode, the view is automatically adjusted to fit the html
265 // content within the given bounds.
266 virtual void enableAutoResizeMode(
267 const WebSize& minSize,
268 const WebSize& maxSize) = 0;
270 // Turn off auto-resize.
271 virtual void disableAutoResizeMode() = 0;
273 // Media ---------------------------------------------------------------
275 // Performs the specified media player action on the node at the given location.
276 virtual void performMediaPlayerAction(
277 const WebMediaPlayerAction&, const WebPoint& location) = 0;
279 // Performs the specified plugin action on the node at the given location.
280 virtual void performPluginAction(
281 const WebPluginAction&, const WebPoint& location) = 0;
284 // Data exchange -------------------------------------------------------
286 // Copy to the clipboard the image located at a particular point in the
287 // WebView (if there is such an image)
288 virtual void copyImageAt(const WebPoint&) = 0;
290 // Notifies the WebView that a drag has terminated.
291 virtual void dragSourceEndedAt(
292 const WebPoint& clientPoint, const WebPoint& screenPoint,
293 WebDragOperation operation) = 0;
295 // Notifies the WebView that a drag is going on.
296 virtual void dragSourceMovedTo(
297 const WebPoint& clientPoint, const WebPoint& screenPoint,
298 WebDragOperation operation) = 0;
300 // Notfies the WebView that the system drag and drop operation has ended.
301 virtual void dragSourceSystemDragEnded() = 0;
303 // Callback methods when a drag-and-drop operation is trying to drop
304 // something on the WebView.
305 virtual WebDragOperation dragTargetDragEnter(
307 const WebPoint& clientPoint, const WebPoint& screenPoint,
308 WebDragOperationsMask operationsAllowed) = 0;
309 virtual WebDragOperation dragTargetDragOver(
310 const WebPoint& clientPoint, const WebPoint& screenPoint,
311 WebDragOperationsMask operationsAllowed) = 0;
312 virtual void dragTargetDragLeave() = 0;
313 virtual void dragTargetDrop(
314 const WebPoint& clientPoint, const WebPoint& screenPoint) = 0;
317 // Support for resource loading initiated by plugins -------------------
319 // Returns next unused request identifier which is unique within the
321 virtual unsigned long createUniqueIdentifierForRequest() = 0;
324 // Developer tools -----------------------------------------------------
326 // Inspect a particular point in the WebView. (x = -1 || y = -1) is a
327 // special case, meaning inspect the current page and not a specific
329 virtual void inspectElementAt(const WebPoint&) = 0;
331 // Settings used by the inspector.
332 virtual WebString inspectorSettings() const = 0;
333 virtual void setInspectorSettings(const WebString&) = 0;
334 virtual bool inspectorSetting(const WebString& key,
335 WebString* value) const = 0;
336 virtual void setInspectorSetting(const WebString& key,
337 const WebString& value) = 0;
339 // The embedder may optionally engage a WebDevToolsAgent. This may only
340 // be set once per WebView.
341 virtual WebDevToolsAgent* devToolsAgent() = 0;
344 // Accessibility -------------------------------------------------------
346 // Returns the accessibility object for this view.
347 virtual WebAccessibilityObject accessibilityObject() = 0;
350 // Autofill -----------------------------------------------------------
352 // Notifies the WebView that Autofill suggestions are available for a node.
353 // |itemIDs| is a vector of IDs for the menu items. A positive itemID is a
354 // unique ID for the Autofill entries. Other MenuItemIDs are defined in
355 // WebAutofillClient.h
356 virtual void applyAutofillSuggestions(
358 const WebVector<WebString>& names,
359 const WebVector<WebString>& labels,
360 const WebVector<WebString>& icons,
361 const WebVector<int>& itemIDs,
362 int separatorIndex = -1) = 0;
364 // Hides any popup (suggestions, selects...) that might be showing.
365 virtual void hidePopups() = 0;
368 // Context menu --------------------------------------------------------
370 virtual void performCustomContextMenuAction(unsigned action) = 0;
373 // Popup menu ----------------------------------------------------------
375 // Sets whether select popup menus should be rendered by the browser.
376 WEBKIT_EXPORT static void setUseExternalPopupMenus(bool);
379 // Visited link state --------------------------------------------------
381 // Tells all WebView instances to update the visited link state for the
383 WEBKIT_EXPORT static void updateVisitedLinkState(unsigned long long hash);
385 // Tells all WebView instances to update the visited state for all
387 WEBKIT_EXPORT static void resetVisitedLinkState();
390 // Custom colors -------------------------------------------------------
392 virtual void setScrollbarColors(unsigned inactiveColor,
393 unsigned activeColor,
394 unsigned trackColor) = 0;
396 virtual void setSelectionColors(unsigned activeBackgroundColor,
397 unsigned activeForegroundColor,
398 unsigned inactiveBackgroundColor,
399 unsigned inactiveForegroundColor) = 0;
401 // User scripts --------------------------------------------------------
402 WEBKIT_EXPORT static void addUserScript(const WebString& sourceCode,
403 const WebVector<WebString>& patterns,
404 UserScriptInjectAt injectAt,
405 UserContentInjectIn injectIn);
406 WEBKIT_EXPORT static void addUserStyleSheet(const WebString& sourceCode,
407 const WebVector<WebString>& patterns,
408 UserContentInjectIn injectIn,
409 UserStyleInjectionTime injectionTime = UserStyleInjectInSubsequentDocuments);
410 WEBKIT_EXPORT static void removeAllUserContent();
412 // Modal dialog support ------------------------------------------------
414 // Call these methods before and after running a nested, modal event loop
415 // to suspend script callbacks and resource loads.
416 WEBKIT_EXPORT static void willEnterModalLoop();
417 WEBKIT_EXPORT static void didExitModalLoop();
419 // GPU acceleration support --------------------------------------------
421 // Returns the (on-screen) WebGraphicsContext3D associated with
422 // this WebView. One will be created if it doesn't already exist.
423 // This is used to set up sharing between this context (which is
424 // that used by the compositor) and contexts for WebGL and other
426 virtual WebGraphicsContext3D* graphicsContext3D() = 0;
428 // Context that's in the compositor's share group, but is not the compositor context itself.
429 // Can be used for allocating resources that the compositor will later access.
430 virtual WebGraphicsContext3D* sharedGraphicsContext3D() = 0;
432 // Called to inform the WebView that a wheel fling animation was started externally (for instance
433 // by the compositor) but must be completed by the WebView.
434 virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingParameters&) = 0;
436 // Visibility -----------------------------------------------------------
438 // Sets the visibility of the WebView.
439 virtual void setVisibilityState(WebPageVisibilityState visibilityState,
440 bool isInitialState) { }
442 // PageOverlay ----------------------------------------------------------
444 // Adds/removes page overlay to this WebView. These functions change the
445 // graphical appearance of the WebView. WebPageOverlay paints the
446 // contents of the page overlay. It also provides an z-order number for
447 // the page overlay. The z-order number defines the paint order the page
448 // overlays. Page overlays with larger z-order number will be painted after
449 // page overlays with smaller z-order number. That is, they appear above
450 // the page overlays with smaller z-order number. If two page overlays have
451 // the same z-order number, the later added one will be on top.
452 virtual void addPageOverlay(WebPageOverlay*, int /*z-order*/) = 0;
453 virtual void removePageOverlay(WebPageOverlay*) = 0;
455 // Battery status API support -------------------------------------------
457 // Updates the battery status in the BatteryClient. This also triggers the
458 // appropriate JS events (e.g. sends a 'levelchange' event to JS if the
459 // level is changed in this update from the previous update).
460 virtual void updateBatteryStatus(const WebBatteryStatus&) { }
462 // Testing functionality for LayoutTestController -----------------------
464 // Simulates a compositor lost context.
465 virtual void loseCompositorContext(int numTimes) = 0;
471 } // namespace WebKit