Home | History | Annotate | Download | only in renderer_host
      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 <string>
     10 #include <vector>
     11 
     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/resources/texture_mailbox.h"
     19 #include "content/browser/accessibility/browser_accessibility_manager.h"
     20 #include "content/browser/aura/image_transport_factory.h"
     21 #include "content/browser/renderer_host/render_widget_host_view_base.h"
     22 #include "content/common/content_export.h"
     23 #include "content/common/gpu/client/gl_helper.h"
     24 #include "third_party/skia/include/core/SkRegion.h"
     25 #include "ui/aura/client/activation_change_observer.h"
     26 #include "ui/aura/client/activation_delegate.h"
     27 #include "ui/aura/client/cursor_client_observer.h"
     28 #include "ui/aura/client/focus_change_observer.h"
     29 #include "ui/aura/root_window_observer.h"
     30 #include "ui/aura/window_delegate.h"
     31 #include "ui/base/ime/text_input_client.h"
     32 #include "ui/compositor/compositor.h"
     33 #include "ui/compositor/compositor_observer.h"
     34 #include "ui/gfx/display_observer.h"
     35 #include "ui/gfx/rect.h"
     36 #include "webkit/common/cursors/webcursor.h"
     37 
     38 namespace aura {
     39 class WindowTracker;
     40 }
     41 
     42 namespace cc {
     43 class CopyOutputResult;
     44 class DelegatedFrameData;
     45 }
     46 
     47 namespace gfx {
     48 class Canvas;
     49 class Display;
     50 }
     51 
     52 namespace ui {
     53 class CompositorLock;
     54 class InputMethod;
     55 class Texture;
     56 }
     57 
     58 namespace content {
     59 class MemoryHolder;
     60 class RenderWidgetHostImpl;
     61 class RenderWidgetHostView;
     62 
     63 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
     64 class RenderWidgetHostViewAura
     65     : public RenderWidgetHostViewBase,
     66       public ui::CompositorObserver,
     67       public ui::TextInputClient,
     68       public gfx::DisplayObserver,
     69       public aura::RootWindowObserver,
     70       public aura::WindowDelegate,
     71       public aura::client::ActivationDelegate,
     72       public aura::client::ActivationChangeObserver,
     73       public aura::client::FocusChangeObserver,
     74       public aura::client::CursorClientObserver,
     75       public ImageTransportFactoryObserver,
     76       public BrowserAccessibilityDelegate,
     77       public base::SupportsWeakPtr<RenderWidgetHostViewAura> {
     78  public:
     79   // Used to notify whenever the paint-content of the view changes.
     80   class PaintObserver {
     81    public:
     82     PaintObserver() {}
     83     virtual ~PaintObserver() {}
     84 
     85     // This is called when painting of the page is completed.
     86     virtual void OnPaintComplete() = 0;
     87 
     88     // This is called when compositor painting of the page is completed.
     89     virtual void OnCompositingComplete() = 0;
     90 
     91     // This is called when the contents for compositor painting changes.
     92     virtual void OnUpdateCompositorContent() = 0;
     93 
     94     // This is called loading the page has completed.
     95     virtual void OnPageLoadComplete() = 0;
     96 
     97     // This is called when the view is destroyed, so that the observer can
     98     // perform any necessary clean-up.
     99     virtual void OnViewDestroyed() = 0;
    100   };
    101 
    102   // Displays and controls touch editing elements such as selection handles.
    103   class TouchEditingClient {
    104    public:
    105     TouchEditingClient() {}
    106 
    107     // Tells the client to start showing touch editing handles.
    108     virtual void StartTouchEditing() = 0;
    109 
    110     // Notifies the client that touch editing is no longer needed.
    111     virtual void EndTouchEditing() = 0;
    112 
    113     // Notifies the client that the selection bounds need to be updated.
    114     virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
    115                                             const gfx::Rect& focus) = 0;
    116 
    117     // Notifies the client that the current text input type as changed.
    118     virtual void OnTextInputTypeChanged(ui::TextInputType type) = 0;
    119 
    120     // Notifies the client that an input event is about to be sent to the
    121     // renderer. Returns true if the client wants to stop event propagation.
    122     virtual bool HandleInputEvent(const ui::Event* event) = 0;
    123 
    124     // Notifies the client that a gesture event ack was received.
    125     virtual void GestureEventAck(int gesture_event_type) = 0;
    126 
    127     // This is called when the view is destroyed, so that the client can
    128     // perform any necessary clean-up.
    129     virtual void OnViewDestroyed() = 0;
    130 
    131    protected:
    132     virtual ~TouchEditingClient() {}
    133   };
    134 
    135   void set_paint_observer(PaintObserver* observer) {
    136     paint_observer_ = observer;
    137   }
    138 
    139   void set_touch_editing_client(TouchEditingClient* client) {
    140     touch_editing_client_ = client;
    141   }
    142 
    143   // RenderWidgetHostView implementation.
    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;
    158 #if defined(OS_WIN)
    159   virtual gfx::NativeViewAccessible AccessibleObjectFromChildId(long child_id)
    160       OVERRIDE;
    161 #endif
    162 
    163   // Overridden from RenderWidgetHostViewPort:
    164   virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
    165                            const gfx::Rect& pos) OVERRIDE;
    166   virtual void InitAsFullscreen(
    167       RenderWidgetHostView* reference_host_view) OVERRIDE;
    168   virtual void WasShown() OVERRIDE;
    169   virtual void WasHidden() OVERRIDE;
    170   virtual void MovePluginWindows(
    171       const gfx::Vector2d& scroll_offset,
    172       const std::vector<WebPluginGeometry>& moves) OVERRIDE;
    173   virtual void Focus() OVERRIDE;
    174   virtual void Blur() OVERRIDE;
    175   virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
    176   virtual void SetIsLoading(bool is_loading) OVERRIDE;
    177   virtual void TextInputTypeChanged(ui::TextInputType type,
    178                                     bool can_compose_inline,
    179                                     ui::TextInputMode input_mode) OVERRIDE;
    180   virtual void ImeCancelComposition() OVERRIDE;
    181   virtual void ImeCompositionRangeChanged(
    182       const ui::Range& range,
    183       const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
    184   virtual void DidUpdateBackingStore(
    185       const gfx::Rect& scroll_rect,
    186       const gfx::Vector2d& scroll_delta,
    187       const std::vector<gfx::Rect>& copy_rects,
    188       const ui::LatencyInfo& latency_info) OVERRIDE;
    189   virtual void RenderProcessGone(base::TerminationStatus status,
    190                                  int error_code) OVERRIDE;
    191   virtual void Destroy() OVERRIDE;
    192   virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE;
    193   virtual void SelectionChanged(const string16& text,
    194                                 size_t offset,
    195                                 const ui::Range& range) OVERRIDE;
    196   virtual void SelectionBoundsChanged(
    197       const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
    198   virtual void ScrollOffsetChanged() OVERRIDE;
    199   virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
    200   virtual void CopyFromCompositingSurface(
    201       const gfx::Rect& src_subrect,
    202       const gfx::Size& dst_size,
    203       const base::Callback<void(bool, const SkBitmap&)>& callback) 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 AcceleratedSurfaceBuffersSwapped(
    215       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
    216       int gpu_host_id) OVERRIDE;
    217   virtual void AcceleratedSurfacePostSubBuffer(
    218       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
    219       int gpu_host_id) OVERRIDE;
    220   virtual void AcceleratedSurfaceSuspend() OVERRIDE;
    221   virtual void AcceleratedSurfaceRelease() OVERRIDE;
    222   virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
    223   virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
    224   virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
    225   virtual void GestureEventAck(int gesture_event_type,
    226                                InputEventAckState ack_result) OVERRIDE;
    227   virtual void ProcessAckedTouchEvent(
    228       const TouchEventWithLatencyInfo& touch,
    229       InputEventAckState ack_result) OVERRIDE;
    230   virtual SmoothScrollGesture* CreateSmoothScrollGesture(
    231       bool scroll_down,
    232       int pixels_to_scroll,
    233       int mouse_event_x,
    234       int mouse_event_y) OVERRIDE;
    235   virtual void SetHasHorizontalScrollbar(
    236       bool has_horizontal_scrollbar) OVERRIDE;
    237   virtual void SetScrollOffsetPinning(
    238       bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
    239   virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
    240   virtual void OnAccessibilityNotifications(
    241       const std::vector<AccessibilityHostMsg_NotificationParams>&
    242           params) OVERRIDE;
    243   virtual bool LockMouse() OVERRIDE;
    244   virtual void UnlockMouse() OVERRIDE;
    245   virtual void OnSwapCompositorFrame(
    246       uint32 output_surface_id,
    247       scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
    248 #if defined(OS_WIN)
    249   virtual void SetParentNativeViewAccessible(
    250       gfx::NativeViewAccessible accessible_parent) OVERRIDE;
    251 #endif
    252 
    253   // Overridden from ui::TextInputClient:
    254   virtual void SetCompositionText(
    255       const ui::CompositionText& composition) OVERRIDE;
    256   virtual void ConfirmCompositionText() OVERRIDE;
    257   virtual void ClearCompositionText() OVERRIDE;
    258   virtual void InsertText(const string16& text) OVERRIDE;
    259   virtual void InsertChar(char16 ch, int flags) OVERRIDE;
    260   virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE;
    261   virtual ui::TextInputType GetTextInputType() const OVERRIDE;
    262   virtual ui::TextInputMode GetTextInputMode() const OVERRIDE;
    263   virtual bool CanComposeInline() const OVERRIDE;
    264   virtual gfx::Rect GetCaretBounds() OVERRIDE;
    265   virtual bool GetCompositionCharacterBounds(uint32 index,
    266                                              gfx::Rect* rect) OVERRIDE;
    267   virtual bool HasCompositionText() OVERRIDE;
    268   virtual bool GetTextRange(ui::Range* range) OVERRIDE;
    269   virtual bool GetCompositionTextRange(ui::Range* range) OVERRIDE;
    270   virtual bool GetSelectionRange(ui::Range* range) OVERRIDE;
    271   virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE;
    272   virtual bool DeleteRange(const ui::Range& range) OVERRIDE;
    273   virtual bool GetTextFromRange(const ui::Range& range,
    274                                 string16* text) OVERRIDE;
    275   virtual void OnInputMethodChanged() OVERRIDE;
    276   virtual bool ChangeTextDirectionAndLayoutAlignment(
    277       base::i18n::TextDirection direction) OVERRIDE;
    278   virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE;
    279   virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE;
    280 
    281   // Overridden from gfx::DisplayObserver:
    282   virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
    283   virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
    284   virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
    285 
    286   // Overridden from aura::WindowDelegate:
    287   virtual gfx::Size GetMinimumSize() const OVERRIDE;
    288   virtual gfx::Size GetMaximumSize() const OVERRIDE;
    289   virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
    290                                const gfx::Rect& new_bounds) OVERRIDE;
    291   virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
    292   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
    293   virtual bool ShouldDescendIntoChildForEventHandling(
    294       aura::Window* child,
    295       const gfx::Point& location) OVERRIDE;
    296   virtual bool CanFocus() OVERRIDE;
    297   virtual void OnCaptureLost() OVERRIDE;
    298   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    299   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    300   virtual void OnWindowDestroying() OVERRIDE;
    301   virtual void OnWindowDestroyed() OVERRIDE;
    302   virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
    303   virtual bool HasHitTestMask() const OVERRIDE;
    304   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
    305   virtual scoped_refptr<ui::Texture> CopyTexture() 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::RootWindowObserver:
    329   virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
    330                                      const gfx::Point& new_origin) OVERRIDE;
    331 
    332   bool CanCopyToBitmap() const;
    333 
    334 #if defined(OS_WIN)
    335   // Sets the cutout rects from constrained windows. These are rectangles that
    336   // windowed NPAPI plugins shouldn't paint in. Overwrites any previous cutout
    337   // rects.
    338   void UpdateConstrainedWindowRects(const std::vector<gfx::Rect>& rects);
    339 #endif
    340 
    341  protected:
    342   friend class RenderWidgetHostView;
    343 
    344   // Should construct only via RenderWidgetHostView::CreateViewForWidget.
    345   explicit RenderWidgetHostViewAura(RenderWidgetHost* host);
    346 
    347   RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
    348     return frame_subscriber_.get();
    349   }
    350 
    351  private:
    352   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SetCompositionText);
    353   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventState);
    354   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventSyncAsync);
    355 
    356   class WindowObserver;
    357   friend class WindowObserver;
    358 #if defined(OS_WIN)
    359   class TransientWindowObserver;
    360   friend class TransientWindowObserver;
    361 #endif
    362 
    363   // Overridden from ui::CompositorObserver:
    364   virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE;
    365   virtual void OnCompositingStarted(ui::Compositor* compositor,
    366                                     base::TimeTicks start_time) OVERRIDE;
    367   virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE;
    368   virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE;
    369   virtual void OnCompositingLockStateChanged(
    370       ui::Compositor* compositor) OVERRIDE;
    371   virtual void OnUpdateVSyncParameters(ui::Compositor* compositor,
    372                                        base::TimeTicks timebase,
    373                                        base::TimeDelta interval) OVERRIDE;
    374 
    375   // Overridden from ImageTransportFactoryObserver:
    376   virtual void OnLostResources() OVERRIDE;
    377 
    378   // Overridden from BrowserAccessibilityDelegate:
    379   virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
    380   virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
    381   virtual void AccessibilityScrollToMakeVisible(
    382       int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
    383   virtual void AccessibilityScrollToPoint(
    384       int acc_obj_id, gfx::Point point) OVERRIDE;
    385   virtual void AccessibilitySetTextSelection(
    386       int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
    387   virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
    388   virtual void FatalAccessibilityTreeError() OVERRIDE;
    389 
    390   virtual ~RenderWidgetHostViewAura();
    391 
    392   void UpdateCursorIfOverSelf();
    393   bool ShouldSkipFrame(gfx::Size size_in_dip) const;
    394 
    395   // Lazily grab a resize lock if the aura window size doesn't match the current
    396   // frame size, to give time to the renderer.
    397   void MaybeCreateResizeLock();
    398 
    399   // Checks if the resize lock can be released because we received an new frame.
    400   void CheckResizeLock();
    401 
    402   void UpdateExternalTexture();
    403   ui::InputMethod* GetInputMethod() const;
    404 
    405   // Returns whether the widget needs an input grab to work properly.
    406   bool NeedsInputGrab();
    407 
    408   // Confirm existing composition text in the webpage and ask the input method
    409   // to cancel its ongoing composition session.
    410   void FinishImeCompositionSession();
    411 
    412   // This method computes movementX/Y and keeps track of mouse location for
    413   // mouse lock on all mouse move events.
    414   void ModifyEventMovementAndCoords(WebKit::WebMouseEvent* event);
    415 
    416   // Sends an IPC to the renderer process to communicate whether or not
    417   // the mouse cursor is visible anywhere on the screen.
    418   void NotifyRendererOfCursorVisibilityState(bool is_visible);
    419 
    420   // If |clip| is non-empty and and doesn't contain |rect| or |clip| is empty
    421   // SchedulePaint() is invoked for |rect|.
    422   void SchedulePaintIfNotInClip(const gfx::Rect& rect, const gfx::Rect& clip);
    423 
    424   // Helper method to determine if, in mouse locked mode, the cursor should be
    425   // moved to center.
    426   bool ShouldMoveToCenter();
    427 
    428   // Run all on compositing commit callbacks.
    429   void RunOnCommitCallbacks();
    430 
    431   // Add on compositing commit callback.
    432   void AddOnCommitCallbackAndDisableLocks(const base::Closure& callback);
    433 
    434   // Called after |window_| is parented to a RootWindow.
    435   void AddedToRootWindow();
    436 
    437   // Called prior to removing |window_| from a RootWindow.
    438   void RemovingFromRootWindow();
    439 
    440   // Called after commit for the last reference to the texture going away
    441   // after it was released as the frontbuffer.
    442   void SetSurfaceNotInUseByCompositor(scoped_refptr<ui::Texture>);
    443 
    444   // Called after async thumbnailer task completes.  Scales and crops the result
    445   // of the copy.
    446   static void CopyFromCompositingSurfaceHasResult(
    447       const gfx::Size& dst_size_in_pixel,
    448       const base::Callback<void(bool, const SkBitmap&)>& callback,
    449       scoped_ptr<cc::CopyOutputResult> result);
    450   static void PrepareTextureCopyOutputResult(
    451       const gfx::Size& dst_size_in_pixel,
    452       const base::Callback<void(bool, const SkBitmap&)>& callback,
    453       scoped_ptr<cc::CopyOutputResult> result);
    454   static void PrepareBitmapCopyOutputResult(
    455       const gfx::Size& dst_size_in_pixel,
    456       const base::Callback<void(bool, const SkBitmap&)>& callback,
    457       scoped_ptr<cc::CopyOutputResult> result);
    458   static void CopyFromCompositingSurfaceHasResultForVideo(
    459       base::WeakPtr<RenderWidgetHostViewAura> rwhva,
    460       scoped_refptr<media::VideoFrame> video_frame,
    461       const base::Callback<void(bool)>& callback,
    462       scoped_ptr<cc::CopyOutputResult> result);
    463 
    464   ui::Compositor* GetCompositor() const;
    465 
    466   // Detaches |this| from the input method object.
    467   void DetachFromInputMethod();
    468 
    469   // Dismisses a Web Popup on mouse press outside the popup and its parent.
    470   void ApplyEventFilterForPopupExit(ui::MouseEvent* event);
    471 
    472   // Converts |rect| from window coordinate to screen coordinate.
    473   gfx::Rect ConvertRectToScreen(const gfx::Rect& rect);
    474 
    475   // Converts |rect| from screen coordinate to window coordinate.
    476   gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect);
    477 
    478   typedef base::Callback<void(bool, const scoped_refptr<ui::Texture>&)>
    479       BufferPresentedCallback;
    480 
    481   // The common entry point for buffer updates from renderer
    482   // and GPU process.
    483   void BuffersSwapped(const gfx::Size& surface_size,
    484                       const gfx::Rect& damage_rect,
    485                       float surface_scale_factor,
    486                       const std::string& mailbox_name,
    487                       const ui::LatencyInfo& latency_info,
    488                       const BufferPresentedCallback& ack_callback);
    489 
    490   bool SwapBuffersPrepare(const gfx::Rect& surface_rect,
    491                           float surface_scale_factor,
    492                           const gfx::Rect& damage_rect,
    493                           const std::string& mailbox_name,
    494                           const BufferPresentedCallback& ack_callback);
    495 
    496   void SwapBuffersCompleted(
    497       const BufferPresentedCallback& ack_callback,
    498       const scoped_refptr<ui::Texture>& texture_to_return);
    499 
    500   void SwapDelegatedFrame(
    501       uint32 output_surface_id,
    502       scoped_ptr<cc::DelegatedFrameData> frame_data,
    503       float frame_device_scale_factor,
    504       const ui::LatencyInfo& latency_info);
    505   void SendDelegatedFrameAck(uint32 output_surface_id);
    506 
    507   void SwapSoftwareFrame(
    508       uint32 output_surface_id,
    509       scoped_ptr<cc::SoftwareFrameData> frame_data,
    510       float frame_device_scale_factor,
    511       const ui::LatencyInfo& latency_info);
    512   void SendSoftwareFrameAck(uint32 output_surface_id,
    513                             unsigned software_frame_id);
    514 
    515   void DidReceiveFrameFromRenderer();
    516 
    517   BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager();
    518 
    519 #if defined(OS_WIN)
    520   // Sets the cutout rects from transient windows. These are rectangles that
    521   // windowed NPAPI plugins shouldn't paint in. Overwrites any previous cutout
    522   // rects.
    523   void UpdateTransientRects(const std::vector<gfx::Rect>& rects);
    524 
    525   // Updates the total list of cutout rects, which is the union of transient
    526   // windows and constrained windows.
    527   void UpdateCutoutRects();
    528 #endif
    529 
    530   // The model object.
    531   RenderWidgetHostImpl* host_;
    532 
    533   aura::Window* window_;
    534 
    535   scoped_ptr<WindowObserver> window_observer_;
    536 
    537   // Are we in the process of closing?  Tracked so fullscreen views can avoid
    538   // sending a second shutdown request to the host when they lose the focus
    539   // after requesting shutdown for another reason (e.g. Escape key).
    540   bool in_shutdown_;
    541 
    542   // Is this a fullscreen view?
    543   bool is_fullscreen_;
    544 
    545   // Our parent host view, if this is a popup.  NULL otherwise.
    546   RenderWidgetHostViewAura* popup_parent_host_view_;
    547 
    548   // Our child popup host. NULL if we do not have a child popup.
    549   RenderWidgetHostViewAura* popup_child_host_view_;
    550 
    551   class EventFilterForPopupExit;
    552   friend class EventFilterForPopupExit;
    553   scoped_ptr<ui::EventHandler> event_filter_for_popup_exit_;
    554 
    555   // True when content is being loaded. Used to show an hourglass cursor.
    556   bool is_loading_;
    557 
    558   // The cursor for the page. This is passed up from the renderer.
    559   WebCursor current_cursor_;
    560 
    561   // The touch-event. Its touch-points are updated as necessary. A new
    562   // touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is
    563   // removed from the list on an ET_TOUCH_RELEASED event.
    564   WebKit::WebTouchEvent touch_event_;
    565 
    566   // The current text input type.
    567   ui::TextInputType text_input_type_;
    568   bool can_compose_inline_;
    569 
    570   // Rectangles for the selection anchor and focus.
    571   gfx::Rect selection_anchor_rect_;
    572   gfx::Rect selection_focus_rect_;
    573 
    574   // The current composition character bounds.
    575   std::vector<gfx::Rect> composition_character_bounds_;
    576 
    577   // Indicates if there is onging composition text.
    578   bool has_composition_text_;
    579 
    580   // Current tooltip text.
    581   string16 tooltip_;
    582 
    583   std::vector<base::Closure> on_compositing_did_commit_callbacks_;
    584 
    585   // The current frontbuffer texture.
    586   scoped_refptr<ui::Texture> current_surface_;
    587 
    588   // This holds the current software framebuffer.
    589   scoped_refptr<MemoryHolder> framebuffer_holder_;
    590 
    591   // The damage in the previously presented buffer.
    592   SkRegion previous_damage_;
    593 
    594   // Pending damage from previous frames that we skipped.
    595   SkRegion skipped_damage_;
    596 
    597   // The size of the last frame that was swapped (even if we skipped it).
    598   // Used to determine when the skipped_damage_ needs to be reset due to
    599   // size changes between front- and backbuffer.
    600   gfx::Size last_swapped_surface_size_;
    601   float last_swapped_surface_scale_factor_;
    602 
    603   gfx::GLSurfaceHandle shared_surface_handle_;
    604 
    605   // If non-NULL we're in OnPaint() and this is the supplied canvas.
    606   gfx::Canvas* paint_canvas_;
    607 
    608   // Used to record the last position of the mouse.
    609   // While the mouse is locked, they store the last known position just as mouse
    610   // lock was entered.
    611   // Relative to the upper-left corner of the view.
    612   gfx::Point unlocked_mouse_position_;
    613   // Relative to the upper-left corner of the screen.
    614   gfx::Point unlocked_global_mouse_position_;
    615   // Last cursor position relative to screen. Used to compute movementX/Y.
    616   gfx::Point global_mouse_position_;
    617   // In mouse locked mode, we syntheticaly move the mouse cursor to the center
    618   // of the window when it reaches the window borders to avoid it going outside.
    619   // This flag is used to differentiate between these synthetic mouse move
    620   // events vs. normal mouse move events.
    621   bool synthetic_move_sent_;
    622 
    623   // Signals that the accelerated compositing has been turned on or off.
    624   // This is used to signal to turn off the external texture as soon as the
    625   // software backing store is updated.
    626   bool accelerated_compositing_state_changed_;
    627 
    628   // Used to prevent further resizes while a resize is pending.
    629   class ResizeLock;
    630 
    631   // This lock is the one waiting for a frame of the right size to come back
    632   // from the renderer/GPU process. It is set from the moment the aura window
    633   // got resized, to the moment we committed the renderer frame of the same
    634   // size. It keeps track of the size we expect from the renderer, and locks the
    635   // compositor, as well as the UI for a short time to give a chance to the
    636   // renderer of producing a frame of the right size.
    637   scoped_ptr<ResizeLock> resize_lock_;
    638 
    639   // Keeps track of the current frame size.
    640   gfx::Size current_frame_size_;
    641 
    642   // This lock is for waiting for a front surface to become available to draw.
    643   scoped_refptr<ui::CompositorLock> released_front_lock_;
    644 
    645   // Used to track the state of the window we're created from. Only used when
    646   // created fullscreen.
    647   scoped_ptr<aura::WindowTracker> host_tracker_;
    648 
    649   enum CanLockCompositorState {
    650     YES,
    651     // We locked, so at some point we'll need to kick a frame.
    652     YES_DID_LOCK,
    653     // No. A lock timed out, we need to kick a new frame before locking again.
    654     NO_PENDING_RENDERER_FRAME,
    655     // No. We've got a frame, but it hasn't been committed.
    656     NO_PENDING_COMMIT,
    657   };
    658   CanLockCompositorState can_lock_compositor_;
    659 
    660   // Used to track the last cursor visibility update that was sent to the
    661   // renderer via NotifyRendererOfCursorVisibilityState().
    662   enum CursorVisibilityState {
    663     UNKNOWN,
    664     VISIBLE,
    665     NOT_VISIBLE,
    666   };
    667   CursorVisibilityState cursor_visibility_state_in_renderer_;
    668 
    669   // An observer to notify that the paint content of the view has changed. The
    670   // observer is not owned by the view, and must remove itself as an oberver
    671   // when it is being destroyed.
    672   PaintObserver* paint_observer_;
    673 
    674 #if defined(OS_WIN)
    675   scoped_ptr<TransientWindowObserver> transient_observer_;
    676 
    677   // The list of rectangles from transient and constrained windows over this
    678   // view. Windowed NPAPI plugins shouldn't draw over them.
    679   std::vector<gfx::Rect> transient_rects_;
    680   std::vector<gfx::Rect> constrained_rects_;
    681 
    682   typedef std::map<HWND, WebPluginGeometry> PluginWindowMoves;
    683   // Contains information about each windowed plugin's clip and cutout rects (
    684   // from the renderer). This is needed because when the transient windoiws
    685   // over this view changes, we need this information in order to create a new
    686   // region for the HWND.
    687   PluginWindowMoves plugin_window_moves_;
    688 #endif
    689 
    690   base::TimeTicks last_draw_ended_;
    691 
    692   // Subscriber that listens to frame presentation events.
    693   scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
    694 
    695   // YUV readback pipeline.
    696   scoped_ptr<content::ReadbackYUVInterface>
    697       yuv_readback_pipeline_;
    698 
    699   TouchEditingClient* touch_editing_client_;
    700 
    701   ui::LatencyInfo software_latency_info_;
    702 
    703   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAura);
    704 };
    705 
    706 }  // namespace content
    707 
    708 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_
    709