Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / web / WebWidgetClient.h
blobc1ce416eb6c0355249171c581bc26725f8459619
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef WebWidgetClient_h
32 #define WebWidgetClient_h
34 #include "WebNavigationPolicy.h"
35 #include "public/platform/WebCommon.h"
36 #include "public/platform/WebLayerTreeView.h"
37 #include "public/platform/WebPoint.h"
38 #include "public/platform/WebRect.h"
39 #include "public/platform/WebScreenInfo.h"
40 #include "public/web/WebTouchAction.h"
42 namespace blink {
44 class WebGestureEvent;
45 class WebNode;
46 class WebString;
47 class WebWidget;
48 struct WebCursorInfo;
49 struct WebFloatPoint;
50 struct WebFloatSize;
51 struct WebSize;
53 class WebWidgetClient {
54 public:
55 // Called when a region of the WebWidget needs to be re-painted.
56 virtual void didInvalidateRect(const WebRect&) { }
58 // Called when the Widget has changed size as a result of an auto-resize.
59 virtual void didAutoResize(const WebSize& newSize) { }
61 // Called when the Widget has a new layout size. As a result of
62 // setting the new layout size, the frame for this widget has possibly
63 // been marked as needing layout. Widgets must mark their containers
64 // for layout when the plguin container controls widget layout, otherwise
65 // the frame layout will not occur.
66 virtual void didUpdateLayoutSize(const WebSize& newSize) { }
68 // Attempt to initialize compositing for this widget. If this is successful,
69 // layerTreeView() will return a valid WebLayerTreeView.
70 virtual void initializeLayerTreeView() { }
72 // Return a compositing view used for this widget. This is owned by the
73 // WebWidgetClient.
74 virtual WebLayerTreeView* layerTreeView() { return 0; }
75 // FIXME: Remove all overrides of this and change layerTreeView() above to ASSERT_NOT_REACHED.
76 virtual bool allowsBrokenNullLayerTreeView() const { return false; }
78 // Called when a call to WebWidget::animate is required
79 virtual void scheduleAnimation() { }
81 // Called when one of the following things were involved during the layout:
82 // * > 200 text characters
83 // * > 1024 image pixels
84 // * a plugin
85 // * a canvas
86 // An approximation for first layout that resulted in pixels on screen.
87 // Not the best heuristic, and we should replace it with something better.
88 virtual void didFirstVisuallyNonEmptyLayout() { }
90 // The frame's document first layout immediately after the parsing finished.
91 // Another way to put it: first frame produced after DOMContentLoaded was dispatched.
92 virtual void didFirstLayoutAfterFinishedParsing() { }
94 // Called when the widget acquires or loses focus, respectively.
95 virtual void didFocus() { }
96 virtual void didBlur() { }
98 // Called when the cursor for the widget changes.
99 virtual void didChangeCursor(const WebCursorInfo&) { }
101 // Called when the widget should be closed. WebWidget::close() should
102 // be called asynchronously as a result of this notification.
103 virtual void closeWidgetSoon() { }
105 // Called to show the widget according to the given policy.
106 virtual void show(WebNavigationPolicy) { }
108 // Called to get/set the position of the widget in screen coordinates.
109 virtual WebRect windowRect() { return WebRect(); }
110 virtual void setWindowRect(const WebRect&) { }
112 // Called when a tooltip should be shown at the current cursor position.
113 virtual void setToolTipText(const WebString&, WebTextDirection hint) { }
115 // Called to get the position of the resizer rect in window coordinates.
116 virtual WebRect windowResizerRect() { return WebRect(); }
118 // Called to get the position of the root window containing the widget
119 // in screen coordinates.
120 virtual WebRect rootWindowRect() { return WebRect(); }
122 // Called to query information about the screen where this widget is
123 // displayed.
124 virtual WebScreenInfo screenInfo() { return WebScreenInfo(); }
126 // Called to get the scale factor of the display.
127 virtual float deviceScaleFactor() { return 1; }
129 // When this method gets called, WebWidgetClient implementation should
130 // reset the input method by cancelling any ongoing composition.
131 virtual void resetInputMethod() { }
133 // Requests to lock the mouse cursor. If true is returned, the success
134 // result will be asynchronously returned via a single call to
135 // WebWidget::didAcquirePointerLock() or
136 // WebWidget::didNotAcquirePointerLock().
137 // If false, the request has been denied synchronously.
138 virtual bool requestPointerLock() { return false; }
140 // Cause the pointer lock to be released. This may be called at any time,
141 // including when a lock is pending but not yet acquired.
142 // WebWidget::didLosePointerLock() is called when unlock is complete.
143 virtual void requestPointerUnlock() { }
145 // Returns true iff the pointer is locked to this widget.
146 virtual bool isPointerLocked() { return false; }
148 // Called when a gesture event is handled.
149 virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled) { }
151 // Called when overscrolled on main thread.
152 virtual void didOverscroll(const WebFloatSize& unusedDelta, const WebFloatSize& accumulatedRootOverScroll, const WebFloatPoint& position, const WebFloatSize& velocity) { }
154 // Called to update if touch events should be sent.
155 virtual void hasTouchEventHandlers(bool) { }
157 // Called during WebWidget::HandleInputEvent for a TouchStart event to inform the embedder
158 // of the touch actions that are permitted for this touch.
159 virtual void setTouchAction(WebTouchAction touchAction) { }
161 // Called when value of focused text field gets dirty, e.g. value is
162 // modified by script, not by user input.
163 virtual void didUpdateTextOfFocusedElementByNonUserInput() { }
165 // Request the browser to show the IME for current input type.
166 virtual void showImeIfNeeded() { }
168 // Request that the browser show a UI for an unhandled tap, if needed.
169 // Invoked during the handling of a GestureTap input event whenever the
170 // event is not consumed.
171 // |tappedPosition| is the point where the mouseDown occurred in client
172 // coordinates.
173 // |tappedNode| is the node that the mouseDown event hit, provided so the
174 // UI can be shown only on certain kinds of nodes in specific locations.
175 // |pageChanged| is true if and only if the DOM tree or style was
176 // modified during the dispatch of the mouse*, or click events associated
177 // with the tap.
178 // This provides a heuristic to help identify when a page is doing
179 // something as a result of a tap without explicitly consuming the event.
180 virtual void showUnhandledTapUIIfNeeded(const WebPoint& tappedPosition,
181 const WebNode& tappedNode, bool pageChanged) { }
183 // Called immediately after a mousedown event is dispatched due to a mouse
184 // press or gesture tap.
185 // Note: This is called even when the mouse down event is prevent default.
186 virtual void onMouseDown(const WebNode& mouseDownNode) { }
187 protected:
188 ~WebWidgetClient() { }
191 } // namespace blink
193 #endif