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