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/WebPoint.h" 37 #include "../platform/WebRect.h" 38 #include "../platform/WebSize.h" 39 #include "WebBeginFrameArgs.h" 40 #include "WebCompositionUnderline.h" 41 #include "WebTextDirection.h" 42 #include "WebTextInputInfo.h" 43 44 namespace blink { 45 46 class WebCompositeAndReadbackAsyncCallback; 47 class WebInputEvent; 48 class WebLayerTreeView; 49 class WebMouseEvent; 50 class WebPagePopup; 51 class WebString; 52 class WebWidgetClient; 53 struct WebPoint; 54 struct WebRenderingStats; 55 template <typename T> class WebVector; 56 57 class WebWidget { 58 public: 59 // This method closes and deletes the WebWidget. close()60 virtual void close() { } 61 62 // Returns the current size of the WebWidget. size()63 virtual WebSize size() { return WebSize(); } 64 65 // Used to group a series of resize events. For example, if the user 66 // drags a resizer then willStartLiveResize will be called, followed by a 67 // sequence of resize events, ending with willEndLiveResize when the user 68 // lets go of the resizer. willStartLiveResize()69 virtual void willStartLiveResize() { } 70 71 // Called to resize the WebWidget. resize(const WebSize &)72 virtual void resize(const WebSize&) { } 73 74 // Resizes the unscaled pinch viewport. Normally the unscaled pinch 75 // viewport is the same size as the main frame. The passed size becomes the 76 // size of the viewport when unscaled (i.e. scale = 1). This is used to 77 // shrink the visible viewport to allow things like the ChromeOS virtual 78 // keyboard to overlay over content but allow scrolling it into view. resizePinchViewport(const WebSize &)79 virtual void resizePinchViewport(const WebSize&) { } 80 81 // Ends a group of resize events that was started with a call to 82 // willStartLiveResize. willEndLiveResize()83 virtual void willEndLiveResize() { } 84 85 // Called to notify the WebWidget of entering/exiting fullscreen mode. The 86 // resize method may be called between will{Enter,Exit}FullScreen and 87 // did{Enter,Exit}FullScreen. willEnterFullScreen()88 virtual void willEnterFullScreen() { } didEnterFullScreen()89 virtual void didEnterFullScreen() { } willExitFullScreen()90 virtual void willExitFullScreen() { } didExitFullScreen()91 virtual void didExitFullScreen() { } 92 93 // Called to update imperative animation state. This should be called before 94 // paint, although the client can rate-limit these calls. 95 // FIXME: Remove this function once Chrome side patch lands. animate(double monotonicFrameBeginTime)96 void animate(double monotonicFrameBeginTime) 97 { 98 beginFrame(WebBeginFrameArgs(monotonicFrameBeginTime)); 99 } beginFrame(const WebBeginFrameArgs & frameTime)100 virtual void beginFrame(const WebBeginFrameArgs& frameTime) { } 101 102 // Called to notify that a previously begun frame was finished and 103 // committed to the compositor. This is used to schedule lower priority 104 // work after tasks such as input processing and painting. didCommitFrameToCompositor()105 virtual void didCommitFrameToCompositor() { } 106 107 // Called to layout the WebWidget. This MUST be called before Paint, 108 // and it may result in calls to WebWidgetClient::didInvalidateRect. layout()109 virtual void layout() { } 110 111 // Called to paint the rectangular region within the WebWidget 112 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call 113 // Layout before calling this method. It is okay to call paint 114 // multiple times once layout has been called, assuming no other 115 // changes are made to the WebWidget (e.g., once events are 116 // processed, it should be assumed that another call to layout is 117 // warranted before painting again). paint(WebCanvas *,const WebRect & viewPort)118 virtual void paint(WebCanvas*, const WebRect& viewPort) { } 119 paintCompositedDeprecated(WebCanvas *,const WebRect &)120 virtual void paintCompositedDeprecated(WebCanvas*, const WebRect&) { } 121 122 // The caller is responsible for keeping the WebCompositeAndReadbackAsyncCallback 123 // object alive until it is called. This should only be called when 124 // isAcceleratedCompositingActive() is true. compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback *)125 virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) { } 126 127 // Returns true if we've started tracking repaint rectangles. isTrackingRepaints()128 virtual bool isTrackingRepaints() const { return false; } 129 130 // Indicates that the compositing surface associated with this WebWidget is 131 // ready to use. setCompositorSurfaceReady()132 virtual void setCompositorSurfaceReady() { } 133 134 // Called to inform the WebWidget of a change in theme. 135 // Implementors that cache rendered copies of widgets need to re-render 136 // on receiving this message themeChanged()137 virtual void themeChanged() { } 138 139 // Called to inform the WebWidget of an input event. Returns true if 140 // the event has been processed, false otherwise. handleInputEvent(const WebInputEvent &)141 virtual bool handleInputEvent(const WebInputEvent&) { return false; } 142 143 // Called to inform the WebWidget of the mouse cursor's visibility. setCursorVisibilityState(bool isVisible)144 virtual void setCursorVisibilityState(bool isVisible) { } 145 146 // Check whether the given point hits any registered touch event handlers. hasTouchEventHandlersAt(const WebPoint &)147 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; } 148 149 // Applies viewport related properties during a commit from the compositor 150 // thread. applyViewportDeltas(const WebSize & scrollDelta,float scaleFactor,float topControlsDelta)151 virtual void applyViewportDeltas( 152 const WebSize& scrollDelta, 153 float scaleFactor, 154 float topControlsDelta) { } 155 156 // Applies viewport related properties during a commit from the compositor 157 // thread. applyViewportDeltas(const WebSize & pinchViewportDelta,const WebSize & mainFrameDelta,float scaleFactor,float topControlsDelta)158 virtual void applyViewportDeltas( 159 const WebSize& pinchViewportDelta, 160 const WebSize& mainFrameDelta, 161 float scaleFactor, 162 float topControlsDelta) { } 163 164 // Called to inform the WebWidget that mouse capture was lost. mouseCaptureLost()165 virtual void mouseCaptureLost() { } 166 167 // Called to inform the WebWidget that it has gained or lost keyboard focus. setFocus(bool)168 virtual void setFocus(bool) { } 169 170 // Called to inform the WebWidget of a new composition text. 171 // If selectionStart and selectionEnd has the same value, then it indicates 172 // the input caret position. If the text is empty, then the existing 173 // composition text will be cancelled. 174 // Returns true if the composition text was set successfully. setComposition(const WebString & text,const WebVector<WebCompositionUnderline> & underlines,int selectionStart,int selectionEnd)175 virtual bool setComposition( 176 const WebString& text, 177 const WebVector<WebCompositionUnderline>& underlines, 178 int selectionStart, 179 int selectionEnd) { return false; } 180 181 enum ConfirmCompositionBehavior { 182 DoNotKeepSelection, 183 KeepSelection, 184 }; 185 186 // Called to inform the WebWidget to confirm an ongoing composition. 187 // This method is same as confirmComposition(WebString()); 188 // Returns true if there is an ongoing composition. confirmComposition()189 virtual bool confirmComposition() { return false; } // Deprecated confirmComposition(ConfirmCompositionBehavior selectionBehavior)190 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; } 191 192 // Called to inform the WebWidget to confirm an ongoing composition with a 193 // new composition text. If the text is empty then the current composition 194 // text is confirmed. If there is no ongoing composition, then deletes the 195 // current selection and inserts the text. This method has no effect if 196 // there is no ongoing composition and the text is empty. 197 // Returns true if there is an ongoing composition or the text is inserted. confirmComposition(const WebString & text)198 virtual bool confirmComposition(const WebString& text) { return false; } 199 200 // Fetches the character range of the current composition, also called the 201 // "marked range." Returns true and fills the out-paramters on success; 202 // returns false on failure. compositionRange(size_t * location,size_t * length)203 virtual bool compositionRange(size_t* location, size_t* length) { return false; } 204 205 // Returns information about the current text input of this WebWidget. textInputInfo()206 virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); } 207 208 // Returns the anchor and focus bounds of the current selection. 209 // If the selection range is empty, it returns the caret bounds. selectionBounds(WebRect & anchor,WebRect & focus)210 virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; } 211 212 // Called to notify that IME candidate window has changed its visibility or 213 // its appearance. These calls correspond to trigger 214 // candidatewindow{show,update,hide} events defined in W3C IME API. didShowCandidateWindow()215 virtual void didShowCandidateWindow() { } didUpdateCandidateWindow()216 virtual void didUpdateCandidateWindow() { } didHideCandidateWindow()217 virtual void didHideCandidateWindow() { } 218 219 // Returns the text direction at the start and end bounds of the current selection. 220 // If the selection range is empty, it returns false. selectionTextDirection(WebTextDirection & start,WebTextDirection & end)221 virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; } 222 223 // Returns true if the selection range is nonempty and its anchor is first 224 // (i.e its anchor is its start). isSelectionAnchorFirst()225 virtual bool isSelectionAnchorFirst() const { return false; } 226 227 // Fetch the current selection range of this WebWidget. If there is no 228 // selection, it will output a 0-length range with the location at the 229 // caret. Returns true and fills the out-paramters on success; returns false 230 // on failure. caretOrSelectionRange(size_t * location,size_t * length)231 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; } 232 233 // Changes the text direction of the selected input node. setTextDirection(WebTextDirection)234 virtual void setTextDirection(WebTextDirection) { } 235 236 // Returns true if the WebWidget uses GPU accelerated compositing 237 // to render its contents. isAcceleratedCompositingActive()238 virtual bool isAcceleratedCompositingActive() const { return false; } 239 240 // Returns true if the WebWidget created is of type WebPagePopup. isPagePopup()241 virtual bool isPagePopup() const { return false; } 242 // Returns true if the WebWidget created is of type WebPopupMenu. isPopupMenu()243 virtual bool isPopupMenu() const { return false; } 244 245 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and 246 // is no longer safe to access. willCloseLayerTreeView()247 virtual void willCloseLayerTreeView() { } 248 249 // Calling WebWidgetClient::requestPointerLock() will result in one 250 // return call to didAcquirePointerLock() or didNotAcquirePointerLock(). didAcquirePointerLock()251 virtual void didAcquirePointerLock() { } didNotAcquirePointerLock()252 virtual void didNotAcquirePointerLock() { } 253 254 // Pointer lock was held, but has been lost. This may be due to a 255 // request via WebWidgetClient::requestPointerUnlock(), or for other 256 // reasons such as the user exiting lock, window focus changing, etc. didLosePointerLock()257 virtual void didLosePointerLock() { } 258 259 // Informs the WebWidget that the resizer rect changed. Happens for example 260 // on mac, when a widget appears below the WebWidget without changing the 261 // WebWidget's size (WebWidget::resize() automatically checks the resizer 262 // rect.) didChangeWindowResizerRect()263 virtual void didChangeWindowResizerRect() { } 264 265 // The page background color. Can be used for filling in areas without 266 // content. backgroundColor()267 virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ } 268 269 // The currently open page popup, which are calendar and datalist pickers 270 // but not the select popup. pagePopup()271 virtual WebPagePopup* pagePopup() const { return 0; } 272 273 // Sets the height subtracted from the Widget to accomodate the top controls. setTopControlsLayoutHeight(float)274 virtual void setTopControlsLayoutHeight(float) { } 275 276 protected: ~WebWidget()277 ~WebWidget() { } 278 }; 279 280 } // namespace blink 281 282 #endif 283