OLD | NEW |
| (Empty) |
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/WebString.h" | |
35 #include "../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 // Returns the "preferred" contents size, defined as the preferred minimum w
idth of the main document's contents | |
270 // and the minimum height required to display the main document without scro
llbars. | |
271 // The returned size has the page zoom factor applied. | |
272 virtual WebSize contentsPreferredMinimumSize() = 0; | |
273 | |
274 // FIXME(aelias): Delete this after Chromium switches to the other name. | |
275 void setIgnoreViewportTagMaximumScale(bool ignore) { setIgnoreViewportTagSca
leLimits(ignore); } | |
276 | |
277 // The ratio of the current device's screen DPI to the target device's scree
n DPI. | |
278 virtual float deviceScaleFactor() const = 0; | |
279 | |
280 // Sets the ratio as computed by computePageScaleConstraints. | |
281 virtual void setDeviceScaleFactor(float) = 0; | |
282 | |
283 | |
284 // Fixed Layout -------------------------------------------------------- | |
285 | |
286 // In fixed layout mode, the layout of the page is independent of the | |
287 // view port size, given by WebWidget::size(). | |
288 | |
289 virtual bool isFixedLayoutModeEnabled() const = 0; | |
290 virtual void enableFixedLayoutMode(bool enable) = 0; | |
291 | |
292 virtual WebSize fixedLayoutSize() const = 0; | |
293 virtual void setFixedLayoutSize(const WebSize&) = 0; | |
294 | |
295 | |
296 // Auto-Resize ----------------------------------------------------------- | |
297 | |
298 // In auto-resize mode, the view is automatically adjusted to fit the html | |
299 // content within the given bounds. | |
300 virtual void enableAutoResizeMode( | |
301 const WebSize& minSize, | |
302 const WebSize& maxSize) = 0; | |
303 | |
304 // Turn off auto-resize. | |
305 virtual void disableAutoResizeMode() = 0; | |
306 | |
307 // Media --------------------------------------------------------------- | |
308 | |
309 // Performs the specified media player action on the node at the given locat
ion. | |
310 virtual void performMediaPlayerAction( | |
311 const WebMediaPlayerAction&, const WebPoint& location) = 0; | |
312 | |
313 // Performs the specified plugin action on the node at the given location. | |
314 virtual void performPluginAction( | |
315 const WebPluginAction&, const WebPoint& location) = 0; | |
316 | |
317 | |
318 // Data exchange ------------------------------------------------------- | |
319 | |
320 // Do a hit test at given point and return the HitTestResult. | |
321 virtual WebHitTestResult hitTestResultAt(const WebPoint&) = 0; | |
322 | |
323 // Copy to the clipboard the image located at a particular point in the | |
324 // WebView (if there is such an image) | |
325 virtual void copyImageAt(const WebPoint&) = 0; | |
326 | |
327 // Notifies the WebView that a drag has terminated. | |
328 virtual void dragSourceEndedAt( | |
329 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
330 WebDragOperation operation) = 0; | |
331 | |
332 // Notifies the WebView that a drag is going on. | |
333 virtual void dragSourceMovedTo( | |
334 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
335 WebDragOperation operation) = 0; | |
336 | |
337 // Notfies the WebView that the system drag and drop operation has ended. | |
338 virtual void dragSourceSystemDragEnded() = 0; | |
339 | |
340 // Callback methods when a drag-and-drop operation is trying to drop | |
341 // something on the WebView. | |
342 virtual WebDragOperation dragTargetDragEnter( | |
343 const WebDragData&, | |
344 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
345 WebDragOperationsMask operationsAllowed, | |
346 int keyModifiers) = 0; | |
347 virtual WebDragOperation dragTargetDragOver( | |
348 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
349 WebDragOperationsMask operationsAllowed, | |
350 int keyModifiers) = 0; | |
351 virtual void dragTargetDragLeave() = 0; | |
352 virtual void dragTargetDrop( | |
353 const WebPoint& clientPoint, const WebPoint& screenPoint, | |
354 int keyModifiers) = 0; | |
355 | |
356 // Retrieves a list of spelling markers. | |
357 virtual void spellingMarkers(WebVector<uint32_t>* markers) = 0; | |
358 | |
359 | |
360 // Support for resource loading initiated by plugins ------------------- | |
361 | |
362 // Returns next unused request identifier which is unique within the | |
363 // parent Page. | |
364 virtual unsigned long createUniqueIdentifierForRequest() = 0; | |
365 | |
366 | |
367 // Developer tools ----------------------------------------------------- | |
368 | |
369 // Inspect a particular point in the WebView. (x = -1 || y = -1) is a | |
370 // special case, meaning inspect the current page and not a specific | |
371 // point. | |
372 virtual void inspectElementAt(const WebPoint&) = 0; | |
373 | |
374 // Settings used by the inspector. | |
375 virtual WebString inspectorSettings() const = 0; | |
376 virtual void setInspectorSettings(const WebString&) = 0; | |
377 virtual bool inspectorSetting(const WebString& key, | |
378 WebString* value) const = 0; | |
379 virtual void setInspectorSetting(const WebString& key, | |
380 const WebString& value) = 0; | |
381 | |
382 // The embedder may optionally engage a WebDevToolsAgent. This may only | |
383 // be set once per WebView. | |
384 virtual WebDevToolsAgent* devToolsAgent() = 0; | |
385 | |
386 | |
387 // Accessibility ------------------------------------------------------- | |
388 | |
389 // Returns the accessibility object for this view. | |
390 virtual WebAccessibilityObject accessibilityObject() = 0; | |
391 | |
392 | |
393 // Autofill ----------------------------------------------------------- | |
394 | |
395 // Notifies the WebView that Autofill suggestions are available for a node. | |
396 // |itemIDs| is a vector of IDs for the menu items. A positive itemID is a | |
397 // unique ID for the Autofill entries. Other MenuItemIDs are defined in | |
398 // WebAutofillClient.h | |
399 virtual void applyAutofillSuggestions( | |
400 const WebNode&, | |
401 const WebVector<WebString>& names, | |
402 const WebVector<WebString>& labels, | |
403 const WebVector<WebString>& icons, | |
404 const WebVector<int>& itemIDs, | |
405 int separatorIndex = -1) = 0; | |
406 | |
407 // Hides any popup (suggestions, selects...) that might be showing. | |
408 virtual void hidePopups() = 0; | |
409 | |
410 virtual void selectAutofillSuggestionAtIndex(unsigned listIndex) = 0; | |
411 | |
412 | |
413 // Context menu -------------------------------------------------------- | |
414 | |
415 virtual void performCustomContextMenuAction(unsigned action) = 0; | |
416 | |
417 // Shows a context menu for the currently focused element. | |
418 virtual void showContextMenu() = 0; | |
419 | |
420 | |
421 // Popup menu ---------------------------------------------------------- | |
422 | |
423 // Sets whether select popup menus should be rendered by the browser. | |
424 WEBKIT_EXPORT static void setUseExternalPopupMenus(bool); | |
425 | |
426 | |
427 // Visited link state -------------------------------------------------- | |
428 | |
429 // Tells all WebView instances to update the visited link state for the | |
430 // specified hash. | |
431 WEBKIT_EXPORT static void updateVisitedLinkState(unsigned long long hash); | |
432 | |
433 // Tells all WebView instances to update the visited state for all | |
434 // their links. | |
435 WEBKIT_EXPORT static void resetVisitedLinkState(); | |
436 | |
437 | |
438 // Custom colors ------------------------------------------------------- | |
439 | |
440 virtual void setScrollbarColors(unsigned inactiveColor, | |
441 unsigned activeColor, | |
442 unsigned trackColor) = 0; | |
443 | |
444 virtual void setSelectionColors(unsigned activeBackgroundColor, | |
445 unsigned activeForegroundColor, | |
446 unsigned inactiveBackgroundColor, | |
447 unsigned inactiveForegroundColor) = 0; | |
448 | |
449 // User scripts -------------------------------------------------------- | |
450 WEBKIT_EXPORT static void addUserStyleSheet(const WebString& sourceCode, | |
451 const WebVector<WebString>& patt
erns, | |
452 UserContentInjectIn injectIn, | |
453 UserStyleInjectionTime injection
Time = UserStyleInjectInSubsequentDocuments); | |
454 WEBKIT_EXPORT static void removeAllUserContent(); | |
455 | |
456 // Modal dialog support ------------------------------------------------ | |
457 | |
458 // Call these methods before and after running a nested, modal event loop | |
459 // to suspend script callbacks and resource loads. | |
460 WEBKIT_EXPORT static void willEnterModalLoop(); | |
461 WEBKIT_EXPORT static void didExitModalLoop(); | |
462 | |
463 // Called to inform the WebView that a wheel fling animation was started ext
ernally (for instance | |
464 // by the compositor) but must be completed by the WebView. | |
465 virtual void transferActiveWheelFlingAnimation(const WebActiveWheelFlingPara
meters&) = 0; | |
466 | |
467 virtual bool setEditableSelectionOffsets(int start, int end) = 0; | |
468 virtual bool setCompositionFromExistingText(int compositionStart, int compos
itionEnd, const WebVector<WebCompositionUnderline>& underlines) = 0; | |
469 virtual void extendSelectionAndDelete(int before, int after) = 0; | |
470 | |
471 virtual bool isSelectionEditable() const = 0; | |
472 | |
473 virtual void setShowPaintRects(bool) = 0; | |
474 virtual void setShowFPSCounter(bool) = 0; | |
475 virtual void setContinuousPaintingEnabled(bool) = 0; | |
476 | |
477 // Benchmarking support ------------------------------------------------- | |
478 | |
479 virtual WebViewBenchmarkSupport* benchmarkSupport() { return 0; } | |
480 | |
481 // Visibility ----------------------------------------------------------- | |
482 | |
483 // Sets the visibility of the WebView. | |
484 virtual void setVisibilityState(WebPageVisibilityState visibilityState, | |
485 bool isInitialState) { } | |
486 | |
487 // PageOverlay ---------------------------------------------------------- | |
488 | |
489 // Adds/removes page overlay to this WebView. These functions change the | |
490 // graphical appearance of the WebView. WebPageOverlay paints the | |
491 // contents of the page overlay. It also provides an z-order number for | |
492 // the page overlay. The z-order number defines the paint order the page | |
493 // overlays. Page overlays with larger z-order number will be painted after | |
494 // page overlays with smaller z-order number. That is, they appear above | |
495 // the page overlays with smaller z-order number. If two page overlays have | |
496 // the same z-order number, the later added one will be on top. | |
497 virtual void addPageOverlay(WebPageOverlay*, int /*z-order*/) = 0; | |
498 virtual void removePageOverlay(WebPageOverlay*) = 0; | |
499 | |
500 // Battery status API support ------------------------------------------- | |
501 | |
502 // Updates the battery status in the BatteryClient. This also triggers the | |
503 // appropriate JS events (e.g. sends a 'levelchange' event to JS if the | |
504 // level is changed in this update from the previous update). | |
505 virtual void updateBatteryStatus(const WebBatteryStatus&) { } | |
506 | |
507 // Testing functionality for TestRunner --------------------------------- | |
508 | |
509 protected: | |
510 ~WebView() {} | |
511 }; | |
512 | |
513 } // namespace WebKit | |
514 | |
515 #endif | |
OLD | NEW |