• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
close()56     virtual void close() { }
57 
58     // Returns the current size of the WebWidget.
size()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.
willStartLiveResize()65     virtual void willStartLiveResize() { }
66 
67     // Called to resize the WebWidget.
resize(const WebSize &)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.
resizePinchViewport(const WebSize &)75     virtual void resizePinchViewport(const WebSize&) { }
76 
77     // Ends a group of resize events that was started with a call to
78     // willStartLiveResize.
willEndLiveResize()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.
willEnterFullScreen()84     virtual void willEnterFullScreen() { }
didEnterFullScreen()85     virtual void didEnterFullScreen() { }
willExitFullScreen()86     virtual void willExitFullScreen() { }
didExitFullScreen()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.
animate(double monotonicFrameBeginTime)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.
layout()95     virtual void layout() { }
96 
97     // Called to paint the rectangular region within the WebWidget
98     // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
99     // Layout before calling this method. It is okay to call paint
100     // multiple times once layout has been called, assuming no other
101     // changes are made to the WebWidget (e.g., once events are
102     // processed, it should be assumed that another call to layout is
103     // warranted before painting again).
paint(WebCanvas *,const WebRect & viewPort)104     virtual void paint(WebCanvas*, const WebRect& viewPort) { }
105 
paintCompositedDeprecated(WebCanvas *,const WebRect &)106     virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) { }
107 
108     // The caller is responsible for keeping the WebCompositeAndReadbackAsyncCallback
109     // object alive until it is called. This should only be called when
110     // isAcceleratedCompositingActive() is true.
compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback *)111     virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) { }
112 
113     // Returns true if we've started tracking repaint rectangles.
isTrackingRepaints()114     virtual bool isTrackingRepaints() const { return false; }
115 
116     // Indicates that the compositing surface associated with this WebWidget is
117     // ready to use.
setCompositorSurfaceReady()118     virtual void setCompositorSurfaceReady() { }
119 
120     // Called to inform the WebWidget of a change in theme.
121     // Implementors that cache rendered copies of widgets need to re-render
122     // on receiving this message
themeChanged()123     virtual void themeChanged() { }
124 
125     // Called to inform the WebWidget of an input event. Returns true if
126     // the event has been processed, false otherwise.
handleInputEvent(const WebInputEvent &)127     virtual bool handleInputEvent(const WebInputEvent&) { return false; }
128 
129     // Called to inform the WebWidget of the mouse cursor's visibility.
setCursorVisibilityState(bool isVisible)130     virtual void setCursorVisibilityState(bool isVisible) { }
131 
132     // Check whether the given point hits any registered touch event handlers.
hasTouchEventHandlersAt(const WebPoint &)133     virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
134 
135     // Applies a scroll delta to the root layer, which is bundled with a page
136     // scale factor that may apply a CSS transform on the whole document (used
137     // for mobile-device pinch zooming). This is triggered by events sent to the
138     // compositor thread.
applyScrollAndScale(const WebSize & scrollDelta,float scaleFactor)139     virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { }
140 
141     // Called to inform the WebWidget that mouse capture was lost.
mouseCaptureLost()142     virtual void mouseCaptureLost() { }
143 
144     // Called to inform the WebWidget that it has gained or lost keyboard focus.
setFocus(bool)145     virtual void setFocus(bool) { }
146 
147     // Called to inform the WebWidget of a new composition text.
148     // If selectionStart and selectionEnd has the same value, then it indicates
149     // the input caret position. If the text is empty, then the existing
150     // composition text will be cancelled.
151     // Returns true if the composition text was set successfully.
setComposition(const WebString & text,const WebVector<WebCompositionUnderline> & underlines,int selectionStart,int selectionEnd)152     virtual bool setComposition(
153         const WebString& text,
154         const WebVector<WebCompositionUnderline>& underlines,
155         int selectionStart,
156         int selectionEnd) { return false; }
157 
158     enum ConfirmCompositionBehavior {
159         DoNotKeepSelection,
160         KeepSelection,
161     };
162 
163     // Called to inform the WebWidget to confirm an ongoing composition.
164     // This method is same as confirmComposition(WebString());
165     // Returns true if there is an ongoing composition.
confirmComposition()166     virtual bool confirmComposition() { return false; } // Deprecated
confirmComposition(ConfirmCompositionBehavior selectionBehavior)167     virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; }
168 
169     // Called to inform the WebWidget to confirm an ongoing composition with a
170     // new composition text. If the text is empty then the current composition
171     // text is confirmed. If there is no ongoing composition, then deletes the
172     // current selection and inserts the text. This method has no effect if
173     // there is no ongoing composition and the text is empty.
174     // Returns true if there is an ongoing composition or the text is inserted.
confirmComposition(const WebString & text)175     virtual bool confirmComposition(const WebString& text) { return false; }
176 
177     // Fetches the character range of the current composition, also called the
178     // "marked range." Returns true and fills the out-paramters on success;
179     // returns false on failure.
compositionRange(size_t * location,size_t * length)180     virtual bool compositionRange(size_t* location, size_t* length) { return false; }
181 
182     // Returns information about the current text input of this WebWidget.
textInputInfo()183     virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
184 
185     // Returns the anchor and focus bounds of the current selection.
186     // If the selection range is empty, it returns the caret bounds.
selectionBounds(WebRect & anchor,WebRect & focus)187     virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; }
188 
189     // Called to notify that IME candidate window has changed its visibility or
190     // its appearance. These calls correspond to trigger
191     // candidatewindow{show,update,hide} events defined in W3C IME API.
didShowCandidateWindow()192     virtual void didShowCandidateWindow() { }
didUpdateCandidateWindow()193     virtual void didUpdateCandidateWindow() { }
didHideCandidateWindow()194     virtual void didHideCandidateWindow() { }
195 
196     // Returns the text direction at the start and end bounds of the current selection.
197     // If the selection range is empty, it returns false.
selectionTextDirection(WebTextDirection & start,WebTextDirection & end)198     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
199 
200     // Returns true if the selection range is nonempty and its anchor is first
201     // (i.e its anchor is its start).
isSelectionAnchorFirst()202     virtual bool isSelectionAnchorFirst() const { return false; }
203 
204     // Fetch the current selection range of this WebWidget. If there is no
205     // selection, it will output a 0-length range with the location at the
206     // caret. Returns true and fills the out-paramters on success; returns false
207     // on failure.
caretOrSelectionRange(size_t * location,size_t * length)208     virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
209 
210     // Changes the text direction of the selected input node.
setTextDirection(WebTextDirection)211     virtual void setTextDirection(WebTextDirection) { }
212 
213     // Returns true if the WebWidget uses GPU accelerated compositing
214     // to render its contents.
isAcceleratedCompositingActive()215     virtual bool isAcceleratedCompositingActive() const { return false; }
216 
217     // Returns true if the WebWidget created is of type WebPagePopup.
isPagePopup()218     virtual bool isPagePopup() const { return false; }
219     // Returns true if the WebWidget created is of type WebPopupMenu.
isPopupMenu()220     virtual bool isPopupMenu() const { return false; }
221 
222     // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
223     // is no longer safe to access.
willCloseLayerTreeView()224     virtual void willCloseLayerTreeView() { }
225 
226     // Calling WebWidgetClient::requestPointerLock() will result in one
227     // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
didAcquirePointerLock()228     virtual void didAcquirePointerLock() { }
didNotAcquirePointerLock()229     virtual void didNotAcquirePointerLock() { }
230 
231     // Pointer lock was held, but has been lost. This may be due to a
232     // request via WebWidgetClient::requestPointerUnlock(), or for other
233     // reasons such as the user exiting lock, window focus changing, etc.
didLosePointerLock()234     virtual void didLosePointerLock() { }
235 
236     // Informs the WebWidget that the resizer rect changed. Happens for example
237     // on mac, when a widget appears below the WebWidget without changing the
238     // WebWidget's size (WebWidget::resize() automatically checks the resizer
239     // rect.)
didChangeWindowResizerRect()240     virtual void didChangeWindowResizerRect() { }
241 
242     // The page background color. Can be used for filling in areas without
243     // content.
backgroundColor()244     virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }
245 
246 protected:
~WebWidget()247     ~WebWidget() { }
248 };
249 
250 } // namespace blink
251 
252 #endif
253