2 * Copyright (C) 2009 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 "../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"
44 class WebCompositeAndReadbackAsyncCallback;
46 class WebLayerTreeView;
50 struct WebRenderingStats;
51 template <typename T> class WebVector;
55 // This method closes and deletes the WebWidget.
56 virtual void close() { }
58 // Returns the current size of the WebWidget.
59 virtual WebSize size() { return WebSize(); }
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() { }
67 // Called to resize the WebWidget.
68 virtual void resize(const WebSize&) { }
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&) { }
77 // Ends a group of resize events that was started with a call to
78 // willStartLiveResize.
79 virtual void willEndLiveResize() { }
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() { }
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) { }
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() { }
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) { }
102 // Attempt to fulfill the painting request by reading back from the
103 // compositor, assuming we're using a compositor to render.
104 ReadbackFromCompositorIfAvailable,
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.
110 // Note: This option exists on OS(ANDROID) and will hopefully be
111 // removed once the link disambiguation feature renders using
113 ForceSoftwareRenderingAndIgnoreGPUResidentContent,
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) { }
125 virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) { }
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*) { }
132 // Returns true if we've started tracking repaint rectangles.
133 virtual bool isTrackingRepaints() const { return false; }
135 // Indicates that the compositing surface associated with this WebWidget is
137 virtual void setCompositorSurfaceReady() { }
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() { }
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; }
148 // Called to inform the WebWidget of the mouse cursor's visibility.
149 virtual void setCursorVisibilityState(bool isVisible) { }
151 // Check whether the given point hits any registered touch event handlers.
152 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
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) { }
160 // Called to inform the WebWidget that mouse capture was lost.
161 virtual void mouseCaptureLost() { }
163 // Called to inform the WebWidget that it has gained or lost keyboard focus.
164 virtual void setFocus(bool) { }
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,
175 int selectionEnd) { return false; }
177 enum ConfirmCompositionBehavior {
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; }
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; }
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; }
201 // Returns information about the current text input of this WebWidget.
202 virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
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; }
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() { }
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; }
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; }
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
227 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
229 // Changes the text direction of the selected input node.
230 virtual void setTextDirection(WebTextDirection) { }
232 // Returns true if the WebWidget uses GPU accelerated compositing
233 // to render its contents.
234 virtual bool isAcceleratedCompositingActive() const { return false; }
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; }
241 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
242 // is no longer safe to access.
243 virtual void willCloseLayerTreeView() { }
245 // Calling WebWidgetClient::requestPointerLock() will result in one
246 // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
247 virtual void didAcquirePointerLock() { }
248 virtual void didNotAcquirePointerLock() { }
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() { }
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
259 virtual void didChangeWindowResizerRect() { }
261 // The page background color. Can be used for filling in areas without
263 virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }