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
;
103 bool GetScreenColorProfile(std::vector
<char>* color_profile
) override
;
105 #if defined(OS_MACOSX)
106 // RenderWidgetHostView implementation.
107 void SetActive(bool active
) override
;
108 void SetWindowVisibility(bool visible
) override
;
109 void WindowFrameChanged() override
;
110 void ShowDefinitionForSelection() override
;
111 bool SupportsSpeech() const override
;
112 void SpeakSelection() override
;
113 bool IsSpeaking() const override
;
114 void StopSpeaking() override
;
116 // RenderWidgetHostViewBase implementation.
117 bool PostProcessEventForPluginIme(
118 const NativeWebKeyboardEvent
& event
) override
;
119 #endif // defined(OS_MACOSX)
121 #if defined(OS_ANDROID) || defined(USE_AURA)
122 // RenderWidgetHostViewBase implementation.
123 void ShowDisambiguationPopup(const gfx::Rect
& rect_pixels
,
124 const SkBitmap
& zoomed_bitmap
) override
;
125 #endif // defined(OS_ANDROID) || defined(USE_AURA)
127 #if defined(OS_ANDROID)
128 void LockCompositingSurface() override
;
129 void UnlockCompositingSurface() override
;
130 #endif // defined(OS_ANDROID)
133 void SetParentNativeViewAccessible(
134 gfx::NativeViewAccessible accessible_parent
) override
;
135 gfx::NativeViewId
GetParentForWindowlessPlugin() const override
;
138 // Overridden from ui::GestureEventHelper.
139 bool CanDispatchToConsumer(ui::GestureConsumer
* consumer
) override
;
140 void DispatchGestureEvent(ui::GestureEvent
* event
) override
;
141 void DispatchCancelTouchEvent(ui::TouchEvent
* event
) override
;
144 friend class RenderWidgetHostView
;
147 // Destroys this view without calling |Destroy| on |platform_view_|.
148 void DestroyGuestView();
150 // Builds and forwards a WebKitGestureEvent to the renderer.
151 bool ForwardGestureEventToRenderer(ui::GestureEvent
* gesture
);
153 // Process all of the given gestures (passes them on to renderer)
154 void ProcessGestures(ui::GestureRecognizer::Gestures
* gestures
);
156 RenderWidgetHostViewBase
* GetOwnerRenderWidgetHostView() const;
158 void OnHandleInputEvent(RenderWidgetHostImpl
* embedder
,
159 int browser_plugin_instance_id
,
160 const gfx::Rect
& guest_window_rect
,
161 const blink::WebInputEvent
* event
);
163 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
164 // to one another, therefore we access |guest_| through WeakPtr.
165 base::WeakPtr
<BrowserPluginGuest
> guest_
;
167 // The platform view for this RenderWidgetHostView.
168 // RenderWidgetHostViewGuest mostly only cares about stuff related to
169 // compositing, the rest are directly forwared to this |platform_view_|.
170 base::WeakPtr
<RenderWidgetHostViewBase
> platform_view_
;
171 #if defined(USE_AURA)
172 scoped_ptr
<ui::GestureRecognizer
> gesture_recognizer_
;
174 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest
);
177 } // namespace content
179 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_