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