Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_android.h
blob7de423ee2d0561af961a3809f5d7bd0cf3d07112
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.h"
17 #include "cc/layers/delegated_renderer_layer_client.h"
18 #include "cc/layers/texture_layer_client.h"
19 #include "cc/output/begin_frame_args.h"
20 #include "content/browser/accessibility/browser_accessibility_manager.h"
21 #include "content/browser/renderer_host/ime_adapter_android.h"
22 #include "content/browser/renderer_host/render_widget_host_view_base.h"
23 #include "gpu/command_buffer/common/mailbox.h"
24 #include "third_party/skia/include/core/SkColor.h"
25 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
26 #include "ui/gfx/size.h"
27 #include "ui/gfx/vector2d_f.h"
29 struct ViewHostMsg_TextInputState_Params;
31 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
32 struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
34 namespace cc {
35 class DelegatedRendererLayer;
36 class Layer;
37 class TextureLayer;
40 namespace WebKit {
41 class WebExternalTextureLayer;
42 class WebTouchEvent;
43 class WebMouseEvent;
46 namespace content {
47 class ContentViewCoreImpl;
48 class OverscrollGlow;
49 class RenderWidgetHost;
50 class RenderWidgetHostImpl;
51 class SurfaceTextureTransportClient;
52 struct NativeWebKeyboardEvent;
54 // -----------------------------------------------------------------------------
55 // See comments in render_widget_host_view.h about this class and its members.
56 // -----------------------------------------------------------------------------
57 class RenderWidgetHostViewAndroid
58 : public RenderWidgetHostViewBase,
59 public BrowserAccessibilityDelegate,
60 public cc::TextureLayerClient,
61 public cc::DelegatedRendererLayerClient {
62 public:
63 RenderWidgetHostViewAndroid(RenderWidgetHostImpl* widget,
64 ContentViewCoreImpl* content_view_core);
65 virtual ~RenderWidgetHostViewAndroid();
67 // RenderWidgetHostView implementation.
68 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
69 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
70 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
71 const gfx::Rect& pos) OVERRIDE;
72 virtual void InitAsFullscreen(
73 RenderWidgetHostView* reference_host_view) OVERRIDE;
74 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
75 virtual void WasShown() OVERRIDE;
76 virtual void WasHidden() OVERRIDE;
77 virtual void SetSize(const gfx::Size& size) OVERRIDE;
78 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
79 virtual gfx::NativeView GetNativeView() const OVERRIDE;
80 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
81 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
82 virtual void MovePluginWindows(
83 const gfx::Vector2d& scroll_offset,
84 const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE;
85 virtual void Focus() OVERRIDE;
86 virtual void Blur() OVERRIDE;
87 virtual bool HasFocus() const OVERRIDE;
88 virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
89 virtual void Show() OVERRIDE;
90 virtual void Hide() OVERRIDE;
91 virtual bool IsShowing() OVERRIDE;
92 virtual gfx::Rect GetViewBounds() const OVERRIDE;
93 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE;
94 virtual float GetOverdrawBottomHeight() const OVERRIDE;
95 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
96 virtual void SetIsLoading(bool is_loading) OVERRIDE;
97 virtual void TextInputTypeChanged(ui::TextInputType type,
98 bool can_compose_inline) OVERRIDE;
99 virtual void ImeCancelComposition() OVERRIDE;
100 virtual void ImeCompositionRangeChanged(
101 const ui::Range& range,
102 const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
103 virtual void DidUpdateBackingStore(
104 const gfx::Rect& scroll_rect,
105 const gfx::Vector2d& scroll_delta,
106 const std::vector<gfx::Rect>& copy_rects,
107 const ui::LatencyInfo& latency_info) OVERRIDE;
108 virtual void RenderViewGone(base::TerminationStatus status,
109 int error_code) OVERRIDE;
110 virtual void Destroy() OVERRIDE;
111 virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE;
112 virtual void SelectionChanged(const string16& text,
113 size_t offset,
114 const ui::Range& range) OVERRIDE;
115 virtual void SelectionBoundsChanged(
116 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
117 virtual void ScrollOffsetChanged() OVERRIDE;
118 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
119 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
120 virtual void AcceleratedSurfaceBuffersSwapped(
121 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
122 int gpu_host_id) OVERRIDE;
123 virtual void AcceleratedSurfacePostSubBuffer(
124 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
125 int gpu_host_id) OVERRIDE;
126 virtual void AcceleratedSurfaceSuspend() OVERRIDE;
127 virtual void AcceleratedSurfaceRelease() OVERRIDE;
128 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
129 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
130 virtual void CopyFromCompositingSurface(
131 const gfx::Rect& src_subrect,
132 const gfx::Size& dst_size,
133 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
134 virtual void CopyFromCompositingSurfaceToVideoFrame(
135 const gfx::Rect& src_subrect,
136 const scoped_refptr<media::VideoFrame>& target,
137 const base::Callback<void(bool)>& callback) OVERRIDE;
138 virtual bool CanCopyToVideoFrame() const OVERRIDE;
139 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
140 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
141 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
142 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
143 InputEventAckState ack_result) OVERRIDE;
144 virtual void SetHasHorizontalScrollbar(
145 bool has_horizontal_scrollbar) OVERRIDE;
146 virtual void SetScrollOffsetPinning(
147 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
148 virtual void UnhandledWheelEvent(
149 const WebKit::WebMouseWheelEvent& event) OVERRIDE;
150 virtual InputEventAckState FilterInputEvent(
151 const WebKit::WebInputEvent& input_event) OVERRIDE;
152 virtual void OnAccessibilityNotifications(
153 const std::vector<AccessibilityHostMsg_NotificationParams>&
154 params) OVERRIDE;
155 virtual bool LockMouse() OVERRIDE;
156 virtual void UnlockMouse() OVERRIDE;
157 virtual void HasTouchEventHandlers(bool need_touch_events) OVERRIDE;
158 virtual void OnSwapCompositorFrame(
159 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
160 virtual void OnOverscrolled(gfx::Vector2dF accumulated_overscroll,
161 gfx::Vector2dF current_fling_velocity) OVERRIDE;
162 virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect,
163 const SkBitmap& zoomed_bitmap) OVERRIDE;
164 virtual SmoothScrollGesture* CreateSmoothScrollGesture(
165 bool scroll_down, int pixels_to_scroll, int mouse_event_x,
166 int mouse_event_y) OVERRIDE;
168 // Implementation of BrowserAccessibilityDelegate:
169 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
170 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
171 virtual void AccessibilityScrollToMakeVisible(
172 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
173 virtual void AccessibilityScrollToPoint(
174 int acc_obj_id, gfx::Point point) OVERRIDE;
175 virtual void AccessibilitySetTextSelection(
176 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
177 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
178 virtual void FatalAccessibilityTreeError() OVERRIDE;
180 // cc::TextureLayerClient implementation.
181 virtual unsigned PrepareTexture(cc::ResourceUpdateQueue* queue) OVERRIDE;
182 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
183 virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE;
185 // cc::DelegatedRendererLayerClient implementation.
186 virtual void DidCommitFrameData() OVERRIDE;
188 // Non-virtual methods
189 void SetContentViewCore(ContentViewCoreImpl* content_view_core);
190 SkColor GetCachedBackgroundColor() const;
191 void SendKeyEvent(const NativeWebKeyboardEvent& event);
192 void SendTouchEvent(const WebKit::WebTouchEvent& event);
193 void SendMouseEvent(const WebKit::WebMouseEvent& event);
194 void SendMouseWheelEvent(const WebKit::WebMouseWheelEvent& event);
195 void SendGestureEvent(const WebKit::WebGestureEvent& event);
196 void SendBeginFrame(const cc::BeginFrameArgs& args);
198 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
199 void OnProcessImeBatchStateAck(bool is_begin);
200 void OnDidChangeBodyBackgroundColor(SkColor color);
201 void OnStartContentIntent(const GURL& content_url);
202 void OnSetNeedsBeginFrame(bool enabled);
204 int GetNativeImeAdapter();
206 void WasResized();
208 WebKit::WebGLId GetScaledContentTexture(float scale, gfx::Size* out_size);
209 bool PopulateBitmapWithContents(jobject jbitmap);
211 bool HasValidFrame() const;
213 // Select all text between the given coordinates.
214 void SelectRange(const gfx::Point& start, const gfx::Point& end);
216 void MoveCaret(const gfx::Point& point);
218 void RequestContentClipping(const gfx::Rect& clipping,
219 const gfx::Size& content_size);
221 // Returns true when animation ticks are still needed. This avoids a separate
222 // round-trip for requesting follow-up animation.
223 bool Animate(base::TimeTicks frame_time);
225 void SynchronousFrameMetadata(
226 const cc::CompositorFrameMetadata& frame_metadata);
228 private:
229 void BuffersSwapped(const gpu::Mailbox& mailbox,
230 const base::Closure& ack_callback);
232 void RunAckCallbacks();
234 void SwapDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame_data);
235 void SendDelegatedFrameAck();
237 void UpdateContentViewCoreFrameMetadata(
238 const cc::CompositorFrameMetadata& frame_metadata);
239 void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata);
240 void ResetClipping();
241 void ClipContents(const gfx::Rect& clipping, const gfx::Size& content_size);
243 void AttachLayers();
244 void RemoveLayers();
246 void CreateOverscrollEffectIfNecessary();
247 void UpdateAnimationSize(const cc::CompositorFrameMetadata& frame_metadata);
248 void ScheduleAnimationIfNecessary();
250 // The model object.
251 RenderWidgetHostImpl* host_;
253 // Whether or not this widget is potentially attached to the view hierarchy.
254 // This view may not actually be attached if this is true, but it should be
255 // treated as such, because as soon as a ContentViewCore is set the layer
256 // will be attached automatically.
257 bool are_layers_attached_;
259 // ContentViewCoreImpl is our interface to the view system.
260 ContentViewCoreImpl* content_view_core_;
262 ImeAdapterAndroid ime_adapter_android_;
264 // Body background color of the underlying document.
265 SkColor cached_background_color_;
267 // The texture layer for this view when using browser-side compositing.
268 scoped_refptr<cc::TextureLayer> texture_layer_;
270 scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_;
272 // The layer used for rendering the contents of this view.
273 // It is either owned by texture_layer_ or surface_texture_transport_
274 // depending on the mode.
275 scoped_refptr<cc::Layer> layer_;
277 // The most recent texture id that was pushed to the texture layer.
278 unsigned int texture_id_in_layer_;
280 // The most recent texture size that was pushed to the texture layer.
281 gfx::Size texture_size_in_layer_;
283 // The most recent content size that was pushed to the texture layer.
284 gfx::Size content_size_in_layer_;
286 // Used for image transport when needing to share resources across threads.
287 scoped_ptr<SurfaceTextureTransportClient> surface_texture_transport_;
289 // The mailbox of the previously received frame.
290 gpu::Mailbox current_mailbox_;
292 base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
294 std::queue<base::Closure> ack_callbacks_;
296 // Used to render overscroll overlays.
297 bool overscroll_effect_enabled_;
298 scoped_ptr<OverscrollGlow> overscroll_effect_;
300 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAndroid);
303 } // namespace content
305 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_ANDROID_H_