OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #if defined(OS_MACOSX) | 9 // TODO(jam): remove this file when all files have been converted. |
10 #include <OpenGL/OpenGL.h> | 10 #include "content/browser/renderer_host/render_widget_host_view.h" |
11 #endif | |
12 | |
13 #include <string> | |
14 #include <vector> | |
15 | |
16 #include "app/surface/transport_dib.h" | |
17 #include "base/process_util.h" | |
18 #include "third_party/skia/include/core/SkBitmap.h" | |
19 #include "third_party/skia/include/core/SkColor.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" | |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputType.h" | |
22 #include "ui/gfx/native_widget_types.h" | |
23 #include "ui/gfx/rect.h" | |
24 | |
25 namespace gfx { | |
26 class Rect; | |
27 class Size; | |
28 } | |
29 namespace IPC { | |
30 class Message; | |
31 } | |
32 | |
33 class BackingStore; | |
34 class RenderProcessHost; | |
35 class RenderWidgetHost; | |
36 class WebCursor; | |
37 struct NativeWebKeyboardEvent; | |
38 struct ViewHostMsg_AccessibilityNotification_Params; | |
39 | |
40 namespace webkit_glue { | |
41 struct WebAccessibility; | |
42 } | |
43 | |
44 namespace webkit { | |
45 namespace npapi { | |
46 struct WebPluginGeometry; | |
47 } | |
48 } | |
49 | |
50 // RenderWidgetHostView is an interface implemented by an object that acts as | |
51 // the "View" portion of a RenderWidgetHost. The RenderWidgetHost and its | |
52 // associated RenderProcessHost own the "Model" in this case which is the | |
53 // child renderer process. The View is responsible for receiving events from | |
54 // the surrounding environment and passing them to the RenderWidgetHost, and | |
55 // for actually displaying the content of the RenderWidgetHost when it | |
56 // changes. | |
57 class RenderWidgetHostView { | |
58 public: | |
59 virtual ~RenderWidgetHostView(); | |
60 | |
61 // Platform-specific creator. Use this to construct new RenderWidgetHostViews | |
62 // rather than using RenderWidgetHostViewWin & friends. | |
63 // | |
64 // This function must NOT size it, because the RenderView in the renderer | |
65 // wounldn't have been created yet. The widget would set its "waiting for | |
66 // resize ack" flag, and the ack would never come becasue no RenderView | |
67 // received it. | |
68 // | |
69 // The RenderWidgetHost must already be created (because we can't know if it's | |
70 // going to be a regular RenderWidgetHost or a RenderViewHost (a subclass). | |
71 static RenderWidgetHostView* CreateViewForWidget(RenderWidgetHost* widget); | |
72 | |
73 // Retrieves the RenderWidgetHostView corresponding to the specified | |
74 // |native_view|, or NULL if there is no such instance. | |
75 static RenderWidgetHostView* GetRenderWidgetHostViewFromNativeView( | |
76 gfx::NativeView native_view); | |
77 | |
78 // Perform all the initialization steps necessary for this object to represent | |
79 // a popup (such as a <select> dropdown), then shows the popup at |pos|. | |
80 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, | |
81 const gfx::Rect& pos) = 0; | |
82 | |
83 // Perform all the initialization steps necessary for this object to represent | |
84 // a full screen window. | |
85 virtual void InitAsFullscreen() = 0; | |
86 | |
87 // Returns the associated RenderWidgetHost. | |
88 virtual RenderWidgetHost* GetRenderWidgetHost() const = 0; | |
89 | |
90 // Notifies the View that it has become visible. | |
91 virtual void DidBecomeSelected() = 0; | |
92 | |
93 // Notifies the View that it has been hidden. | |
94 virtual void WasHidden() = 0; | |
95 | |
96 // Tells the View to size itself to the specified size. | |
97 virtual void SetSize(const gfx::Size& size) = 0; | |
98 | |
99 // Retrieves the native view used to contain plugins and identify the | |
100 // renderer in IPC messages. | |
101 virtual gfx::NativeView GetNativeView() = 0; | |
102 | |
103 // Moves all plugin windows as described in the given list. | |
104 virtual void MovePluginWindows( | |
105 const std::vector<webkit::npapi::WebPluginGeometry>& moves) = 0; | |
106 | |
107 // Actually set/take focus to/from the associated View component. | |
108 virtual void Focus() = 0; | |
109 virtual void Blur() = 0; | |
110 | |
111 // Returns true if the View currently has the focus. | |
112 virtual bool HasFocus() = 0; | |
113 | |
114 // Shows/hides the view. These must always be called together in pairs. | |
115 // It is not legal to call Hide() multiple times in a row. | |
116 virtual void Show() = 0; | |
117 virtual void Hide() = 0; | |
118 | |
119 // Whether the view is showing. | |
120 virtual bool IsShowing() = 0; | |
121 | |
122 // Retrieve the bounds of the View, in screen coordinates. | |
123 virtual gfx::Rect GetViewBounds() const = 0; | |
124 | |
125 // Sets the cursor to the one associated with the specified cursor_type | |
126 virtual void UpdateCursor(const WebCursor& cursor) = 0; | |
127 | |
128 // Indicates whether the page has finished loading. | |
129 virtual void SetIsLoading(bool is_loading) = 0; | |
130 | |
131 // Updates the state of the input method attached to the view. | |
132 virtual void ImeUpdateTextInputState(WebKit::WebTextInputType type, | |
133 const gfx::Rect& caret_rect) = 0; | |
134 | |
135 // Cancel the ongoing composition of the input method attached to the view. | |
136 virtual void ImeCancelComposition() = 0; | |
137 | |
138 // Informs the view that a portion of the widget's backing store was scrolled | |
139 // and/or painted. The view should ensure this gets copied to the screen. | |
140 // | |
141 // If the scroll_rect is non-empty, then a portion of the widget's backing | |
142 // store was scrolled by dx pixels horizontally and dy pixels vertically. | |
143 // The exposed rect from the scroll operation is included in copy_rects. | |
144 // | |
145 // There are subtle performance implications here. The RenderWidget gets sent | |
146 // a paint ack after this returns, so if the view only ever invalidates in | |
147 // response to this, then on Windows, where WM_PAINT has lower priority than | |
148 // events which can cause renderer resizes/paint rect updates, e.g. | |
149 // drag-resizing can starve painting; this function thus provides the view its | |
150 // main chance to ensure it stays painted and not just invalidated. On the | |
151 // other hand, if this always blindly paints, then if we're already in the | |
152 // midst of a paint on the callstack, we can double-paint unnecessarily. | |
153 // (Worse, we might recursively call RenderWidgetHost::GetBackingStore().) | |
154 // Thus implementers should generally paint as much of |rect| as possible | |
155 // synchronously with as little overpainting as possible. | |
156 virtual void DidUpdateBackingStore( | |
157 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, | |
158 const std::vector<gfx::Rect>& copy_rects) = 0; | |
159 | |
160 // Notifies the View that the renderer has ceased to exist. | |
161 virtual void RenderViewGone(base::TerminationStatus status, | |
162 int error_code) = 0; | |
163 | |
164 // Notifies the View that the renderer will be delete soon. | |
165 virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) = 0; | |
166 | |
167 // Tells the View to destroy itself. | |
168 virtual void Destroy() = 0; | |
169 | |
170 // Tells the View that the tooltip text for the current mouse position over | |
171 // the page has changed. | |
172 virtual void SetTooltipText(const std::wstring& tooltip_text) = 0; | |
173 | |
174 // Notifies the View that the renderer text selection has changed. | |
175 virtual void SelectionChanged(const std::string& text) {} | |
176 | |
177 // Tells the View whether the context menu is showing. This is used on Linux | |
178 // to suppress updates to webkit focus for the duration of the show. | |
179 virtual void ShowingContextMenu(bool showing) {} | |
180 | |
181 // Allocate a backing store for this view | |
182 virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; | |
183 | |
184 #if defined(OS_MACOSX) | |
185 // Tells the view whether or not to accept first responder status. If |flag| | |
186 // is true, the view does not accept first responder status and instead | |
187 // manually becomes first responder when it receives a mouse down event. If | |
188 // |flag| is false, the view participates in the key-view chain as normal. | |
189 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0; | |
190 | |
191 // Retrieve the bounds of the view, in cocoa view coordinates. | |
192 // If the UI scale factor is 2, |GetViewBounds()| will return a size of e.g. | |
193 // (400, 300) in pixels, while this method will return (200, 150). | |
194 // Even though this returns an gfx::Rect, the result is NOT IN PIXELS. | |
195 virtual gfx::Rect GetViewCocoaBounds() const = 0; | |
196 | |
197 // Get the view's window's position on the screen. | |
198 virtual gfx::Rect GetRootWindowRect() = 0; | |
199 | |
200 // Set the view's active state (i.e., tint state of controls). | |
201 virtual void SetActive(bool active) = 0; | |
202 | |
203 // Notifies the view that its enclosing window has changed visibility | |
204 // (minimized/unminimized, app hidden/unhidden, etc). | |
205 // TODO(stuartmorgan): This is a temporary plugin-specific workaround for | |
206 // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding | |
207 // message and renderer-side handling) can be removed in favor of using | |
208 // WasHidden/DidBecomeSelected. | |
209 virtual void SetWindowVisibility(bool visible) = 0; | |
210 | |
211 // Informs the view that its containing window's frame changed. | |
212 virtual void WindowFrameChanged() = 0; | |
213 | |
214 // Informs the view that a plugin gained or lost focus. | |
215 virtual void PluginFocusChanged(bool focused, int plugin_id) = 0; | |
216 | |
217 // Start plugin IME. | |
218 virtual void StartPluginIme() = 0; | |
219 | |
220 // Does any event handling necessary for plugin IME; should be called after | |
221 // the plugin has already had a chance to process the event. If plugin IME is | |
222 // not enabled, this is a no-op, so it is always safe to call. | |
223 // Returns true if the event was handled by IME. | |
224 virtual bool PostProcessEventForPluginIme( | |
225 const NativeWebKeyboardEvent& event) = 0; | |
226 | |
227 // Methods associated with GPU-accelerated plug-in instances. | |
228 virtual gfx::PluginWindowHandle AllocateFakePluginWindowHandle( | |
229 bool opaque, bool root) = 0; | |
230 virtual void DestroyFakePluginWindowHandle( | |
231 gfx::PluginWindowHandle window) = 0; | |
232 virtual void AcceleratedSurfaceSetIOSurface( | |
233 gfx::PluginWindowHandle window, | |
234 int32 width, | |
235 int32 height, | |
236 uint64 io_surface_identifier) = 0; | |
237 virtual void AcceleratedSurfaceSetTransportDIB( | |
238 gfx::PluginWindowHandle window, | |
239 int32 width, | |
240 int32 height, | |
241 TransportDIB::Handle transport_dib) = 0; | |
242 // |window| and |surface_id| indicate which accelerated surface's | |
243 // buffers swapped. |renderer_id|, |route_id| and | |
244 // |swap_buffers_count| are used to formulate a reply to the GPU | |
245 // process to prevent it from getting too far ahead. They may all be | |
246 // zero, in which case no flow control is enforced; this case is | |
247 // currently used for accelerated plugins. | |
248 virtual void AcceleratedSurfaceBuffersSwapped( | |
249 gfx::PluginWindowHandle window, | |
250 uint64 surface_id, | |
251 int renderer_id, | |
252 int32 route_id, | |
253 uint64 swap_buffers_count) = 0; | |
254 virtual void GpuRenderingStateDidChange() = 0; | |
255 #endif | |
256 | |
257 #if defined(TOOLKIT_USES_GTK) | |
258 virtual void CreatePluginContainer(gfx::PluginWindowHandle id) = 0; | |
259 virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) = 0; | |
260 virtual void AcceleratedCompositingActivated(bool activated) = 0; | |
261 #endif | |
262 | |
263 #if defined(OS_WIN) | |
264 virtual void WillWmDestroy() = 0; | |
265 virtual void ShowCompositorHostWindow(bool show) = 0; | |
266 #endif | |
267 | |
268 virtual gfx::PluginWindowHandle AcquireCompositingSurface() = 0; | |
269 virtual void ReleaseCompositingSurface(gfx::PluginWindowHandle surface) = 0; | |
270 | |
271 // Toggles visual muting of the render view area. This is on when a | |
272 // constrained window is showing, for example. |color| is the shade of | |
273 // the overlay that covers the render view. If |animate| is true, the overlay | |
274 // gradually fades in; otherwise it takes effect immediately. To remove the | |
275 // fade effect, pass a NULL value for |color|. In this case, |animate| is | |
276 // ignored. | |
277 virtual void SetVisuallyDeemphasized(const SkColor* color, bool animate) = 0; | |
278 | |
279 void set_popup_type(WebKit::WebPopupType popup_type) { | |
280 popup_type_ = popup_type; | |
281 } | |
282 WebKit::WebPopupType popup_type() const { return popup_type_; } | |
283 | |
284 // Subclasses should override this method to do what is appropriate to set | |
285 // the custom background for their platform. | |
286 virtual void SetBackground(const SkBitmap& background); | |
287 const SkBitmap& background() const { return background_; } | |
288 | |
289 // Returns true if the native view, |native_view|, is contained within in the | |
290 // widget associated with this RenderWidgetHostView. | |
291 virtual bool ContainsNativeView(gfx::NativeView native_view) const = 0; | |
292 | |
293 virtual void UpdateAccessibilityTree( | |
294 const webkit_glue::WebAccessibility& tree) { } | |
295 virtual void OnAccessibilityNotifications( | |
296 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { | |
297 } | |
298 | |
299 gfx::Rect reserved_contents_rect() const { | |
300 return reserved_rect_; | |
301 } | |
302 void set_reserved_contents_rect(const gfx::Rect& reserved_rect) { | |
303 reserved_rect_ = reserved_rect; | |
304 } | |
305 | |
306 protected: | |
307 // Interface class only, do not construct. | |
308 RenderWidgetHostView() : popup_type_(WebKit::WebPopupTypeNone) {} | |
309 | |
310 // Whether this view is a popup and what kind of popup it is (select, | |
311 // autofill...). | |
312 WebKit::WebPopupType popup_type_; | |
313 | |
314 // A custom background to paint behind the web content. This will be tiled | |
315 // horizontally. Can be null, in which case we fall back to painting white. | |
316 SkBitmap background_; | |
317 | |
318 // The current reserved area in view coordinates where contents should not be | |
319 // rendered to draw the resize corner, sidebar mini tabs etc. | |
320 gfx::Rect reserved_rect_; | |
321 | |
322 private: | |
323 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostView); | |
324 }; | |
325 | 11 |
326 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ | 12 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ |
OLD | NEW |