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