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 RenderWidgetHost
;
23 class RenderWidgetHostImpl
;
24 class BrowserPluginGuest
;
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 // 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 SetBackgroundOpaque(bool opaque
) OVERRIDE
;
57 virtual gfx::Size
GetPhysicalBackingSize() const OVERRIDE
;
58 virtual base::string16
GetSelectedText() const OVERRIDE
;
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
;
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
,
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
;
110 virtual bool LockMouse() OVERRIDE
;
111 virtual void UnlockMouse() OVERRIDE
;
112 virtual void GetScreenInfo(blink::WebScreenInfo
* results
) OVERRIDE
;
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
;
126 // RenderWidgetHostViewBase implementation.
127 virtual bool PostProcessEventForPluginIme(
128 const NativeWebKeyboardEvent
& event
) OVERRIDE
;
129 #endif // defined(OS_MACOSX)
131 #if defined(OS_ANDROID)
132 // RenderWidgetHostViewBase implementation.
133 virtual void ShowDisambiguationPopup(const gfx::Rect
& target_rect
,
134 const SkBitmap
& zoomed_bitmap
) OVERRIDE
;
135 virtual void LockCompositingSurface() OVERRIDE
;
136 virtual void UnlockCompositingSurface() OVERRIDE
;
137 #endif // defined(OS_ANDROID)
140 virtual void SetParentNativeViewAccessible(
141 gfx::NativeViewAccessible accessible_parent
) OVERRIDE
;
142 virtual gfx::NativeViewId
GetParentForWindowlessPlugin() const OVERRIDE
;
145 // Overridden from ui::GestureEventHelper.
146 virtual bool CanDispatchToConsumer(ui::GestureConsumer
* consumer
) OVERRIDE
;
147 virtual void DispatchGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
148 virtual void DispatchCancelTouchEvent(ui::TouchEvent
* event
) OVERRIDE
;
150 virtual SkBitmap::Config
PreferredReadbackFormat() OVERRIDE
;
153 friend class RenderWidgetHostView
;
156 // Destroys this view without calling |Destroy| on |platform_view_|.
157 void DestroyGuestView();
159 // Builds and forwards a WebKitGestureEvent to the renderer.
160 bool ForwardGestureEventToRenderer(ui::GestureEvent
* gesture
);
162 // Process all of the given gestures (passes them on to renderer)
163 void ProcessGestures(ui::GestureRecognizer::Gestures
* gestures
);
165 RenderWidgetHostViewBase
* GetGuestRenderWidgetHostView() const;
167 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
168 // to one another, therefore we access |guest_| through WeakPtr.
169 base::WeakPtr
<BrowserPluginGuest
> guest_
;
171 // The platform view for this RenderWidgetHostView.
172 // RenderWidgetHostViewGuest mostly only cares about stuff related to
173 // compositing, the rest are directly forwared to this |platform_view_|.
174 RenderWidgetHostViewBase
* platform_view_
;
175 #if defined(USE_AURA)
176 scoped_ptr
<ui::GestureRecognizer
> gesture_recognizer_
;
178 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest
);
181 } // namespace content
183 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_