OLD | NEW |
1 /* | 1 #include "../../../../public/webview/WebView.h" |
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 "../../../../public/platform/WebString.h" | |
35 #include "../../../../public/platform/WebVector.h" | |
36 #include "WebDragOperation.h" | |
37 #include "WebPageVisibilityState.h" | |
38 #include "WebWidget.h" | |
39 | |
40 namespace WebKit { | |
41 | |
42 class WebAccessibilityObject; | |
43 class WebAutofillClient; | |
44 class WebBatteryStatus; | |
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 WebTextFieldDecoratorClient; | |
61 class WebValidationMessageClient; | |
62 class WebViewBenchmarkSupport; | |
63 class WebViewClient; | |
64 struct WebActiveWheelFlingParameters; | |
65 struct WebMediaPlayerAction; | |
66 struct WebPluginAction; | |
67 struct WebPoint; | |
68 | |
69 class WebView : public WebWidget { | |
70 public: | |
71 WEBKIT_EXPORT static const double textSizeMultiplierRatio; | |
72 WEBKIT_EXPORT static const double minTextSizeMultiplier; | |
73 WEBKIT_EXPORT static const double maxTextSizeMultiplier; | |
74 WEBKIT_EXPORT static const float minPageScaleFactor; | |
75 WEBKIT_EXPORT static const float maxPageScaleFactor; | |
76 | |
77 // Controls which frames user content is injected into. | |
78 enum UserContentInjectIn { | |
79 UserContentInjectInAllFrames, | |
80 UserContentInjectInTopFrameOnly | |
81 }; | |
82 | |
83 // Controls which documents user styles are injected into. | |
84 enum UserStyleInjectionTime { | |
85 UserStyleInjectInExistingDocuments, | |
86 UserStyleInjectInSubsequentDocuments | |
87 }; | |
88 | |
89 | |
90 // Initialization ------------------------------------------------------ | |
91 | |
92 // Creates a WebView that is NOT yet initialized. You will need to | |
93 // call initializeMainFrame to finish the initialization. It is valid | |
94 // to pass null client pointers. | |
95 WEBKIT_EXPORT static WebView* create(WebViewClient*); | |
96 | |
97 // After creating a WebView, you should immediately call this method. | |
98 // You can optionally modify the settings before calling this method. | |
99 // The WebFrameClient will receive events for the main frame and any | |
100 // child frames. It is valid to pass a null WebFrameClient pointer. | |
101 virtual void initializeMainFrame(WebFrameClient*) = 0; | |
102 | |
103 virtual void initializeHelperPluginFrame(WebFrameClient*) = 0; | |
104 | |
105 // Initializes the various client interfaces. | |
106 virtual void setAutofillClient(WebAutofillClient*) = 0; | |
107 virtual void setDevToolsAgentClient(WebDevToolsAgentClient*) = 0; | |
108 virtual void setPermissionClient(WebPermissionClient*) = 0; | |
109 virtual void setPrerendererClient(WebPrerendererClient*) = 0; | |
110 virtual void setSpellCheckClient(WebSpellCheckClient*) = 0; | |
111 virtual void setValidationMessageClient(WebValidationMessageClient*) = 0; | |
112 virtual void addTextFieldDecoratorClient(WebTextFieldDecoratorClient*) = 0; | |
113 | |
114 | |
115 // Options ------------------------------------------------------------- | |
116 | |
117 // The returned pointer is valid for the lifetime of the WebView. | |
118 virtual WebSettings* settings() = 0; | |
119 | |
120 // Corresponds to the encoding of the main frame. Setting the page | |
121 // encoding may cause the main frame to reload. | |
122 virtual WebString pageEncoding() const = 0; | |
123 virtual void setPageEncoding(const WebString&) = 0; | |
124 | |
125 // Makes the WebView transparent. This is useful if you want to have | |
126 // some custom background rendered behind it. | |
127 virtual bool isTransparent() const = 0; | |
128 virtual void setIsTransparent(bool) = 0; | |
129 | |
130 // Controls whether pressing Tab key advances focus to links. | |
131 virtual bool tabsToLinks() const = 0; | |
132 virtual void setTabsToLinks(bool) = 0; | |
133 | |
134 // Method that controls whether pressing Tab key cycles through page | |
135 // elements or inserts a '\t' char in the focused text area. | |
136 virtual bool tabKeyCyclesThroughElements() const = 0; | |
137 virtual void setTabKeyCyclesThroughElements(bool) = 0; | |
138 | |
139 // Controls the WebView's active state, which may affect the rendering | |
140 // of elements on the page (i.e., tinting of input elements). | |
141 virtual bool isActive() const = 0; | |
142 virtual void setIsActive(bool) = 0; | |
143 | |
144 // Allows disabling domain relaxation. | |
145 virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) = 0
; | |
146 | |
147 | |
148 // Closing ------------------------------------------------------------- | |
149 | |
150 // Runs beforeunload handlers for the current page, returning false if | |
151 // any handler suppressed unloading. | |
152 virtual bool dispatchBeforeUnloadEvent() = 0; | |
153 | |
154 // Runs unload handlers for the current page. | |
155 virtual void dispatchUnloadEvent() = 0; | |
156 | |
157 | |
158 // Frames -------------------------------------------------------------- | |
159 | |
160 virtual WebFrame* mainFrame() = 0; | |
161 | |
162 // Returns the frame identified by the given name. This method | |
163 // supports pseudo-names like _self, _top, and _blank. It traverses | |
164 // the entire frame tree containing this tree looking for a frame that | |
165 // matches the given name. If the optional relativeToFrame parameter | |
166 // is specified, then the search begins with the given frame and its | |
167 // children. | |
168 virtual WebFrame* findFrameByName( | |
169 const WebString& name, WebFrame* relativeToFrame = 0) = 0; | |
170 | |
171 | |
172 // Focus --------------------------------------------------------------- | |
173 | |
174 virtual WebFrame* focusedFrame() = 0; | |
175 virtual void setFocusedFrame(WebFrame*) = 0; | |
176 | |
177 // Focus the first (last if reverse is true) focusable node. | |
178 virtual void setInitialFocus(bool reverse) = 0; | |
179 | |
180 // Clears the focused node (and selection if a text field is focused) | |
181 // to ensure that a text field on the page is not eating keystrokes we | |
182 // send it. | |
183 virtual void clearFocusedNode() = 0; | |
184 | |
185 // Scrolls the node currently in focus into view. | |
186 virtual void scrollFocusedNodeIntoView() = 0; | |
187 | |
188 // Scrolls the node currently in focus into |rect|, where |rect| is in | |
189 // window space. | |
190 virtual void scrollFocusedNodeIntoRect(const WebRect&) { } | |
191 | |
192 // Advance the focus of the WebView forward to the next element or to the | |
193 // previous element in the tab sequence (if reverse is true). | |
194 virtual void advanceFocus(bool reverse) { } | |
195 | |
196 // Animate a scale into the specified find-in-page rect. | |
197 virtual void zoomToFindInPageRect(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 // | |
213 // If |textOnly| is set, only the text will be zoomed; otherwise the entire | |
214 // page will be zoomed. You can only have either text zoom or full page zoom | |
215 // at one time. Changing the mode while the page is zoomed will have odd | |
216 // effects. | |
217 virtual double setZoomLevel(bool textOnly, double zoomLevel) = 0; | |
218 | |
219 // Updates the zoom limits for this view. | |
220 virtual void zoomLimitsChanged(double minimumZoomLevel, | |
221 double maximumZoomLevel) = 0; | |
222 | |
223 // Helper functions to convert between zoom level and zoom factor. zoom | |
224 // factor is zoom percent / 100, so 300% = 3.0. | |
225 WEBKIT_EXPORT static double zoomLevelToZoomFactor(double zoomLevel); | |
226 WEBKIT_EXPORT static double zoomFactorToZoomLevel(double factor); | |
227 | |
228 // Sets the initial page scale to the given factor. This scale setting overr
ides | |
229 // page scale set in the page's viewport meta tag. | |
230 virtual void setInitialPageScaleOverride(float) = 0; | |
231 | |
232 // Gets the scale factor of the page, where 1.0 is the normal size, > 1.0 | |
233 // is scaled up, < 1.0 is scaled down. | |
234 virtual float pageScaleFactor() const = 0; | |
235 | |
236 // Scales the page and the scroll offset by a given factor, while ensuring | |
237 // that the new scroll position does not go beyond the edge of the page. | |
238 virtual void setPageScaleFactorPreservingScrollOffset(float) = 0; | |
239 | |
240 // Scales a page by a factor of scaleFactor and then sets a scroll position
to (x, y). | |
241 // setPageScaleFactor() magnifies and shrinks a page without affecting layou
t. | |
242 // On the other hand, zooming affects layout of the page. | |
243 virtual void setPageScaleFactor(float scaleFactor, const WebPoint& origin) =
0; | |
244 | |
245 // PageScaleFactor will be force-clamped between minPageScale and maxPageSca
le | |
246 // (and these values will persist until setPageScaleFactorLimits is called | |
247 // again). | |
248 virtual void setPageScaleFactorLimits(float minPageScale, float maxPageScale
) = 0; | |
249 | |
250 virtual float minimumPageScaleFactor() const = 0; | |
251 virtual float maximumPageScaleFactor() const = 0; | |
252 | |
253 // Save the WebView's current scroll and scale state. Each call to this func
tion | |
254 // overwrites the previously saved scroll and scale state. | |
255 virtual void saveScrollAndScaleState() = 0; | |
256 | |
257 // Restore the previously saved scroll and scale state. After restoring the | |
258 // state, this function deletes any saved scroll and scale state. | |
259 virtual void restoreScrollAndScaleState() = 0; | |
260 | |
261 // Reset any saved values for the scroll and scale state. | |
262 virtual void resetScrollAndScaleState() = 0; | |
263 | |
264 // Prevent the web page from setting min/max scale via the viewport meta | |
265 // tag. This is an accessibility feature that lets folks zoom in to web | |
266 // pages even if the web page tries to block scaling. | |
267 virtual void setIgnoreViewportTagScaleLimits(bool) = 0; | |
268 | |
269 // FIXME(aelias): Delete this after Chromium switches to the other name. | |
270 void setIgnoreViewportTagMaximumScale(bool ignore) { setIgnoreViewportTagSca
leLimits(ignore); } | |
271 | |
272 // The ratio of the current device's screen DPI to the target device's scree
n DPI. | |
273 virtual float deviceScaleFactor() const = 0; | |
274 | |
275 // Sets the ratio as computed by computePageScaleConstraints. | |
276 virtual void setDeviceScaleFactor(float) = 0; | |
277 | |
278 | |
279 // Fixed Layout -------------------------------------------------------- | |
280 | |
281 // In fixed layout mode, the layout of the page is independent of the | |
282 // view port size, given by WebWidget::size(). | |
283 | |
284 virtual bool isFixedLayoutModeEnabled() const = 0; | |
285 virtual void enableFixedLayoutMode(bool enable) = 0; | |
286 | |
287 virtual WebSize fixedLayoutSize() const = 0; | |
288 virtual void setFixedLayoutSize(const WebSize&) = 0; | |
289 | |
290 | |
291 // Auto-Resize ----------------------------------------------------------- | |
292 | |
293 // In auto-resize mode, the view is automatically adjusted to fit the html | |
294 // content within the given bounds. | |
295 virtual void enableAutoResizeMode( | |
296 const WebSize& minSize, | |
297 const WebSize& maxSize) = 0; | |
298 | |
299 // Turn off auto-resize. | |
300 virtual void disableAutoResizeMode() = 0; | |
301 | |
302 // Media --------------------------------------------------------------- | |
303 | |
304 // Performs the specified media player action on the node at the given locat
ion. | |
305 virtual void performMediaPlayerAction( | |
306 const WebMediaPlayerAction&, const WebPoint& location) = 0; | |
307 | |
308 // Performs the specified plugin action on the node at the given location. | |
309 virtual void performPluginAction( | |
310 const WebPluginAction&, const WebPoint& location) = 0; | |
311 | |
312 | |
313 // Data exchange ------------------------------------------------------- | |
314 | |
315 // Do a hit test at given point and return the HitTestResult. | |
316 virtual WebHitTestResult hitTestResultAt(const WebPoint&) = 0; | |
317 | |
318 // Copy to the clipboard the image located at a particular point in the | |
319 // WebView (if there is such an image) | |
320 virtual void copyImageAt(const WebPoint&) = 0; | |
321 | |
322 // Notifies the WebView that a drag has terminated. | |
323 virtual void dragSourceEndedAt( | |
324 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
325 WebDragOperation operation) = 0; | |
326 | |
327 // Notifies the WebView that a drag is going on. | |
328 virtual void dragSourceMovedTo( | |
329 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
330 WebDragOperation operation) = 0; | |
331 | |
332 // Notfies the WebView that the system drag and drop operation has ended. | |
333 virtual void dragSourceSystemDragEnded() = 0; | |
334 | |
335 // Callback methods when a drag-and-drop operation is trying to drop | |
336 // something on the WebView. | |
337 virtual WebDragOperation dragTargetDragEnter( | |
338 const WebDragData&, | |
339 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
340 WebDragOperationsMask operationsAllowed, | |
341 int keyModifiers) = 0; | |
342 virtual WebDragOperation dragTargetDragOver( | |
343 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
344 WebDragOperationsMask operationsAllowed, | |
345 int keyModifiers) = 0; | |
346 virtual void dragTargetDragLeave() = 0; | |
347 virtual void dragTargetDrop( | |
348 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
349 int keyModifiers) = 0; | |
350 | |
351 // Retrieves a list of spelling markers. | |
352 virtual void spellingMarkers(WebVector<uint32_t>* markers) = 0; | |
353 | |
354 | |
355 // Support for resource loading initiated by plugins ------------------- | |
356 | |
357 // Returns next unused request identifier which is unique within the | |
358 // parent Page. | |
359 virtual unsigned long createUniqueIdentifierForRequest() = 0; | |
360 | |
361 | |
362 // Developer tools ----------------------------------------------------- | |
363 | |
364 // Inspect a particular point in the WebView. (x = -1 || y = -1) is a | |
365 // special case, meaning inspect the current page and not a specific | |
366 // point. | |
367 virtual void inspectElementAt(const WebPoint&) = 0; | |
368 | |
369 // Settings used by the inspector. | |
370 virtual WebString inspectorSettings() const = 0; | |
371 virtual void setInspectorSettings(const WebString&) = 0; | |
372 virtual bool inspectorSetting(const WebString& key, | |
373 WebString* value) const = 0; | |
374 virtual void setInspectorSetting(const WebString& key, | |
375 const WebString& value) = 0; | |
376 | |
377 // The embedder may optionally engage a WebDevToolsAgent. This may only | |
378 // be set once per WebView. | |
379 virtual WebDevToolsAgent* devToolsAgent() = 0; | |
380 | |
381 | |
382 // Accessibility ------------------------------------------------------- | |
383 | |
384 // Returns the accessibility object for this view. | |
385 virtual WebAccessibilityObject accessibilityObject() = 0; | |
386 | |
387 | |
388 // Autofill ----------------------------------------------------------- | |
389 | |
390 // Notifies the WebView that Autofill suggestions are available for a node. | |
391 // |itemIDs| is a vector of IDs for the menu items. A positive itemID is a | |
392 // unique ID for the Autofill entries. Other MenuItemIDs are defined in | |
393 // WebAutofillClient.h | |
394 virtual void applyAutofillSuggestions( | |
395 const WebNode&, | |
396 const WebVector<WebString>& names, | |
397 const WebVector<WebString>& labels, | |
398 const WebVector<WebString>& icons, | |
399 const WebVector<int>& itemIDs, | |
400 int separatorIndex = -1) = 0; | |
401 | |
402 // Hides any popup (suggestions, selects...) that might be showing. | |
403 virtual void hidePopups() = 0; | |
404 | |
405 virtual void selectAutofillSuggestionAtIndex(unsigned listIndex) = 0; | |
406 | |
407 | |
408 // Context menu -------------------------------------------------------- | |
409 | |
410 virtual void performCustomContextMenuAction(unsigned action) = 0; | |
411 | |
412 // Shows a context menu for the currently focused element. | |
413 virtual void showContextMenu() = 0; | |
414 | |
415 | |
416 // Popup menu ---------------------------------------------------------- | |
417 | |
418 // Sets whether select popup menus should be rendered by the browser. | |
419 WEBKIT_EXPORT static void setUseExternalPopupMenus(bool); | |
420 | |
421 | |
422 // Visited link state -------------------------------------------------- | |
423 | |
424 // Tells all WebView instances to update the visited link state for the | |
425 // specified hash. | |
426 WEBKIT_EXPORT static void updateVisitedLinkState(unsigned long long hash); | |
427 | |
428 // Tells all WebView instances to update the visited state for all | |
429 // their links. | |
430 WEBKIT_EXPORT static void resetVisitedLinkState(); | |
431 | |
432 | |
433 // Custom colors ------------------------------------------------------- | |
434 | |
435 virtual void setScrollbarColors(unsigned inactiveColor, | |
436 unsigned activeColor, | |
437 unsigned trackColor) = 0; | |
438 | |
439 virtual void setSelectionColors(unsigned activeBackgroundColor, | |
440 unsigned activeForegroundColor, | |
441 unsigned inactiveBackgroundColor, | |
442 unsigned inactiveForegroundColor) = 0; | |
443 | |
444 // User scripts -------------------------------------------------------- | |
445 WEBKIT_EXPORT static void addUserStyleSheet(const WebString& sourceCode, | |
446 const WebVector<WebString>& patt
erns, | |
447 UserContentInjectIn injectIn, | |
448 UserStyleInjectionTime injection
Time = UserStyleInjectInSubsequentDocuments); | |
449 WEBKIT_EXPORT static void removeAllUserContent(); | |
450 | |
451 // Modal dialog support ------------------------------------------------ | |
452 | |
453 // Call these methods before and after running a nested, modal event loop | |
454 // to suspend script callbacks and resource loads. | |
455 WEBKIT_EXPORT static void willEnterModalLoop(); | |
456 WEBKIT_EXPORT static void didExitModalLoop(); | |
457 | |
458 // Called to inform the WebView that a wheel fling animation was started ext
ernally (for instance | |
459 // by the compositor) but must be completed by the WebView. | |
460 virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingPara
meters&) = 0; | |
461 | |
462 virtual bool setEditableSelectionOffsets(int start, int end) = 0; | |
463 virtual bool setCompositionFromExistingText(int compositionStart, int compos
itionEnd, const WebVector<WebCompositionUnderline>& underlines) = 0; | |
464 virtual void extendSelectionAndDelete(int before, int after) = 0; | |
465 | |
466 virtual bool isSelectionEditable() const = 0; | |
467 | |
468 virtual void setShowPaintRects(bool) = 0; | |
469 virtual void setShowFPSCounter(bool) = 0; | |
470 virtual void setContinuousPaintingEnabled(bool) = 0; | |
471 | |
472 // Benchmarking support ------------------------------------------------- | |
473 | |
474 virtual WebViewBenchmarkSupport* benchmarkSupport() { return 0; } | |
475 | |
476 // Visibility ----------------------------------------------------------- | |
477 | |
478 // Sets the visibility of the WebView. | |
479 virtual void setVisibilityState(WebPageVisibilityState visibilityState, | |
480 bool isInitialState) { } | |
481 | |
482 // PageOverlay ---------------------------------------------------------- | |
483 | |
484 // Adds/removes page overlay to this WebView. These functions change the | |
485 // graphical appearance of the WebView. WebPageOverlay paints the | |
486 // contents of the page overlay. It also provides an z-order number for | |
487 // the page overlay. The z-order number defines the paint order the page | |
488 // overlays. Page overlays with larger z-order number will be painted after | |
489 // page overlays with smaller z-order number. That is, they appear above | |
490 // the page overlays with smaller z-order number. If two page overlays have | |
491 // the same z-order number, the later added one will be on top. | |
492 virtual void addPageOverlay(WebPageOverlay*, int /*z-order*/) = 0; | |
493 virtual void removePageOverlay(WebPageOverlay*) = 0; | |
494 | |
495 // Battery status API support ------------------------------------------- | |
496 | |
497 // Updates the battery status in the BatteryClient. This also triggers the | |
498 // appropriate JS events (e.g. sends a 'levelchange' event to JS if the | |
499 // level is changed in this update from the previous update). | |
500 virtual void updateBatteryStatus(const WebBatteryStatus&) { } | |
501 | |
502 // Testing functionality for TestRunner --------------------------------- | |
503 | |
504 protected: | |
505 ~WebView() {} | |
506 }; | |
507 | |
508 } // namespace WebKit | |
509 | |
510 #endif | |
OLD | NEW |