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
;
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 aura::WindowDelegate
,
45 public aura::client::DragDropDelegate
,
46 public aura::WindowObserver
{
48 WebContentsViewAura(WebContentsImpl
* web_contents
,
49 WebContentsViewDelegate
* delegate
);
51 CONTENT_EXPORT
void SetTouchEditableForTest(
52 TouchEditableImplAura
* touch_editable
);
57 ~WebContentsViewAura() override
;
59 void SizeChangedCommon(const gfx::Size
& size
);
61 void EndDrag(blink::WebDragOperationsMask ops
);
63 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura
* view
);
65 // Sets up the content window in preparation for starting an overscroll
67 void PrepareContentWindowForOverscroll();
69 // Completes the navigation in response to a completed overscroll gesture.
70 // The navigation happens after an animation (either the overlay window
71 // animates in, or the content window animates out).
72 void CompleteOverscrollNavigation(OverscrollMode mode
);
74 void AttachTouchEditableToRenderView();
76 void OverscrollUpdateForWebContentsDelegate(float delta_y
);
78 // Overridden from WebContentsView:
79 gfx::NativeView
GetNativeView() const override
;
80 gfx::NativeView
GetContentNativeView() const override
;
81 gfx::NativeWindow
GetTopLevelNativeWindow() const override
;
82 void GetContainerBounds(gfx::Rect
* out
) const override
;
83 void SizeContents(const gfx::Size
& size
) override
;
84 void Focus() override
;
85 void SetInitialFocus() override
;
86 void StoreFocus() override
;
87 void RestoreFocus() override
;
88 DropData
* GetDropData() const override
;
89 gfx::Rect
GetViewBounds() const override
;
90 void CreateView(const gfx::Size
& initial_size
,
91 gfx::NativeView context
) override
;
92 RenderWidgetHostViewBase
* CreateViewForWidget(
93 RenderWidgetHost
* render_widget_host
,
94 bool is_guest_view_hack
) override
;
95 RenderWidgetHostViewBase
* CreateViewForPopupWidget(
96 RenderWidgetHost
* render_widget_host
) override
;
97 void SetPageTitle(const base::string16
& title
) override
;
98 void RenderViewCreated(RenderViewHost
* host
) override
;
99 void RenderViewSwappedIn(RenderViewHost
* host
) override
;
100 void SetOverscrollControllerEnabled(bool enabled
) override
;
102 // Overridden from RenderViewHostDelegateView:
103 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
104 const ContextMenuParams
& params
) override
;
105 void StartDragging(const DropData
& drop_data
,
106 blink::WebDragOperationsMask operations
,
107 const gfx::ImageSkia
& image
,
108 const gfx::Vector2d
& image_offset
,
109 const DragEventSourceInfo
& event_info
) override
;
110 void UpdateDragCursor(blink::WebDragOperation operation
) override
;
111 void GotFocus() override
;
112 void TakeFocus(bool reverse
) override
;
113 void ShowDisambiguationPopup(
114 const gfx::Rect
& target_rect
,
115 const SkBitmap
& zoomed_bitmap
,
116 const base::Callback
<void(ui::GestureEvent
*)>& gesture_cb
,
117 const base::Callback
<void(ui::MouseEvent
*)>& mouse_cb
) override
;
118 void HideDisambiguationPopup() override
;
120 // Overridden from OverscrollControllerDelegate:
121 gfx::Rect
GetVisibleBounds() const override
;
122 bool OnOverscrollUpdate(float delta_x
, float delta_y
) override
;
123 void OnOverscrollComplete(OverscrollMode overscroll_mode
) override
;
124 void OnOverscrollModeChange(OverscrollMode old_mode
,
125 OverscrollMode new_mode
) override
;
127 // Overridden from aura::WindowDelegate:
128 gfx::Size
GetMinimumSize() const override
;
129 gfx::Size
GetMaximumSize() const override
;
130 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
131 const gfx::Rect
& new_bounds
) override
;
132 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
133 int GetNonClientComponent(const gfx::Point
& point
) const override
;
134 bool ShouldDescendIntoChildForEventHandling(
136 const gfx::Point
& location
) override
;
137 bool CanFocus() override
;
138 void OnCaptureLost() override
;
139 void OnPaint(const ui::PaintContext
& context
) override
;
140 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
141 void OnWindowDestroying(aura::Window
* window
) override
;
142 void OnWindowDestroyed(aura::Window
* window
) override
;
143 void OnWindowTargetVisibilityChanged(bool visible
) override
;
144 bool HasHitTestMask() const override
;
145 void GetHitTestMask(gfx::Path
* mask
) const override
;
147 // Overridden from ui::EventHandler:
148 void OnKeyEvent(ui::KeyEvent
* event
) override
;
149 void OnMouseEvent(ui::MouseEvent
* event
) override
;
151 // Overridden from aura::client::DragDropDelegate:
152 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
153 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
154 void OnDragExited() override
;
155 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
157 // Overridden from aura::WindowObserver:
158 void OnWindowVisibilityChanged(aura::Window
* window
, bool visible
) override
;
160 // Update the web contents visiblity.
161 void UpdateWebContentsVisibility(bool visible
);
163 FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest
, EnableDisableOverscroll
);
165 scoped_ptr
<aura::Window
> window_
;
167 scoped_ptr
<WindowObserver
> window_observer_
;
169 // The WebContentsImpl whose contents we display.
170 WebContentsImpl
* web_contents_
;
172 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
174 blink::WebDragOperationsMask current_drag_op_
;
176 scoped_ptr
<DropData
> current_drop_data_
;
178 WebDragDestDelegate
* drag_dest_delegate_
;
180 // We keep track of the render view host we're dragging over. If it changes
181 // during a drag, we need to re-send the DragEnter message. WARNING:
182 // this pointer should never be dereferenced. We only use it for comparing
184 void* current_rvh_for_drag_
;
186 // The overscroll gesture currently in progress.
187 OverscrollMode current_overscroll_gesture_
;
189 // This is the completed overscroll gesture. This is used for the animation
190 // callback that happens in response to a completed overscroll gesture.
191 OverscrollMode completed_overscroll_gesture_
;
193 // This manages the overlay window that shows the screenshot during a history
194 // navigation triggered by the overscroll gesture.
195 scoped_ptr
<OverscrollNavigationOverlay
> navigation_overlay_
;
197 scoped_ptr
<TouchEditableImplAura
> touch_editable_
;
198 scoped_ptr
<GestureNavSimple
> gesture_nav_simple_
;
200 // On Windows we can run into problems if resources get released within the
201 // initialization phase while the content (and its dimensions) are not known.
202 bool is_or_was_visible_
;
204 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura
);
207 } // namespace content
209 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_