web_contents_view_aura.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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. 4 5#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 7 8#include <vector> 9 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" 20 21namespace aura { 22class Window; 23} 24 25namespace ui { 26class DropTargetEvent; 27} 28 29namespace content { 30class GestureNavSimple; 31class OverscrollNavigationOverlay; 32class RenderWidgetHostImpl; 33class RenderWidgetHostViewAura; 34class ShadowLayerDelegate; 35class TouchEditableImplAura; 36class WebContentsViewDelegate; 37class WebContentsImpl; 38class WebDragDestDelegate; 39 40class 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 { 48 public: 49 WebContentsViewAura(WebContentsImpl* web_contents, 50 WebContentsViewDelegate* delegate); 51 52 CONTENT_EXPORT void SetTouchEditableForTest( 53 TouchEditableImplAura* touch_editable); 54 55 private: 56 class WindowObserver; 57 58 virtual ~WebContentsViewAura(); 59 60 void SizeChangedCommon(const gfx::Size& size); 61 62 void EndDrag(blink::WebDragOperationsMask ops); 63 64 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura* view); 65 66 // Creates and sets up the overlay window that will be displayed during the 67 // overscroll gesture. 68 void PrepareOverscrollWindow(); 69 70 // Sets up the content window in preparation for starting an overscroll 71 // gesture. 72 void PrepareContentWindowForOverscroll(); 73 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 76 // animation. 77 void ResetOverscrollTransform(); 78 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); 83 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(); 88 89 // Returns the amount the animating window should be translated in response to 90 // the overscroll gesture. 91 gfx::Vector2d GetTranslationForOverscroll(int delta_x, int delta_y); 92 93 // A window showing the screenshot is overlayed during a navigation triggered 94 // by overscroll. This function sets this up. 95 void PrepareOverscrollNavigationOverlay(); 96 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); 100 101 void AttachTouchEditableToRenderView(); 102 103 void OverscrollUpdateForWebContentsDelegate(int delta_y); 104 105 // Overridden from WebContentsView: 106 virtual gfx::NativeView GetNativeView() const OVERRIDE; 107 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; 108 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; 109 virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE; 110 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 111 virtual void Focus() OVERRIDE; 112 virtual void SetInitialFocus() OVERRIDE; 113 virtual void StoreFocus() OVERRIDE; 114 virtual void RestoreFocus() OVERRIDE; 115 virtual DropData* GetDropData() const OVERRIDE; 116 virtual gfx::Rect GetViewBounds() const OVERRIDE; 117 virtual void CreateView( 118 const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE; 119 virtual RenderWidgetHostViewBase* CreateViewForWidget( 120 RenderWidgetHost* render_widget_host) OVERRIDE; 121 virtual RenderWidgetHostViewBase* CreateViewForPopupWidget( 122 RenderWidgetHost* render_widget_host) OVERRIDE; 123 virtual void SetPageTitle(const base::string16& title) OVERRIDE; 124 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; 125 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; 126 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; 127 128 // Overridden from RenderViewHostDelegateView: 129 virtual void ShowContextMenu(RenderFrameHost* render_frame_host, 130 const ContextMenuParams& params) OVERRIDE; 131 virtual void StartDragging(const DropData& drop_data, 132 blink::WebDragOperationsMask operations, 133 const gfx::ImageSkia& image, 134 const gfx::Vector2d& image_offset, 135 const DragEventSourceInfo& event_info) OVERRIDE; 136 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; 137 virtual void GotFocus() OVERRIDE; 138 virtual void TakeFocus(bool reverse) OVERRIDE; 139 140 // Overridden from OverscrollControllerDelegate: 141 virtual gfx::Rect GetVisibleBounds() const OVERRIDE; 142 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE; 143 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE; 144 virtual void OnOverscrollModeChange(OverscrollMode old_mode, 145 OverscrollMode new_mode) OVERRIDE; 146 147 // Overridden from ui::ImplicitAnimationObserver: 148 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 149 150 // Overridden from aura::WindowDelegate: 151 virtual gfx::Size GetMinimumSize() const OVERRIDE; 152 virtual gfx::Size GetMaximumSize() const OVERRIDE; 153 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 154 const gfx::Rect& new_bounds) OVERRIDE; 155 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 156 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 157 virtual bool ShouldDescendIntoChildForEventHandling( 158 aura::Window* child, 159 const gfx::Point& location) OVERRIDE; 160 virtual bool CanFocus() OVERRIDE; 161 virtual void OnCaptureLost() OVERRIDE; 162 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 163 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 164 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 165 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; 166 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 167 virtual bool HasHitTestMask() const OVERRIDE; 168 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 169 170 // Overridden from ui::EventHandler: 171 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 172 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 173 174 // Overridden from aura::client::DragDropDelegate: 175 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; 176 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 177 virtual void OnDragExited() OVERRIDE; 178 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; 179 180 // Overridden from aura::WindowObserver: 181 virtual void OnWindowParentChanged(aura::Window* window, 182 aura::Window* parent) OVERRIDE; 183 virtual void OnWindowVisibilityChanged(aura::Window* window, 184 bool visible) OVERRIDE; 185 186 scoped_ptr<aura::Window> window_; 187 188 // The window that shows the screenshot of the history page during an 189 // overscroll navigation gesture. 190 scoped_ptr<aura::Window> overscroll_window_; 191 192 scoped_ptr<WindowObserver> window_observer_; 193 194 // The WebContentsImpl whose contents we display. 195 WebContentsImpl* web_contents_; 196 197 scoped_ptr<WebContentsViewDelegate> delegate_; 198 199 blink::WebDragOperationsMask current_drag_op_; 200 201 scoped_ptr<DropData> current_drop_data_; 202 203 WebDragDestDelegate* drag_dest_delegate_; 204 205 // We keep track of the render view host we're dragging over. If it changes 206 // during a drag, we need to re-send the DragEnter message. WARNING: 207 // this pointer should never be dereferenced. We only use it for comparing 208 // pointers. 209 void* current_rvh_for_drag_; 210 211 bool overscroll_change_brightness_; 212 213 // The overscroll gesture currently in progress. 214 OverscrollMode current_overscroll_gesture_; 215 216 // This is the completed overscroll gesture. This is used for the animation 217 // callback that happens in response to a completed overscroll gesture. 218 OverscrollMode completed_overscroll_gesture_; 219 220 // This manages the overlay window that shows the screenshot during a history 221 // navigation triggered by the overscroll gesture. 222 scoped_ptr<OverscrollNavigationOverlay> navigation_overlay_; 223 224 scoped_ptr<ShadowLayerDelegate> overscroll_shadow_; 225 226 scoped_ptr<TouchEditableImplAura> touch_editable_; 227 scoped_ptr<GestureNavSimple> gesture_nav_simple_; 228 229 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura); 230}; 231 232} // namespace content 233 234#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 235