1/*
2 * Copyright (C) 2009 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 "WebDragOperation.h"
35#include "WebString.h"
36#include "WebVector.h"
37#include "WebWidget.h"
38
39namespace WebKit {
40
41class WebAccessibilityObject;
42class WebAutoFillClient;
43class WebDevToolsAgent;
44class WebDevToolsAgentClient;
45class WebDragData;
46class WebFrame;
47class WebFrameClient;
48class WebGraphicsContext3D;
49class WebNode;
50class WebSettings;
51class WebSpellCheckClient;
52class WebString;
53class WebViewClient;
54struct WebMediaPlayerAction;
55struct WebPoint;
56
57class WebView : public WebWidget {
58public:
59    WEBKIT_API static const double textSizeMultiplierRatio;
60    WEBKIT_API static const double minTextSizeMultiplier;
61    WEBKIT_API static const double maxTextSizeMultiplier;
62
63    // Controls the time that user scripts injected into the document run.
64    enum UserScriptInjectAt {
65        UserScriptInjectAtDocumentStart,
66        UserScriptInjectAtDocumentEnd
67    };
68
69    // Controls which frames user content is injected into.
70    enum UserContentInjectIn {
71        UserContentInjectInAllFrames,
72        UserContentInjectInTopFrameOnly
73    };
74
75    // Controls which documents user styles are injected into.
76    enum UserStyleInjectionTime {
77        UserStyleInjectInExistingDocuments,
78        UserStyleInjectInSubsequentDocuments
79    };
80
81
82    // Initialization ------------------------------------------------------
83
84    // Creates a WebView that is NOT yet initialized.  You will need to
85    // call initializeMainFrame to finish the initialization.  It is valid
86    // to pass null client pointers.
87    WEBKIT_API static WebView* create(WebViewClient*);
88
89    // After creating a WebView, you should immediately call this method.
90    // You can optionally modify the settings before calling this method.
91    // The WebFrameClient will receive events for the main frame and any
92    // child frames.  It is valid to pass a null WebFrameClient pointer.
93    virtual void initializeMainFrame(WebFrameClient*) = 0;
94
95    // Initializes the various client interfaces.
96    virtual void setDevToolsAgentClient(WebDevToolsAgentClient*) = 0;
97    virtual void setAutoFillClient(WebAutoFillClient*) = 0;
98    virtual void setSpellCheckClient(WebSpellCheckClient*) = 0;
99
100
101    // Options -------------------------------------------------------------
102
103    // The returned pointer is valid for the lifetime of the WebView.
104    virtual WebSettings* settings() = 0;
105
106    // Corresponds to the encoding of the main frame.  Setting the page
107    // encoding may cause the main frame to reload.
108    virtual WebString pageEncoding() const = 0;
109    virtual void setPageEncoding(const WebString&) = 0;
110
111    // Makes the WebView transparent.  This is useful if you want to have
112    // some custom background rendered behind it.
113    virtual bool isTransparent() const = 0;
114    virtual void setIsTransparent(bool) = 0;
115
116    // Controls whether pressing Tab key advances focus to links.
117    virtual bool tabsToLinks() const = 0;
118    virtual void setTabsToLinks(bool) = 0;
119
120    // Method that controls whether pressing Tab key cycles through page
121    // elements or inserts a '\t' char in the focused text area.
122    virtual bool tabKeyCyclesThroughElements() const = 0;
123    virtual void setTabKeyCyclesThroughElements(bool) = 0;
124
125    // Controls the WebView's active state, which may affect the rendering
126    // of elements on the page (i.e., tinting of input elements).
127    virtual bool isActive() const = 0;
128    virtual void setIsActive(bool) = 0;
129
130    // Allows disabling domain relaxation.
131    virtual void setDomainRelaxationForbidden(bool, const WebString& scheme) = 0;
132
133
134    // Closing -------------------------------------------------------------
135
136    // Runs beforeunload handlers for the current page, returning false if
137    // any handler suppressed unloading.
138    virtual bool dispatchBeforeUnloadEvent() = 0;
139
140    // Runs unload handlers for the current page.
141    virtual void dispatchUnloadEvent() = 0;
142
143
144    // Frames --------------------------------------------------------------
145
146    virtual WebFrame* mainFrame() = 0;
147
148    // Returns the frame identified by the given name.  This method
149    // supports pseudo-names like _self, _top, and _blank.  It traverses
150    // the entire frame tree containing this tree looking for a frame that
151    // matches the given name.  If the optional relativeToFrame parameter
152    // is specified, then the search begins with the given frame and its
153    // children.
154    virtual WebFrame* findFrameByName(
155        const WebString& name, WebFrame* relativeToFrame = 0) = 0;
156
157
158    // Focus ---------------------------------------------------------------
159
160    virtual WebFrame* focusedFrame() = 0;
161    virtual void setFocusedFrame(WebFrame*) = 0;
162
163    // Focus the first (last if reverse is true) focusable node.
164    virtual void setInitialFocus(bool reverse) = 0;
165
166    // Clears the focused node (and selection if a text field is focused)
167    // to ensure that a text field on the page is not eating keystrokes we
168    // send it.
169    virtual void clearFocusedNode() = 0;
170
171    // Scrolls the node currently in focus into view.
172    virtual void scrollFocusedNodeIntoView() = 0;
173
174
175    // Zoom ----------------------------------------------------------------
176
177    // Returns the current zoom level.  0 is "original size", and each increment
178    // above or below represents zooming 20% larger or smaller to default limits
179    // of 300% and 50% of original size, respectively.  Only plugins use
180    // non whole-numbers, since they might choose to have specific zoom level so
181    // that fixed-width content is fit-to-page-width, for example.
182    virtual double zoomLevel() = 0;
183
184    // Changes the zoom level to the specified level, clamping at the limits
185    // noted above, and returns the current zoom level after applying the
186    // change.
187    //
188    // If |textOnly| is set, only the text will be zoomed; otherwise the entire
189    // page will be zoomed. You can only have either text zoom or full page zoom
190    // at one time.  Changing the mode while the page is zoomed will have odd
191    // effects.
192    virtual double setZoomLevel(bool textOnly, double zoomLevel) = 0;
193
194    // Updates the zoom limits for this view.
195    virtual void zoomLimitsChanged(double minimumZoomLevel,
196                                   double maximumZoomLevel) = 0;
197
198    // Helper functions to convert between zoom level and zoom factor.  zoom
199    // factor is zoom percent / 100, so 300% = 3.0.
200    WEBKIT_API static double zoomLevelToZoomFactor(double zoomLevel);
201    WEBKIT_API static double zoomFactorToZoomLevel(double factor);
202
203
204    // Media ---------------------------------------------------------------
205
206    // Performs the specified action on the node at the given location.
207    virtual void performMediaPlayerAction(
208        const WebMediaPlayerAction&, const WebPoint& location) = 0;
209
210
211    // Data exchange -------------------------------------------------------
212
213    // Copy to the clipboard the image located at a particular point in the
214    // WebView (if there is such an image)
215    virtual void copyImageAt(const WebPoint&) = 0;
216
217    // Notifies the WebView that a drag has terminated.
218    virtual void dragSourceEndedAt(
219        const WebPoint& clientPoint, const WebPoint& screenPoint,
220        WebDragOperation operation) = 0;
221
222    // Notifies the WebView that a drag is going on.
223    virtual void dragSourceMovedTo(
224        const WebPoint& clientPoint, const WebPoint& screenPoint,
225        WebDragOperation operation) = 0;
226
227    // Notfies the WebView that the system drag and drop operation has ended.
228    virtual void dragSourceSystemDragEnded() = 0;
229
230    // Callback methods when a drag-and-drop operation is trying to drop
231    // something on the WebView.
232    virtual WebDragOperation dragTargetDragEnter(
233        const WebDragData&,
234        const WebPoint& clientPoint, const WebPoint& screenPoint,
235        WebDragOperationsMask operationsAllowed) = 0;
236    virtual WebDragOperation dragTargetDragOver(
237        const WebPoint& clientPoint, const WebPoint& screenPoint,
238        WebDragOperationsMask operationsAllowed) = 0;
239    virtual void dragTargetDragLeave() = 0;
240    virtual void dragTargetDrop(
241        const WebPoint& clientPoint, const WebPoint& screenPoint) = 0;
242
243
244    // Support for resource loading initiated by plugins -------------------
245
246    // Returns next unused request identifier which is unique within the
247    // parent Page.
248    virtual unsigned long createUniqueIdentifierForRequest() = 0;
249
250
251    // Developer tools -----------------------------------------------------
252
253    // Inspect a particular point in the WebView.  (x = -1 || y = -1) is a
254    // special case, meaning inspect the current page and not a specific
255    // point.
256    virtual void inspectElementAt(const WebPoint&) = 0;
257
258    // Settings used by the inspector.
259    virtual WebString inspectorSettings() const = 0;
260    virtual void setInspectorSettings(const WebString&) = 0;
261    virtual bool inspectorSetting(const WebString& key,
262                                  WebString* value) const = 0;
263    virtual void setInspectorSetting(const WebString& key,
264                                     const WebString& value) = 0;
265
266    // The embedder may optionally engage a WebDevToolsAgent.  This may only
267    // be set once per WebView.
268    virtual WebDevToolsAgent* devToolsAgent() = 0;
269
270
271    // Accessibility -------------------------------------------------------
272
273    // Returns the accessibility object for this view.
274    virtual WebAccessibilityObject accessibilityObject() = 0;
275
276
277    // AutoFill  -----------------------------------------------------------
278
279    // Notifies the WebView that AutoFill suggestions are available for a node.
280    // |uniqueIDs| is a vector of IDs that represent the unique ID of each
281    // AutoFill profile in the suggestions popup.  If a unique ID is 0, then the
282    // corresponding suggestion comes from Autocomplete rather than AutoFill.
283    // If a unique ID is negative, then the corresponding "suggestion" is
284    // actually a user-facing warning, e.g. explaining why AutoFill is
285    // unavailable for the current form.
286    virtual void applyAutoFillSuggestions(
287        const WebNode&,
288        const WebVector<WebString>& names,
289        const WebVector<WebString>& labels,
290        const WebVector<WebString>& icons,
291        const WebVector<int>& uniqueIDs,
292        int separatorIndex) = 0;
293
294    // Hides any popup (suggestions, selects...) that might be showing.
295    virtual void hidePopups() = 0;
296
297
298    // Context menu --------------------------------------------------------
299
300    virtual void performCustomContextMenuAction(unsigned action) = 0;
301
302
303    // Popup menu ----------------------------------------------------------
304
305    // Sets whether select popup menus should be rendered by the browser.
306    WEBKIT_API static void setUseExternalPopupMenus(bool);
307
308
309    // Visited link state --------------------------------------------------
310
311    // Tells all WebView instances to update the visited link state for the
312    // specified hash.
313    WEBKIT_API static void updateVisitedLinkState(unsigned long long hash);
314
315    // Tells all WebView instances to update the visited state for all
316    // their links.
317    WEBKIT_API static void resetVisitedLinkState();
318
319
320    // Custom colors -------------------------------------------------------
321
322    virtual void setScrollbarColors(unsigned inactiveColor,
323                                    unsigned activeColor,
324                                    unsigned trackColor) = 0;
325
326    virtual void setSelectionColors(unsigned activeBackgroundColor,
327                                    unsigned activeForegroundColor,
328                                    unsigned inactiveBackgroundColor,
329                                    unsigned inactiveForegroundColor) = 0;
330
331    // User scripts --------------------------------------------------------
332    WEBKIT_API static void addUserScript(const WebString& sourceCode,
333                                         const WebVector<WebString>& patterns,
334                                         UserScriptInjectAt injectAt,
335                                         UserContentInjectIn injectIn);
336    WEBKIT_API static void addUserStyleSheet(const WebString& sourceCode,
337                                             const WebVector<WebString>& patterns,
338                                             UserContentInjectIn injectIn,
339                                             UserStyleInjectionTime injectionTime = UserStyleInjectInSubsequentDocuments);
340    WEBKIT_API static void removeAllUserContent();
341
342    // Modal dialog support ------------------------------------------------
343
344    // Call these methods before and after running a nested, modal event loop
345    // to suspend script callbacks and resource loads.
346    WEBKIT_API static void willEnterModalLoop();
347    WEBKIT_API static void didExitModalLoop();
348
349    // GPU acceleration support --------------------------------------------
350
351    // Returns the (on-screen) WebGraphicsContext3D associated with
352    // this WebView. One will be created if it doesn't already exist.
353    // This is used to set up sharing between this context (which is
354    // that used by the compositor) and contexts for WebGL and other
355    // APIs.
356    virtual WebGraphicsContext3D* graphicsContext3D() = 0;
357
358protected:
359    ~WebView() {}
360};
361
362} // namespace WebKit
363
364#endif
365