web_contents_view_aura.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
7
8#include <vector>
9
10#include "base/memory/ref_counted.h"
11#include "base/memory/scoped_ptr.h"
12#include "content/browser/renderer_host/overscroll_controller_delegate.h"
13#include "content/browser/renderer_host/render_view_host_delegate_view.h"
14#include "content/browser/web_contents/web_contents_view.h"
15#include "content/common/content_export.h"
16#include "ui/aura/window_delegate.h"
17#include "ui/aura/window_observer.h"
18#include "ui/compositor/layer_animation_observer.h"
19#include "ui/wm/public/drag_drop_delegate.h"
20
21namespace aura {
22class Window;
23}
24
25namespace ui {
26class DropTargetEvent;
27}
28
29namespace content {
30class GestureNavSimple;
31class OverscrollNavigationOverlay;
32class RenderWidgetHostImpl;
33class ShadowLayerDelegate;
34class TouchEditableImplAura;
35class WebContentsViewDelegate;
36class WebContentsImpl;
37class WebDragDestDelegate;
38
39class WebContentsViewAura
40    : public WebContentsView,
41      public RenderViewHostDelegateView,
42      public OverscrollControllerDelegate,
43      public ui::ImplicitAnimationObserver,
44      public aura::WindowDelegate,
45      public aura::client::DragDropDelegate,
46      public aura::WindowObserver {
47 public:
48  WebContentsViewAura(WebContentsImpl* web_contents,
49                      WebContentsViewDelegate* delegate);
50
51  CONTENT_EXPORT void SetupOverlayWindowForTesting();
52
53  CONTENT_EXPORT void SetTouchEditableForTest(
54      TouchEditableImplAura* touch_editable);
55
56 private:
57  class WindowObserver;
58
59  virtual ~WebContentsViewAura();
60
61  void SizeChangedCommon(const gfx::Size& size);
62
63  void EndDrag(blink::WebDragOperationsMask ops);
64
65  void InstallOverscrollControllerDelegate(RenderWidgetHostImpl* host);
66
67  // Creates and sets up the overlay window that will be displayed during the
68  // overscroll gesture.
69  void PrepareOverscrollWindow();
70
71  // Sets up the content window in preparation for starting an overscroll
72  // gesture.
73  void PrepareContentWindowForOverscroll();
74
75  // Resets any in-progress animation for the overscroll gesture. Note that this
76  // doesn't immediately reset the internal states; that happens after an
77  // animation.
78  void ResetOverscrollTransform();
79
80  // Completes the navigation in response to a completed overscroll gesture.
81  // The navigation happens after an animation (either the overlay window
82  // animates in, or the content window animates out).
83  void CompleteOverscrollNavigation(OverscrollMode mode);
84
85  // Returns the window that should be animated for the overscroll gesture.
86  // (note that during the overscroll gesture, either the overlay window or the
87  // content window can be animated).
88  aura::Window* GetWindowToAnimateForOverscroll();
89
90  // Returns the amount the animating window should be translated in response to
91  // the overscroll gesture.
92  gfx::Vector2d GetTranslationForOverscroll(int delta_x, int delta_y);
93
94  // A window showing the screenshot is overlayed during a navigation triggered
95  // by overscroll. This function sets this up.
96  void PrepareOverscrollNavigationOverlay();
97
98  // Changes the brightness of the layer depending on the amount of horizontal
99  // overscroll (|delta_x|, in pixels).
100  void UpdateOverscrollWindowBrightness(float delta_x);
101
102  void AttachTouchEditableToRenderView();
103
104  void OverscrollUpdateForWebContentsDelegate(int delta_y);
105
106  // Overridden from WebContentsView:
107  virtual gfx::NativeView GetNativeView() const OVERRIDE;
108  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
109  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
110  virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE;
111  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
112  virtual void Focus() OVERRIDE;
113  virtual void SetInitialFocus() OVERRIDE;
114  virtual void StoreFocus() OVERRIDE;
115  virtual void RestoreFocus() OVERRIDE;
116  virtual DropData* GetDropData() const OVERRIDE;
117  virtual gfx::Rect GetViewBounds() const OVERRIDE;
118  virtual void CreateView(
119      const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
120  virtual RenderWidgetHostViewBase* CreateViewForWidget(
121      RenderWidgetHost* render_widget_host) OVERRIDE;
122  virtual RenderWidgetHostViewBase* CreateViewForPopupWidget(
123      RenderWidgetHost* render_widget_host) OVERRIDE;
124  virtual void SetPageTitle(const base::string16& title) OVERRIDE;
125  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
126  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
127  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
128
129  // Overridden from RenderViewHostDelegateView:
130  virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
131                               const ContextMenuParams& params) OVERRIDE;
132  virtual void StartDragging(const DropData& drop_data,
133                             blink::WebDragOperationsMask operations,
134                             const gfx::ImageSkia& image,
135                             const gfx::Vector2d& image_offset,
136                             const DragEventSourceInfo& event_info) OVERRIDE;
137  virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE;
138  virtual void GotFocus() OVERRIDE;
139  virtual void TakeFocus(bool reverse) OVERRIDE;
140
141  // Overridden from OverscrollControllerDelegate:
142  virtual gfx::Rect GetVisibleBounds() const OVERRIDE;
143  virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE;
144  virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE;
145  virtual void OnOverscrollModeChange(OverscrollMode old_mode,
146                                      OverscrollMode new_mode) OVERRIDE;
147
148  // Overridden from ui::ImplicitAnimationObserver:
149  virtual void OnImplicitAnimationsCompleted() OVERRIDE;
150
151  // Overridden from aura::WindowDelegate:
152  virtual gfx::Size GetMinimumSize() const OVERRIDE;
153  virtual gfx::Size GetMaximumSize() const OVERRIDE;
154  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
155                               const gfx::Rect& new_bounds) OVERRIDE;
156  virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
157  virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
158  virtual bool ShouldDescendIntoChildForEventHandling(
159      aura::Window* child,
160      const gfx::Point& location) OVERRIDE;
161  virtual bool CanFocus() OVERRIDE;
162  virtual void OnCaptureLost() OVERRIDE;
163  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
164  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
165  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
166  virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
167  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
168  virtual bool HasHitTestMask() const OVERRIDE;
169  virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
170
171  // Overridden from ui::EventHandler:
172  virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
173  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
174
175  // Overridden from aura::client::DragDropDelegate:
176  virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
177  virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
178  virtual void OnDragExited() OVERRIDE;
179  virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
180
181  // Overridden from aura::WindowObserver:
182  virtual void OnWindowParentChanged(aura::Window* window,
183                                     aura::Window* parent) OVERRIDE;
184  virtual void OnWindowVisibilityChanged(aura::Window* window,
185                                         bool visible) OVERRIDE;
186
187  scoped_ptr<aura::Window> window_;
188
189  // The window that shows the screenshot of the history page during an
190  // overscroll navigation gesture.
191  scoped_ptr<aura::Window> overscroll_window_;
192
193  scoped_ptr<WindowObserver> window_observer_;
194
195  // The WebContentsImpl whose contents we display.
196  WebContentsImpl* web_contents_;
197
198  scoped_ptr<WebContentsViewDelegate> delegate_;
199
200  blink::WebDragOperationsMask current_drag_op_;
201
202  scoped_ptr<DropData> current_drop_data_;
203
204  WebDragDestDelegate* drag_dest_delegate_;
205
206  // We keep track of the render view host we're dragging over.  If it changes
207  // during a drag, we need to re-send the DragEnter message.  WARNING:
208  // this pointer should never be dereferenced.  We only use it for comparing
209  // pointers.
210  void* current_rvh_for_drag_;
211
212  bool overscroll_change_brightness_;
213
214  // The overscroll gesture currently in progress.
215  OverscrollMode current_overscroll_gesture_;
216
217  // This is the completed overscroll gesture. This is used for the animation
218  // callback that happens in response to a completed overscroll gesture.
219  OverscrollMode completed_overscroll_gesture_;
220
221  // This manages the overlay window that shows the screenshot during a history
222  // navigation triggered by the overscroll gesture.
223  scoped_ptr<OverscrollNavigationOverlay> navigation_overlay_;
224
225  scoped_ptr<ShadowLayerDelegate> overscroll_shadow_;
226
227  scoped_ptr<TouchEditableImplAura> touch_editable_;
228  scoped_ptr<GestureNavSimple> gesture_nav_simple_;
229
230  DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura);
231};
232
233}  // namespace content
234
235#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
236