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