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_CHILD_FRAME_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_CHILD_FRAME_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/resources/returned_resource.h"
10 #include "cc/surfaces/surface_factory_client.h"
11 #include "cc/surfaces/surface_id_allocator.h"
12 #include "content/browser/compositor/image_transport_factory.h"
13 #include "content/browser/renderer_host/render_widget_host_view_base.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/readback_types.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/native_widget_types.h"
22 enum class SurfaceDrawStatus
;
25 struct ViewHostMsg_TextInputState_Params
;
28 class CrossProcessFrameConnector
;
29 class RenderWidgetHost
;
30 class RenderWidgetHostImpl
;
31 class RenderWidgetHostViewChildFrameTest
;
32 class RenderWidgetHostViewGuestSurfaceTest
;
34 // RenderWidgetHostViewChildFrame implements the view for a RenderWidgetHost
35 // associated with content being rendered in a separate process from
36 // content that is embedding it. This is not a platform-specific class; rather,
37 // the embedding renderer process implements the platform containing the
38 // widget, and the top-level frame's RenderWidgetHostView will ultimately
39 // manage all native widget interaction.
41 // See comments in render_widget_host_view.h about this class and its members.
42 class CONTENT_EXPORT RenderWidgetHostViewChildFrame
43 : public RenderWidgetHostViewBase
,
44 public cc::SurfaceFactoryClient
{
46 explicit RenderWidgetHostViewChildFrame(RenderWidgetHost
* widget
);
47 ~RenderWidgetHostViewChildFrame() override
;
49 void set_cross_process_frame_connector(
50 CrossProcessFrameConnector
* frame_connector
) {
51 frame_connector_
= frame_connector
;
54 // RenderWidgetHostView implementation.
55 void InitAsChild(gfx::NativeView parent_view
) override
;
56 RenderWidgetHost
* GetRenderWidgetHost() const override
;
57 void SetSize(const gfx::Size
& size
) override
;
58 void SetBounds(const gfx::Rect
& rect
) override
;
59 void Focus() override
;
60 bool HasFocus() const override
;
61 bool IsSurfaceAvailableForCopy() const override
;
64 bool IsShowing() override
;
65 gfx::Rect
GetViewBounds() const override
;
66 gfx::Vector2dF
GetLastScrollOffset() const override
;
67 gfx::NativeView
GetNativeView() const override
;
68 gfx::NativeViewId
GetNativeViewId() const override
;
69 gfx::NativeViewAccessible
GetNativeViewAccessible() override
;
70 void SetBackgroundColor(SkColor color
) override
;
71 gfx::Size
GetPhysicalBackingSize() const override
;
73 // RenderWidgetHostViewBase implementation.
74 void InitAsPopup(RenderWidgetHostView
* parent_host_view
,
75 const gfx::Rect
& bounds
) override
;
76 void InitAsFullscreen(RenderWidgetHostView
* reference_host_view
) override
;
77 void MovePluginWindows(const std::vector
<WebPluginGeometry
>& moves
) override
;
78 void UpdateCursor(const WebCursor
& cursor
) override
;
79 void SetIsLoading(bool is_loading
) override
;
80 void TextInputStateChanged(
81 const ViewHostMsg_TextInputState_Params
& params
) override
;
82 void ImeCancelComposition() override
;
83 void ImeCompositionRangeChanged(
84 const gfx::Range
& range
,
85 const std::vector
<gfx::Rect
>& character_bounds
) override
;
86 void RenderProcessGone(base::TerminationStatus status
,
87 int error_code
) override
;
88 void Destroy() override
;
89 void SetTooltipText(const base::string16
& tooltip_text
) override
;
90 void SelectionChanged(const base::string16
& text
,
92 const gfx::Range
& range
) override
;
93 void SelectionBoundsChanged(
94 const ViewHostMsg_SelectionBounds_Params
& params
) override
;
95 void CopyFromCompositingSurface(
96 const gfx::Rect
& src_subrect
,
97 const gfx::Size
& dst_size
,
98 ReadbackRequestCallback
& callback
,
99 const SkColorType preferred_color_type
) override
;
100 void CopyFromCompositingSurfaceToVideoFrame(
101 const gfx::Rect
& src_subrect
,
102 const scoped_refptr
<media::VideoFrame
>& target
,
103 const base::Callback
<void(bool)>& callback
) override
;
104 bool CanCopyToVideoFrame() const override
;
105 bool HasAcceleratedSurface(const gfx::Size
& desired_size
) override
;
106 void OnSwapCompositorFrame(uint32 output_surface_id
,
107 scoped_ptr
<cc::CompositorFrame
> frame
) override
;
108 // Since the URL of content rendered by this class is not displayed in
109 // the URL bar, this method does not need an implementation.
110 void ClearCompositorFrame() override
{}
111 void GetScreenInfo(blink::WebScreenInfo
* results
) override
;
112 bool GetScreenColorProfile(std::vector
<char>* color_profile
) override
;
113 gfx::Rect
GetBoundsInRootWindow() override
;
114 gfx::GLSurfaceHandle
GetCompositingSurface() override
;
115 #if defined(USE_AURA)
116 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo
& touch
,
117 InputEventAckState ack_result
) override
;
118 #endif // defined(USE_AURA)
119 bool LockMouse() override
;
120 void UnlockMouse() override
;
121 uint32_t GetSurfaceIdNamespace() override
;
122 void ProcessKeyboardEvent(const NativeWebKeyboardEvent
& event
) override
;
123 void ProcessMouseEvent(const blink::WebMouseEvent
& event
) override
;
124 void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent
& event
) override
;
126 #if defined(OS_MACOSX)
127 // RenderWidgetHostView implementation.
128 void SetActive(bool active
) override
;
129 void SetWindowVisibility(bool visible
) override
;
130 void WindowFrameChanged() override
;
131 void ShowDefinitionForSelection() override
;
132 bool SupportsSpeech() const override
;
133 void SpeakSelection() override
;
134 bool IsSpeaking() const override
;
135 void StopSpeaking() override
;
137 // RenderWidgetHostViewBase implementation.
138 bool PostProcessEventForPluginIme(
139 const NativeWebKeyboardEvent
& event
) override
;
140 #endif // defined(OS_MACOSX)
142 // RenderWidgetHostViewBase implementation.
143 #if defined(OS_ANDROID)
144 void LockCompositingSurface() override
;
145 void UnlockCompositingSurface() override
;
146 #endif // defined(OS_ANDROID)
149 void SetParentNativeViewAccessible(
150 gfx::NativeViewAccessible accessible_parent
) override
;
151 gfx::NativeViewId
GetParentForWindowlessPlugin() const override
;
153 BrowserAccessibilityManager
* CreateBrowserAccessibilityManager(
154 BrowserAccessibilityDelegate
* delegate
) override
;
156 // cc::SurfaceFactoryClient implementation.
157 void ReturnResources(const cc::ReturnedResourceArray
& resources
) override
;
159 // Declared 'public' instead of 'protected' here to allow derived classes
161 void SurfaceDrawn(uint32 output_surface_id
, cc::SurfaceDrawStatus drawn
);
164 friend class RenderWidgetHostView
;
165 friend class RenderWidgetHostViewChildFrameTest
;
166 friend class RenderWidgetHostViewGuestSurfaceTest
;
168 // Clears current compositor surface, if one is in use.
169 void ClearCompositorSurfaceIfNecessary();
171 // The last scroll offset of the view.
172 gfx::Vector2dF last_scroll_offset_
;
174 // Members will become private when RenderWidgetHostViewGuest is removed.
176 RenderWidgetHostImpl
* host_
;
178 // Flag determining whether we render into a compositing Surface.
181 // Surface-related state.
182 scoped_ptr
<cc::SurfaceIdAllocator
> id_allocator_
;
183 scoped_ptr
<cc::SurfaceFactory
> surface_factory_
;
184 cc::SurfaceId surface_id_
;
185 uint32 next_surface_sequence_
;
186 uint32 last_output_surface_id_
;
187 gfx::Size current_surface_size_
;
188 float current_surface_scale_factor_
;
189 uint32 ack_pending_count_
;
190 cc::ReturnedResourceArray surface_returned_resources_
;
192 // frame_connector_ provides a platform abstraction. Messages
193 // sent through it are routed to the embedding renderer process.
194 CrossProcessFrameConnector
* frame_connector_
;
196 base::WeakPtr
<RenderWidgetHostViewChildFrame
> AsWeakPtr() {
197 return weak_factory_
.GetWeakPtr();
201 base::WeakPtrFactory
<RenderWidgetHostViewChildFrame
> weak_factory_
;
202 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewChildFrame
);
205 } // namespace content
207 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_CHILD_FRAME_H_