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"
45 class WebLayerTreeView;
49 struct WebRenderingStats;
50 template <typename T> class WebVector;
54 // This method closes and deletes the WebWidget.
55 virtual void close() { }
57 // Returns the current size of the WebWidget.
58 virtual WebSize size() { return WebSize(); }
60 // Used to group a series of resize events. For example, if the user
61 // drags a resizer then willStartLiveResize will be called, followed by a
62 // sequence of resize events, ending with willEndLiveResize when the user
63 // lets go of the resizer.
64 virtual void willStartLiveResize() { }
66 // Called to resize the WebWidget.
67 virtual void resize(const WebSize&) { }
69 // Ends a group of resize events that was started with a call to
70 // willStartLiveResize.
71 virtual void willEndLiveResize() { }
73 // Called to notify the WebWidget of entering/exiting fullscreen mode. The
74 // resize method may be called between will{Enter,Exit}FullScreen and
75 // did{Enter,Exit}FullScreen.
76 virtual void willEnterFullScreen() { }
77 virtual void didEnterFullScreen() { }
78 virtual void willExitFullScreen() { }
79 virtual void didExitFullScreen() { }
81 // Called to update imperative animation state. This should be called before
82 // paint, although the client can rate-limit these calls.
83 virtual void animate(double monotonicFrameBeginTime) { }
85 // Called to layout the WebWidget. This MUST be called before Paint,
86 // and it may result in calls to WebWidgetClient::didInvalidateRect.
87 virtual void layout() { }
89 // Called to toggle the WebWidget in or out of force compositing mode. This
90 // should be called before paint.
91 virtual void enterForceCompositingMode(bool enter) { }
93 // Called to notify the WebWidget that the widget has exited compositing
94 // mode and cannot reenter.
95 virtual void didExitCompositingMode() { }
98 // Attempt to fulfill the painting request by reading back from the
99 // compositor, assuming we're using a compositor to render.
100 ReadbackFromCompositorIfAvailable,
102 // Force the widget to rerender onto the canvas using software. This
103 // mode ignores 3d transforms and ignores GPU-resident content, such
104 // as video, canvas, and WebGL.
106 // Note: This option exists on OS(ANDROID) and will hopefully be
107 // removed once the link disambiguation feature renders using
109 ForceSoftwareRenderingAndIgnoreGPUResidentContent,
112 // Called to paint the rectangular region within the WebWidget
113 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
114 // Layout before calling this method. It is okay to call paint
115 // multiple times once layout has been called, assuming no other
116 // changes are made to the WebWidget (e.g., once events are
117 // processed, it should be assumed that another call to layout is
118 // warranted before painting again).
119 virtual void paint(WebCanvas*, const WebRect& viewPort, PaintOptions = ReadbackFromCompositorIfAvailable) { }
121 // Returns true if we've started tracking repaint rectangles.
122 virtual bool isTrackingRepaints() const { return false; }
124 // Indicates that the compositing surface associated with this WebWidget is
126 virtual void setCompositorSurfaceReady() { }
128 // Called to inform the WebWidget of a change in theme.
129 // Implementors that cache rendered copies of widgets need to re-render
130 // on receiving this message
131 virtual void themeChanged() { }
133 // Called to inform the WebWidget of an input event. Returns true if
134 // the event has been processed, false otherwise.
135 virtual bool handleInputEvent(const WebInputEvent&) { return false; }
137 // Called to inform the WebWidget of the mouse cursor's visibility.
138 virtual void setCursorVisibilityState(bool isVisible) { }
140 // Check whether the given point hits any registered touch event handlers.
141 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
143 // Applies a scroll delta to the root layer, which is bundled with a page
144 // scale factor that may apply a CSS transform on the whole document (used
145 // for mobile-device pinch zooming). This is triggered by events sent to the
146 // compositor thread.
147 virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { }
149 // Called to inform the WebWidget that mouse capture was lost.
150 virtual void mouseCaptureLost() { }
152 // Called to inform the WebWidget that it has gained or lost keyboard focus.
153 virtual void setFocus(bool) { }
155 // Called to inform the WebWidget of a new composition text.
156 // If selectionStart and selectionEnd has the same value, then it indicates
157 // the input caret position. If the text is empty, then the existing
158 // composition text will be cancelled.
159 // Returns true if the composition text was set successfully.
160 virtual bool setComposition(
161 const WebString& text,
162 const WebVector<WebCompositionUnderline>& underlines,
164 int selectionEnd) { return false; }
166 enum ConfirmCompositionBehavior {
171 // Called to inform the WebWidget to confirm an ongoing composition.
172 // This method is same as confirmComposition(WebString());
173 // Returns true if there is an ongoing composition.
174 virtual bool confirmComposition() { return false; } // Deprecated
175 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; }
177 // Called to inform the WebWidget to confirm an ongoing composition with a
178 // new composition text. If the text is empty then the current composition
179 // text is confirmed. If there is no ongoing composition, then deletes the
180 // current selection and inserts the text. This method has no effect if
181 // there is no ongoing composition and the text is empty.
182 // Returns true if there is an ongoing composition or the text is inserted.
183 virtual bool confirmComposition(const WebString& text) { return false; }
185 // Fetches the character range of the current composition, also called the
186 // "marked range." Returns true and fills the out-paramters on success;
187 // returns false on failure.
188 virtual bool compositionRange(size_t* location, size_t* length) { return false; }
190 // Returns information about the current text input of this WebWidget.
191 virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
193 // Returns the anchor and focus bounds of the current selection.
194 // If the selection range is empty, it returns the caret bounds.
195 virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; }
197 // Called to notify that IME candidate window has changed its visibility or
198 // its appearance. These calls correspond to trigger
199 // candidatewindow{show,update,hide} events defined in W3C IME API.
200 virtual void didShowCandidateWindow() { }
201 virtual void didUpdateCandidateWindow() { }
202 virtual void didHideCandidateWindow() { }
204 // Returns the text direction at the start and end bounds of the current selection.
205 // If the selection range is empty, it returns false.
206 virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
208 // Returns true if the selection range is nonempty and its anchor is first
209 // (i.e its anchor is its start).
210 virtual bool isSelectionAnchorFirst() const { return false; }
212 // Fetch the current selection range of this WebWidget. If there is no
213 // selection, it will output a 0-length range with the location at the
214 // caret. Returns true and fills the out-paramters on success; returns false
216 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
218 // Changes the text direction of the selected input node.
219 virtual void setTextDirection(WebTextDirection) { }
221 // Returns true if the WebWidget uses GPU accelerated compositing
222 // to render its contents.
223 virtual bool isAcceleratedCompositingActive() const { return false; }
225 // Returns true if the WebWidget created is of type WebPagePopup.
226 virtual bool isPagePopup() const { return false; }
227 // Returns true if the WebWidget created is of type WebPopupMenu.
228 virtual bool isPopupMenu() const { return false; }
229 // Returns true if the WebWidget created is of type WebHelperPlugin.
230 virtual bool isHelperPlugin() const { return false; }
232 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
233 // is no longer safe to access.
234 virtual void willCloseLayerTreeView() { }
236 // Calling WebWidgetClient::requestPointerLock() will result in one
237 // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
238 virtual void didAcquirePointerLock() { }
239 virtual void didNotAcquirePointerLock() { }
241 // Pointer lock was held, but has been lost. This may be due to a
242 // request via WebWidgetClient::requestPointerUnlock(), or for other
243 // reasons such as the user exiting lock, window focus changing, etc.
244 virtual void didLosePointerLock() { }
246 // Informs the WebWidget that the resizer rect changed. Happens for example
247 // on mac, when a widget appears below the WebWidget without changing the
248 // WebWidget's size (WebWidget::resize() automatically checks the resizer
250 virtual void didChangeWindowResizerRect() { }
252 // The page background color. Can be used for filling in areas without
254 virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }