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