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() OVERRIDE;
299 virtual void OnWindowDestroyed() 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(const aura::RootWindow* root,
329 const gfx::Point& new_origin) OVERRIDE;
331 // SoftwareFrameManagerClient implementation:
332 virtual void SoftwareFrameWasFreed(
333 uint32 output_surface_id, unsigned frame_id) OVERRIDE;
334 virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE;
336 bool CanCopyToBitmap() const;
338 void OnTextInputStateChanged(const ViewHostMsg_TextInputState_Params& params);
341 // Sets the cutout rects from constrained windows. These are rectangles that
342 // windowed NPAPI plugins shouldn't paint in. Overwrites any previous cutout
344 void UpdateConstrainedWindowRects(const std::vector<gfx::Rect>& rects);
347 // Method to indicate if this instance is shutting down or closing.
348 // TODO(shrikant): Discuss around to see if it makes sense to add this method
349 // as part of RenderWidgetHostView.
350 bool IsClosing() const { return in_shutdown_; }
353 friend class RenderWidgetHostView;
354 virtual ~RenderWidgetHostViewAura();
356 // Should be constructed via RenderWidgetHostView::CreateViewForWidget.
357 explicit RenderWidgetHostViewAura(RenderWidgetHost* host);
359 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
360 return frame_subscriber_.get();
363 virtual bool ShouldCreateResizeLock();
364 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock);
366 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request);
368 // Exposed for tests.
369 aura::Window* window() { return window_; }
370 gfx::Size current_frame_size() const { return current_frame_size_; }
371 void LockResources();
372 void UnlockResources();
374 // Overridden from ui::CompositorObserver:
375 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE;
376 virtual void OnCompositingStarted(ui::Compositor* compositor,
377 base::TimeTicks start_time) OVERRIDE;
378 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE;
379 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE;
380 virtual void OnCompositingLockStateChanged(
381 ui::Compositor* compositor) OVERRIDE;
383 // Overridden from ui::CompositorVSyncManager::Observer
384 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase,
385 base::TimeDelta interval) OVERRIDE;
388 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SetCompositionText);
389 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventState);
390 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventSyncAsync);
391 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SwapNotifiesWindow);
392 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
393 SkippedDelegatedFrames);
394 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange);
395 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
396 DiscardDelegatedFrames);
397 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
398 DiscardDelegatedFramesWithLocking);
399 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SoftwareDPIChange);
400 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
401 UpdateCursorIfOverSelf);
402 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest,
403 DestroyedAfterCopyRequest);
405 class WindowObserver;
406 friend class WindowObserver;
408 // Overridden from ImageTransportFactoryObserver:
409 virtual void OnLostResources() OVERRIDE;
411 // Overridden from BrowserAccessibilityDelegate:
412 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
413 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
414 virtual void AccessibilityScrollToMakeVisible(
415 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
416 virtual void AccessibilityScrollToPoint(
417 int acc_obj_id, gfx::Point point) OVERRIDE;
418 virtual void AccessibilitySetTextSelection(
419 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
420 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
421 virtual void FatalAccessibilityTreeError() OVERRIDE;
423 void UpdateCursorIfOverSelf();
424 bool ShouldSkipFrame(gfx::Size size_in_dip) const;
426 // Set the bounds of the window and handle size changes. Assumes the caller
427 // has already adjusted the origin of |rect| to conform to whatever coordinate
428 // space is required by the aura::Window.
429 void InternalSetBounds(const gfx::Rect& rect);
431 // Lazily grab a resize lock if the aura window size doesn't match the current
432 // frame size, to give time to the renderer.
433 void MaybeCreateResizeLock();
435 // Checks if the resize lock can be released because we received an new frame.
436 void CheckResizeLock();
438 void UpdateExternalTexture();
439 ui::InputMethod* GetInputMethod() const;
441 // Returns whether the widget needs an input grab to work properly.
442 bool NeedsInputGrab();
444 // Confirm existing composition text in the webpage and ask the input method
445 // to cancel its ongoing composition session.
446 void FinishImeCompositionSession();
448 // This method computes movementX/Y and keeps track of mouse location for
449 // mouse lock on all mouse move events.
450 void ModifyEventMovementAndCoords(blink::WebMouseEvent* event);
452 // Sends an IPC to the renderer process to communicate whether or not
453 // the mouse cursor is visible anywhere on the screen.
454 void NotifyRendererOfCursorVisibilityState(bool is_visible);
456 // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty
457 // SchedulePaint() is invoked for |rect|.
458 void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip);
460 // Helper method to determine if, in mouse locked mode, the cursor should be
462 bool ShouldMoveToCenter();
464 // Run all on compositing commit callbacks.
465 void RunOnCommitCallbacks();
467 // Add on compositing commit callback.
468 void AddOnCommitCallbackAndDisableLocks(const base::Closure& callback);
470 // Called after |window_| is parented to a RootWindow.
471 void AddedToRootWindow();
473 // Called prior to removing |window_| from a RootWindow.
474 void RemovingFromRootWindow();
476 // Called after commit for the last reference to the texture going away
477 // after it was released as the frontbuffer.
478 void SetSurfaceNotInUseByCompositor(scoped_refptr<ui::Texture>);
480 // Called after async thumbnailer task completes. Scales and crops the result
482 static void CopyFromCompositingSurfaceHasResult(
483 const gfx::Size& dst_size_in_pixel,
484 const SkBitmap::Config config,
485 const base::Callback<void(bool, const SkBitmap&)>& callback,
486 scoped_ptr<cc::CopyOutputResult> result);
487 static void PrepareTextureCopyOutputResult(
488 const gfx::Size& dst_size_in_pixel,
489 const SkBitmap::Config config,
490 const base::Callback<void(bool, const SkBitmap&)>& callback,
491 scoped_ptr<cc::CopyOutputResult> result);
492 static void PrepareBitmapCopyOutputResult(
493 const gfx::Size& dst_size_in_pixel,
494 const SkBitmap::Config config,
495 const base::Callback<void(bool, const SkBitmap&)>& callback,
496 scoped_ptr<cc::CopyOutputResult> result);
497 static void CopyFromCompositingSurfaceHasResultForVideo(
498 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
499 scoped_refptr<OwnedMailbox> subscriber_texture,
500 scoped_refptr<media::VideoFrame> video_frame,
501 const base::Callback<void(bool)>& callback,
502 scoped_ptr<cc::CopyOutputResult> result);
503 static void CopyFromCompositingSurfaceFinishedForVideo(
504 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
505 const base::Callback<void(bool)>& callback,
506 scoped_refptr<OwnedMailbox> subscriber_texture,
507 scoped_ptr<cc::SingleReleaseCallback> release_callback,
509 static void ReturnSubscriberTexture(
510 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
511 scoped_refptr<OwnedMailbox> subscriber_texture,
514 ui::Compositor* GetCompositor() const;
516 // Detaches |this| from the input method object.
517 void DetachFromInputMethod();
519 // Dismisses a Web Popup on a mouse or touch press outside the popup and its
521 void ApplyEventFilterForPopupExit(ui::LocatedEvent* event);
523 // Converts |rect| from window coordinate to screen coordinate.
524 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const;
526 // Converts |rect| from screen coordinate to window coordinate.
527 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
529 typedef base::Callback<void(bool, const scoped_refptr<ui::Texture>&)>
530 BufferPresentedCallback;
532 // The common entry point for buffer updates from renderer
534 void BuffersSwapped(const gfx::Size& surface_size,
535 const gfx::Rect& damage_rect,
536 float surface_scale_factor,
537 const gpu::Mailbox& mailbox,
538 const std::vector<ui::LatencyInfo>& latency_info,
539 const BufferPresentedCallback& ack_callback);
541 bool SwapBuffersPrepare(const gfx::Rect& surface_rect,
542 float surface_scale_factor,
543 const gfx::Rect& damage_rect,
544 const gpu::Mailbox& mailbox,
545 const BufferPresentedCallback& ack_callback);
547 void SwapBuffersCompleted(
548 const BufferPresentedCallback& ack_callback,
549 const scoped_refptr<ui::Texture>& texture_to_return);
551 void SwapDelegatedFrame(
552 uint32 output_surface_id,
553 scoped_ptr<cc::DelegatedFrameData> frame_data,
554 float frame_device_scale_factor,
555 const std::vector<ui::LatencyInfo>& latency_info);
556 void SendDelegatedFrameAck(uint32 output_surface_id);
557 void SendReturnedDelegatedResources(uint32 output_surface_id);
559 // DelegatedFrameEvictorClient implementation.
560 virtual void EvictDelegatedFrame() OVERRIDE;
562 // cc::DelegatedFrameProviderClient implementation.
563 virtual void UnusedResourcesAreAvailable() OVERRIDE;
565 void SwapSoftwareFrame(uint32 output_surface_id,
566 scoped_ptr<cc::SoftwareFrameData> frame_data,
567 float frame_device_scale_factor,
568 const std::vector<ui::LatencyInfo>& latency_info);
569 void SendSoftwareFrameAck(uint32 output_surface_id);
570 void SendReclaimSoftwareFrames();
571 void ReleaseSoftwareFrame(uint32 output_surface_id,
572 unsigned software_frame_id);
574 void DidReceiveFrameFromRenderer();
576 // Helper function to set keyboard focus to the main window.
577 void SetKeyboardFocus();
580 RenderWidgetHostImpl* host_;
582 aura::Window* window_;
584 scoped_ptr<WindowObserver> window_observer_;
586 // Are we in the process of closing? Tracked so fullscreen views can avoid
587 // sending a second shutdown request to the host when they lose the focus
588 // after requesting shutdown for another reason (e.g. Escape key).
591 // True if in the process of handling a window bounds changed notification.
592 bool in_bounds_changed_;
594 // Is this a fullscreen view?
597 // Our parent host view, if this is a popup. NULL otherwise.
598 RenderWidgetHostViewAura* popup_parent_host_view_;
600 // Our child popup host. NULL if we do not have a child popup.
601 RenderWidgetHostViewAura* popup_child_host_view_;
603 class EventFilterForPopupExit;
604 friend class EventFilterForPopupExit;
605 scoped_ptr<ui::EventHandler> event_filter_for_popup_exit_;
607 // True when content is being loaded. Used to show an hourglass cursor.
610 // The cursor for the page. This is passed up from the renderer.
611 WebCursor current_cursor_;
613 // The touch-event. Its touch-points are updated as necessary. A new
614 // touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is
615 // removed from the list on an ET_TOUCH_RELEASED event.
616 blink::WebTouchEvent touch_event_;
618 // The current text input type.
619 ui::TextInputType text_input_type_;
620 // The current text input mode corresponding to HTML5 inputmode attribute.
621 ui::TextInputMode text_input_mode_;
622 bool can_compose_inline_;
624 // Rectangles for the selection anchor and focus.
625 gfx::Rect selection_anchor_rect_;
626 gfx::Rect selection_focus_rect_;
628 // The current composition character bounds.
629 std::vector<gfx::Rect> composition_character_bounds_;
631 // Indicates if there is onging composition text.
632 bool has_composition_text_;
634 // Whether return characters should be passed on to the RenderWidgetHostImpl.
635 bool accept_return_character_;
637 // Current tooltip text.
638 base::string16 tooltip_;
640 std::vector<base::Closure> on_compositing_did_commit_callbacks_;
642 // The current frontbuffer texture.
643 scoped_refptr<ui::Texture> current_surface_;
645 // This holds the current software framebuffer, if any.
646 scoped_ptr<SoftwareFrameManager> software_frame_manager_;
648 // The vsync manager we are observing for changes, if any.
649 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_;
651 // With delegated renderer, this is the last output surface, used to
652 // disambiguate resources with the same id coming from different output
654 uint32 last_output_surface_id_;
656 // The number of delegated frame acks that are pending, to delay resource
657 // returns until the acks are sent.
658 int pending_delegated_ack_count_;
660 // The damage in the previously presented buffer.
661 SkRegion previous_damage_;
663 // Pending damage from previous frames that we skipped.
664 SkRegion skipped_damage_;
666 // True after a delegated frame has been skipped, until a frame is not
668 bool skipped_frames_;
670 // Holds delegated resources that have been given to a DelegatedFrameProvider,
671 // and gives back resources when they are no longer in use for return to the
673 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
675 // Provides delegated frame updates to the cc::DelegatedRendererLayer.
676 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
678 // The size of the last frame that was swapped (even if we skipped it).
679 // Used to determine when the skipped_damage_ needs to be reset due to
680 // size changes between front- and backbuffer.
681 gfx::Size last_swapped_surface_size_;
682 float last_swapped_surface_scale_factor_;
684 // If non-NULL we're in OnPaint() and this is the supplied canvas.
685 gfx::Canvas* paint_canvas_;
687 // Used to record the last position of the mouse.
688 // While the mouse is locked, they store the last known position just as mouse
690 // Relative to the upper-left corner of the view.
691 gfx::Point unlocked_mouse_position_;
692 // Relative to the upper-left corner of the screen.
693 gfx::Point unlocked_global_mouse_position_;
694 // Last cursor position relative to screen. Used to compute movementX/Y.
695 gfx::Point global_mouse_position_;
696 // In mouse locked mode, we syntheticaly move the mouse cursor to the center
697 // of the window when it reaches the window borders to avoid it going outside.
698 // This flag is used to differentiate between these synthetic mouse move
699 // events vs. normal mouse move events.
700 bool synthetic_move_sent_;
702 // Signals that the accelerated compositing has been turned on or off.
703 // This is used to signal to turn off the external texture as soon as the
704 // software backing store is updated.
705 bool accelerated_compositing_state_changed_;
707 // This lock is the one waiting for a frame of the right size to come back
708 // from the renderer/GPU process. It is set from the moment the aura window
709 // got resized, to the moment we committed the renderer frame of the same
710 // size. It keeps track of the size we expect from the renderer, and locks the
711 // compositor, as well as the UI for a short time to give a chance to the
712 // renderer of producing a frame of the right size.
713 scoped_ptr<ResizeLock> resize_lock_;
715 // Keeps track of the current frame size.
716 gfx::Size current_frame_size_;
718 // This lock is for waiting for a front surface to become available to draw.
719 scoped_refptr<ui::CompositorLock> released_front_lock_;
721 // Used to track the state of the window we're created from. Only used when
722 // created fullscreen.
723 scoped_ptr<aura::WindowTracker> host_tracker_;
725 enum CanLockCompositorState {
727 // We locked, so at some point we'll need to kick a frame.
729 // No. A lock timed out, we need to kick a new frame before locking again.
730 NO_PENDING_RENDERER_FRAME,
731 // No. We've got a frame, but it hasn't been committed.
734 CanLockCompositorState can_lock_compositor_;
736 // Used to track the last cursor visibility update that was sent to the
737 // renderer via NotifyRendererOfCursorVisibilityState().
738 enum CursorVisibilityState {
743 CursorVisibilityState cursor_visibility_state_in_renderer_;
746 // The list of rectangles from constrained windows over this view. Windowed
747 // NPAPI plugins shouldn't draw over them.
748 std::vector<gfx::Rect> constrained_rects_;
750 typedef std::map<HWND, WebPluginGeometry> PluginWindowMoves;
751 // Contains information about each windowed plugin's clip and cutout rects (
752 // from the renderer). This is needed because when the transient windoiws
753 // over this view changes, we need this information in order to create a new
754 // region for the HWND.
755 PluginWindowMoves plugin_window_moves_;
758 base::TimeTicks last_draw_ended_;
760 // Subscriber that listens to frame presentation events.
761 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
762 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_;
763 std::set<OwnedMailbox*> active_frame_subscriber_textures_;
765 // YUV readback pipeline.
766 scoped_ptr<content::ReadbackYUVInterface>
767 yuv_readback_pipeline_;
769 TouchEditingClient* touch_editing_client_;
771 std::vector<ui::LatencyInfo> software_latency_info_;
773 struct ReleasedFrameInfo {
774 ReleasedFrameInfo(uint32 output_id, unsigned software_frame_id)
775 : output_surface_id(output_id), frame_id(software_frame_id) {}
776 uint32 output_surface_id;
779 scoped_ptr<ReleasedFrameInfo> released_software_frame_;
780 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_;
782 scoped_ptr<aura::client::ScopedTooltipDisabler> tooltip_disabler_;
784 base::WeakPtrFactory<RenderWidgetHostViewAura> weak_ptr_factory_;
787 // The LegacyRenderWidgetHostHWND class provides a dummy HWND which is used
788 // for accessibility, as the container for windowless plugins like
789 // Flash/Silverlight, etc and for legacy drivers for trackpoints/trackpads,
791 scoped_ptr<content::LegacyRenderWidgetHostHWND>
792 legacy_render_widget_host_HWND_;
794 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura);
797 } // namespace content
799 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_