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 ui::TextInputClient
* GetFocusedTextInputClient() override
;
163 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
164 int GetNonClientComponent(const gfx::Point
& point
) const override
;
165 bool ShouldDescendIntoChildForEventHandling(
167 const gfx::Point
& location
) override
;
168 bool CanFocus() override
;
169 void OnCaptureLost() override
;
170 void OnPaint(const ui::PaintContext
& context
) override
;
171 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
172 void OnWindowDestroying(aura::Window
* window
) override
;
173 void OnWindowDestroyed(aura::Window
* window
) override
;
174 void OnWindowTargetVisibilityChanged(bool visible
) override
;
175 bool HasHitTestMask() const override
;
176 void GetHitTestMask(gfx::Path
* mask
) const override
;
178 // Overridden from ui::EventHandler:
179 void OnKeyEvent(ui::KeyEvent
* event
) override
;
180 void OnMouseEvent(ui::MouseEvent
* event
) override
;
182 // Overridden from aura::client::DragDropDelegate:
183 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
184 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
185 void OnDragExited() override
;
186 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
188 // Overridden from aura::WindowObserver:
189 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
;
191 // Update the web contents visiblity.
192 void UpdateWebContentsVisibility(bool visible
);
194 scoped_ptr
<aura::Window
> window_
;
196 // The window that shows the screenshot of the history page during an
197 // overscroll navigation gesture.
198 scoped_ptr
<aura::Window
> overscroll_window_
;
200 scoped_ptr
<WindowObserver
> window_observer_
;
202 // The WebContentsImpl whose contents we display.
203 WebContentsImpl
* web_contents_
;
205 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
207 blink::WebDragOperationsMask current_drag_op_
;
209 scoped_ptr
<DropData
> current_drop_data_
;
211 WebDragDestDelegate
* drag_dest_delegate_
;
213 // We keep track of the render view host we're dragging over. If it changes
214 // during a drag, we need to re-send the DragEnter message. WARNING:
215 // this pointer should never be dereferenced. We only use it for comparing
217 void* current_rvh_for_drag_
;
219 bool overscroll_change_brightness_
;
221 // The overscroll gesture currently in progress.
222 OverscrollMode current_overscroll_gesture_
;
224 // This is the completed overscroll gesture. This is used for the animation
225 // callback that happens in response to a completed overscroll gesture.
226 OverscrollMode completed_overscroll_gesture_
;
228 // This manages the overlay window that shows the screenshot during a history
229 // navigation triggered by the overscroll gesture.
230 scoped_ptr
<OverscrollNavigationOverlay
> navigation_overlay_
;
232 scoped_ptr
<ShadowLayerDelegate
> overscroll_shadow_
;
234 scoped_ptr
<TouchEditableImplAura
> touch_editable_
;
235 scoped_ptr
<GestureNavSimple
> gesture_nav_simple_
;
237 // On Windows we can run into problems if resources get released within the
238 // initialization phase while the content (and its dimensions) are not known.
239 bool is_or_was_visible_
;
241 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura
);
244 } // namespace content
246 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_