Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / public / web / WebWidget.h
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 WebWidget_h
32 #define WebWidget_h
33
34 #include "../platform/WebCanvas.h"
35 #include "../platform/WebCommon.h"
36 #include "../platform/WebRect.h"
37 #include "../platform/WebSize.h"
38 #include "WebCompositionUnderline.h"
39 #include "WebTextDirection.h"
40 #include "WebTextInputInfo.h"
41
42 namespace blink {
43
44 class WebCompositeAndReadbackAsyncCallback;
45 class WebInputEvent;
46 class WebLayerTreeView;
47 class WebMouseEvent;
48 class WebString;
49 struct WebPoint;
50 struct WebRenderingStats;
51 template <typename T> class WebVector;
52
53 class WebWidget {
54 public:
55     // This method closes and deletes the WebWidget.
56     virtual void close() { }
57
58     // Returns the current size of the WebWidget.
59     virtual WebSize size() { return WebSize(); }
60
61     // Used to group a series of resize events. For example, if the user
62     // drags a resizer then willStartLiveResize will be called, followed by a
63     // sequence of resize events, ending with willEndLiveResize when the user
64     // lets go of the resizer.
65     virtual void willStartLiveResize() { }
66
67     // Called to resize the WebWidget.
68     virtual void resize(const WebSize&) { }
69
70     // Resizes the unscaled pinch viewport. Normally the unscaled pinch
71     // viewport is the same size as the main frame. The passed size becomes the
72     // size of the viewport when unscaled (i.e. scale = 1). This is used to
73     // shrink the visible viewport to allow things like the ChromeOS virtual
74     // keyboard to overlay over content but allow scrolling it into view.
75     virtual void resizePinchViewport(const WebSize&) { }
76
77     // Ends a group of resize events that was started with a call to
78     // willStartLiveResize.
79     virtual void willEndLiveResize() { }
80
81     // Called to notify the WebWidget of entering/exiting fullscreen mode. The
82     // resize method may be called between will{Enter,Exit}FullScreen and
83     // did{Enter,Exit}FullScreen.
84     virtual void willEnterFullScreen() { }
85     virtual void didEnterFullScreen() { }
86     virtual void willExitFullScreen() { }
87     virtual void didExitFullScreen() { }
88
89     // Called to update imperative animation state. This should be called before
90     // paint, although the client can rate-limit these calls.
91     virtual void animate(double monotonicFrameBeginTime) { }
92
93     // Called to layout the WebWidget. This MUST be called before Paint,
94     // and it may result in calls to WebWidgetClient::didInvalidateRect.
95     virtual void layout() { }
96
97     // Called to toggle the WebWidget in or out of force compositing mode. This
98     // should be called before paint.
99     virtual void enterForceCompositingMode(bool enter) { }
100
101     enum PaintOptions {
102         // Attempt to fulfill the painting request by reading back from the
103         // compositor, assuming we're using a compositor to render.
104         ReadbackFromCompositorIfAvailable,
105
106         // Force the widget to rerender onto the canvas using software. This
107         // mode ignores 3d transforms and ignores GPU-resident content, such
108         // as video, canvas, and WebGL.
109         //
110         // Note: This option exists on OS(ANDROID) and will hopefully be
111         //       removed once the link disambiguation feature renders using
112         //       the compositor.
113         ForceSoftwareRenderingAndIgnoreGPUResidentContent,
114     };
115
116     // Called to paint the rectangular region within the WebWidget
117     // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
118     // Layout before calling this method. It is okay to call paint
119     // multiple times once layout has been called, assuming no other
120     // changes are made to the WebWidget (e.g., once events are
121     // processed, it should be assumed that another call to layout is
122     // warranted before painting again).
123     virtual void paint(WebCanvas*, const WebRect& viewPort, PaintOptions = ReadbackFromCompositorIfAvailable) { }
124
125     virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) { }
126
127     // The caller is responsible for keeping the WebCompositeAndReadbackAsyncCallback
128     // object alive until it is called. This should only be called when
129     // isAcceleratedCompositingActive() is true.
130     virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) { }
131
132     // Returns true if we've started tracking repaint rectangles.
133     virtual bool isTrackingRepaints() const { return false; }
134
135     // Indicates that the compositing surface associated with this WebWidget is
136     // ready to use.
137     virtual void setCompositorSurfaceReady() { }
138
139     // Called to inform the WebWidget of a change in theme.
140     // Implementors that cache rendered copies of widgets need to re-render
141     // on receiving this message
142     virtual void themeChanged() { }
143
144     // Called to inform the WebWidget of an input event. Returns true if
145     // the event has been processed, false otherwise.
146     virtual bool handleInputEvent(const WebInputEvent&) { return false; }
147
148     // Called to inform the WebWidget of the mouse cursor's visibility.
149     virtual void setCursorVisibilityState(bool isVisible) { }
150
151     // Check whether the given point hits any registered touch event handlers.
152     virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
153
154     // Applies a scroll delta to the root layer, which is bundled with a page
155     // scale factor that may apply a CSS transform on the whole document (used
156     // for mobile-device pinch zooming). This is triggered by events sent to the
157     // compositor thread.
158     virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { }
159
160     // Called to inform the WebWidget that mouse capture was lost.
161     virtual void mouseCaptureLost() { }
162
163     // Called to inform the WebWidget that it has gained or lost keyboard focus.
164     virtual void setFocus(bool) { }
165
166     // Called to inform the WebWidget of a new composition text.
167     // If selectionStart and selectionEnd has the same value, then it indicates
168     // the input caret position. If the text is empty, then the existing
169     // composition text will be cancelled.
170     // Returns true if the composition text was set successfully.
171     virtual bool setComposition(
172         const WebString& text,
173         const WebVector<WebCompositionUnderline>& underlines,
174         int selectionStart,
175         int selectionEnd) { return false; }
176
177     enum ConfirmCompositionBehavior {
178         DoNotKeepSelection,
179         KeepSelection,
180     };
181
182     // Called to inform the WebWidget to confirm an ongoing composition.
183     // This method is same as confirmComposition(WebString());
184     // Returns true if there is an ongoing composition.
185     virtual bool confirmComposition() { return false; } // Deprecated
186     virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; }
187
188     // Called to inform the WebWidget to confirm an ongoing composition with a
189     // new composition text. If the text is empty then the current composition
190     // text is confirmed. If there is no ongoing composition, then deletes the
191     // current selection and inserts the text. This method has no effect if
192     // there is no ongoing composition and the text is empty.
193     // Returns true if there is an ongoing composition or the text is inserted.
194     virtual bool confirmComposition(const WebString& text) { return false; }
195
196     // Fetches the character range of the current composition, also called the
197     // "marked range." Returns true and fills the out-paramters on success;
198     // returns false on failure.
199     virtual bool compositionRange(size_t* location, size_t* length) { return false; }
200
201     // Returns information about the current text input of this WebWidget.
202     virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
203
204     // Returns the anchor and focus bounds of the current selection.
205     // If the selection range is empty, it returns the caret bounds.
206     virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; }
207
208     // Called to notify that IME candidate window has changed its visibility or
209     // its appearance. These calls correspond to trigger
210     // candidatewindow{show,update,hide} events defined in W3C IME API.
211     virtual void didShowCandidateWindow() { }
212     virtual void didUpdateCandidateWindow() { }
213     virtual void didHideCandidateWindow() { }
214
215     // Returns the text direction at the start and end bounds of the current selection.
216     // If the selection range is empty, it returns false.
217     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
218
219     // Returns true if the selection range is nonempty and its anchor is first
220     // (i.e its anchor is its start).
221     virtual bool isSelectionAnchorFirst() const { return false; }
222
223     // Fetch the current selection range of this WebWidget. If there is no
224     // selection, it will output a 0-length range with the location at the
225     // caret. Returns true and fills the out-paramters on success; returns false
226     // on failure.
227     virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
228
229     // Changes the text direction of the selected input node.
230     virtual void setTextDirection(WebTextDirection) { }
231
232     // Returns true if the WebWidget uses GPU accelerated compositing
233     // to render its contents.
234     virtual bool isAcceleratedCompositingActive() const { return false; }
235
236     // Returns true if the WebWidget created is of type WebPagePopup.
237     virtual bool isPagePopup() const { return false; }
238     // Returns true if the WebWidget created is of type WebPopupMenu.
239     virtual bool isPopupMenu() const { return false; }
240
241     // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
242     // is no longer safe to access.
243     virtual void willCloseLayerTreeView() { }
244
245     // Calling WebWidgetClient::requestPointerLock() will result in one
246     // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
247     virtual void didAcquirePointerLock() { }
248     virtual void didNotAcquirePointerLock() { }
249
250     // Pointer lock was held, but has been lost. This may be due to a
251     // request via WebWidgetClient::requestPointerUnlock(), or for other
252     // reasons such as the user exiting lock, window focus changing, etc.
253     virtual void didLosePointerLock() { }
254
255     // Informs the WebWidget that the resizer rect changed. Happens for example
256     // on mac, when a widget appears below the WebWidget without changing the
257     // WebWidget's size (WebWidget::resize() automatically checks the resizer
258     // rect.)
259     virtual void didChangeWindowResizerRect() { }
260
261     // The page background color. Can be used for filling in areas without
262     // content.
263     virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }
264
265 protected:
266     ~WebWidget() { }
267 };
268
269 } // namespace blink
270
271 #endif