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/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
14 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
15 #include "content/browser/web_contents/web_contents_view.h"
16 #include "content/common/content_export.h"
17 #include "ui/aura/window_delegate.h"
18 #include "ui/aura/window_observer.h"
19 #include "ui/wm/public/drag_drop_delegate.h"
26 class DropTargetEvent
;
27 class TouchSelectionController
;
31 class GestureNavSimple
;
32 class OverscrollNavigationOverlay
;
33 class RenderWidgetHostImpl
;
34 class RenderWidgetHostViewAura
;
35 class ShadowLayerDelegate
;
36 class TouchSelectionControllerClientAura
;
37 class WebContentsViewDelegate
;
38 class WebContentsImpl
;
39 class WebDragDestDelegate
;
41 class WebContentsViewAura
42 : public WebContentsView
,
43 public RenderViewHostDelegateView
,
44 public OverscrollControllerDelegate
,
45 public aura::WindowDelegate
,
46 public aura::client::DragDropDelegate
,
47 public aura::WindowObserver
{
49 WebContentsViewAura(WebContentsImpl
* web_contents
,
50 WebContentsViewDelegate
* delegate
);
55 ~WebContentsViewAura() override
;
57 void SizeChangedCommon(const gfx::Size
& size
);
59 void EndDrag(blink::WebDragOperationsMask ops
);
61 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura
* view
);
63 // Sets up the content window in preparation for starting an overscroll
65 void PrepareContentWindowForOverscroll();
67 // Completes the navigation in response to a completed overscroll gesture.
68 // The navigation happens after an animation (either the overlay window
69 // animates in, or the content window animates out).
70 void CompleteOverscrollNavigation(OverscrollMode mode
);
72 void OverscrollUpdateForWebContentsDelegate(float delta_y
);
74 ui::TouchSelectionController
* GetSelectionController() const;
75 TouchSelectionControllerClientAura
* GetSelectionControllerClient() const;
77 // Overridden from WebContentsView:
78 gfx::NativeView
GetNativeView() const override
;
79 gfx::NativeView
GetContentNativeView() const override
;
80 gfx::NativeWindow
GetTopLevelNativeWindow() const override
;
81 void GetContainerBounds(gfx::Rect
* out
) const override
;
82 void SizeContents(const gfx::Size
& size
) override
;
83 void Focus() override
;
84 void SetInitialFocus() override
;
85 void StoreFocus() override
;
86 void RestoreFocus() override
;
87 DropData
* GetDropData() const override
;
88 gfx::Rect
GetViewBounds() const override
;
89 void CreateView(const gfx::Size
& initial_size
,
90 gfx::NativeView context
) override
;
91 RenderWidgetHostViewBase
* CreateViewForWidget(
92 RenderWidgetHost
* render_widget_host
,
93 bool is_guest_view_hack
) override
;
94 RenderWidgetHostViewBase
* CreateViewForPopupWidget(
95 RenderWidgetHost
* render_widget_host
) override
;
96 void SetPageTitle(const base::string16
& title
) override
;
97 void RenderViewCreated(RenderViewHost
* host
) override
;
98 void RenderViewSwappedIn(RenderViewHost
* host
) override
;
99 void SetOverscrollControllerEnabled(bool enabled
) override
;
101 // Overridden from RenderViewHostDelegateView:
102 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
103 const ContextMenuParams
& params
) override
;
104 void StartDragging(const DropData
& drop_data
,
105 blink::WebDragOperationsMask operations
,
106 const gfx::ImageSkia
& image
,
107 const gfx::Vector2d
& image_offset
,
108 const DragEventSourceInfo
& event_info
) override
;
109 void UpdateDragCursor(blink::WebDragOperation operation
) override
;
110 void GotFocus() override
;
111 void TakeFocus(bool reverse
) override
;
112 void ShowDisambiguationPopup(
113 const gfx::Rect
& target_rect
,
114 const SkBitmap
& zoomed_bitmap
,
115 const base::Callback
<void(ui::GestureEvent
*)>& gesture_cb
,
116 const base::Callback
<void(ui::MouseEvent
*)>& mouse_cb
) override
;
117 void HideDisambiguationPopup() override
;
119 // Overridden from OverscrollControllerDelegate:
120 gfx::Rect
GetVisibleBounds() const override
;
121 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
;
122 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
;
123 void OnOverscrollModeChange(OverscrollMode old_mode
,
124 OverscrollMode new_mode
) override
;
126 // Overridden from aura::WindowDelegate:
127 gfx::Size
GetMinimumSize() const override
;
128 gfx::Size
GetMaximumSize() const override
;
129 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
130 const gfx::Rect
& new_bounds
) override
;
131 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
132 int GetNonClientComponent(const gfx::Point
& point
) const override
;
133 bool ShouldDescendIntoChildForEventHandling(
135 const gfx::Point
& location
) override
;
136 bool CanFocus() override
;
137 void OnCaptureLost() override
;
138 void OnPaint(const ui::PaintContext
& context
) override
;
139 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
140 void OnWindowDestroying(aura::Window
* window
) override
;
141 void OnWindowDestroyed(aura::Window
* window
) override
;
142 void OnWindowTargetVisibilityChanged(bool visible
) override
;
143 bool HasHitTestMask() const override
;
144 void GetHitTestMask(gfx::Path
* mask
) const override
;
146 // Overridden from ui::EventHandler:
147 void OnKeyEvent(ui::KeyEvent
* event
) override
;
148 void OnMouseEvent(ui::MouseEvent
* event
) override
;
150 // Overridden from aura::client::DragDropDelegate:
151 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
152 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
153 void OnDragExited() override
;
154 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
156 // Overridden from aura::WindowObserver:
157 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
;
159 // Update the web contents visiblity.
160 void UpdateWebContentsVisibility(bool visible
);
162 FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest
, EnableDisableOverscroll
);
164 scoped_ptr
<aura::Window
> window_
;
166 scoped_ptr
<WindowObserver
> window_observer_
;
168 // The WebContentsImpl whose contents we display.
169 WebContentsImpl
* web_contents_
;
171 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
173 blink::WebDragOperationsMask current_drag_op_
;
175 scoped_ptr
<DropData
> current_drop_data_
;
177 WebDragDestDelegate
* drag_dest_delegate_
;
179 // We keep track of the render view host we're dragging over. If it changes
180 // during a drag, we need to re-send the DragEnter message. WARNING:
181 // this pointer should never be dereferenced. We only use it for comparing
183 void* current_rvh_for_drag_
;
185 // The overscroll gesture currently in progress.
186 OverscrollMode current_overscroll_gesture_
;
188 // This is the completed overscroll gesture. This is used for the animation
189 // callback that happens in response to a completed overscroll gesture.
190 OverscrollMode completed_overscroll_gesture_
;
192 // This manages the overlay window that shows the screenshot during a history
193 // navigation triggered by the overscroll gesture.
194 scoped_ptr
<OverscrollNavigationOverlay
> navigation_overlay_
;
196 scoped_ptr
<GestureNavSimple
> gesture_nav_simple_
;
198 // On Windows we can run into problems if resources get released within the
199 // initialization phase while the content (and its dimensions) are not known.
200 bool is_or_was_visible_
;
202 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura
);
205 } // namespace content
207 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_