render_widget_host_view_guest.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
6#define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
7
8#include <vector>
9
10#include "base/memory/scoped_ptr.h"
11#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
12#include "content/common/content_export.h"
13#include "content/common/cursors/webcursor.h"
14#include "ui/events/event.h"
15#include "ui/events/gestures/gesture_recognizer.h"
16#include "ui/events/gestures/gesture_types.h"
17#include "ui/gfx/native_widget_types.h"
18#include "ui/gfx/rect.h"
19#include "ui/gfx/vector2d_f.h"
20
21struct ViewHostMsg_TextInputState_Params;
22
23namespace content {
24class RenderWidgetHost;
25class RenderWidgetHostImpl;
26class BrowserPluginGuest;
27struct NativeWebKeyboardEvent;
28
29// See comments in render_widget_host_view.h about this class and its members.
30// This version is for the BrowserPlugin which handles a lot of the
31// functionality in a diffent place and isn't platform specific.
32// The BrowserPlugin is currently a special case for out-of-process rendered
33// content and therefore inherits from RenderWidgetHostViewChildFrame.
34// Eventually all RenderWidgetHostViewGuest code will be subsumed by
35// RenderWidgetHostViewChildFrame and this class will be removed.
36//
37// Some elements that are platform specific will be deal with by delegating
38// the relevant calls to the platform view.
39class CONTENT_EXPORT RenderWidgetHostViewGuest
40    : public RenderWidgetHostViewChildFrame,
41      public ui::GestureConsumer,
42      public ui::GestureEventHelper {
43 public:
44  RenderWidgetHostViewGuest(RenderWidgetHost* widget,
45                            BrowserPluginGuest* guest,
46                            RenderWidgetHostViewBase* platform_view);
47  virtual ~RenderWidgetHostViewGuest();
48
49  // RenderWidgetHostView implementation.
50  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
51  virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
52  virtual void SetSize(const gfx::Size& size) OVERRIDE;
53  virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
54  virtual gfx::NativeView GetNativeView() const OVERRIDE;
55  virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
56  virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
57  virtual gfx::Rect GetViewBounds() const OVERRIDE;
58  virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
59  virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
60  virtual base::string16 GetSelectedText() const OVERRIDE;
61
62  // RenderWidgetHostViewBase implementation.
63  virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
64                           const gfx::Rect& pos) OVERRIDE;
65  virtual void InitAsFullscreen(
66      RenderWidgetHostView* reference_host_view) OVERRIDE;
67  virtual void WasShown() OVERRIDE;
68  virtual void WasHidden() OVERRIDE;
69  virtual void MovePluginWindows(
70      const std::vector<WebPluginGeometry>& moves) OVERRIDE;
71  virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
72  virtual void SetIsLoading(bool is_loading) OVERRIDE;
73  virtual void TextInputStateChanged(
74      const ViewHostMsg_TextInputState_Params& params) OVERRIDE;
75  virtual void ImeCancelComposition() OVERRIDE;
76#if defined(OS_MACOSX) || defined(USE_AURA)
77  virtual void ImeCompositionRangeChanged(
78      const gfx::Range& range,
79      const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
80#endif
81  virtual void RenderProcessGone(base::TerminationStatus status,
82                                 int error_code) OVERRIDE;
83  virtual void Destroy() OVERRIDE;
84  virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
85  virtual void SelectionChanged(const base::string16& text,
86                                size_t offset,
87                                const gfx::Range& range) OVERRIDE;
88  virtual void SelectionBoundsChanged(
89      const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
90  virtual void CopyFromCompositingSurface(
91      const gfx::Rect& src_subrect,
92      const gfx::Size& dst_size,
93      const base::Callback<void(bool, const SkBitmap&)>& callback,
94      const SkBitmap::Config config) OVERRIDE;
95  virtual void AcceleratedSurfaceBuffersSwapped(
96      const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
97      int gpu_host_id) OVERRIDE;
98  virtual void AcceleratedSurfacePostSubBuffer(
99      const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
100      int gpu_host_id) OVERRIDE;
101  virtual void OnSwapCompositorFrame(
102      uint32 output_surface_id,
103      scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
104#if defined(USE_AURA)
105  virtual void ProcessAckedTouchEvent(
106      const TouchEventWithLatencyInfo& touch,
107      InputEventAckState ack_result) OVERRIDE;
108#endif
109  virtual bool LockMouse() OVERRIDE;
110  virtual void UnlockMouse() OVERRIDE;
111  virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
112
113#if defined(OS_MACOSX)
114  // RenderWidgetHostView implementation.
115  virtual void SetActive(bool active) OVERRIDE;
116  virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
117  virtual void SetWindowVisibility(bool visible) OVERRIDE;
118  virtual void WindowFrameChanged() OVERRIDE;
119  virtual void ShowDefinitionForSelection() OVERRIDE;
120  virtual bool SupportsSpeech() const OVERRIDE;
121  virtual void SpeakSelection() OVERRIDE;
122  virtual bool IsSpeaking() const OVERRIDE;
123  virtual void StopSpeaking() OVERRIDE;
124
125  // RenderWidgetHostViewBase implementation.
126  virtual bool PostProcessEventForPluginIme(
127      const NativeWebKeyboardEvent& event) OVERRIDE;
128#endif  // defined(OS_MACOSX)
129
130#if defined(OS_ANDROID)
131  // RenderWidgetHostViewBase implementation.
132  virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
133                                       const SkBitmap& zoomed_bitmap) OVERRIDE;
134  virtual void LockCompositingSurface() OVERRIDE;
135  virtual void UnlockCompositingSurface() OVERRIDE;
136#endif  // defined(OS_ANDROID)
137
138#if defined(OS_WIN)
139  virtual void SetParentNativeViewAccessible(
140      gfx::NativeViewAccessible accessible_parent) OVERRIDE;
141  virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE;
142#endif
143
144  // Overridden from ui::GestureEventHelper.
145  virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
146  virtual void DispatchGestureEvent(ui::GestureEvent* event) OVERRIDE;
147  virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
148
149  virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
150
151 protected:
152  friend class RenderWidgetHostView;
153
154 private:
155  // Destroys this view without calling |Destroy| on |platform_view_|.
156  void DestroyGuestView();
157
158  // Builds and forwards a WebKitGestureEvent to the renderer.
159  bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture);
160
161  // Process all of the given gestures (passes them on to renderer)
162  void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
163
164  RenderWidgetHostViewBase* GetGuestRenderWidgetHostView() const;
165
166  // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
167  // to one another, therefore we access |guest_| through WeakPtr.
168  base::WeakPtr<BrowserPluginGuest> guest_;
169  gfx::Size size_;
170  // The platform view for this RenderWidgetHostView.
171  // RenderWidgetHostViewGuest mostly only cares about stuff related to
172  // compositing, the rest are directly forwared to this |platform_view_|.
173  RenderWidgetHostViewBase* platform_view_;
174#if defined(USE_AURA)
175  scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
176#endif
177  DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest);
178};
179
180}  // namespace content
181
182#endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
183