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 WebWidgetClient_h 32 #define WebWidgetClient_h 33 34 #include "WebNavigationPolicy.h" 35 #include "public/platform/WebCommon.h" 36 #include "public/platform/WebLayerTreeView.h" 37 #include "public/platform/WebRect.h" 38 #include "public/platform/WebScreenInfo.h" 39 #include "public/web/WebTouchAction.h" 40 41 namespace blink { 42 43 class WebGestureEvent; 44 class WebString; 45 class WebWidget; 46 struct WebCursorInfo; 47 struct WebSize; 48 49 class WebWidgetClient { 50 public: 51 // Called when a region of the WebWidget needs to be re-painted. 52 virtual void didInvalidateRect(const WebRect&) { } 53 54 // Called when a region of the WebWidget, given by clipRect, should be 55 // scrolled by the specified dx and dy amounts. 56 virtual void didScrollRect(int dx, int dy, const WebRect& clipRect) { } 57 58 // Called when the Widget has changed size as a result of an auto-resize. 59 virtual void didAutoResize(const WebSize& newSize) { } 60 61 // Called when the compositor is enabled or disabled. The parameter to 62 // didActivateCompositor() is meaningless. 63 // FIXME: Remove parameter from didActivateCompositor(). 64 virtual void didActivateCompositor(int deprecated) { } 65 virtual void didDeactivateCompositor() { } 66 67 // Attempt to initialize compositing for this widget. If this is successful, 68 // layerTreeView() will return a valid WebLayerTreeView. 69 virtual void initializeLayerTreeView() { } 70 71 // Return a compositing view used for this widget. This is owned by the 72 // WebWidgetClient. 73 virtual WebLayerTreeView* layerTreeView() { return 0; } 74 75 // Sometimes the WebWidget enters a state where it will generate a sequence 76 // of invalidations that should not, by themselves, trigger the compositor 77 // to schedule a new frame. This call indicates to the embedder that it 78 // should suppress compositor scheduling temporarily. 79 virtual void suppressCompositorScheduling(bool enable) { } 80 81 // Indicates to the embedder that the compositor is about to begin a 82 // frame. This is primarily to signal to flow control mechanisms that a 83 // frame is beginning, not to perform actual painting work. 84 virtual void willBeginCompositorFrame() { } 85 86 // Indicates to the embedder that the WebWidget is ready for additional 87 // input. 88 virtual void didBecomeReadyForAdditionalInput() { } 89 90 // Called for compositing mode when a frame commit operation has finished. 91 virtual void didCommitCompositorFrame() { } 92 93 // Called for compositing mode when the draw commands for a WebKit-side 94 // frame have been issued. 95 virtual void didCommitAndDrawCompositorFrame() { } 96 97 // Called for compositing mode when swapbuffers has been posted in the GPU 98 // process. 99 virtual void didCompleteSwapBuffers() { } 100 101 // Called when a call to WebWidget::animate is required 102 virtual void scheduleAnimation() { } 103 104 // Called to query the state of the rendering back-end. Should return true 105 // when scheduleAnimation (or possibly some other cause for another frame) 106 // was called, but before WebWidget::animate actually does a frame. 107 virtual bool isCompositorFramePending() const { return false; } 108 109 // Called when the widget acquires or loses focus, respectively. 110 virtual void didFocus() { } 111 virtual void didBlur() { } 112 113 // Called when the cursor for the widget changes. 114 virtual void didChangeCursor(const WebCursorInfo&) { } 115 116 // Called when the widget should be closed. WebWidget::close() should 117 // be called asynchronously as a result of this notification. 118 virtual void closeWidgetSoon() { } 119 120 // Called to show the widget according to the given policy. 121 virtual void show(WebNavigationPolicy) { } 122 123 // Called to block execution of the current thread until the widget is 124 // closed. 125 virtual void runModal() { } 126 127 // Called to enter/exit fullscreen mode. If enterFullScreen returns true, 128 // then WebWidget::{will,Did}EnterFullScreen should bound resizing the 129 // WebWidget into fullscreen mode. Similarly, when exitFullScreen is 130 // called, WebWidget::{will,Did}ExitFullScreen should bound resizing the 131 // WebWidget out of fullscreen mode. 132 virtual bool enterFullScreen() { return false; } 133 virtual void exitFullScreen() { } 134 135 // Called to get/set the position of the widget in screen coordinates. 136 virtual WebRect windowRect() { return WebRect(); } 137 virtual void setWindowRect(const WebRect&) { } 138 139 // Called when a tooltip should be shown at the current cursor position. 140 virtual void setToolTipText(const WebString&, WebTextDirection hint) { } 141 142 // Called to get the position of the resizer rect in window coordinates. 143 virtual WebRect windowResizerRect() { return WebRect(); } 144 145 // Called to get the position of the root window containing the widget 146 // in screen coordinates. 147 virtual WebRect rootWindowRect() { return WebRect(); } 148 149 // Called to query information about the screen where this widget is 150 // displayed. 151 virtual WebScreenInfo screenInfo() { return WebScreenInfo(); } 152 153 // Called to get the scale factor of the display. 154 virtual float deviceScaleFactor() { return 1; } 155 156 // When this method gets called, WebWidgetClient implementation should 157 // reset the input method by cancelling any ongoing composition. 158 virtual void resetInputMethod() { } 159 160 // Requests to lock the mouse cursor. If true is returned, the success 161 // result will be asynchronously returned via a single call to 162 // WebWidget::didAcquirePointerLock() or 163 // WebWidget::didNotAcquirePointerLock(). 164 // If false, the request has been denied synchronously. 165 virtual bool requestPointerLock() { return false; } 166 167 // Cause the pointer lock to be released. This may be called at any time, 168 // including when a lock is pending but not yet acquired. 169 // WebWidget::didLosePointerLock() is called when unlock is complete. 170 virtual void requestPointerUnlock() { } 171 172 // Returns true iff the pointer is locked to this widget. 173 virtual bool isPointerLocked() { return false; } 174 175 // Called when a gesture event is handled. 176 virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled) { } 177 178 // Called to update if touch events should be sent. 179 virtual void hasTouchEventHandlers(bool) { } 180 181 // Called during WebWidget::HandleInputEvent for a TouchStart event to inform the embedder 182 // of the touch actions that are permitted for this touch. 183 virtual void setTouchAction(WebTouchAction touchAction) { } 184 185 protected: 186 ~WebWidgetClient() { } 187 }; 188 189 } // namespace blink 190 191 #endif 192