Simplify ChildProcessLauncher
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_android.h
blob296c78547454d5f56073abfa94bcfdddcd03dc46
1 // Copyright (c) 2012 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_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_
8 #include <map>
9 #include <queue>
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/i18n/rtl.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/process/process.h"
17 #include "cc/layers/delegated_frame_resource_collection.h"
18 #include "cc/output/begin_frame_args.h"
19 #include "cc/surfaces/surface_factory_client.h"
20 #include "cc/surfaces/surface_id.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/renderer_host/delegated_frame_evictor.h"
23 #include "content/browser/renderer_host/ime_adapter_android.h"
24 #include "content/browser/renderer_host/input/stylus_text_selector.h"
25 #include "content/browser/renderer_host/render_widget_host_view_base.h"
26 #include "content/common/content_export.h"
27 #include "content/public/browser/readback_types.h"
28 #include "gpu/command_buffer/common/mailbox.h"
29 #include "third_party/skia/include/core/SkColor.h"
30 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
31 #include "ui/android/window_android_observer.h"
32 #include "ui/events/gesture_detection/filtered_gesture_provider.h"
33 #include "ui/gfx/geometry/size.h"
34 #include "ui/gfx/geometry/vector2d_f.h"
35 #include "ui/touch_selection/touch_selection_controller.h"
37 struct ViewHostMsg_TextInputState_Params;
39 namespace cc {
40 class CopyOutputResult;
41 class DelegatedFrameProvider;
42 class DelegatedRendererLayer;
43 class Layer;
44 class SurfaceFactory;
45 class SurfaceIdAllocator;
46 enum class SurfaceDrawStatus;
49 namespace blink {
50 class WebExternalTextureLayer;
51 class WebTouchEvent;
52 class WebMouseEvent;
55 namespace content {
56 class ContentViewCoreImpl;
57 class OverscrollControllerAndroid;
58 class RenderWidgetHost;
59 class RenderWidgetHostImpl;
60 struct DidOverscrollParams;
61 struct NativeWebKeyboardEvent;
63 class ReadbackRequest {
64 public:
65 explicit ReadbackRequest(float scale,
66 SkColorType color_type,
67 gfx::Rect src_subrect,
68 ReadbackRequestCallback& result_callback);
69 ~ReadbackRequest();
70 float GetScale() { return scale_; }
71 SkColorType GetColorFormat() { return color_type_; }
72 const gfx::Rect GetCaptureRect() { return src_subrect_; }
73 ReadbackRequestCallback& GetResultCallback() { return result_callback_; }
75 private:
76 ReadbackRequest();
77 float scale_;
78 SkColorType color_type_;
79 gfx::Rect src_subrect_;
80 ReadbackRequestCallback result_callback_;
83 // -----------------------------------------------------------------------------
84 // See comments in render_widget_host_view.h about this class and its members.
85 // -----------------------------------------------------------------------------
86 class CONTENT_EXPORT RenderWidgetHostViewAndroid
87 : public RenderWidgetHostViewBase,
88 public cc::DelegatedFrameResourceCollectionClient,
89 public cc::SurfaceFactoryClient,
90 public ui::GestureProviderClient,
91 public ui::WindowAndroidObserver,
92 public DelegatedFrameEvictorClient,
93 public StylusTextSelectorClient,
94 public ui::TouchSelectionControllerClient {
95 public:
96 RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget,
97 ContentViewCoreImpl* content_view_core);
98 ~RenderWidgetHostViewAndroid() override;
100 // RenderWidgetHostView implementation.
101 bool OnMessageReceived(const IPC::Message& msg) override;
102 void InitAsChild(gfx::NativeView parent_view) override;
103 void InitAsPopup(RenderWidgetHostView* parent_host_view,
104 const gfx::Rect& pos) override;
105 void InitAsFullscreen(RenderWidgetHostView* reference_host_view) override;
106 RenderWidgetHost* GetRenderWidgetHost() const override;
107 void SetSize(const gfx::Size& size) override;
108 void SetBounds(const gfx::Rect& rect) override;
109 gfx::Vector2dF GetLastScrollOffset() const override;
110 gfx::NativeView GetNativeView() const override;
111 gfx::NativeViewId GetNativeViewId() const override;
112 gfx::NativeViewAccessible GetNativeViewAccessible() override;
113 void MovePluginWindows(const std::vector<WebPluginGeometry>& moves) override;
114 void Focus() override;
115 void Blur() override;
116 bool HasFocus() const override;
117 bool IsSurfaceAvailableForCopy() const override;
118 void Show() override;
119 void Hide() override;
120 bool IsShowing() override;
121 gfx::Rect GetViewBounds() const override;
122 gfx::Size GetPhysicalBackingSize() const override;
123 bool DoTopControlsShrinkBlinkSize() const override;
124 float GetTopControlsHeight() const override;
125 void UpdateCursor(const WebCursor& cursor) override;
126 void SetIsLoading(bool is_loading) override;
127 void TextInputTypeChanged(ui::TextInputType type,
128 ui::TextInputMode input_mode,
129 bool can_compose_inline,
130 int flags) override;
131 void ImeCancelComposition() override;
132 void ImeCompositionRangeChanged(
133 const gfx::Range& range,
134 const std::vector<gfx::Rect>& character_bounds) override;
135 void FocusedNodeChanged(bool is_editable_node) override;
136 void RenderProcessGone(base::TerminationStatus status,
137 int error_code) override;
138 void Destroy() override;
139 void SetTooltipText(const base::string16& tooltip_text) override;
140 void SelectionChanged(const base::string16& text,
141 size_t offset,
142 const gfx::Range& range) override;
143 void SelectionBoundsChanged(
144 const ViewHostMsg_SelectionBounds_Params& params) override;
145 void AcceleratedSurfaceInitialized(int route_id) override;
146 bool HasAcceleratedSurface(const gfx::Size& desired_size) override;
147 void SetBackgroundColor(SkColor color) override;
148 void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
149 const gfx::Size& dst_size,
150 ReadbackRequestCallback& callback,
151 const SkColorType color_type) override;
152 void CopyFromCompositingSurfaceToVideoFrame(
153 const gfx::Rect& src_subrect,
154 const scoped_refptr<media::VideoFrame>& target,
155 const base::Callback<void(bool)>& callback) override;
156 bool CanCopyToVideoFrame() const override;
157 void GetScreenInfo(blink::WebScreenInfo* results) override;
158 gfx::Rect GetBoundsInRootWindow() override;
159 gfx::GLSurfaceHandle GetCompositingSurface() override;
160 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
161 InputEventAckState ack_result) override;
162 InputEventAckState FilterInputEvent(
163 const blink::WebInputEvent& input_event) override;
164 void OnSetNeedsFlushInput() override;
165 void GestureEventAck(const blink::WebGestureEvent& event,
166 InputEventAckState ack_result) override;
167 BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
168 BrowserAccessibilityDelegate* delegate) override;
169 bool LockMouse() override;
170 void UnlockMouse() override;
171 void OnSwapCompositorFrame(uint32 output_surface_id,
172 scoped_ptr<cc::CompositorFrame> frame) override;
173 void DidOverscroll(const DidOverscrollParams& params) override;
174 void DidStopFlinging() override;
175 void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
176 const SkBitmap& zoomed_bitmap) override;
177 scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget() override;
178 void LockCompositingSurface() override;
179 void UnlockCompositingSurface() override;
180 void OnTextSurroundingSelectionResponse(const base::string16& content,
181 size_t start_offset,
182 size_t end_offset) override;
183 void OnDidNavigateMainFrameToNewPage() override;
185 // cc::DelegatedFrameResourceCollectionClient implementation.
186 void UnusedResourcesAreAvailable() override;
188 // cc::SurfaceFactoryClient implementation.
189 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
191 // ui::GestureProviderClient implementation.
192 void OnGestureEvent(const ui::GestureEventData& gesture) override;
194 // ui::WindowAndroidObserver implementation.
195 void OnCompositingDidCommit() override;
196 void OnRootWindowVisibilityChanged(bool visible) override;
197 void OnAttachCompositor() override;
198 void OnDetachCompositor() override;
199 void OnVSync(base::TimeTicks frame_time,
200 base::TimeDelta vsync_period) override;
201 void OnAnimate(base::TimeTicks begin_frame_time) override;
202 void OnActivityPaused() override;
203 void OnActivityResumed() override;
205 // DelegatedFrameEvictor implementation
206 void EvictDelegatedFrame() override;
208 SkColorType PreferredReadbackFormat() override;
210 // StylusTextSelectorClient implementation.
211 void OnStylusSelectBegin(float x0, float y0, float x1, float y1) override;
212 void OnStylusSelectUpdate(float x, float y) override;
213 void OnStylusSelectEnd() override;
214 void OnStylusSelectTap(base::TimeTicks time, float x, float y) override;
216 // ui::TouchSelectionControllerClient implementation.
217 bool SupportsAnimation() const override;
218 void SetNeedsAnimate() override;
219 void MoveCaret(const gfx::PointF& position) override;
220 void MoveRangeSelectionExtent(const gfx::PointF& extent) override;
221 void SelectBetweenCoordinates(const gfx::PointF& base,
222 const gfx::PointF& extent) override;
223 void OnSelectionEvent(ui::SelectionEventType event,
224 const gfx::PointF& anchor_position) override;
225 scoped_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
227 // Non-virtual methods
228 void SetContentViewCore(ContentViewCoreImpl* content_view_core);
229 SkColor GetCachedBackgroundColor() const;
230 void SendKeyEvent(const NativeWebKeyboardEvent& event);
231 void SendMouseEvent(const blink::WebMouseEvent& event);
232 void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event);
233 void SendGestureEvent(const blink::WebGestureEvent& event);
235 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
236 void OnDidChangeBodyBackgroundColor(SkColor color);
237 void OnStartContentIntent(const GURL& content_url);
238 void OnSetNeedsBeginFrames(bool enabled);
239 void OnSmartClipDataExtracted(const base::string16& text,
240 const base::string16& html,
241 const gfx::Rect rect);
243 bool OnTouchEvent(const ui::MotionEvent& event);
244 bool OnTouchHandleEvent(const ui::MotionEvent& event);
245 void ResetGestureDetection();
246 void SetDoubleTapSupportEnabled(bool enabled);
247 void SetMultiTouchZoomSupportEnabled(bool enabled);
249 long GetNativeImeAdapter();
251 void WasResized();
253 void GetScaledContentBitmap(float scale,
254 SkColorType color_type,
255 gfx::Rect src_subrect,
256 ReadbackRequestCallback& result_callback);
258 scoped_refptr<cc::Layer> CreateDelegatedLayer() const;
260 bool HasValidFrame() const;
262 void MoveCaret(const gfx::Point& point);
263 void DismissTextHandles();
264 void SetTextHandlesTemporarilyHidden(bool hidden);
265 void OnShowingPastePopup(const gfx::PointF& point);
266 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
268 void SynchronousFrameMetadata(
269 const cc::CompositorFrameMetadata& frame_metadata);
271 void SetOverlayVideoMode(bool enabled);
273 typedef base::Callback<
274 void(const base::string16& content, int start_offset, int end_offset)>
275 TextSurroundingSelectionCallback;
276 void SetTextSurroundingSelectionCallback(
277 const TextSurroundingSelectionCallback& callback);
279 static void OnContextLost();
281 private:
282 void RunAckCallbacks(cc::SurfaceDrawStatus status);
284 void DestroyDelegatedContent();
285 void CheckOutputSurfaceChanged(uint32 output_surface_id);
286 void SubmitFrame(scoped_ptr<cc::DelegatedFrameData> frame_data);
287 void SwapDelegatedFrame(uint32 output_surface_id,
288 scoped_ptr<cc::DelegatedFrameData> frame_data);
289 void SendDelegatedFrameAck(uint32 output_surface_id);
290 void SendReturnedDelegatedResources(uint32 output_surface_id);
292 void OnFrameMetadataUpdated(
293 const cc::CompositorFrameMetadata& frame_metadata);
294 void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata);
296 void ShowInternal();
297 void HideInternal(bool hide_frontbuffer, bool stop_observing_root_window);
298 void AttachLayers();
299 void RemoveLayers();
301 // Called after async screenshot task completes. Scales and crops the result
302 // of the copy.
303 static void PrepareTextureCopyOutputResult(
304 const gfx::Size& dst_size_in_pixel,
305 const SkColorType color_type,
306 const base::TimeTicks& start_time,
307 ReadbackRequestCallback& callback,
308 scoped_ptr<cc::CopyOutputResult> result);
309 static void PrepareTextureCopyOutputResultForDelegatedReadback(
310 const gfx::Size& dst_size_in_pixel,
311 const SkColorType color_type,
312 const base::TimeTicks& start_time,
313 scoped_refptr<cc::Layer> readback_layer,
314 ReadbackRequestCallback& callback,
315 scoped_ptr<cc::CopyOutputResult> result);
317 // DevTools ScreenCast support for Android WebView.
318 void SynchronousCopyContents(const gfx::Rect& src_subrect_in_pixel,
319 const gfx::Size& dst_size_in_pixel,
320 ReadbackRequestCallback& callback,
321 const SkColorType color_type);
323 // If we have locks on a frame during a ContentViewCore swap or a context
324 // lost, the frame is no longer valid and we can safely release all the locks.
325 // Use this method to release all the locks.
326 void ReleaseLocksOnSurface();
328 // Drop any incoming frames from the renderer when there are locks on the
329 // current frame.
330 void RetainFrame(uint32 output_surface_id,
331 scoped_ptr<cc::CompositorFrame> frame);
333 void InternalSwapCompositorFrame(uint32 output_surface_id,
334 scoped_ptr<cc::CompositorFrame> frame);
335 void OnLostResources();
337 enum VSyncRequestType {
338 FLUSH_INPUT = 1 << 0,
339 BEGIN_FRAME = 1 << 1,
340 PERSISTENT_BEGIN_FRAME = 1 << 2
342 void RequestVSyncUpdate(uint32 requests);
343 void StartObservingRootWindow();
344 void StopObservingRootWindow();
345 void SendBeginFrame(base::TimeTicks frame_time, base::TimeDelta vsync_period);
346 bool Animate(base::TimeTicks frame_time);
348 // Handles all unprocessed and pending readback requests.
349 void AbortPendingReadbackRequests();
351 // The model object.
352 RenderWidgetHostImpl* host_;
354 bool use_surfaces_;
356 // Used to control action dispatch at the next |OnVSync()| call.
357 uint32 outstanding_vsync_requests_;
359 bool is_showing_;
361 // ContentViewCoreImpl is our interface to the view system.
362 ContentViewCoreImpl* content_view_core_;
364 ImeAdapterAndroid ime_adapter_android_;
366 // Body background color of the underlying document.
367 SkColor cached_background_color_;
369 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
370 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
371 scoped_refptr<cc::Layer> layer_;
373 scoped_ptr<cc::SurfaceIdAllocator> id_allocator_;
374 scoped_ptr<cc::SurfaceFactory> surface_factory_;
375 cc::SurfaceId surface_id_;
376 gfx::Size current_surface_size_;
377 cc::ReturnedResourceArray surface_returned_resources_;
379 // The most recent texture size that was pushed to the texture layer.
380 gfx::Size texture_size_in_layer_;
382 // The most recent content size that was pushed to the texture layer.
383 gfx::Size content_size_in_layer_;
385 // The output surface id of the last received frame.
386 uint32_t last_output_surface_id_;
389 std::queue<base::Closure> ack_callbacks_;
391 // Used to control and render overscroll-related effects.
392 scoped_ptr<OverscrollControllerAndroid> overscroll_controller_;
394 // Provides gesture synthesis given a stream of touch events (derived from
395 // Android MotionEvent's) and touch event acks.
396 ui::FilteredGestureProvider gesture_provider_;
398 // Handles gesture based text selection
399 StylusTextSelector stylus_text_selector_;
401 // Manages selection handle rendering and manipulation.
402 // This will always be NULL if |content_view_core_| is NULL.
403 scoped_ptr<ui::TouchSelectionController> selection_controller_;
405 int accelerated_surface_route_id_;
407 // Size to use if we have no backing ContentViewCore
408 gfx::Size default_size_;
410 const bool using_browser_compositor_;
412 scoped_ptr<DelegatedFrameEvictor> frame_evictor_;
414 size_t locks_on_frame_count_;
415 bool observing_root_window_;
417 struct LastFrameInfo {
418 LastFrameInfo(uint32 output_id,
419 scoped_ptr<cc::CompositorFrame> output_frame);
420 ~LastFrameInfo();
421 uint32 output_surface_id;
422 scoped_ptr<cc::CompositorFrame> frame;
425 scoped_ptr<LastFrameInfo> last_frame_info_;
427 TextSurroundingSelectionCallback text_surrounding_selection_callback_;
429 // List of readbackrequests waiting for arrival of a valid frame.
430 std::queue<ReadbackRequest> readbacks_waiting_for_frame_;
432 // The last scroll offset of the view.
433 gfx::Vector2dF last_scroll_offset_;
435 base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
437 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
440 } // namespace content
442 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_