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 44namespace blink { 45 46class WebCompositeAndReadbackAsyncCallback; 47class WebInputEvent; 48class WebLayerTreeView; 49class WebMouseEvent; 50class WebPagePopup; 51class WebString; 52class WebWidgetClient; 53struct WebPoint; 54struct WebRenderingStats; 55template <typename T> class WebVector; 56 57class WebWidget { 58public: 59 // This method closes and deletes the WebWidget. 60 virtual void close() { } 61 62 // Returns the current size of the WebWidget. 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. 69 virtual void willStartLiveResize() { } 70 71 // Called to resize the WebWidget. 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. 79 virtual void resizePinchViewport(const WebSize&) { } 80 81 // Ends a group of resize events that was started with a call to 82 // willStartLiveResize. 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. 88 virtual void willEnterFullScreen() { } 89 virtual void didEnterFullScreen() { } 90 virtual void willExitFullScreen() { } 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. 96 void animate(double monotonicFrameBeginTime) 97 { 98 beginFrame(WebBeginFrameArgs(monotonicFrameBeginTime)); 99 } 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. 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. 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). 118 virtual void paint(WebCanvas*, const WebRect& viewPort) { } 119 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. 125 virtual void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) { } 126 127 // Returns true if we've started tracking repaint rectangles. 128 virtual bool isTrackingRepaints() const { return false; } 129 130 // Indicates that the compositing surface associated with this WebWidget is 131 // ready to use. 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 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. 141 virtual bool handleInputEvent(const WebInputEvent&) { return false; } 142 143 // Called to inform the WebWidget of the mouse cursor's visibility. 144 virtual void setCursorVisibilityState(bool isVisible) { } 145 146 // Check whether the given point hits any registered touch event handlers. 147 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; } 148 149 // Applies viewport related properties during a commit from the compositor 150 // thread. 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. 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. 165 virtual void mouseCaptureLost() { } 166 167 // Called to inform the WebWidget that it has gained or lost keyboard focus. 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. 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. 189 virtual bool confirmComposition() { return false; } // Deprecated 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. 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. 203 virtual bool compositionRange(size_t* location, size_t* length) { return false; } 204 205 // Returns information about the current text input of this WebWidget. 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. 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. 215 virtual void didShowCandidateWindow() { } 216 virtual void didUpdateCandidateWindow() { } 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. 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). 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. 231 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; } 232 233 // Changes the text direction of the selected input node. 234 virtual void setTextDirection(WebTextDirection) { } 235 236 // Returns true if the WebWidget uses GPU accelerated compositing 237 // to render its contents. 238 virtual bool isAcceleratedCompositingActive() const { return false; } 239 240 // Returns true if the WebWidget created is of type WebPagePopup. 241 virtual bool isPagePopup() const { return false; } 242 // Returns true if the WebWidget created is of type WebPopupMenu. 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. 247 virtual void willCloseLayerTreeView() { } 248 249 // Calling WebWidgetClient::requestPointerLock() will result in one 250 // return call to didAcquirePointerLock() or didNotAcquirePointerLock(). 251 virtual void didAcquirePointerLock() { } 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. 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.) 263 virtual void didChangeWindowResizerRect() { } 264 265 // The page background color. Can be used for filling in areas without 266 // content. 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. 271 virtual WebPagePopup* pagePopup() const { return 0; } 272 273 // Sets the height subtracted from the Widget to accomodate the top controls. 274 virtual void setTopControlsLayoutHeight(float) { } 275 276protected: 277 ~WebWidget() { } 278}; 279 280} // namespace blink 281 282#endif 283