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 WebKit { 43 44 class WebInputEvent; 45 class WebLayerTreeView; 46 class WebMouseEvent; 47 class WebString; 48 struct WebPoint; 49 struct WebRenderingStats; 50 template <typename T> class WebVector; 51 52 class WebWidget { 53 public: 54 // This method closes and deletes the WebWidget. 55 virtual void close() { } 56 57 // Returns the current size of the WebWidget. 58 virtual WebSize size() { return WebSize(); } 59 60 // Used to group a series of resize events. For example, if the user 61 // drags a resizer then willStartLiveResize will be called, followed by a 62 // sequence of resize events, ending with willEndLiveResize when the user 63 // lets go of the resizer. 64 virtual void willStartLiveResize() { } 65 66 // Called to resize the WebWidget. 67 virtual void resize(const WebSize&) { } 68 69 // Ends a group of resize events that was started with a call to 70 // willStartLiveResize. 71 virtual void willEndLiveResize() { } 72 73 // Called to notify the WebWidget of entering/exiting fullscreen mode. The 74 // resize method may be called between will{Enter,Exit}FullScreen and 75 // did{Enter,Exit}FullScreen. 76 virtual void willEnterFullScreen() { } 77 virtual void didEnterFullScreen() { } 78 virtual void willExitFullScreen() { } 79 virtual void didExitFullScreen() { } 80 81 // Called to update imperative animation state. This should be called before 82 // paint, although the client can rate-limit these calls. 83 virtual void animate(double monotonicFrameBeginTime) { } 84 85 // Called to layout the WebWidget. This MUST be called before Paint, 86 // and it may result in calls to WebWidgetClient::didInvalidateRect. 87 virtual void layout() { } 88 89 // Called to toggle the WebWidget in or out of force compositing mode. This 90 // should be called before paint. 91 virtual void enterForceCompositingMode(bool enter) { } 92 93 // Called to notify the WebWidget that the widget has exited compositing 94 // mode and cannot reenter. 95 virtual void didExitCompositingMode() { } 96 97 enum PaintOptions { 98 // Attempt to fulfill the painting request by reading back from the 99 // compositor, assuming we're using a compositor to render. 100 ReadbackFromCompositorIfAvailable, 101 102 // Force the widget to rerender onto the canvas using software. This 103 // mode ignores 3d transforms and ignores GPU-resident content, such 104 // as video, canvas, and WebGL. 105 // 106 // Note: This option exists on OS(ANDROID) and will hopefully be 107 // removed once the link disambiguation feature renders using 108 // the compositor. 109 ForceSoftwareRenderingAndIgnoreGPUResidentContent, 110 }; 111 112 // Called to paint the rectangular region within the WebWidget 113 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call 114 // Layout before calling this method. It is okay to call paint 115 // multiple times once layout has been called, assuming no other 116 // changes are made to the WebWidget (e.g., once events are 117 // processed, it should be assumed that another call to layout is 118 // warranted before painting again). 119 virtual void paint(WebCanvas*, const WebRect& viewPort, PaintOptions = ReadbackFromCompositorIfAvailable) { } 120 121 // Returns true if we've started tracking repaint rectangles. 122 virtual bool isTrackingRepaints() const { return false; } 123 124 // Indicates that the compositing surface associated with this WebWidget is 125 // ready to use. 126 virtual void setCompositorSurfaceReady() { } 127 128 // Temporary method for the embedder to notify the WebWidget that the widget 129 // has taken damage, e.g. due to a window expose. This method will be 130 // removed when the WebWidget inversion patch lands --- http://crbug.com/112837 131 virtual void setNeedsRedraw() { } 132 133 // Called to inform the WebWidget of a change in theme. 134 // Implementors that cache rendered copies of widgets need to re-render 135 // on receiving this message 136 virtual void themeChanged() { } 137 138 // Called to inform the WebWidget of an input event. Returns true if 139 // the event has been processed, false otherwise. 140 virtual bool handleInputEvent(const WebInputEvent&) { return false; } 141 142 // Called to inform the WebWidget of the mouse cursor's visibility. 143 virtual void setCursorVisibilityState(bool isVisible) { } 144 145 // Check whether the given point hits any registered touch event handlers. 146 virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; } 147 148 // Applies a scroll delta to the root layer, which is bundled with a page 149 // scale factor that may apply a CSS transform on the whole document (used 150 // for mobile-device pinch zooming). This is triggered by events sent to the 151 // compositor thread. 152 virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { } 153 154 // Called to inform the WebWidget that mouse capture was lost. 155 virtual void mouseCaptureLost() { } 156 157 // Called to inform the WebWidget that it has gained or lost keyboard focus. 158 virtual void setFocus(bool) { } 159 160 // Called to inform the WebWidget of a new composition text. 161 // If selectionStart and selectionEnd has the same value, then it indicates 162 // the input caret position. If the text is empty, then the existing 163 // composition text will be cancelled. 164 // Returns true if the composition text was set successfully. 165 virtual bool setComposition( 166 const WebString& text, 167 const WebVector<WebCompositionUnderline>& underlines, 168 int selectionStart, 169 int selectionEnd) { return false; } 170 171 enum ConfirmCompositionBehavior { 172 DoNotKeepSelection, 173 KeepSelection, 174 }; 175 176 // Called to inform the WebWidget to confirm an ongoing composition. 177 // This method is same as confirmComposition(WebString()); 178 // Returns true if there is an ongoing composition. 179 virtual bool confirmComposition() { return false; } // Deprecated 180 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; } 181 182 // Called to inform the WebWidget to confirm an ongoing composition with a 183 // new composition text. If the text is empty then the current composition 184 // text is confirmed. If there is no ongoing composition, then deletes the 185 // current selection and inserts the text. This method has no effect if 186 // there is no ongoing composition and the text is empty. 187 // Returns true if there is an ongoing composition or the text is inserted. 188 virtual bool confirmComposition(const WebString& text) { return false; } 189 190 // Fetches the character range of the current composition, also called the 191 // "marked range." Returns true and fills the out-paramters on success; 192 // returns false on failure. 193 virtual bool compositionRange(size_t* location, size_t* length) { return false; } 194 195 // Returns information about the current text input of this WebWidget. 196 virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); } 197 198 // Returns the anchor and focus bounds of the current selection. 199 // If the selection range is empty, it returns the caret bounds. 200 virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; } 201 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; } 205 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; } 209 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 213 // on failure. 214 virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; } 215 216 // Changes the text direction of the selected input node. 217 virtual void setTextDirection(WebTextDirection) { } 218 219 // Returns true if the WebWidget uses GPU accelerated compositing 220 // to render its contents. 221 virtual bool isAcceleratedCompositingActive() const { return false; } 222 223 // The WebLayerTreeView initialized on this WebWidgetClient will be going away and 224 // is no longer safe to access. 225 virtual void willCloseLayerTreeView() { } 226 227 // Calling WebWidgetClient::requestPointerLock() will result in one 228 // return call to didAcquirePointerLock() or didNotAcquirePointerLock(). 229 virtual void didAcquirePointerLock() { } 230 virtual void didNotAcquirePointerLock() { } 231 232 // Pointer lock was held, but has been lost. This may be due to a 233 // request via WebWidgetClient::requestPointerUnlock(), or for other 234 // reasons such as the user exiting lock, window focus changing, etc. 235 virtual void didLosePointerLock() { } 236 237 // Informs the WebWidget that the resizer rect changed. Happens for example 238 // on mac, when a widget appears below the WebWidget without changing the 239 // WebWidget's size (WebWidget::resize() automatically checks the resizer 240 // rect.) 241 virtual void didChangeWindowResizerRect() { } 242 243 // The page background color. Can be used for filling in areas without 244 // content. 245 virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ } 246 247 protected: 248 ~WebWidget() { } 249 }; 250 251 } // namespace WebKit 252 253 #endif 254