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/aura/window_observer.h"
18 #include "ui/compositor/layer_animation_observer.h"
19 #include "ui/wm/public/drag_drop_delegate.h"
26 class DropTargetEvent
;
30 class GestureNavSimple
;
31 class OverscrollNavigationOverlay
;
32 class RenderWidgetHostImpl
;
33 class RenderWidgetHostViewAura
;
34 class ShadowLayerDelegate
;
35 class TouchEditableImplAura
;
36 class WebContentsViewDelegate
;
37 class WebContentsImpl
;
38 class WebDragDestDelegate
;
40 class WebContentsViewAura
41 : public WebContentsView
,
42 public RenderViewHostDelegateView
,
43 public OverscrollControllerDelegate
,
44 public ui::ImplicitAnimationObserver
,
45 public aura::WindowDelegate
,
46 public aura::client::DragDropDelegate
,
47 public aura::WindowObserver
{
49 WebContentsViewAura(WebContentsImpl
* web_contents
,
50 WebContentsViewDelegate
* delegate
);
52 CONTENT_EXPORT
void SetTouchEditableForTest(
53 TouchEditableImplAura
* touch_editable
);
58 ~WebContentsViewAura() override
;
60 void SizeChangedCommon(const gfx::Size
& size
);
62 void EndDrag(blink::WebDragOperationsMask ops
);
64 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura
* view
);
66 // Creates and sets up the overlay window that will be displayed during the
67 // overscroll gesture.
68 void PrepareOverscrollWindow();
70 // Sets up the content window in preparation for starting an overscroll
72 void PrepareContentWindowForOverscroll();
74 // Resets any in-progress animation for the overscroll gesture. Note that this
75 // doesn't immediately reset the internal states; that happens after an
77 void ResetOverscrollTransform();
79 // Completes the navigation in response to a completed overscroll gesture.
80 // The navigation happens after an animation (either the overlay window
81 // animates in, or the content window animates out).
82 void CompleteOverscrollNavigation(OverscrollMode mode
);
84 // Returns the window that should be animated for the overscroll gesture.
85 // (note that during the overscroll gesture, either the overlay window or the
86 // content window can be animated).
87 aura::Window
* GetWindowToAnimateForOverscroll();
89 // Returns the amount the animating window should be translated in response to
90 // the overscroll gesture.
91 gfx::Vector2dF
GetTranslationForOverscroll(float delta_x
, float delta_y
);
93 // A window showing the screenshot is overlayed during a navigation triggered
94 // by overscroll. This function sets this up.
95 void PrepareOverscrollNavigationOverlay();
97 // Changes the brightness of the layer depending on the amount of horizontal
98 // overscroll (|delta_x|, in pixels).
99 void UpdateOverscrollWindowBrightness(float delta_x
);
101 void AttachTouchEditableToRenderView();
103 void OverscrollUpdateForWebContentsDelegate(float delta_y
);
105 // Overridden from WebContentsView:
106 gfx::NativeView
GetNativeView() const override
;
107 gfx::NativeView
GetContentNativeView() const override
;
108 gfx::NativeWindow
GetTopLevelNativeWindow() const override
;
109 void GetContainerBounds(gfx::Rect
* out
) const override
;
110 void SizeContents(const gfx::Size
& size
) override
;
111 void Focus() override
;
112 void SetInitialFocus() override
;
113 void StoreFocus() override
;
114 void RestoreFocus() override
;
115 DropData
* GetDropData() const override
;
116 gfx::Rect
GetViewBounds() const override
;
117 void CreateView(const gfx::Size
& initial_size
,
118 gfx::NativeView context
) override
;
119 RenderWidgetHostViewBase
* CreateViewForWidget(
120 RenderWidgetHost
* render_widget_host
,
121 bool is_guest_view_hack
) override
;
122 RenderWidgetHostViewBase
* CreateViewForPopupWidget(
123 RenderWidgetHost
* render_widget_host
) override
;
124 void SetPageTitle(const base::string16
& title
) override
;
125 void RenderViewCreated(RenderViewHost
* host
) override
;
126 void RenderViewSwappedIn(RenderViewHost
* host
) override
;
127 void SetOverscrollControllerEnabled(bool enabled
) override
;
129 // Overridden from RenderViewHostDelegateView:
130 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
131 const ContextMenuParams
& params
) override
;
132 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 void UpdateDragCursor(blink::WebDragOperation operation
) override
;
138 void GotFocus() override
;
139 void TakeFocus(bool reverse
) override
;
140 void ShowDisambiguationPopup(
141 const gfx::Rect
& target_rect
,
142 const SkBitmap
& zoomed_bitmap
,
143 const base::Callback
<void(ui::GestureEvent
*)>& gesture_cb
,
144 const base::Callback
<void(ui::MouseEvent
*)>& mouse_cb
) override
;
145 void HideDisambiguationPopup() override
;
147 // Overridden from OverscrollControllerDelegate:
148 gfx::Rect
GetVisibleBounds() const override
;
149 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
;
150 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
;
151 void OnOverscrollModeChange(OverscrollMode old_mode
,
152 OverscrollMode new_mode
) override
;
154 // Overridden from ui::ImplicitAnimationObserver:
155 void OnImplicitAnimationsCompleted() override
;
157 // Overridden from aura::WindowDelegate:
158 gfx::Size
GetMinimumSize() const override
;
159 gfx::Size
GetMaximumSize() const override
;
160 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
161 const gfx::Rect
& new_bounds
) override
;
162 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
163 int GetNonClientComponent(const gfx::Point
& point
) const override
;
164 bool ShouldDescendIntoChildForEventHandling(
166 const gfx::Point
& location
) override
;
167 bool CanFocus() override
;
168 void OnCaptureLost() override
;
169 void OnPaint(gfx::Canvas
* canvas
) override
;
170 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
171 void OnWindowDestroying(aura::Window
* window
) override
;
172 void OnWindowDestroyed(aura::Window
* window
) override
;
173 void OnWindowTargetVisibilityChanged(bool visible
) override
;
174 bool HasHitTestMask() const override
;
175 void GetHitTestMask(gfx::Path
* mask
) const override
;
177 // Overridden from ui::EventHandler:
178 void OnKeyEvent(ui::KeyEvent
* event
) override
;
179 void OnMouseEvent(ui::MouseEvent
* event
) override
;
181 // Overridden from aura::client::DragDropDelegate:
182 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
183 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
184 void OnDragExited() override
;
185 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
187 // Overridden from aura::WindowObserver:
188 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
;
190 // Update the web contents visiblity.
191 void UpdateWebContentsVisibility(bool visible
);
193 scoped_ptr
<aura::Window
> window_
;
195 // The window that shows the screenshot of the history page during an
196 // overscroll navigation gesture.
197 scoped_ptr
<aura::Window
> overscroll_window_
;
199 scoped_ptr
<WindowObserver
> window_observer_
;
201 // The WebContentsImpl whose contents we display.
202 WebContentsImpl
* web_contents_
;
204 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
206 blink::WebDragOperationsMask current_drag_op_
;
208 scoped_ptr
<DropData
> current_drop_data_
;
210 WebDragDestDelegate
* drag_dest_delegate_
;
212 // We keep track of the render view host we're dragging over. If it changes
213 // during a drag, we need to re-send the DragEnter message. WARNING:
214 // this pointer should never be dereferenced. We only use it for comparing
216 void* current_rvh_for_drag_
;
218 bool overscroll_change_brightness_
;
220 // The overscroll gesture currently in progress.
221 OverscrollMode current_overscroll_gesture_
;
223 // This is the completed overscroll gesture. This is used for the animation
224 // callback that happens in response to a completed overscroll gesture.
225 OverscrollMode completed_overscroll_gesture_
;
227 // This manages the overlay window that shows the screenshot during a history
228 // navigation triggered by the overscroll gesture.
229 scoped_ptr
<OverscrollNavigationOverlay
> navigation_overlay_
;
231 scoped_ptr
<ShadowLayerDelegate
> overscroll_shadow_
;
233 scoped_ptr
<TouchEditableImplAura
> touch_editable_
;
234 scoped_ptr
<GestureNavSimple
> gesture_nav_simple_
;
236 // On Windows we can run into problems if resources get released within the
237 // initialization phase while the content (and its dimensions) are not known.
238 bool is_or_was_visible_
;
240 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura
);
243 } // namespace content
245 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_