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