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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
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"
22 class BrowserPluginGuest;
23 class RenderWidgetHost;
24 class RenderWidgetHostImpl;
25 struct NativeWebKeyboardEvent;
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.
35 // Some elements that are platform specific will be deal with by delegating
36 // the relevant calls to the platform view.
37 class CONTENT_EXPORT RenderWidgetHostViewGuest
38 : public RenderWidgetHostViewChildFrame,
39 public ui::GestureConsumer,
40 public ui::GestureEventHelper {
42 RenderWidgetHostViewGuest(RenderWidgetHost* widget,
43 BrowserPluginGuest* guest,
44 RenderWidgetHostViewBase* platform_view);
45 virtual ~RenderWidgetHostViewGuest();
47 bool OnMessageReceivedFromEmbedder(const IPC::Message& message,
48 RenderWidgetHostImpl* embedder);
50 // RenderWidgetHostView implementation.
51 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
52 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
53 virtual void SetSize(const gfx::Size& size) OVERRIDE;
54 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
55 virtual void Focus() OVERRIDE;
56 virtual bool HasFocus() const OVERRIDE;
57 virtual gfx::NativeView GetNativeView() const OVERRIDE;
58 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
59 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
60 virtual gfx::Rect GetViewBounds() const OVERRIDE;
61 virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
62 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
63 virtual base::string16 GetSelectedText() const OVERRIDE;
65 // RenderWidgetHostViewBase implementation.
66 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
67 const gfx::Rect& pos) OVERRIDE;
68 virtual void InitAsFullscreen(
69 RenderWidgetHostView* reference_host_view) OVERRIDE;
70 virtual void WasShown() OVERRIDE;
71 virtual void WasHidden() OVERRIDE;
72 virtual void MovePluginWindows(
73 const std::vector<WebPluginGeometry>& moves) OVERRIDE;
74 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
75 virtual void SetIsLoading(bool is_loading) OVERRIDE;
76 virtual void TextInputTypeChanged(ui::TextInputType type,
77 ui::TextInputMode input_mode,
78 bool can_compose_inline) OVERRIDE;
79 virtual void ImeCancelComposition() OVERRIDE;
80 #if defined(OS_MACOSX) || defined(USE_AURA)
81 virtual void ImeCompositionRangeChanged(
82 const gfx::Range& range,
83 const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
85 virtual void RenderProcessGone(base::TerminationStatus status,
86 int error_code) OVERRIDE;
87 virtual void Destroy() OVERRIDE;
88 virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
89 virtual void SelectionChanged(const base::string16& text,
91 const gfx::Range& range) OVERRIDE;
92 virtual void SelectionBoundsChanged(
93 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
94 virtual void CopyFromCompositingSurface(
95 const gfx::Rect& src_subrect,
96 const gfx::Size& dst_size,
97 CopyFromCompositingSurfaceCallback& callback,
98 const SkColorType color_type) OVERRIDE;
99 virtual void AcceleratedSurfaceBuffersSwapped(
100 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
101 int gpu_host_id) OVERRIDE;
102 virtual void AcceleratedSurfacePostSubBuffer(
103 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
104 int gpu_host_id) OVERRIDE;
105 virtual void OnSwapCompositorFrame(
106 uint32 output_surface_id,
107 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
108 #if defined(USE_AURA)
109 virtual void ProcessAckedTouchEvent(
110 const TouchEventWithLatencyInfo& touch,
111 InputEventAckState ack_result) OVERRIDE;
113 virtual bool LockMouse() OVERRIDE;
114 virtual void UnlockMouse() OVERRIDE;
115 virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
117 #if defined(OS_MACOSX)
118 // RenderWidgetHostView implementation.
119 virtual void SetActive(bool active) OVERRIDE;
120 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
121 virtual void SetWindowVisibility(bool visible) OVERRIDE;
122 virtual void WindowFrameChanged() OVERRIDE;
123 virtual void ShowDefinitionForSelection() OVERRIDE;
124 virtual bool SupportsSpeech() const OVERRIDE;
125 virtual void SpeakSelection() OVERRIDE;
126 virtual bool IsSpeaking() const OVERRIDE;
127 virtual void StopSpeaking() OVERRIDE;
129 // RenderWidgetHostViewBase implementation.
130 virtual bool PostProcessEventForPluginIme(
131 const NativeWebKeyboardEvent& event) OVERRIDE;
132 #endif // defined(OS_MACOSX)
134 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
135 // RenderWidgetHostViewBase implementation.
136 virtual void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
137 const SkBitmap& zoomed_bitmap) OVERRIDE;
138 #endif // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
140 #if defined(OS_ANDROID)
141 virtual void LockCompositingSurface() OVERRIDE;
142 virtual void UnlockCompositingSurface() OVERRIDE;
143 #endif // defined(OS_ANDROID)
146 virtual void SetParentNativeViewAccessible(
147 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
148 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE;
151 // Overridden from ui::GestureEventHelper.
152 virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
153 virtual void DispatchGestureEvent(ui::GestureEvent* event) OVERRIDE;
154 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
156 virtual SkColorType PreferredReadbackFormat() OVERRIDE;
159 friend class RenderWidgetHostView;
162 // Destroys this view without calling |Destroy| on |platform_view_|.
163 void DestroyGuestView();
165 // Builds and forwards a WebKitGestureEvent to the renderer.
166 bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture);
168 // Process all of the given gestures (passes them on to renderer)
169 void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
171 RenderWidgetHostViewBase* GetGuestRenderWidgetHostView() const;
173 void OnHandleInputEvent(RenderWidgetHostImpl* embedder,
174 int browser_plugin_instance_id,
175 const gfx::Rect& guest_window_rect,
176 const blink::WebInputEvent* event);
178 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
179 // to one another, therefore we access |guest_| through WeakPtr.
180 base::WeakPtr<BrowserPluginGuest> guest_;
182 // The platform view for this RenderWidgetHostView.
183 // RenderWidgetHostViewGuest mostly only cares about stuff related to
184 // compositing, the rest are directly forwared to this |platform_view_|.
185 RenderWidgetHostViewBase* platform_view_;
186 #if defined(USE_AURA)
187 scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
189 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest);
192 } // namespace content
194 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_