web_contents_view_aura.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/common/content_export.h" 14#include "content/port/browser/render_view_host_delegate_view.h" 15#include "content/port/browser/web_contents_view_port.h" 16#include "ui/aura/client/drag_drop_delegate.h" 17#include "ui/aura/window_delegate.h" 18#include "ui/compositor/layer_animation_observer.h" 19 20namespace aura { 21class Window; 22} 23 24namespace ui { 25class DropTargetEvent; 26} 27 28namespace content { 29class OverscrollNavigationOverlay; 30class ShadowWindow; 31class WebContentsViewDelegate; 32class WebContentsImpl; 33class WebDragDestDelegate; 34 35class CONTENT_EXPORT WebContentsViewAura 36 : public WebContentsViewPort, 37 public RenderViewHostDelegateView, 38 NON_EXPORTED_BASE(public OverscrollControllerDelegate), 39 public ui::ImplicitAnimationObserver, 40 public aura::WindowDelegate, 41 public aura::client::DragDropDelegate { 42 public: 43 WebContentsViewAura(WebContentsImpl* web_contents, 44 WebContentsViewDelegate* delegate); 45 46 void SetupOverlayWindowForTesting(); 47 48 private: 49 class WindowObserver; 50#if defined(OS_WIN) 51 class ChildWindowObserver; 52#endif 53 54 virtual ~WebContentsViewAura(); 55 56 void SizeChangedCommon(const gfx::Size& size); 57 58 void EndDrag(WebKit::WebDragOperationsMask ops); 59 60 // Creates and sets up the overlay window that will be displayed during the 61 // overscroll gesture. 62 void PrepareOverscrollWindow(); 63 64 // Sets up the content window in preparation for starting an overscroll 65 // gesture. 66 void PrepareContentWindowForOverscroll(); 67 68 // Resets any in-progress animation for the overscroll gesture. Note that this 69 // doesn't immediately reset the internal states; that happens after an 70 // animation. 71 void ResetOverscrollTransform(); 72 73 // Completes the navigation in response to a completed overscroll gesture. 74 // The navigation happens after an animation (either the overlay window 75 // animates in, or the content window animates out). 76 void CompleteOverscrollNavigation(OverscrollMode mode); 77 78 // Returns the window that should be animated for the overscroll gesture. 79 // (note that during the overscroll gesture, either the overlay window or the 80 // content window can be animated). 81 aura::Window* GetWindowToAnimateForOverscroll(); 82 83 // Returns the amount the animating window should be translated in response to 84 // the overscroll gesture. 85 gfx::Vector2d GetTranslationForOverscroll(int delta_x, int delta_y); 86 87 // A window showing the screenshot is overlayed during a navigation triggered 88 // by overscroll. This function sets this up. 89 void PrepareOverscrollNavigationOverlay(); 90 91 // Changes the brightness of the layer depending on the amount of horizontal 92 // overscroll (|delta_x|, in pixels). 93 void UpdateOverscrollWindowBrightness(float delta_x); 94 95 // Overridden from WebContentsView: 96 virtual gfx::NativeView GetNativeView() const OVERRIDE; 97 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; 98 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; 99 virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE; 100 virtual void OnTabCrashed(base::TerminationStatus status, 101 int error_code) OVERRIDE; 102 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 103 virtual void Focus() OVERRIDE; 104 virtual void SetInitialFocus() OVERRIDE; 105 virtual void StoreFocus() OVERRIDE; 106 virtual void RestoreFocus() OVERRIDE; 107 virtual WebDropData* GetDropData() const OVERRIDE; 108 virtual gfx::Rect GetViewBounds() const OVERRIDE; 109 110 // Overridden from WebContentsViewPort: 111 virtual void CreateView( 112 const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE; 113 virtual RenderWidgetHostView* CreateViewForWidget( 114 RenderWidgetHost* render_widget_host) OVERRIDE; 115 virtual RenderWidgetHostView* CreateViewForPopupWidget( 116 RenderWidgetHost* render_widget_host) OVERRIDE; 117 virtual void SetPageTitle(const string16& title) OVERRIDE; 118 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; 119 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; 120 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; 121 122 // Overridden from RenderViewHostDelegateView: 123 virtual void ShowContextMenu( 124 const ContextMenuParams& params, 125 ContextMenuSourceType type) OVERRIDE; 126 virtual void ShowPopupMenu(const gfx::Rect& bounds, 127 int item_height, 128 double item_font_size, 129 int selected_item, 130 const std::vector<WebMenuItem>& items, 131 bool right_aligned, 132 bool allow_multiple_selection) OVERRIDE; 133 virtual void StartDragging(const WebDropData& drop_data, 134 WebKit::WebDragOperationsMask operations, 135 const gfx::ImageSkia& image, 136 const gfx::Vector2d& image_offset, 137 const DragEventSourceInfo& event_info) OVERRIDE; 138 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; 139 virtual void GotFocus() OVERRIDE; 140 virtual void TakeFocus(bool reverse) OVERRIDE; 141 142 // Overridden from OverscrollControllerDelegate: 143 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE; 144 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE; 145 virtual void OnOverscrollModeChange(OverscrollMode old_mode, 146 OverscrollMode new_mode) OVERRIDE; 147 148 // Overridden from ui::ImplicitAnimationObserver: 149 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 150 151 // Overridden from aura::WindowDelegate: 152 virtual gfx::Size GetMinimumSize() const OVERRIDE; 153 virtual gfx::Size GetMaximumSize() const OVERRIDE; 154 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 155 const gfx::Rect& new_bounds) OVERRIDE; 156 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 157 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 158 virtual bool ShouldDescendIntoChildForEventHandling( 159 aura::Window* child, 160 const gfx::Point& location) OVERRIDE; 161 virtual bool CanFocus() OVERRIDE; 162 virtual void OnCaptureLost() OVERRIDE; 163 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 164 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 165 virtual void OnWindowDestroying() OVERRIDE; 166 virtual void OnWindowDestroyed() OVERRIDE; 167 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 168 virtual bool HasHitTestMask() const OVERRIDE; 169 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 170 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE; 171 172 // Overridden from ui::EventHandler: 173 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 174 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 175 176 // Overridden from aura::client::DragDropDelegate: 177 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; 178 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 179 virtual void OnDragExited() OVERRIDE; 180 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; 181 182 scoped_ptr<aura::Window> window_; 183 184 // The window that shows the screenshot of the history page during an 185 // overscroll navigation gesture. 186 scoped_ptr<aura::Window> overscroll_window_; 187 188 scoped_ptr<WindowObserver> window_observer_; 189#if defined(OS_WIN) 190 scoped_ptr<ChildWindowObserver> child_window_observer_; 191#endif 192 193 // The WebContentsImpl whose contents we display. 194 WebContentsImpl* web_contents_; 195 196 scoped_ptr<WebContentsViewDelegate> delegate_; 197 198 WebKit::WebDragOperationsMask current_drag_op_; 199 200 scoped_ptr<WebDropData> current_drop_data_; 201 202 WebDragDestDelegate* drag_dest_delegate_; 203 204 // We keep track of the render view host we're dragging over. If it changes 205 // during a drag, we need to re-send the DragEnter message. WARNING: 206 // this pointer should never be dereferenced. We only use it for comparing 207 // pointers. 208 void* current_rvh_for_drag_; 209 210 // The container for the content-window. The doc for ShadowWindow explains its 211 // lifetime and ownership. 212 ShadowWindow* content_container_; 213 214 bool overscroll_change_brightness_; 215 216 // The overscroll gesture currently in progress. 217 OverscrollMode current_overscroll_gesture_; 218 219 // This is the completed overscroll gesture. This is used for the animation 220 // callback that happens in response to a completed overscroll gesture. 221 OverscrollMode completed_overscroll_gesture_; 222 223 // This manages the overlay window that shows the screenshot during a history 224 // navigation triggered by the overscroll gesture. 225 scoped_ptr<OverscrollNavigationOverlay> navigation_overlay_; 226 227 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura); 228}; 229 230} // namespace content 231 232#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 233