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