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_AURA_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_
13 #include "base/callback.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "cc/layers/delegated_frame_provider.h"
20 #include "cc/layers/delegated_frame_resource_collection.h"
21 #include "cc/resources/texture_mailbox.h"
22 #include "content/browser/accessibility/browser_accessibility_manager.h"
23 #include "content/browser/compositor/image_transport_factory.h"
24 #include "content/browser/compositor/owned_mailbox.h"
25 #include "content/browser/renderer_host/delegated_frame_evictor.h"
26 #include "content/browser/renderer_host/render_widget_host_view_base.h"
27 #include "content/browser/renderer_host/software_frame_manager.h"
28 #include "content/common/content_export.h"
29 #include "content/common/cursors/webcursor.h"
30 #include "content/common/gpu/client/gl_helper.h"
31 #include "third_party/skia/include/core/SkRegion.h"
32 #include "ui/aura/client/cursor_client_observer.h"
33 #include "ui/aura/client/focus_change_observer.h"
34 #include "ui/aura/window_delegate.h"
35 #include "ui/aura/window_tree_host_observer.h"
36 #include "ui/base/ime/text_input_client.h"
37 #include "ui/compositor/compositor.h"
38 #include "ui/compositor/compositor_observer.h"
39 #include "ui/compositor/compositor_vsync_manager.h"
40 #include "ui/compositor/layer_owner_delegate.h"
41 #include "ui/gfx/display_observer.h"
42 #include "ui/gfx/rect.h"
43 #include "ui/wm/public/activation_change_observer.h"
44 #include "ui/wm/public/activation_delegate.h"
49 class ScopedTooltipDisabler;
54 class CopyOutputRequest;
55 class CopyOutputResult;
56 class DelegatedFrameData;
70 class CompositorVSyncManager;
78 class LegacyRenderWidgetHostHWND;
81 class RenderFrameHostImpl;
82 class RenderWidgetHostImpl;
83 class RenderWidgetHostView;
86 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
87 class CONTENT_EXPORT RenderWidgetHostViewAura
88 : public RenderWidgetHostViewBase,
89 public ui::CompositorObserver,
90 public ui::CompositorVSyncManager::Observer,
91 public ui::LayerOwnerDelegate,
92 public ui::TextInputClient,
93 public gfx::DisplayObserver,
94 public aura::WindowTreeHostObserver,
95 public aura::WindowDelegate,
96 public aura::client::ActivationDelegate,
97 public aura::client::ActivationChangeObserver,
98 public aura::client::FocusChangeObserver,
99 public aura::client::CursorClientObserver,
100 public ImageTransportFactoryObserver,
101 public BrowserAccessibilityDelegate,
102 public SoftwareFrameManagerClient,
103 public DelegatedFrameEvictorClient,
104 public base::SupportsWeakPtr<RenderWidgetHostViewAura>,
105 public cc::DelegatedFrameResourceCollectionClient {
107 // Displays and controls touch editing elements such as selection handles.
108 class TouchEditingClient {
110 TouchEditingClient() {}
112 // Tells the client to start showing touch editing handles.
113 virtual void StartTouchEditing() = 0;
115 // Notifies the client that touch editing is no longer needed. |quick|
116 // determines whether the handles should fade out quickly or slowly.
117 virtual void EndTouchEditing(bool quick) = 0;
119 // Notifies the client that the selection bounds need to be updated.
120 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
121 const gfx::Rect& focus) = 0;
123 // Notifies the client that the current text input type as changed.
124 virtual void OnTextInputTypeChanged(ui::TextInputType type) = 0;
126 // Notifies the client that an input event is about to be sent to the
127 // renderer. Returns true if the client wants to stop event propagation.
128 virtual bool HandleInputEvent(const ui::Event* event) = 0;
130 // Notifies the client that a gesture event ack was received.
131 virtual void GestureEventAck(int gesture_event_type) = 0;
133 // This is called when the view is destroyed, so that the client can
134 // perform any necessary clean-up.
135 virtual void OnViewDestroyed() = 0;
138 virtual ~TouchEditingClient() {}
141 void set_touch_editing_client(TouchEditingClient* client) {
142 touch_editing_client_ = client;
145 // RenderWidgetHostView implementation.
146 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
147 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
148 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
149 virtual void SetSize(const gfx::Size& size) OVERRIDE;
150 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
151 virtual gfx::NativeView GetNativeView() const OVERRIDE;
152 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
153 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
154 virtual bool HasFocus() const OVERRIDE;
155 virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
156 virtual void Show() OVERRIDE;
157 virtual void Hide() OVERRIDE;
158 virtual bool IsShowing() OVERRIDE;
159 virtual gfx::Rect GetViewBounds() const OVERRIDE;
160 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
162 // Overridden from RenderWidgetHostViewPort:
163 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
164 const gfx::Rect& pos) OVERRIDE;
165 virtual void InitAsFullscreen(
166 RenderWidgetHostView* reference_host_view) OVERRIDE;
167 virtual void WasShown() OVERRIDE;
168 virtual void WasHidden() OVERRIDE;
169 virtual void MovePluginWindows(
170 const gfx::Vector2d& scroll_offset,
171 const std::vector<WebPluginGeometry>& moves) OVERRIDE;
172 virtual void Focus() OVERRIDE;
173 virtual void Blur() OVERRIDE;
174 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
175 virtual void SetIsLoading(bool is_loading) OVERRIDE;
176 virtual void TextInputTypeChanged(ui::TextInputType type,
177 ui::TextInputMode input_mode,
178 bool can_compose_inline) OVERRIDE;
179 virtual void ImeCancelComposition() OVERRIDE;
180 virtual void ImeCompositionRangeChanged(
181 const gfx::Range& range,
182 const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
183 virtual void DidUpdateBackingStore(
184 const gfx::Rect& scroll_rect,
185 const gfx::Vector2d& scroll_delta,
186 const std::vector<gfx::Rect>& copy_rects,
187 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
188 virtual void RenderProcessGone(base::TerminationStatus status,
189 int error_code) OVERRIDE;
190 virtual void Destroy() OVERRIDE;
191 virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
192 virtual void SelectionChanged(const base::string16& text,
194 const gfx::Range& range) OVERRIDE;
195 virtual void SelectionBoundsChanged(
196 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
197 virtual void ScrollOffsetChanged() OVERRIDE;
198 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
199 virtual void CopyFromCompositingSurface(
200 const gfx::Rect& src_subrect,
201 const gfx::Size& dst_size,
202 const base::Callback<void(bool, const SkBitmap&)>& callback,
203 const SkBitmap::Config config) OVERRIDE;
204 virtual void CopyFromCompositingSurfaceToVideoFrame(
205 const gfx::Rect& src_subrect,
206 const scoped_refptr<media::VideoFrame>& target,
207 const base::Callback<void(bool)>& callback) OVERRIDE;
208 virtual bool CanCopyToVideoFrame() const OVERRIDE;
209 virtual bool CanSubscribeFrame() const OVERRIDE;
210 virtual void BeginFrameSubscription(
211 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
212 virtual void EndFrameSubscription() OVERRIDE;
213 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
214 virtual void AcceleratedSurfaceInitialized(int host_id,
215 int route_id) OVERRIDE;
216 virtual void AcceleratedSurfaceBuffersSwapped(
217 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
218 int gpu_host_id) OVERRIDE;
219 virtual void AcceleratedSurfacePostSubBuffer(
220 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
221 int gpu_host_id) OVERRIDE;
222 virtual void AcceleratedSurfaceSuspend() OVERRIDE;
223 virtual void AcceleratedSurfaceRelease() OVERRIDE;
224 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
225 virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
226 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
227 virtual void GestureEventAck(const blink::WebGestureEvent& event,
228 InputEventAckState ack_result) OVERRIDE;
229 virtual void ProcessAckedTouchEvent(
230 const TouchEventWithLatencyInfo& touch,
231 InputEventAckState ack_result) OVERRIDE;
232 virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget()
234 virtual void SetHasHorizontalScrollbar(
235 bool has_horizontal_scrollbar) OVERRIDE;
236 virtual void SetScrollOffsetPinning(
237 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
238 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
239 virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE;
240 virtual bool LockMouse() OVERRIDE;
241 virtual void UnlockMouse() OVERRIDE;
242 virtual void OnSwapCompositorFrame(
243 uint32 output_surface_id,
244 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
246 virtual void SetParentNativeViewAccessible(
247 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
248 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE;
251 // Overridden from ui::TextInputClient:
252 virtual void SetCompositionText(
253 const ui::CompositionText& composition) OVERRIDE;
254 virtual void ConfirmCompositionText() OVERRIDE;
255 virtual void ClearCompositionText() OVERRIDE;
256 virtual void InsertText(const base::string16& text) OVERRIDE;
257 virtual void InsertChar(base::char16 ch, int flags) OVERRIDE;
258 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE;
259 virtual ui::TextInputType GetTextInputType() const OVERRIDE;
260 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE;
261 virtual bool CanComposeInline() const OVERRIDE;
262 virtual gfx::Rect GetCaretBounds() const OVERRIDE;
263 virtual bool GetCompositionCharacterBounds(uint32 index,
264 gfx::Rect* rect) const OVERRIDE;
265 virtual bool HasCompositionText() const OVERRIDE;
266 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE;
267 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE;
268 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE;
269 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE;
270 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE;
271 virtual bool GetTextFromRange(const gfx::Range& range,
272 base::string16* text) const OVERRIDE;
273 virtual void OnInputMethodChanged() OVERRIDE;
274 virtual bool ChangeTextDirectionAndLayoutAlignment(
275 base::i18n::TextDirection direction) OVERRIDE;
276 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE;
277 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE;
278 virtual void OnCandidateWindowShown() OVERRIDE;
279 virtual void OnCandidateWindowUpdated() OVERRIDE;
280 virtual void OnCandidateWindowHidden() OVERRIDE;
282 // Overridden from gfx::DisplayObserver:
283 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
284 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
285 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
287 // Overridden from aura::WindowDelegate:
288 virtual gfx::Size GetMinimumSize() const OVERRIDE;
289 virtual gfx::Size GetMaximumSize() const OVERRIDE;
290 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
291 const gfx::Rect& new_bounds) OVERRIDE;
292 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
293 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
294 virtual bool ShouldDescendIntoChildForEventHandling(
296 const gfx::Point& location) OVERRIDE;
297 virtual bool CanFocus() OVERRIDE;
298 virtual void OnCaptureLost() OVERRIDE;
299 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
300 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
301 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
302 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
303 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
304 virtual bool HasHitTestMask() const OVERRIDE;
305 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
307 // Overridden from ui::EventHandler:
308 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
309 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
310 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
311 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
312 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
314 // Overridden from aura::client::ActivationDelegate:
315 virtual bool ShouldActivate() const OVERRIDE;
317 // Overridden from aura::client::ActivationChangeObserver:
318 virtual void OnWindowActivated(aura::Window* gained_activation,
319 aura::Window* lost_activation) OVERRIDE;
321 // Overridden from aura::client::CursorClientObserver:
322 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE;
324 // Overridden from aura::client::FocusChangeObserver:
325 virtual void OnWindowFocused(aura::Window* gained_focus,
326 aura::Window* lost_focus) OVERRIDE;
328 // Overridden from aura::WindowTreeHostObserver:
329 virtual void OnHostMoved(const aura::WindowTreeHost* host,
330 const gfx::Point& new_origin) OVERRIDE;
332 // SoftwareFrameManagerClient implementation:
333 virtual void SoftwareFrameWasFreed(
334 uint32 output_surface_id, unsigned frame_id) OVERRIDE;
335 virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE;
337 bool CanCopyToBitmap() const;
339 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
342 // Sets the cutout rects from constrained windows. These are rectangles that
343 // windowed NPAPI plugins shouldn't paint in. Overwrites any previous cutout
345 void UpdateConstrainedWindowRects(const std::vector<gfx::Rect>& rects);
347 // Updates the cursor clip region. Used for mouse locking.
348 void UpdateMouseLockRegion();
351 // Method to indicate if this instance is shutting down or closing.
352 // TODO(shrikant): Discuss around to see if it makes sense to add this method
353 // as part of RenderWidgetHostView.
354 bool IsClosing() const { return in_shutdown_; }
357 friend class RenderWidgetHostView;
358 virtual ~RenderWidgetHostViewAura();
360 // Should be constructed via RenderWidgetHostView::CreateViewForWidget.
361 explicit RenderWidgetHostViewAura(RenderWidgetHost* host);
363 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
364 return frame_subscriber_.get();
367 virtual bool ShouldCreateResizeLock();
368 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock);
370 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request);
372 // Exposed for tests.
373 aura::Window* window() { return window_; }
374 gfx::Size current_frame_size() const { return current_frame_size_; }
375 void LockResources();
376 void UnlockResources();
378 // Overridden from ui::CompositorObserver:
379 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE;
380 virtual void OnCompositingStarted(ui::Compositor* compositor,
381 base::TimeTicks start_time) OVERRIDE;
382 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE;
383 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE;
384 virtual void OnCompositingLockStateChanged(
385 ui::Compositor* compositor) OVERRIDE;
387 // Overridden from ui::CompositorVSyncManager::Observer:
388 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase,
389 base::TimeDelta interval) OVERRIDE;
390 virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
392 // Overridden from ui::LayerOwnerObserver:
393 virtual void OnLayerRecreated(ui::Layer* old_layer,
394 ui::Layer* new_layer) OVERRIDE;
397 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SetCompositionText);
398 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventState);
399 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventSyncAsync);
400 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SwapNotifiesWindow);
401 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
402 SkippedDelegatedFrames);
403 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange);
404 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
405 DiscardDelegatedFrames);
406 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
407 DiscardDelegatedFramesWithLocking);
408 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SoftwareDPIChange);
409 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
410 UpdateCursorIfOverSelf);
411 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest,
412 DestroyedAfterCopyRequest);
414 class WindowObserver;
415 friend class WindowObserver;
417 // Overridden from ImageTransportFactoryObserver:
418 virtual void OnLostResources() OVERRIDE;
420 // Overridden from BrowserAccessibilityDelegate:
421 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
422 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
423 virtual void AccessibilityScrollToMakeVisible(
424 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
425 virtual void AccessibilityScrollToPoint(
426 int acc_obj_id, gfx::Point point) OVERRIDE;
427 virtual void AccessibilitySetTextSelection(
428 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
429 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
430 virtual void FatalAccessibilityTreeError() OVERRIDE;
432 void UpdateCursorIfOverSelf();
433 bool ShouldSkipFrame(gfx::Size size_in_dip) const;
435 // Set the bounds of the window and handle size changes. Assumes the caller
436 // has already adjusted the origin of |rect| to conform to whatever coordinate
437 // space is required by the aura::Window.
438 void InternalSetBounds(const gfx::Rect& rect);
440 // Lazily grab a resize lock if the aura window size doesn't match the current
441 // frame size, to give time to the renderer.
442 void MaybeCreateResizeLock();
444 // Checks if the resize lock can be released because we received an new frame.
445 void CheckResizeLock();
447 void UpdateExternalTexture();
448 ui::InputMethod* GetInputMethod() const;
450 // Returns whether the widget needs an input grab to work properly.
451 bool NeedsInputGrab();
453 // Confirm existing composition text in the webpage and ask the input method
454 // to cancel its ongoing composition session.
455 void FinishImeCompositionSession();
457 // This method computes movementX/Y and keeps track of mouse location for
458 // mouse lock on all mouse move events.
459 void ModifyEventMovementAndCoords(blink::WebMouseEvent* event);
461 // Sends an IPC to the renderer process to communicate whether or not
462 // the mouse cursor is visible anywhere on the screen.
463 void NotifyRendererOfCursorVisibilityState(bool is_visible);
465 // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty
466 // SchedulePaint() is invoked for |rect|.
467 void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip);
469 // Helper method to determine if, in mouse locked mode, the cursor should be
471 bool ShouldMoveToCenter();
473 // Run all on compositing commit callbacks.
474 void RunOnCommitCallbacks();
476 // Add on compositing commit callback.
477 void AddOnCommitCallbackAndDisableLocks(const base::Closure& callback);
479 // Called after |window_| is parented to a WindowEventDispatcher.
480 void AddedToRootWindow();
482 // Called prior to removing |window_| from a WindowEventDispatcher.
483 void RemovingFromRootWindow();
485 // Called after commit for the last reference to the texture going away
486 // after it was released as the frontbuffer.
487 void SetSurfaceNotInUseByCompositor(scoped_refptr<ui::Texture>);
489 // Called after async thumbnailer task completes. Scales and crops the result
491 static void CopyFromCompositingSurfaceHasResult(
492 const gfx::Size& dst_size_in_pixel,
493 const SkBitmap::Config config,
494 const base::Callback<void(bool, const SkBitmap&)>& callback,
495 scoped_ptr<cc::CopyOutputResult> result);
496 static void PrepareTextureCopyOutputResult(
497 const gfx::Size& dst_size_in_pixel,
498 const SkBitmap::Config config,
499 const base::Callback<void(bool, const SkBitmap&)>& callback,
500 scoped_ptr<cc::CopyOutputResult> result);
501 static void PrepareBitmapCopyOutputResult(
502 const gfx::Size& dst_size_in_pixel,
503 const SkBitmap::Config config,
504 const base::Callback<void(bool, const SkBitmap&)>& callback,
505 scoped_ptr<cc::CopyOutputResult> result);
506 static void CopyFromCompositingSurfaceHasResultForVideo(
507 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
508 scoped_refptr<OwnedMailbox> subscriber_texture,
509 scoped_refptr<media::VideoFrame> video_frame,
510 const base::Callback<void(bool)>& callback,
511 scoped_ptr<cc::CopyOutputResult> result);
512 static void CopyFromCompositingSurfaceFinishedForVideo(
513 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
514 const base::Callback<void(bool)>& callback,
515 scoped_refptr<OwnedMailbox> subscriber_texture,
516 scoped_ptr<cc::SingleReleaseCallback> release_callback,
518 static void ReturnSubscriberTexture(
519 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
520 scoped_refptr<OwnedMailbox> subscriber_texture,
523 ui::Compositor* GetCompositor() const;
525 // Detaches |this| from the input method object.
526 void DetachFromInputMethod();
528 // Before calling RenderWidgetHost::ForwardKeyboardEvent(), this method
529 // calls our keybindings handler against the event and send matched
530 // edit commands to renderer instead.
531 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event);
533 // Dismisses a Web Popup on a mouse or touch press outside the popup and its
535 void ApplyEventFilterForPopupExit(ui::LocatedEvent* event);
537 // Converts |rect| from window coordinate to screen coordinate.
538 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const;
540 // Converts |rect| from screen coordinate to window coordinate.
541 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
543 typedef base::Callback<void(bool, const scoped_refptr<ui::Texture>&)>
544 BufferPresentedCallback;
546 // The common entry point for buffer updates from renderer
548 void BuffersSwapped(const gfx::Size& surface_size,
549 const gfx::Rect& damage_rect,
550 float surface_scale_factor,
551 const gpu::Mailbox& mailbox,
552 const std::vector<ui::LatencyInfo>& latency_info,
553 const BufferPresentedCallback& ack_callback);
555 bool SwapBuffersPrepare(const gfx::Rect& surface_rect,
556 float surface_scale_factor,
557 const gfx::Rect& damage_rect,
558 const gpu::Mailbox& mailbox,
559 const BufferPresentedCallback& ack_callback);
561 void SwapBuffersCompleted(
562 const BufferPresentedCallback& ack_callback,
563 const scoped_refptr<ui::Texture>& texture_to_return);
565 void SwapDelegatedFrame(
566 uint32 output_surface_id,
567 scoped_ptr<cc::DelegatedFrameData> frame_data,
568 float frame_device_scale_factor,
569 const std::vector<ui::LatencyInfo>& latency_info);
570 void SendDelegatedFrameAck(uint32 output_surface_id);
571 void SendReturnedDelegatedResources(uint32 output_surface_id);
573 // DelegatedFrameEvictorClient implementation.
574 virtual void EvictDelegatedFrame() OVERRIDE;
576 // cc::DelegatedFrameProviderClient implementation.
577 virtual void UnusedResourcesAreAvailable() OVERRIDE;
579 void SwapSoftwareFrame(uint32 output_surface_id,
580 scoped_ptr<cc::SoftwareFrameData> frame_data,
581 float frame_device_scale_factor,
582 const std::vector<ui::LatencyInfo>& latency_info);
583 void SendSoftwareFrameAck(uint32 output_surface_id);
584 void SendReclaimSoftwareFrames();
585 void ReleaseSoftwareFrame(uint32 output_surface_id,
586 unsigned software_frame_id);
588 void DidReceiveFrameFromRenderer();
590 // Helper function to set keyboard focus to the main window.
591 void SetKeyboardFocus();
593 RenderFrameHostImpl* GetFocusedFrame();
596 RenderWidgetHostImpl* host_;
598 aura::Window* window_;
600 scoped_ptr<WindowObserver> window_observer_;
602 // Are we in the process of closing? Tracked so fullscreen views can avoid
603 // sending a second shutdown request to the host when they lose the focus
604 // after requesting shutdown for another reason (e.g. Escape key).
607 // True if in the process of handling a window bounds changed notification.
608 bool in_bounds_changed_;
610 // Is this a fullscreen view?
613 // Our parent host view, if this is a popup. NULL otherwise.
614 RenderWidgetHostViewAura* popup_parent_host_view_;
616 // Our child popup host. NULL if we do not have a child popup.
617 RenderWidgetHostViewAura* popup_child_host_view_;
619 class EventFilterForPopupExit;
620 friend class EventFilterForPopupExit;
621 scoped_ptr<ui::EventHandler> event_filter_for_popup_exit_;
623 // True when content is being loaded. Used to show an hourglass cursor.
626 // The cursor for the page. This is passed up from the renderer.
627 WebCursor current_cursor_;
629 // The touch-event. Its touch-points are updated as necessary. A new
630 // touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is
631 // removed from the list on an ET_TOUCH_RELEASED event.
632 blink::WebTouchEvent touch_event_;
634 // The current text input type.
635 ui::TextInputType text_input_type_;
636 // The current text input mode corresponding to HTML5 inputmode attribute.
637 ui::TextInputMode text_input_mode_;
638 bool can_compose_inline_;
640 // Rectangles for the selection anchor and focus.
641 gfx::Rect selection_anchor_rect_;
642 gfx::Rect selection_focus_rect_;
644 // The current composition character bounds.
645 std::vector<gfx::Rect> composition_character_bounds_;
647 // Indicates if there is onging composition text.
648 bool has_composition_text_;
650 // Whether return characters should be passed on to the RenderWidgetHostImpl.
651 bool accept_return_character_;
653 // Current tooltip text.
654 base::string16 tooltip_;
656 std::vector<base::Closure> on_compositing_did_commit_callbacks_;
658 // The current frontbuffer texture.
659 scoped_refptr<ui::Texture> current_surface_;
661 // This holds the current software framebuffer, if any.
662 scoped_ptr<SoftwareFrameManager> software_frame_manager_;
664 // The vsync manager we are observing for changes, if any.
665 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_;
667 // With delegated renderer, this is the last output surface, used to
668 // disambiguate resources with the same id coming from different output
670 uint32 last_output_surface_id_;
672 // The number of delegated frame acks that are pending, to delay resource
673 // returns until the acks are sent.
674 int pending_delegated_ack_count_;
676 // The damage in the previously presented buffer.
677 SkRegion previous_damage_;
679 // Pending damage from previous frames that we skipped.
680 SkRegion skipped_damage_;
682 // True after a delegated frame has been skipped, until a frame is not
684 bool skipped_frames_;
686 // Holds delegated resources that have been given to a DelegatedFrameProvider,
687 // and gives back resources when they are no longer in use for return to the
689 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
691 // Provides delegated frame updates to the cc::DelegatedRendererLayer.
692 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
694 // The size of the last frame that was swapped (even if we skipped it).
695 // Used to determine when the skipped_damage_ needs to be reset due to
696 // size changes between front- and backbuffer.
697 gfx::Size last_swapped_surface_size_;
698 float last_swapped_surface_scale_factor_;
700 // If non-NULL we're in OnPaint() and this is the supplied canvas.
701 gfx::Canvas* paint_canvas_;
703 // Used to record the last position of the mouse.
704 // While the mouse is locked, they store the last known position just as mouse
706 // Relative to the upper-left corner of the view.
707 gfx::Point unlocked_mouse_position_;
708 // Relative to the upper-left corner of the screen.
709 gfx::Point unlocked_global_mouse_position_;
710 // Last cursor position relative to screen. Used to compute movementX/Y.
711 gfx::Point global_mouse_position_;
712 // In mouse locked mode, we syntheticaly move the mouse cursor to the center
713 // of the window when it reaches the window borders to avoid it going outside.
714 // This flag is used to differentiate between these synthetic mouse move
715 // events vs. normal mouse move events.
716 bool synthetic_move_sent_;
718 // Signals that the accelerated compositing has been turned on or off.
719 // This is used to signal to turn off the external texture as soon as the
720 // software backing store is updated.
721 bool accelerated_compositing_state_changed_;
723 // This lock is the one waiting for a frame of the right size to come back
724 // from the renderer/GPU process. It is set from the moment the aura window
725 // got resized, to the moment we committed the renderer frame of the same
726 // size. It keeps track of the size we expect from the renderer, and locks the
727 // compositor, as well as the UI for a short time to give a chance to the
728 // renderer of producing a frame of the right size.
729 scoped_ptr<ResizeLock> resize_lock_;
731 // Keeps track of the current frame size.
732 gfx::Size current_frame_size_;
734 // This lock is for waiting for a front surface to become available to draw.
735 scoped_refptr<ui::CompositorLock> released_front_lock_;
737 // Used to track the state of the window we're created from. Only used when
738 // created fullscreen.
739 scoped_ptr<aura::WindowTracker> host_tracker_;
741 enum CanLockCompositorState {
743 // We locked, so at some point we'll need to kick a frame.
745 // No. A lock timed out, we need to kick a new frame before locking again.
746 NO_PENDING_RENDERER_FRAME,
747 // No. We've got a frame, but it hasn't been committed.
750 CanLockCompositorState can_lock_compositor_;
752 // Used to track the last cursor visibility update that was sent to the
753 // renderer via NotifyRendererOfCursorVisibilityState().
754 enum CursorVisibilityState {
759 CursorVisibilityState cursor_visibility_state_in_renderer_;
762 // The list of rectangles from constrained windows over this view. Windowed
763 // NPAPI plugins shouldn't draw over them.
764 std::vector<gfx::Rect> constrained_rects_;
766 typedef std::map<HWND, WebPluginGeometry> PluginWindowMoves;
767 // Contains information about each windowed plugin's clip and cutout rects (
768 // from the renderer). This is needed because when the transient windoiws
769 // over this view changes, we need this information in order to create a new
770 // region for the HWND.
771 PluginWindowMoves plugin_window_moves_;
774 base::TimeTicks last_draw_ended_;
776 // Subscriber that listens to frame presentation events.
777 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
778 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_;
779 std::set<OwnedMailbox*> active_frame_subscriber_textures_;
781 // YUV readback pipeline.
782 scoped_ptr<content::ReadbackYUVInterface>
783 yuv_readback_pipeline_;
785 TouchEditingClient* touch_editing_client_;
787 std::vector<ui::LatencyInfo> software_latency_info_;
789 struct ReleasedFrameInfo {
790 ReleasedFrameInfo(uint32 output_id, unsigned software_frame_id)
791 : output_surface_id(output_id), frame_id(software_frame_id) {}
792 uint32 output_surface_id;
795 scoped_ptr<ReleasedFrameInfo> released_software_frame_;
796 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_;
798 scoped_ptr<aura::client::ScopedTooltipDisabler> tooltip_disabler_;
800 base::WeakPtrFactory<RenderWidgetHostViewAura> weak_ptr_factory_;
803 // The LegacyRenderWidgetHostHWND class provides a dummy HWND which is used
804 // for accessibility, as the container for windowless plugins like
805 // Flash/Silverlight, etc and for legacy drivers for trackpoints/trackpads,
807 scoped_ptr<content::LegacyRenderWidgetHostHWND>
808 legacy_render_widget_host_HWND_;
810 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura);
813 } // namespace content
815 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_