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/geometry/rect.h"
18 #include "ui/gfx/geometry/vector2d_f.h"
19 #include "ui/gfx/native_widget_types.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(
45 RenderWidgetHost
* widget
,
46 BrowserPluginGuest
* guest
,
47 base::WeakPtr
<RenderWidgetHostViewBase
> platform_view
);
48 ~RenderWidgetHostViewGuest() override
;
50 bool OnMessageReceivedFromEmbedder(const IPC::Message
& message
,
51 RenderWidgetHostImpl
* embedder
);
53 // RenderWidgetHostView implementation.
54 bool OnMessageReceived(const IPC::Message
& msg
) override
;
55 void InitAsChild(gfx::NativeView parent_view
) override
;
56 void SetSize(const gfx::Size
& size
) override
;
57 void SetBounds(const gfx::Rect
& rect
) override
;
58 void Focus() override
;
59 bool HasFocus() const override
;
62 gfx::NativeView
GetNativeView() const override
;
63 gfx::NativeViewId
GetNativeViewId() const override
;
64 gfx::NativeViewAccessible
GetNativeViewAccessible() override
;
65 gfx::Rect
GetViewBounds() const override
;
66 void SetBackgroundColor(SkColor color
) override
;
67 gfx::Size
GetPhysicalBackingSize() const override
;
68 base::string16
GetSelectedText() const override
;
70 // RenderWidgetHostViewBase implementation.
71 void InitAsPopup(RenderWidgetHostView
* parent_host_view
,
72 const gfx::Rect
& bounds
) override
;
73 void InitAsFullscreen(RenderWidgetHostView
* reference_host_view
) override
;
74 void MovePluginWindows(const std::vector
<WebPluginGeometry
>& moves
) override
;
75 void UpdateCursor(const WebCursor
& cursor
) override
;
76 void SetIsLoading(bool is_loading
) override
;
77 void TextInputStateChanged(
78 const ViewHostMsg_TextInputState_Params
& params
) override
;
79 void ImeCancelComposition() override
;
80 #if defined(OS_MACOSX) || defined(USE_AURA)
81 void ImeCompositionRangeChanged(
82 const gfx::Range
& range
,
83 const std::vector
<gfx::Rect
>& character_bounds
) override
;
85 void RenderProcessGone(base::TerminationStatus status
,
86 int error_code
) override
;
87 void Destroy() override
;
88 void SetTooltipText(const base::string16
& tooltip_text
) override
;
89 void SelectionChanged(const base::string16
& text
,
91 const gfx::Range
& range
) override
;
92 void SelectionBoundsChanged(
93 const ViewHostMsg_SelectionBounds_Params
& params
) override
;
94 void OnSwapCompositorFrame(uint32 output_surface_id
,
95 scoped_ptr
<cc::CompositorFrame
> frame
) override
;
97 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo
& touch
,
98 InputEventAckState ack_result
) override
;
100 bool LockMouse() override
;
101 void UnlockMouse() override
;
102 void GetScreenInfo(blink::WebScreenInfo
* results
) override
;
104 #if defined(OS_MACOSX)
105 // RenderWidgetHostView implementation.
106 void SetActive(bool active
) override
;
107 void SetWindowVisibility(bool visible
) override
;
108 void WindowFrameChanged() override
;
109 void ShowDefinitionForSelection() override
;
110 bool SupportsSpeech() const override
;
111 void SpeakSelection() override
;
112 bool IsSpeaking() const override
;
113 void StopSpeaking() override
;
115 // RenderWidgetHostViewBase implementation.
116 bool PostProcessEventForPluginIme(
117 const NativeWebKeyboardEvent
& event
) override
;
118 #endif // defined(OS_MACOSX)
120 #if defined(OS_ANDROID) || defined(USE_AURA)
121 // RenderWidgetHostViewBase implementation.
122 void ShowDisambiguationPopup(const gfx::Rect
& rect_pixels
,
123 const SkBitmap
& zoomed_bitmap
) override
;
124 #endif // defined(OS_ANDROID) || defined(USE_AURA)
126 #if defined(OS_ANDROID)
127 void LockCompositingSurface() override
;
128 void UnlockCompositingSurface() override
;
129 #endif // defined(OS_ANDROID)
132 void SetParentNativeViewAccessible(
133 gfx::NativeViewAccessible accessible_parent
) override
;
134 gfx::NativeViewId
GetParentForWindowlessPlugin() const override
;
137 // Overridden from ui::GestureEventHelper.
138 bool CanDispatchToConsumer(ui::GestureConsumer
* consumer
) override
;
139 void DispatchGestureEvent(ui::GestureEvent
* event
) override
;
140 void DispatchCancelTouchEvent(ui::TouchEvent
* event
) override
;
143 friend class RenderWidgetHostView
;
146 // Destroys this view without calling |Destroy| on |platform_view_|.
147 void DestroyGuestView();
149 // Builds and forwards a WebKitGestureEvent to the renderer.
150 bool ForwardGestureEventToRenderer(ui::GestureEvent
* gesture
);
152 // Process all of the given gestures (passes them on to renderer)
153 void ProcessGestures(ui::GestureRecognizer::Gestures
* gestures
);
155 RenderWidgetHostViewBase
* GetOwnerRenderWidgetHostView() const;
157 void OnHandleInputEvent(RenderWidgetHostImpl
* embedder
,
158 int browser_plugin_instance_id
,
159 const gfx::Rect
& guest_window_rect
,
160 const blink::WebInputEvent
* event
);
162 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
163 // to one another, therefore we access |guest_| through WeakPtr.
164 base::WeakPtr
<BrowserPluginGuest
> guest_
;
166 // The platform view for this RenderWidgetHostView.
167 // RenderWidgetHostViewGuest mostly only cares about stuff related to
168 // compositing, the rest are directly forwared to this |platform_view_|.
169 base::WeakPtr
<RenderWidgetHostViewBase
> platform_view_
;
170 #if defined(USE_AURA)
171 scoped_ptr
<ui::GestureRecognizer
> gesture_recognizer_
;
173 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest
);
176 } // namespace content
178 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_