Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view.h

Issue 9347042: Introduce content::RenderWidgetHostViewPort (in content/port/browser). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_
7 #pragma once 7 #pragma once
8 8
9 #if defined(OS_MACOSX) 9 // TODO(joi): Remove this placeholder file.
10 #include <OpenGL/OpenGL.h>
11 #endif
12 10
13 #if defined(TOOLKIT_USES_GTK) 11 #include "content/browser/renderer_host/render_widget_host_view_base.h"
14 #include <gdk/gdk.h>
15 #endif
16
17 #include <string>
18 #include <vector>
19
20 #include "base/memory/scoped_ptr.h"
21 #include "base/process_util.h"
22 #include "base/callback_forward.h"
23 #include "content/common/content_export.h"
24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "third_party/skia/include/core/SkColor.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
28 #include "ui/base/ime/text_input_type.h"
29 #include "ui/base/range/range.h"
30 #include "ui/gfx/native_widget_types.h"
31 #include "ui/gfx/surface/transport_dib.h"
32
33 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
34 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
35
36 class BackingStore;
37 class BrowserAccessibilityManager;
38 class RenderWidgetHost;
39 class WebCursor;
40 struct AccessibilityHostMsg_NotificationParams;
41 struct NativeWebKeyboardEvent;
42
43 namespace content {
44 class RenderProcessHost;
45 }
46
47 namespace gfx {
48 class Rect;
49 class Size;
50 }
51
52 namespace webkit {
53 namespace npapi {
54 struct WebPluginGeometry;
55 }
56 }
57
58 #if defined(OS_POSIX) || defined(USE_AURA)
59 namespace WebKit {
60 struct WebScreenInfo;
61 }
62 #endif
63
64 // RenderWidgetHostView is an interface implemented by an object that acts as
65 // the "View" portion of a RenderWidgetHost. The RenderWidgetHost and its
66 // associated RenderProcessHost own the "Model" in this case which is the
67 // child renderer process. The View is responsible for receiving events from
68 // the surrounding environment and passing them to the RenderWidgetHost, and
69 // for actually displaying the content of the RenderWidgetHost when it
70 // changes.
71 //
72 // TODO(joi): Move this to content/public/browser
73 class CONTENT_EXPORT RenderWidgetHostView {
74 public:
75 virtual ~RenderWidgetHostView();
76
77 // Platform-specific creator. Use this to construct new RenderWidgetHostViews
78 // rather than using RenderWidgetHostViewWin & friends.
79 //
80 // This function must NOT size it, because the RenderView in the renderer
81 // wouldn't have been created yet. The widget would set its "waiting for
82 // resize ack" flag, and the ack would never come becasue no RenderView
83 // received it.
84 //
85 // The RenderWidgetHost must already be created (because we can't know if it's
86 // going to be a regular RenderWidgetHost or a RenderViewHost (a subclass).
87 static RenderWidgetHostView* CreateViewForWidget(
88 RenderWidgetHost* widget);
89
90 // Initialize this object for use as a drawing area. |parent_view| may be
91 // left as NULL on platforms where a parent view is not required to initialize
92 // a child window.
93 virtual void InitAsChild(gfx::NativeView parent_view) = 0;
94
95 // Returns the associated RenderWidgetHost.
96 virtual RenderWidgetHost* GetRenderWidgetHost() const = 0;
97
98 // Tells the View to size itself to the specified size.
99 virtual void SetSize(const gfx::Size& size) = 0;
100
101 // Tells the View to size and move itself to the specified size and point in
102 // screen space.
103 virtual void SetBounds(const gfx::Rect& rect) = 0;
104
105 // Retrieves the native view used to contain plugins and identify the
106 // renderer in IPC messages.
107 virtual gfx::NativeView GetNativeView() const = 0;
108 virtual gfx::NativeViewId GetNativeViewId() const = 0;
109 virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0;
110
111 // Set focus to the associated View component.
112 virtual void Focus() = 0;
113 // Returns true if the View currently has the focus.
114 virtual bool HasFocus() const = 0;
115
116 // Shows/hides the view. These must always be called together in pairs.
117 // It is not legal to call Hide() multiple times in a row.
118 virtual void Show() = 0;
119 virtual void Hide() = 0;
120
121 // Whether the view is showing.
122 virtual bool IsShowing() = 0;
123
124 // Retrieve the bounds of the View, in screen coordinates.
125 virtual gfx::Rect GetViewBounds() const = 0;
126
127 // Returns true if the View's context menu is showing.
128 virtual bool IsShowingContextMenu() const = 0;
129
130 // Tells the View whether the context menu is showing.
131 virtual void SetShowingContextMenu(bool showing) = 0;
132
133 #if defined(OS_MACOSX)
134 // Set the view's active state (i.e., tint state of controls).
135 virtual void SetActive(bool active) = 0;
136
137 // Tells the view whether or not to accept first responder status. If |flag|
138 // is true, the view does not accept first responder status and instead
139 // manually becomes first responder when it receives a mouse down event. If
140 // |flag| is false, the view participates in the key-view chain as normal.
141 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0;
142
143 // Notifies the view that its enclosing window has changed visibility
144 // (minimized/unminimized, app hidden/unhidden, etc).
145 // TODO(stuartmorgan): This is a temporary plugin-specific workaround for
146 // <http://crbug.com/34266>. Once that is fixed, this (and the corresponding
147 // message and renderer-side handling) can be removed in favor of using
148 // WasHidden/DidBecomeSelected.
149 virtual void SetWindowVisibility(bool visible) = 0;
150
151 // Informs the view that its containing window's frame changed.
152 virtual void WindowFrameChanged() = 0;
153 #endif // defined(OS_MACOSX)
154
155 #if defined(TOOLKIT_USES_GTK)
156 // Gets the event for the last mouse down.
157 virtual GdkEventButton* GetLastMouseDown() = 0;
158 #if !defined(TOOLKIT_VIEWS)
159 // Builds a submenu containing all the gtk input method commands.
160 virtual gfx::NativeView BuildInputMethodsGtkMenu() = 0;
161 #endif // !defined(TOOLKIT_VIEWS)
162 #endif // defined(TOOLKIT_USES_GTK)
163
164 // TODO(joi): May be able to move into impl if RWHVMacDelegate stops
165 // being exposed to Chrome.
166 virtual void UnhandledWheelEvent(const WebKit::WebMouseWheelEvent& event) = 0;
167
168 // Subclasses should override this method to do what is appropriate to set
169 // the custom background for their platform.
170 virtual void SetBackground(const SkBitmap& background) = 0;
171 virtual const SkBitmap& GetBackground() = 0;
172
173 // TODO(joi): Remove this when we remove the dependency by chrome/
174 // on browser_accessibility* files in content.
175 virtual BrowserAccessibilityManager*
176 GetBrowserAccessibilityManager() const = 0;
177
178 protected:
179 RenderWidgetHostView();
180
181 private:
182 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostView);
183 };
184
185 // This is the larger RenderWidgetHostView interface exposed only
186 // within content/, plus some basic implementation.
187 //
188 // TODO(joi): Extract a pure virtual interface from these additional
189 // methods (named RenderWidgetHostViewPort?), move it to content/port,
190 // and have content/ use that interface everywhere except where it is
191 // using concrete implementation classes. The RWHVBase class might
192 // still exist for shared implementation between existing concrete
193 // implementations.
194 class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView {
195 public:
196 virtual ~RenderWidgetHostViewBase();
197
198 // Does the cast for you.
199 static RenderWidgetHostViewBase* FromRWHV(RenderWidgetHostView* rwhv);
200
201 // Convenience function instead of
202 // RenderWidgetHostView::CreateViewForWidget if you want a
203 // RenderWidgetHostViewBase.
204 static RenderWidgetHostViewBase* CreateViewForWidget(
205 RenderWidgetHost* widget);
206
207 // Perform all the initialization steps necessary for this object to represent
208 // a popup (such as a <select> dropdown), then shows the popup at |pos|.
209 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
210 const gfx::Rect& pos) = 0;
211
212 // Perform all the initialization steps necessary for this object to represent
213 // a full screen window.
214 // |reference_host_view| is the view associated with the creating page that
215 // helps to position the full screen widget on the correct monitor.
216 virtual void InitAsFullscreen(
217 RenderWidgetHostView* reference_host_view) = 0;
218
219 // Notifies the View that it has become visible.
220 virtual void DidBecomeSelected() = 0;
221
222 // Notifies the View that it has been hidden.
223 virtual void WasHidden() = 0;
224
225 // Moves all plugin windows as described in the given list.
226 virtual void MovePluginWindows(
227 const std::vector<webkit::npapi::WebPluginGeometry>& moves) = 0;
228
229 // Take focus from the associated View component.
230 virtual void Blur() = 0;
231
232 // Sets the cursor to the one associated with the specified cursor_type
233 virtual void UpdateCursor(const WebCursor& cursor) = 0;
234
235 // Indicates whether the page has finished loading.
236 virtual void SetIsLoading(bool is_loading) = 0;
237
238 // Updates the state of the input method attached to the view.
239 virtual void TextInputStateChanged(ui::TextInputType type,
240 bool can_compose_inline) = 0;
241
242 // Cancel the ongoing composition of the input method attached to the view.
243 virtual void ImeCancelComposition() = 0;
244
245 // Updates the range of the marked text in an IME composition.
246 virtual void ImeCompositionRangeChanged(const ui::Range& range) {}
247
248 // Informs the view that a portion of the widget's backing store was scrolled
249 // and/or painted. The view should ensure this gets copied to the screen.
250 //
251 // If the scroll_rect is non-empty, then a portion of the widget's backing
252 // store was scrolled by dx pixels horizontally and dy pixels vertically.
253 // The exposed rect from the scroll operation is included in copy_rects.
254 //
255 // There are subtle performance implications here. The RenderWidget gets sent
256 // a paint ack after this returns, so if the view only ever invalidates in
257 // response to this, then on Windows, where WM_PAINT has lower priority than
258 // events which can cause renderer resizes/paint rect updates, e.g.
259 // drag-resizing can starve painting; this function thus provides the view its
260 // main chance to ensure it stays painted and not just invalidated. On the
261 // other hand, if this always blindly paints, then if we're already in the
262 // midst of a paint on the callstack, we can double-paint unnecessarily.
263 // (Worse, we might recursively call RenderWidgetHost::GetBackingStore().)
264 // Thus implementers should generally paint as much of |rect| as possible
265 // synchronously with as little overpainting as possible.
266 virtual void DidUpdateBackingStore(
267 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
268 const std::vector<gfx::Rect>& copy_rects) = 0;
269
270 // Notifies the View that the renderer has ceased to exist.
271 virtual void RenderViewGone(base::TerminationStatus status,
272 int error_code) = 0;
273
274 // Tells the View to destroy itself.
275 virtual void Destroy() = 0;
276
277 // Tells the View that the tooltip text for the current mouse position over
278 // the page has changed.
279 virtual void SetTooltipText(const string16& tooltip_text) = 0;
280
281 // Notifies the View that the renderer text selection has changed.
282 virtual void SelectionChanged(const string16& text,
283 size_t offset,
284 const ui::Range& range);
285
286 // Notifies the View that the renderer selection bounds has changed.
287 // |start_rect| and |end_rect| are the bounds end of the selection in the
288 // coordinate system of the render view.
289 virtual void SelectionBoundsChanged(const gfx::Rect& start_rect,
290 const gfx::Rect& end_rect) {}
291
292 // Allocate a backing store for this view.
293 virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0;
294
295 // Called when accelerated compositing state changes.
296 virtual void OnAcceleratedCompositingStateChange() = 0;
297 // |params.window| and |params.surface_id| indicate which accelerated
298 // surface's buffers swapped. |params.renderer_id| and |params.route_id|
299 // are used to formulate a reply to the GPU process to prevent it from getting
300 // too far ahead. They may all be zero, in which case no flow control is
301 // enforced; this case is currently used for accelerated plugins.
302 virtual void AcceleratedSurfaceBuffersSwapped(
303 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
304 int gpu_host_id) = 0;
305 // Similar to above, except |params.(x|y|width|height)| define the region
306 // of the surface that changed.
307 virtual void AcceleratedSurfacePostSubBuffer(
308 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
309 int gpu_host_id) = 0;
310
311 // Release the accelerated surface temporarily. It will be recreated on the
312 // next swap buffers or post sub buffer.
313 virtual void AcceleratedSurfaceSuspend() = 0;
314
315 #if defined(OS_MACOSX)
316 // Retrieve the bounds of the view, in cocoa view coordinates.
317 // If the UI scale factor is 2, |GetViewBounds()| will return a size of e.g.
318 // (400, 300) in pixels, while this method will return (200, 150).
319 // Even though this returns an gfx::Rect, the result is NOT IN PIXELS.
320 virtual gfx::Rect GetViewCocoaBounds() const = 0;
321
322 // Informs the view that a plugin gained or lost focus.
323 virtual void PluginFocusChanged(bool focused, int plugin_id) = 0;
324
325 // Start plugin IME.
326 virtual void StartPluginIme() = 0;
327
328 // Does any event handling necessary for plugin IME; should be called after
329 // the plugin has already had a chance to process the event. If plugin IME is
330 // not enabled, this is a no-op, so it is always safe to call.
331 // Returns true if the event was handled by IME.
332 virtual bool PostProcessEventForPluginIme(
333 const NativeWebKeyboardEvent& event) = 0;
334
335 // Methods associated with GPU-accelerated plug-in instances.
336 virtual gfx::PluginWindowHandle AllocateFakePluginWindowHandle(
337 bool opaque, bool root) = 0;
338 virtual void DestroyFakePluginWindowHandle(
339 gfx::PluginWindowHandle window) = 0;
340 virtual void AcceleratedSurfaceSetIOSurface(
341 gfx::PluginWindowHandle window,
342 int32 width,
343 int32 height,
344 uint64 io_surface_identifier) = 0;
345 virtual void AcceleratedSurfaceSetTransportDIB(
346 gfx::PluginWindowHandle window,
347 int32 width,
348 int32 height,
349 TransportDIB::Handle transport_dib) = 0;
350 #endif
351
352 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
353 virtual void AcceleratedSurfaceNew(
354 int32 width,
355 int32 height,
356 uint64* surface_id,
357 TransportDIB::Handle* surface_handle) = 0;
358 virtual void AcceleratedSurfaceRelease(uint64 surface_id) = 0;
359 #endif
360
361 #if defined(TOOLKIT_USES_GTK)
362 virtual void CreatePluginContainer(gfx::PluginWindowHandle id) = 0;
363 virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) = 0;
364 #endif // defined(TOOLKIT_USES_GTK)
365
366 #if defined(OS_WIN) && !defined(USE_AURA)
367 virtual void WillWmDestroy() = 0;
368 #endif
369
370 #if defined(OS_POSIX) || defined(USE_AURA)
371 static void GetDefaultScreenInfo(
372 WebKit::WebScreenInfo* results);
373 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) = 0;
374 virtual gfx::Rect GetRootWindowBounds() = 0;
375 #endif
376
377 virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0;
378
379 // Because the associated remote WebKit instance can asynchronously
380 // prevent-default on a dispatched touch event, the touch events are queued in
381 // the GestureRecognizer until invocation of ProcessTouchAck releases it to be
382 // processed (when |processed| is false) or ignored (when |processed| is true)
383 virtual void ProcessTouchAck(bool processed) = 0;
384
385 virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar) = 0;
386 virtual void SetScrollOffsetPinning(
387 bool is_pinned_to_left, bool is_pinned_to_right) = 0;
388
389 // Return value indicates whether the mouse is locked successfully or not.
390 virtual bool LockMouse() = 0;
391 virtual void UnlockMouse() = 0;
392
393 virtual void OnAccessibilityNotifications(
394 const std::vector<AccessibilityHostMsg_NotificationParams>& params) {
395 }
396
397 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
398 virtual const SkBitmap& GetBackground() OVERRIDE;
399
400 virtual bool IsShowingContextMenu() const OVERRIDE;
401 virtual void SetShowingContextMenu(bool) OVERRIDE;
402
403 virtual BrowserAccessibilityManager*
404 GetBrowserAccessibilityManager() const OVERRIDE;
405
406 void set_popup_type(WebKit::WebPopupType popup_type) {
407 popup_type_ = popup_type;
408 }
409 WebKit::WebPopupType popup_type() const { return popup_type_; }
410
411 void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager);
412
413 bool mouse_locked() const { return mouse_locked_; }
414
415 protected:
416 // Interface class only, do not construct.
417 RenderWidgetHostViewBase();
418
419 // Whether this view is a popup and what kind of popup it is (select,
420 // autofill...).
421 WebKit::WebPopupType popup_type_;
422
423 // A custom background to paint behind the web content. This will be tiled
424 // horizontally. Can be null, in which case we fall back to painting white.
425 SkBitmap background_;
426
427 // While the mouse is locked, the cursor is hidden from the user. Mouse events
428 // are still generated. However, the position they report is the last known
429 // mouse position just as mouse lock was entered; the movement they report
430 // indicates what the change in position of the mouse would be had it not been
431 // locked.
432 bool mouse_locked_;
433
434 // Whether we are showing a context menu.
435 bool showing_context_menu_;
436
437 // A buffer containing the text inside and around the current selection range.
438 string16 selection_text_;
439
440 // The offset of the text stored in |selection_text_| relative to the start of
441 // the web page.
442 size_t selection_text_offset_;
443
444 // The current selection range relative to the start of the web page.
445 ui::Range selection_range_;
446
447 private:
448 // Manager of the tree representation of the WebKit render tree.
449 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
450
451 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase);
452 };
453 12
454 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_ 13 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_unittest.cc ('k') | content/browser/renderer_host/render_widget_host_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698