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_
12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "cc/layers/delegated_frame_provider.h"
19 #include "cc/layers/delegated_frame_resource_collection.h"
20 #include "cc/resources/texture_mailbox.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/aura/image_transport_factory.h"
23 #include "content/browser/renderer_host/delegated_frame_evictor.h"
24 #include "content/browser/renderer_host/render_widget_host_view_base.h"
25 #include "content/browser/renderer_host/software_frame_manager.h"
26 #include "content/common/content_export.h"
27 #include "content/common/gpu/client/gl_helper.h"
28 #include "third_party/skia/include/core/SkRegion.h"
29 #include "ui/aura/client/activation_change_observer.h"
30 #include "ui/aura/client/activation_delegate.h"
31 #include "ui/aura/client/cursor_client_observer.h"
32 #include "ui/aura/client/focus_change_observer.h"
33 #include "ui/aura/root_window_observer.h"
34 #include "ui/aura/window_delegate.h"
35 #include "ui/base/ime/text_input_client.h"
36 #include "ui/compositor/compositor.h"
37 #include "ui/compositor/compositor_observer.h"
38 #include "ui/gfx/display_observer.h"
39 #include "ui/gfx/rect.h"
40 #include "webkit/common/cursors/webcursor.h"
47 class CopyOutputResult;
48 class DelegatedFrameData;
63 class RenderWidgetHostImpl;
64 class RenderWidgetHostView;
67 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
68 class CONTENT_EXPORT RenderWidgetHostViewAura
69 : public RenderWidgetHostViewBase,
70 public ui::CompositorObserver,
71 public ui::TextInputClient,
72 public gfx::DisplayObserver,
73 public aura::RootWindowObserver,
74 public aura::WindowDelegate,
75 public aura::client::ActivationDelegate,
76 public aura::client::ActivationChangeObserver,
77 public aura::client::FocusChangeObserver,
78 public aura::client::CursorClientObserver,
79 public ImageTransportFactoryObserver,
80 public BrowserAccessibilityDelegate,
81 public SoftwareFrameManagerClient,
82 public DelegatedFrameEvictorClient,
83 public base::SupportsWeakPtr<RenderWidgetHostViewAura>,
84 public cc::DelegatedFrameResourceCollectionClient {
86 // Used to notify whenever the paint-content of the view changes.
90 virtual ~PaintObserver() {}
92 // This is called when painting of the page is completed.
93 virtual void OnPaintComplete() = 0;
95 // This is called when compositor painting of the page is completed.
96 virtual void OnCompositingComplete() = 0;
98 // This is called when the contents for compositor painting changes.
99 virtual void OnUpdateCompositorContent() = 0;
101 // This is called loading the page has completed.
102 virtual void OnPageLoadComplete() = 0;
104 // This is called when the view is destroyed, so that the observer can
105 // perform any necessary clean-up.
106 virtual void OnViewDestroyed() = 0;
109 // Displays and controls touch editing elements such as selection handles.
110 class TouchEditingClient {
112 TouchEditingClient() {}
114 // Tells the client to start showing touch editing handles.
115 virtual void StartTouchEditing() = 0;
117 // Notifies the client that touch editing is no longer needed.
118 virtual void EndTouchEditing() = 0;
120 // Notifies the client that the selection bounds need to be updated.
121 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
122 const gfx::Rect& focus) = 0;
124 // Notifies the client that the current text input type as changed.
125 virtual void OnTextInputTypeChanged(ui::TextInputType type) = 0;
127 // Notifies the client that an input event is about to be sent to the
128 // renderer. Returns true if the client wants to stop event propagation.
129 virtual bool HandleInputEvent(const ui::Event* event) = 0;
131 // Notifies the client that a gesture event ack was received.
132 virtual void GestureEventAck(int gesture_event_type) = 0;
134 // This is called when the view is destroyed, so that the client can
135 // perform any necessary clean-up.
136 virtual void OnViewDestroyed() = 0;
139 virtual ~TouchEditingClient() {}
142 void set_paint_observer(PaintObserver* observer) {
143 paint_observer_ = observer;
146 void set_touch_editing_client(TouchEditingClient* client) {
147 touch_editing_client_ = client;
150 // RenderWidgetHostView implementation.
151 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
152 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
153 virtual void SetSize(const gfx::Size& size) OVERRIDE;
154 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
155 virtual gfx::NativeView GetNativeView() const OVERRIDE;
156 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
157 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
158 virtual bool HasFocus() const OVERRIDE;
159 virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
160 virtual void Show() OVERRIDE;
161 virtual void Hide() OVERRIDE;
162 virtual bool IsShowing() OVERRIDE;
163 virtual gfx::Rect GetViewBounds() const OVERRIDE;
164 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
166 // Overridden from RenderWidgetHostViewPort:
167 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
168 const gfx::Rect& pos) OVERRIDE;
169 virtual void InitAsFullscreen(
170 RenderWidgetHostView* reference_host_view) OVERRIDE;
171 virtual void WasShown() OVERRIDE;
172 virtual void WasHidden() OVERRIDE;
173 virtual void MovePluginWindows(
174 const gfx::Vector2d& scroll_offset,
175 const std::vector<WebPluginGeometry>& moves) OVERRIDE;
176 virtual void Focus() OVERRIDE;
177 virtual void Blur() OVERRIDE;
178 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
179 virtual void SetIsLoading(bool is_loading) OVERRIDE;
180 virtual void TextInputTypeChanged(ui::TextInputType type,
181 ui::TextInputMode input_mode,
182 bool can_compose_inline) OVERRIDE;
183 virtual void ImeCancelComposition() OVERRIDE;
184 virtual void ImeCompositionRangeChanged(
185 const gfx::Range& range,
186 const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
187 virtual void DidUpdateBackingStore(
188 const gfx::Rect& scroll_rect,
189 const gfx::Vector2d& scroll_delta,
190 const std::vector<gfx::Rect>& copy_rects,
191 const ui::LatencyInfo& latency_info) OVERRIDE;
192 virtual void RenderProcessGone(base::TerminationStatus status,
193 int error_code) OVERRIDE;
194 virtual void Destroy() OVERRIDE;
195 virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE;
196 virtual void SelectionChanged(const string16& text,
198 const gfx::Range& range) OVERRIDE;
199 virtual void SelectionBoundsChanged(
200 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
201 virtual void ScrollOffsetChanged() OVERRIDE;
202 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
203 virtual void CopyFromCompositingSurface(
204 const gfx::Rect& src_subrect,
205 const gfx::Size& dst_size,
206 const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
207 virtual void CopyFromCompositingSurfaceToVideoFrame(
208 const gfx::Rect& src_subrect,
209 const scoped_refptr<media::VideoFrame>& target,
210 const base::Callback<void(bool)>& callback) OVERRIDE;
211 virtual bool CanCopyToVideoFrame() const OVERRIDE;
212 virtual bool CanSubscribeFrame() const OVERRIDE;
213 virtual void BeginFrameSubscription(
214 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
215 virtual void EndFrameSubscription() OVERRIDE;
216 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
217 virtual void AcceleratedSurfaceBuffersSwapped(
218 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
219 int gpu_host_id) OVERRIDE;
220 virtual void AcceleratedSurfacePostSubBuffer(
221 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
222 int gpu_host_id) OVERRIDE;
223 virtual void AcceleratedSurfaceSuspend() OVERRIDE;
224 virtual void AcceleratedSurfaceRelease() OVERRIDE;
225 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
226 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
227 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
228 virtual void GestureEventAck(int gesture_event_type,
229 InputEventAckState ack_result) OVERRIDE;
230 virtual void ProcessAckedTouchEvent(
231 const TouchEventWithLatencyInfo& touch,
232 InputEventAckState ack_result) OVERRIDE;
233 virtual SyntheticGesture* CreateSmoothScrollGesture(
235 int pixels_to_scroll,
237 int mouse_event_y) OVERRIDE;
238 virtual void SetHasHorizontalScrollbar(
239 bool has_horizontal_scrollbar) OVERRIDE;
240 virtual void SetScrollOffsetPinning(
241 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
242 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
243 virtual void OnAccessibilityEvents(
244 const std::vector<AccessibilityHostMsg_EventParams>&
246 virtual bool LockMouse() OVERRIDE;
247 virtual void UnlockMouse() OVERRIDE;
248 virtual void OnSwapCompositorFrame(
249 uint32 output_surface_id,
250 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
252 virtual void SetParentNativeViewAccessible(
253 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
256 // Overridden from ui::TextInputClient:
257 virtual void SetCompositionText(
258 const ui::CompositionText& composition) OVERRIDE;
259 virtual void ConfirmCompositionText() OVERRIDE;
260 virtual void ClearCompositionText() OVERRIDE;
261 virtual void InsertText(const string16& text) OVERRIDE;
262 virtual void InsertChar(char16 ch, int flags) OVERRIDE;
263 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE;
264 virtual ui::TextInputType GetTextInputType() const OVERRIDE;
265 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE;
266 virtual bool CanComposeInline() const OVERRIDE;
267 virtual gfx::Rect GetCaretBounds() const OVERRIDE;
268 virtual bool GetCompositionCharacterBounds(uint32 index,
269 gfx::Rect* rect) const OVERRIDE;
270 virtual bool HasCompositionText() const OVERRIDE;
271 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE;
272 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE;
273 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE;
274 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE;
275 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE;
276 virtual bool GetTextFromRange(const gfx::Range& range,
277 string16* text) const OVERRIDE;
278 virtual void OnInputMethodChanged() OVERRIDE;
279 virtual bool ChangeTextDirectionAndLayoutAlignment(
280 base::i18n::TextDirection direction) OVERRIDE;
281 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE;
282 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE;
284 // Overridden from gfx::DisplayObserver:
285 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
286 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
287 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
289 // Overridden from aura::WindowDelegate:
290 virtual gfx::Size GetMinimumSize() const OVERRIDE;
291 virtual gfx::Size GetMaximumSize() const OVERRIDE;
292 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
293 const gfx::Rect& new_bounds) OVERRIDE;
294 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
295 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
296 virtual bool ShouldDescendIntoChildForEventHandling(
298 const gfx::Point& location) OVERRIDE;
299 virtual bool CanFocus() OVERRIDE;
300 virtual void OnCaptureLost() OVERRIDE;
301 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
302 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
303 virtual void OnWindowDestroying() OVERRIDE;
304 virtual void OnWindowDestroyed() OVERRIDE;
305 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
306 virtual bool HasHitTestMask() const OVERRIDE;
307 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
308 virtual void DidRecreateLayer(ui::Layer *old_layer,
309 ui::Layer *new_layer) OVERRIDE;
311 // Overridden from ui::EventHandler:
312 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
313 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
314 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
315 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
316 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
318 // Overridden from aura::client::ActivationDelegate:
319 virtual bool ShouldActivate() const OVERRIDE;
321 // Overridden from aura::client::ActivationChangeObserver:
322 virtual void OnWindowActivated(aura::Window* gained_activation,
323 aura::Window* lost_activation) OVERRIDE;
325 // Overridden from aura::client::CursorClientObserver:
326 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE;
328 // Overridden from aura::client::FocusChangeObserver:
329 virtual void OnWindowFocused(aura::Window* gained_focus,
330 aura::Window* lost_focus) OVERRIDE;
332 // Overridden from aura::RootWindowObserver:
333 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
334 const gfx::Point& new_origin) OVERRIDE;
336 // SoftwareFrameManagerClient implementation:
337 virtual void SoftwareFrameWasFreed(
338 uint32 output_surface_id, unsigned frame_id) OVERRIDE;
339 virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE;
341 bool CanCopyToBitmap() const;
344 // Sets the cutout rects from constrained windows. These are rectangles that
345 // windowed NPAPI plugins shouldn't paint in. Overwrites any previous cutout
347 void UpdateConstrainedWindowRects(const std::vector<gfx::Rect>& rects);
350 // Method to indicate if this instance is shutting down or closing.
351 // TODO(shrikant): Discuss around to see if it makes sense to add this method
352 // as part of RenderWidgetHostView.
353 bool IsClosing() const { return in_shutdown_; };
356 friend class RenderWidgetHostView;
357 virtual ~RenderWidgetHostViewAura();
359 // Should be constructed via RenderWidgetHostView::CreateViewForWidget.
360 explicit RenderWidgetHostViewAura(RenderWidgetHost* host);
362 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
363 return frame_subscriber_.get();
366 virtual bool ShouldCreateResizeLock();
367 virtual scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock);
369 // Exposed for tests.
370 aura::Window* window() { return window_; }
371 gfx::Size current_frame_size() const { return current_frame_size_; }
373 // Overridden from ui::CompositorObserver:
374 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE;
375 virtual void OnCompositingStarted(ui::Compositor* compositor,
376 base::TimeTicks start_time) OVERRIDE;
377 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE;
378 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE;
379 virtual void OnCompositingLockStateChanged(
380 ui::Compositor* compositor) OVERRIDE;
381 virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
382 base::TimeTicks timebase,
383 base::TimeDelta interval) OVERRIDE;
386 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SetCompositionText);
387 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventState);
388 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventSyncAsync);
389 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SwapNotifiesWindow);
390 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
391 SkippedDelegatedFrames);
392 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange);
393 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
394 DiscardDelegatedFrames);
396 class WindowObserver;
397 friend class WindowObserver;
399 // Overridden from ImageTransportFactoryObserver:
400 virtual void OnLostResources() OVERRIDE;
402 // Overridden from BrowserAccessibilityDelegate:
403 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
404 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
405 virtual void AccessibilityScrollToMakeVisible(
406 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
407 virtual void AccessibilityScrollToPoint(
408 int acc_obj_id, gfx::Point point) OVERRIDE;
409 virtual void AccessibilitySetTextSelection(
410 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
411 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
412 virtual void FatalAccessibilityTreeError() OVERRIDE;
414 void UpdateCursorIfOverSelf();
415 bool ShouldSkipFrame(gfx::Size size_in_dip) const;
417 // Set the bounds of the window and handle size changes. Assumes the caller
418 // has already adjusted the origin of |rect| to conform to whatever coordinate
419 // space is required by the aura::Window.
420 void InternalSetBounds(const gfx::Rect& rect);
422 // Lazily grab a resize lock if the aura window size doesn't match the current
423 // frame size, to give time to the renderer.
424 void MaybeCreateResizeLock();
426 // Checks if the resize lock can be released because we received an new frame.
427 void CheckResizeLock();
429 void UpdateExternalTexture();
430 ui::InputMethod* GetInputMethod() const;
432 // Returns whether the widget needs an input grab to work properly.
433 bool NeedsInputGrab();
435 // Confirm existing composition text in the webpage and ask the input method
436 // to cancel its ongoing composition session.
437 void FinishImeCompositionSession();
439 // This method computes movementX/Y and keeps track of mouse location for
440 // mouse lock on all mouse move events.
441 void ModifyEventMovementAndCoords(WebKit::WebMouseEvent* event);
443 // Sends an IPC to the renderer process to communicate whether or not
444 // the mouse cursor is visible anywhere on the screen.
445 void NotifyRendererOfCursorVisibilityState(bool is_visible);
447 // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty
448 // SchedulePaint() is invoked for |rect|.
449 void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip);
451 // Helper method to determine if, in mouse locked mode, the cursor should be
453 bool ShouldMoveToCenter();
455 // Run all on compositing commit callbacks.
456 void RunOnCommitCallbacks();
458 // Add on compositing commit callback.
459 void AddOnCommitCallbackAndDisableLocks(const base::Closure& callback);
461 // Called after |window_| is parented to a RootWindow.
462 void AddedToRootWindow();
464 // Called prior to removing |window_| from a RootWindow.
465 void RemovingFromRootWindow();
467 // Called after commit for the last reference to the texture going away
468 // after it was released as the frontbuffer.
469 void SetSurfaceNotInUseByCompositor(scoped_refptr<ui::Texture>);
471 // Called after async thumbnailer task completes. Scales and crops the result
473 static void CopyFromCompositingSurfaceHasResult(
474 const gfx::Size& dst_size_in_pixel,
475 const base::Callback<void(bool, const SkBitmap&)>& callback,
476 scoped_ptr<cc::CopyOutputResult> result);
477 static void PrepareTextureCopyOutputResult(
478 const gfx::Size& dst_size_in_pixel,
479 const base::Callback<void(bool, const SkBitmap&)>& callback,
480 scoped_ptr<cc::CopyOutputResult> result);
481 static void PrepareBitmapCopyOutputResult(
482 const gfx::Size& dst_size_in_pixel,
483 const base::Callback<void(bool, const SkBitmap&)>& callback,
484 scoped_ptr<cc::CopyOutputResult> result);
485 static void CopyFromCompositingSurfaceHasResultForVideo(
486 base::WeakPtr<RenderWidgetHostViewAura> rwhva,
487 scoped_refptr<media::VideoFrame> video_frame,
488 const base::Callback<void(bool)>& callback,
489 scoped_ptr<cc::CopyOutputResult> result);
491 ui::Compositor* GetCompositor() const;
493 // Detaches |this| from the input method object.
494 void DetachFromInputMethod();
496 // Dismisses a Web Popup on mouse press outside the popup and its parent.
497 void ApplyEventFilterForPopupExit(ui::MouseEvent* event);
499 // Converts |rect| from window coordinate to screen coordinate.
500 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const;
502 // Converts |rect| from screen coordinate to window coordinate.
503 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
505 typedef base::Callback<void(bool, const scoped_refptr<ui::Texture>&)>
506 BufferPresentedCallback;
508 // The common entry point for buffer updates from renderer
510 void BuffersSwapped(const gfx::Size& surface_size,
511 const gfx::Rect& damage_rect,
512 float surface_scale_factor,
513 const std::string& mailbox_name,
514 const ui::LatencyInfo& latency_info,
515 const BufferPresentedCallback& ack_callback);
517 bool SwapBuffersPrepare(const gfx::Rect& surface_rect,
518 float surface_scale_factor,
519 const gfx::Rect& damage_rect,
520 const std::string& mailbox_name,
521 const BufferPresentedCallback& ack_callback);
523 void SwapBuffersCompleted(
524 const BufferPresentedCallback& ack_callback,
525 const scoped_refptr<ui::Texture>& texture_to_return);
527 void SwapDelegatedFrame(
528 uint32 output_surface_id,
529 scoped_ptr<cc::DelegatedFrameData> frame_data,
530 float frame_device_scale_factor,
531 const ui::LatencyInfo& latency_info);
532 void SendDelegatedFrameAck(uint32 output_surface_id);
533 void SendReturnedDelegatedResources(uint32 output_surface_id);
535 // DelegatedFrameEvictorClient implementation.
536 virtual void EvictDelegatedFrame() OVERRIDE;
538 // cc::DelegatedFrameProviderClient implementation.
539 virtual void UnusedResourcesAreAvailable() OVERRIDE;
541 void SwapSoftwareFrame(uint32 output_surface_id,
542 scoped_ptr<cc::SoftwareFrameData> frame_data,
543 float frame_device_scale_factor,
544 const ui::LatencyInfo& latency_info);
545 void SendSoftwareFrameAck(uint32 output_surface_id);
546 void SendReclaimSoftwareFrames();
547 void ReleaseSoftwareFrame(uint32 output_surface_id,
548 unsigned software_frame_id);
550 void DidReceiveFrameFromRenderer();
552 BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager();
555 // Updates the total list of cutout rects, which is the union of transient
556 // windows and constrained windows.
557 void UpdateCutoutRects();
561 RenderWidgetHostImpl* host_;
563 aura::Window* window_;
565 scoped_ptr<WindowObserver> window_observer_;
567 // Are we in the process of closing? Tracked so fullscreen views can avoid
568 // sending a second shutdown request to the host when they lose the focus
569 // after requesting shutdown for another reason (e.g. Escape key).
572 // Is this a fullscreen view?
575 // Our parent host view, if this is a popup. NULL otherwise.
576 RenderWidgetHostViewAura* popup_parent_host_view_;
578 // Our child popup host. NULL if we do not have a child popup.
579 RenderWidgetHostViewAura* popup_child_host_view_;
581 class EventFilterForPopupExit;
582 friend class EventFilterForPopupExit;
583 scoped_ptr<ui::EventHandler> event_filter_for_popup_exit_;
585 // True when content is being loaded. Used to show an hourglass cursor.
588 // The cursor for the page. This is passed up from the renderer.
589 WebCursor current_cursor_;
591 // The touch-event. Its touch-points are updated as necessary. A new
592 // touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is
593 // removed from the list on an ET_TOUCH_RELEASED event.
594 WebKit::WebTouchEvent touch_event_;
596 // The current text input type.
597 ui::TextInputType text_input_type_;
598 // The current text input mode corresponding to HTML5 inputmode attribute.
599 ui::TextInputMode text_input_mode_;
600 bool can_compose_inline_;
602 // Rectangles for the selection anchor and focus.
603 gfx::Rect selection_anchor_rect_;
604 gfx::Rect selection_focus_rect_;
606 // The current composition character bounds.
607 std::vector<gfx::Rect> composition_character_bounds_;
609 // Indicates if there is onging composition text.
610 bool has_composition_text_;
612 // Current tooltip text.
615 std::vector<base::Closure> on_compositing_did_commit_callbacks_;
617 // The current frontbuffer texture.
618 scoped_refptr<ui::Texture> current_surface_;
620 // This holds the current software framebuffer, if any.
621 scoped_ptr<SoftwareFrameManager> software_frame_manager_;
623 // With delegated renderer, this is the last output surface, used to
624 // disambiguate resources with the same id coming from different output
626 uint32 last_output_surface_id_;
628 // The number of delegated frame acks that are pending, to delay resource
629 // returns until the acks are sent.
630 int pending_delegated_ack_count_;
632 // The damage in the previously presented buffer.
633 SkRegion previous_damage_;
635 // Pending damage from previous frames that we skipped.
636 SkRegion skipped_damage_;
638 // True after a delegated frame has been skipped, until a frame is not
640 bool skipped_frames_;
642 // Holds delegated resources that have been given to a DelegatedFrameProvider,
643 // and gives back resources when they are no longer in use for return to the
645 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_;
647 // Provides delegated frame updates to the cc::DelegatedRendererLayer.
648 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_;
650 // The size of the last frame that was swapped (even if we skipped it).
651 // Used to determine when the skipped_damage_ needs to be reset due to
652 // size changes between front- and backbuffer.
653 gfx::Size last_swapped_surface_size_;
654 float last_swapped_surface_scale_factor_;
656 gfx::GLSurfaceHandle shared_surface_handle_;
658 // If non-NULL we're in OnPaint() and this is the supplied canvas.
659 gfx::Canvas* paint_canvas_;
661 // Used to record the last position of the mouse.
662 // While the mouse is locked, they store the last known position just as mouse
664 // Relative to the upper-left corner of the view.
665 gfx::Point unlocked_mouse_position_;
666 // Relative to the upper-left corner of the screen.
667 gfx::Point unlocked_global_mouse_position_;
668 // Last cursor position relative to screen. Used to compute movementX/Y.
669 gfx::Point global_mouse_position_;
670 // In mouse locked mode, we syntheticaly move the mouse cursor to the center
671 // of the window when it reaches the window borders to avoid it going outside.
672 // This flag is used to differentiate between these synthetic mouse move
673 // events vs. normal mouse move events.
674 bool synthetic_move_sent_;
676 // Signals that the accelerated compositing has been turned on or off.
677 // This is used to signal to turn off the external texture as soon as the
678 // software backing store is updated.
679 bool accelerated_compositing_state_changed_;
681 // This lock is the one waiting for a frame of the right size to come back
682 // from the renderer/GPU process. It is set from the moment the aura window
683 // got resized, to the moment we committed the renderer frame of the same
684 // size. It keeps track of the size we expect from the renderer, and locks the
685 // compositor, as well as the UI for a short time to give a chance to the
686 // renderer of producing a frame of the right size.
687 scoped_ptr<ResizeLock> resize_lock_;
689 // Keeps track of the current frame size.
690 gfx::Size current_frame_size_;
692 // This lock is for waiting for a front surface to become available to draw.
693 scoped_refptr<ui::CompositorLock> released_front_lock_;
695 // Used to track the state of the window we're created from. Only used when
696 // created fullscreen.
697 scoped_ptr<aura::WindowTracker> host_tracker_;
699 enum CanLockCompositorState {
701 // We locked, so at some point we'll need to kick a frame.
703 // No. A lock timed out, we need to kick a new frame before locking again.
704 NO_PENDING_RENDERER_FRAME,
705 // No. We've got a frame, but it hasn't been committed.
708 CanLockCompositorState can_lock_compositor_;
710 // Used to track the last cursor visibility update that was sent to the
711 // renderer via NotifyRendererOfCursorVisibilityState().
712 enum CursorVisibilityState {
717 CursorVisibilityState cursor_visibility_state_in_renderer_;
719 // An observer to notify that the paint content of the view has changed. The
720 // observer is not owned by the view, and must remove itself as an oberver
721 // when it is being destroyed.
722 PaintObserver* paint_observer_;
725 // The list of rectangles from constrained windows over this view. Windowed
726 // NPAPI plugins shouldn't draw over them.
727 std::vector<gfx::Rect> constrained_rects_;
729 typedef std::map<HWND, WebPluginGeometry> PluginWindowMoves;
730 // Contains information about each windowed plugin's clip and cutout rects (
731 // from the renderer). This is needed because when the transient windoiws
732 // over this view changes, we need this information in order to create a new
733 // region for the HWND.
734 PluginWindowMoves plugin_window_moves_;
737 base::TimeTicks last_draw_ended_;
739 // Subscriber that listens to frame presentation events.
740 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
742 // YUV readback pipeline.
743 scoped_ptr<content::ReadbackYUVInterface>
744 yuv_readback_pipeline_;
746 TouchEditingClient* touch_editing_client_;
748 ui::LatencyInfo software_latency_info_;
750 struct ReleasedFrameInfo {
751 ReleasedFrameInfo(uint32 output_id, unsigned software_frame_id)
752 : output_surface_id(output_id), frame_id(software_frame_id) {}
753 uint32 output_surface_id;
756 scoped_ptr<ReleasedFrameInfo> released_software_frame_;
757 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_;
759 base::WeakPtrFactory<RenderWidgetHostViewAura> weak_ptr_factory_;
760 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura);
763 } // namespace content
765 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_