3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "../platform/WebCanvas.h"
36 #include "../platform/WebCommon.h"
37 #include "../platform/WebFloatSize.h"
38 #include "../platform/WebFrameTimingEvent.h"
39 #include "../platform/WebPoint.h"
40 #include "../platform/WebRect.h"
41 #include "../platform/WebSize.h"
42 #include "../platform/WebTopControlsState.h"
43 #include "WebBeginFrameArgs.h"
44 #include "WebCompositionUnderline.h"
45 #include "WebTextDirection.h"
46 #include "WebTextInputInfo.h"
50 class WebCompositeAndReadbackAsyncCallback
;
52 class WebLayoutAndPaintAsyncCallback
;
56 template <typename T
> class WebVector
;
60 // This method closes and deletes the WebWidget.
61 virtual void close() { }
63 // Returns the current size of the WebWidget.
64 virtual WebSize
size() { return WebSize(); }
66 // Used to group a series of resize events. For example, if the user
67 // drags a resizer then willStartLiveResize will be called, followed by a
68 // sequence of resize events, ending with willEndLiveResize when the user
69 // lets go of the resizer.
70 virtual void willStartLiveResize() { }
72 // Called to resize the WebWidget.
73 virtual void resize(const WebSize
&) { }
75 // Resizes the unscaled visual viewport. Normally the unscaled visual
76 // viewport is the same size as the main frame. The passed size becomes the
77 // size of the viewport when unscaled (i.e. scale = 1). This is used to
78 // shrink the visible viewport to allow things like the ChromeOS virtual
79 // keyboard to overlay over content but allow scrolling it into view.
80 virtual void resizeVisualViewport(const WebSize
&) { }
82 // TODO(bokan): Renamed to visual viewport above. Remove once chromium-side
83 // callers are renamed.
84 virtual void resizePinchViewport(const WebSize
&) { }
86 // Ends a group of resize events that was started with a call to
87 // willStartLiveResize.
88 virtual void willEndLiveResize() { }
90 // Called to notify the WebWidget of entering/exiting fullscreen mode.
91 virtual void didEnterFullScreen() { }
92 virtual void didExitFullScreen() { }
94 // Called to update imperative animation state. This should be called before
95 // paint, although the client can rate-limit these calls.
96 virtual void beginFrame(const WebBeginFrameArgs
& frameTime
) { }
98 // Called to layout the WebWidget. This MUST be called before Paint,
99 // and it may result in calls to WebWidgetClient::didInvalidateRect.
100 virtual void layout() { }
102 // Called to paint the rectangular region within the WebWidget
103 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
104 // Layout before calling this method. It is okay to call paint
105 // multiple times once layout has been called, assuming no other
106 // changes are made to the WebWidget (e.g., once events are
107 // processed, it should be assumed that another call to layout is
108 // warranted before painting again).
109 virtual void paint(WebCanvas
*, const WebRect
& viewPort
) { }
111 virtual void paintCompositedDeprecated(WebCanvas
*, const WebRect
&) { }
113 // Run layout and paint of all pending document changes asynchronously.
114 // The caller is resposible for keeping the WebLayoutAndPaintAsyncCallback
115 // object alive until it is called.
116 virtual void layoutAndPaintAsync(WebLayoutAndPaintAsyncCallback
*) { }
118 // The caller is responsible for keeping the WebCompositeAndReadbackAsyncCallback
119 // object alive until it is called. This should only be called when
120 // isAcceleratedCompositingActive() is true.
121 virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback
*) { }
123 // Called to inform the WebWidget of a change in theme.
124 // Implementors that cache rendered copies of widgets need to re-render
125 // on receiving this message
126 virtual void themeChanged() { }
128 // Called to inform the WebWidget of an input event. Returns true if
129 // the event has been processed, false otherwise.
130 virtual bool handleInputEvent(const WebInputEvent
&) { return false; }
132 // Called to inform the WebWidget of the mouse cursor's visibility.
133 virtual void setCursorVisibilityState(bool isVisible
) { }
135 // Check whether the given point hits any registered touch event handlers.
136 virtual bool hasTouchEventHandlersAt(const WebPoint
&) { return true; }
138 // Applies viewport related properties during a commit from the compositor
140 virtual void applyViewportDeltas(
141 const WebFloatSize
& visualViewportDelta
,
142 const WebFloatSize
& layoutViewportDelta
,
143 const WebFloatSize
& elasticOverscrollDelta
,
145 float topControlsShownRatioDelta
) { }
147 // Records composite or render events for the Performance Timeline.
148 // See http://w3c.github.io/frame-timing/ for definition of terms.
149 enum FrameTimingEventType
{
153 virtual void recordFrameTimingEvent(FrameTimingEventType eventType
, int64_t RectId
, const WebVector
<WebFrameTimingEvent
>& events
) { }
155 // Called to inform the WebWidget that mouse capture was lost.
156 virtual void mouseCaptureLost() { }
158 // Called to inform the WebWidget that it has gained or lost keyboard focus.
159 virtual void setFocus(bool) { }
161 // Called to inform the WebWidget of a new composition text.
162 // If selectionStart and selectionEnd has the same value, then it indicates
163 // the input caret position. If the text is empty, then the existing
164 // composition text will be cancelled.
165 // Returns true if the composition text was set successfully.
166 virtual bool setComposition(
167 const WebString
& text
,
168 const WebVector
<WebCompositionUnderline
>& underlines
,
170 int selectionEnd
) { return false; }
172 enum ConfirmCompositionBehavior
{
177 // Called to inform the WebWidget to confirm an ongoing composition.
178 // This method is same as confirmComposition(WebString());
179 // Returns true if there is an ongoing composition.
180 virtual bool confirmComposition() { return false; } // Deprecated
181 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior
) { return false; }
183 // Called to inform the WebWidget to confirm an ongoing composition with a
184 // new composition text. If the text is empty then the current composition
185 // text is confirmed. If there is no ongoing composition, then deletes the
186 // current selection and inserts the text. This method has no effect if
187 // there is no ongoing composition and the text is empty.
188 // Returns true if there is an ongoing composition or the text is inserted.
189 virtual bool confirmComposition(const WebString
& text
) { return false; }
191 // Fetches the character range of the current composition, also called the
192 // "marked range." Returns true and fills the out-paramters on success;
193 // returns false on failure.
194 virtual bool compositionRange(size_t* location
, size_t* length
) { return false; }
196 // Returns information about the current text input of this WebWidget.
197 virtual WebTextInputInfo
textInputInfo() { return WebTextInputInfo(); }
199 // Returns the anchor and focus bounds of the current selection.
200 // If the selection range is empty, it returns the caret bounds.
201 virtual bool selectionBounds(WebRect
& anchor
, WebRect
& focus
) const { return false; }
203 // Returns the text direction at the start and end bounds of the current selection.
204 // If the selection range is empty, it returns false.
205 virtual bool selectionTextDirection(WebTextDirection
& start
, WebTextDirection
& end
) const { return false; }
207 // Returns true if the selection range is nonempty and its anchor is first
208 // (i.e its anchor is its start).
209 virtual bool isSelectionAnchorFirst() const { return false; }
211 // Fetch the current selection range of this WebWidget. If there is no
212 // selection, it will output a 0-length range with the location at the
213 // caret. Returns true and fills the out-paramters on success; returns false
215 virtual bool caretOrSelectionRange(size_t* location
, size_t* length
) { return false; }
217 // Changes the text direction of the selected input node.
218 virtual void setTextDirection(WebTextDirection
) { }
220 // Returns true if the WebWidget uses GPU accelerated compositing
221 // to render its contents.
222 virtual bool isAcceleratedCompositingActive() const { return false; }
224 // Returns true if the WebWidget created is of type WebView.
225 virtual bool isWebView() const { return false; }
226 // Returns true if the WebWidget created is of type WebPagePopup.
227 virtual bool isPagePopup() const { return false; }
229 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
230 // is no longer safe to access.
231 virtual void willCloseLayerTreeView() { }
233 // Calling WebWidgetClient::requestPointerLock() will result in one
234 // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
235 virtual void didAcquirePointerLock() { }
236 virtual void didNotAcquirePointerLock() { }
238 // Pointer lock was held, but has been lost. This may be due to a
239 // request via WebWidgetClient::requestPointerUnlock(), or for other
240 // reasons such as the user exiting lock, window focus changing, etc.
241 virtual void didLosePointerLock() { }
243 // Informs the WebWidget that the resizer rect changed. Happens for example
244 // on mac, when a widget appears below the WebWidget without changing the
245 // WebWidget's size (WebWidget::resize() automatically checks the resizer
247 virtual void didChangeWindowResizerRect() { }
249 // The page background color. Can be used for filling in areas without
251 virtual WebColor
backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }
253 // The currently open page popup, which are calendar and datalist pickers
254 // but not the select popup.
255 virtual WebPagePopup
* pagePopup() const { return 0; }
257 // Notification about the top controls height. If the boolean is true, then
258 // the embedder shrunk the WebView size by the top controls height.
259 virtual void setTopControlsHeight(float height
, bool topControlsShrinkLayoutSize
) { }
261 // Updates top controls constraints and current state. Allows embedder to
262 // control what are valid states for top controls and if it should animate.
263 virtual void updateTopControlsState(WebTopControlsState constraints
, WebTopControlsState current
, bool animate
) { }