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