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 "WebBeginFrameArgs.h"
39 #include "WebCompositionUnderline.h"
40 #include "WebTextDirection.h"
41 #include "WebTextInputInfo.h"
45 class WebCompositeAndReadbackAsyncCallback;
47 class WebLayerTreeView;
51 struct WebRenderingStats;
52 template <typename T> class WebVector;
56 // This method closes and deletes the WebWidget.
57 virtual void close() { }
59 // Returns the current size of the WebWidget.
60 virtual WebSize size() { return WebSize(); }
62 // Used to group a series of resize events. For example, if the user
63 // drags a resizer then willStartLiveResize will be called, followed by a
64 // sequence of resize events, ending with willEndLiveResize when the user
65 // lets go of the resizer.
66 virtual void willStartLiveResize() { }
68 // Called to resize the WebWidget.
69 virtual void resize(const WebSize&) { }
71 // Resizes the unscaled pinch viewport. Normally the unscaled pinch
72 // viewport is the same size as the main frame. The passed size becomes the
73 // size of the viewport when unscaled (i.e. scale = 1). This is used to
74 // shrink the visible viewport to allow things like the ChromeOS virtual
75 // keyboard to overlay over content but allow scrolling it into view.
76 virtual void resizePinchViewport(const WebSize&) { }
78 // Ends a group of resize events that was started with a call to
79 // willStartLiveResize.
80 virtual void willEndLiveResize() { }
82 // Called to notify the WebWidget of entering/exiting fullscreen mode. The
83 // resize method may be called between will{Enter,Exit}FullScreen and
84 // did{Enter,Exit}FullScreen.
85 virtual void willEnterFullScreen() { }
86 virtual void didEnterFullScreen() { }
87 virtual void willExitFullScreen() { }
88 virtual void didExitFullScreen() { }
90 // Called to update imperative animation state. This should be called before
91 // paint, although the client can rate-limit these calls.
92 // FIXME: Remove this function once Chrome side patch lands.
93 void animate(double monotonicFrameBeginTime)
95 beginFrame(WebBeginFrameArgs(monotonicFrameBeginTime));
97 virtual void beginFrame(const WebBeginFrameArgs& frameTime) { }
99 // Called to layout the WebWidget. This MUST be called before Paint,
100 // and it may result in calls to WebWidgetClient::didInvalidateRect.
101 virtual void layout() { }
103 // Called to paint the rectangular region within the WebWidget
104 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
105 // Layout before calling this method. It is okay to call paint
106 // multiple times once layout has been called, assuming no other
107 // changes are made to the WebWidget (e.g., once events are
108 // processed, it should be assumed that another call to layout is
109 // warranted before painting again).
110 virtual void paint(WebCanvas*, const WebRect& viewPort) { }
112 virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) { }
114 // The caller is responsible for keeping the WebCompositeAndReadbackAsyncCallback
115 // object alive until it is called. This should only be called when
116 // isAcceleratedCompositingActive() is true.
117 virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) { }
119 // Returns true if we've started tracking repaint rectangles.
120 virtual bool isTrackingRepaints() const { return false; }
122 // Indicates that the compositing surface associated with this WebWidget is
124 virtual void setCompositorSurfaceReady() { }
126 // Called to inform the WebWidget of a change in theme.
127 // Implementors that cache rendered copies of widgets need to re-render
128 // on receiving this message
129 virtual void themeChanged() { }
131 // Called to inform the WebWidget of an input event. Returns true if
132 // the event has been processed, false otherwise.
133 virtual bool handleInputEvent(const WebInputEvent&) { return false; }
135 // Called to inform the WebWidget of the mouse cursor's visibility.
136 virtual void setCursorVisibilityState(bool isVisible) { }
138 // Check whether the given point hits any registered touch event handlers.
139 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
141 // Applies a scroll delta to the root layer, which is bundled with a page
142 // scale factor that may apply a CSS transform on the whole document (used
143 // for mobile-device pinch zooming). This is triggered by events sent to the
144 // compositor thread.
145 virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { }
147 // Called to inform the WebWidget that mouse capture was lost.
148 virtual void mouseCaptureLost() { }
150 // Called to inform the WebWidget that it has gained or lost keyboard focus.
151 virtual void setFocus(bool) { }
153 // Called to inform the WebWidget of a new composition text.
154 // If selectionStart and selectionEnd has the same value, then it indicates
155 // the input caret position. If the text is empty, then the existing
156 // composition text will be cancelled.
157 // Returns true if the composition text was set successfully.
158 virtual bool setComposition(
159 const WebString& text,
160 const WebVector<WebCompositionUnderline>& underlines,
162 int selectionEnd) { return false; }
164 enum ConfirmCompositionBehavior {
169 // Called to inform the WebWidget to confirm an ongoing composition.
170 // This method is same as confirmComposition(WebString());
171 // Returns true if there is an ongoing composition.
172 virtual bool confirmComposition() { return false; } // Deprecated
173 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; }
175 // Called to inform the WebWidget to confirm an ongoing composition with a
176 // new composition text. If the text is empty then the current composition
177 // text is confirmed. If there is no ongoing composition, then deletes the
178 // current selection and inserts the text. This method has no effect if
179 // there is no ongoing composition and the text is empty.
180 // Returns true if there is an ongoing composition or the text is inserted.
181 virtual bool confirmComposition(const WebString& text) { return false; }
183 // Fetches the character range of the current composition, also called the
184 // "marked range." Returns true and fills the out-paramters on success;
185 // returns false on failure.
186 virtual bool compositionRange(size_t* location, size_t* length) { return false; }
188 // Returns information about the current text input of this WebWidget.
189 virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
191 // Returns the anchor and focus bounds of the current selection.
192 // If the selection range is empty, it returns the caret bounds.
193 virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; }
195 // Called to notify that IME candidate window has changed its visibility or
196 // its appearance. These calls correspond to trigger
197 // candidatewindow{show,update,hide} events defined in W3C IME API.
198 virtual void didShowCandidateWindow() { }
199 virtual void didUpdateCandidateWindow() { }
200 virtual void didHideCandidateWindow() { }
202 // Returns the text direction at the start and end bounds of the current selection.
203 // If the selection range is empty, it returns false.
204 virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
206 // Returns true if the selection range is nonempty and its anchor is first
207 // (i.e its anchor is its start).
208 virtual bool isSelectionAnchorFirst() const { return false; }
210 // Fetch the current selection range of this WebWidget. If there is no
211 // selection, it will output a 0-length range with the location at the
212 // caret. Returns true and fills the out-paramters on success; returns false
214 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
216 // Changes the text direction of the selected input node.
217 virtual void setTextDirection(WebTextDirection) { }
219 // Returns true if the WebWidget uses GPU accelerated compositing
220 // to render its contents.
221 virtual bool isAcceleratedCompositingActive() const { return false; }
223 // Returns true if the WebWidget created is of type WebPagePopup.
224 virtual bool isPagePopup() const { return false; }
225 // Returns true if the WebWidget created is of type WebPopupMenu.
226 virtual bool isPopupMenu() const { return false; }
228 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
229 // is no longer safe to access.
230 virtual void willCloseLayerTreeView() { }
232 // Calling WebWidgetClient::requestPointerLock() will result in one
233 // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
234 virtual void didAcquirePointerLock() { }
235 virtual void didNotAcquirePointerLock() { }
237 // Pointer lock was held, but has been lost. This may be due to a
238 // request via WebWidgetClient::requestPointerUnlock(), or for other
239 // reasons such as the user exiting lock, window focus changing, etc.
240 virtual void didLosePointerLock() { }
242 // Informs the WebWidget that the resizer rect changed. Happens for example
243 // on mac, when a widget appears below the WebWidget without changing the
244 // WebWidget's size (WebWidget::resize() automatically checks the resizer
246 virtual void didChangeWindowResizerRect() { }
248 // The page background color. Can be used for filling in areas without
250 virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }