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