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