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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
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"
25 class DropTargetEvent
;
29 class GestureNavSimple
;
30 class OverscrollNavigationOverlay
;
31 class RenderWidgetHostImpl
;
32 class ShadowLayerDelegate
;
33 class TouchEditableImplAura
;
34 class WebContentsViewDelegate
;
35 class WebContentsImpl
;
36 class WebDragDestDelegate
;
38 class 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
{
46 WebContentsViewAura(WebContentsImpl
* web_contents
,
47 WebContentsViewDelegate
* delegate
);
49 void SetupOverlayWindowForTesting();
51 void SetTouchEditableForTest(TouchEditableImplAura
* touch_editable
);
56 virtual ~WebContentsViewAura();
58 void SizeChangedCommon(const gfx::Size
& size
);
60 void EndDrag(blink::WebDragOperationsMask ops
);
62 void InstallOverscrollControllerDelegate(RenderWidgetHostImpl
* host
);
64 // Creates and sets up the overlay window that will be displayed during the
65 // overscroll gesture.
66 void PrepareOverscrollWindow();
68 // Sets up the content window in preparation for starting an overscroll
70 void PrepareContentWindowForOverscroll();
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
75 void ResetOverscrollTransform();
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
);
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();
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
);
91 // A window showing the screenshot is overlayed during a navigation triggered
92 // by overscroll. This function sets this up.
93 void PrepareOverscrollNavigationOverlay();
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
);
99 void AttachTouchEditableToRenderView();
101 void OverscrollUpdateForWebContentsDelegate(int delta_y
);
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
;
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
;
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
;
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
;
149 // Overridden from ui::ImplicitAnimationObserver:
150 virtual void OnImplicitAnimationsCompleted() OVERRIDE
;
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(
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
;
172 // Overridden from ui::EventHandler:
173 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
;
174 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
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
;
182 scoped_ptr
<aura::Window
> window_
;
184 // The window that shows the screenshot of the history page during an
185 // overscroll navigation gesture.
186 scoped_ptr
<aura::Window
> overscroll_window_
;
188 scoped_ptr
<WindowObserver
> window_observer_
;
190 // The WebContentsImpl whose contents we display.
191 WebContentsImpl
* web_contents_
;
193 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
195 blink::WebDragOperationsMask current_drag_op_
;
197 scoped_ptr
<DropData
> current_drop_data_
;
199 WebDragDestDelegate
* drag_dest_delegate_
;
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
205 void* current_rvh_for_drag_
;
207 bool overscroll_change_brightness_
;
209 // The overscroll gesture currently in progress.
210 OverscrollMode current_overscroll_gesture_
;
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_
;
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_
;
220 scoped_ptr
<ShadowLayerDelegate
> overscroll_shadow_
;
222 scoped_ptr
<TouchEditableImplAura
> touch_editable_
;
223 scoped_ptr
<GestureNavSimple
> gesture_nav_simple_
;
225 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura
);
228 } // namespace content
230 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_