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/wm/public/drag_drop_delegate.h"
25 class DropTargetEvent
;
29 class GestureNavSimple
;
30 class OverscrollNavigationOverlay
;
31 class RenderWidgetHostImpl
;
32 class RenderWidgetHostViewAura
;
33 class ShadowLayerDelegate
;
34 class TouchEditableImplAura
;
35 class WebContentsViewDelegate
;
36 class WebContentsImpl
;
37 class WebDragDestDelegate
;
39 class WebContentsViewAura
40 : public WebContentsView
,
41 public RenderViewHostDelegateView
,
42 public OverscrollControllerDelegate
,
43 public aura::WindowDelegate
,
44 public aura::client::DragDropDelegate
,
45 public aura::WindowObserver
{
47 WebContentsViewAura(WebContentsImpl
* web_contents
,
48 WebContentsViewDelegate
* delegate
);
50 CONTENT_EXPORT
void SetTouchEditableForTest(
51 TouchEditableImplAura
* touch_editable
);
56 ~WebContentsViewAura() override
;
58 void SizeChangedCommon(const gfx::Size
& size
);
60 void EndDrag(blink::WebDragOperationsMask ops
);
62 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura
* view
);
64 // Sets up the content window in preparation for starting an overscroll
66 void PrepareContentWindowForOverscroll();
68 // Completes the navigation in response to a completed overscroll gesture.
69 // The navigation happens after an animation (either the overlay window
70 // animates in, or the content window animates out).
71 void CompleteOverscrollNavigation(OverscrollMode mode
);
73 void AttachTouchEditableToRenderView();
75 void OverscrollUpdateForWebContentsDelegate(float delta_y
);
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 ui::TextInputClient
* GetFocusedTextInputClient() 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 scoped_ptr
<aura::Window
> window_
;
165 scoped_ptr
<WindowObserver
> window_observer_
;
167 // The WebContentsImpl whose contents we display.
168 WebContentsImpl
* web_contents_
;
170 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
172 blink::WebDragOperationsMask current_drag_op_
;
174 scoped_ptr
<DropData
> current_drop_data_
;
176 WebDragDestDelegate
* drag_dest_delegate_
;
178 // We keep track of the render view host we're dragging over. If it changes
179 // during a drag, we need to re-send the DragEnter message. WARNING:
180 // this pointer should never be dereferenced. We only use it for comparing
182 void* current_rvh_for_drag_
;
184 // The overscroll gesture currently in progress.
185 OverscrollMode current_overscroll_gesture_
;
187 // This is the completed overscroll gesture. This is used for the animation
188 // callback that happens in response to a completed overscroll gesture.
189 OverscrollMode completed_overscroll_gesture_
;
191 // This manages the overlay window that shows the screenshot during a history
192 // navigation triggered by the overscroll gesture.
193 scoped_ptr
<OverscrollNavigationOverlay
> navigation_overlay_
;
195 scoped_ptr
<TouchEditableImplAura
> touch_editable_
;
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_