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 20 namespace aura { 21 class Window; 22 } 23 24 namespace ui { 25 class DropTargetEvent; 26 } 27 28 namespace content { 29 class OverscrollNavigationOverlay; 30 class ShadowLayerDelegate; 31 class TouchEditableImplAura; 32 class WebContentsViewDelegate; 33 class WebContentsImpl; 34 class WebDragDestDelegate; 35 36 class 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 54 virtual ~WebContentsViewAura(); 55 56 void SizeChangedCommon(const gfx::Size& size); 57 58 void EndDrag(blink::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 void AttachTouchEditableToRenderView(); 96 97 void OverscrollUpdateForWebContentsDelegate(int delta_y); 98 99 // Overridden from WebContentsView: 100 virtual gfx::NativeView GetNativeView() const OVERRIDE; 101 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; 102 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; 103 virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE; 104 virtual void OnTabCrashed(base::TerminationStatus status, 105 int error_code) OVERRIDE; 106 virtual void SizeContents(const gfx::Size& size) OVERRIDE; 107 virtual void Focus() OVERRIDE; 108 virtual void SetInitialFocus() OVERRIDE; 109 virtual void StoreFocus() OVERRIDE; 110 virtual void RestoreFocus() OVERRIDE; 111 virtual DropData* GetDropData() const OVERRIDE; 112 virtual gfx::Rect GetViewBounds() const OVERRIDE; 113 114 // Overridden from WebContentsViewPort: 115 virtual void CreateView( 116 const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE; 117 virtual RenderWidgetHostView* CreateViewForWidget( 118 RenderWidgetHost* render_widget_host) OVERRIDE; 119 virtual RenderWidgetHostView* CreateViewForPopupWidget( 120 RenderWidgetHost* render_widget_host) OVERRIDE; 121 virtual void SetPageTitle(const base::string16& title) OVERRIDE; 122 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; 123 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE; 124 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE; 125 126 // Overridden from RenderViewHostDelegateView: 127 virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE; 128 virtual void ShowPopupMenu(const gfx::Rect& bounds, 129 int item_height, 130 double item_font_size, 131 int selected_item, 132 const std::vector<MenuItem>& items, 133 bool right_aligned, 134 bool allow_multiple_selection) OVERRIDE; 135 virtual void StartDragging(const DropData& drop_data, 136 blink::WebDragOperationsMask operations, 137 const gfx::ImageSkia& image, 138 const gfx::Vector2d& image_offset, 139 const DragEventSourceInfo& event_info) OVERRIDE; 140 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE; 141 virtual void GotFocus() OVERRIDE; 142 virtual void TakeFocus(bool reverse) OVERRIDE; 143 144 // Overridden from OverscrollControllerDelegate: 145 virtual gfx::Rect GetVisibleBounds() const OVERRIDE; 146 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE; 147 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE; 148 virtual void OnOverscrollModeChange(OverscrollMode old_mode, 149 OverscrollMode new_mode) OVERRIDE; 150 151 // Overridden from ui::ImplicitAnimationObserver: 152 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 153 154 // Overridden from aura::WindowDelegate: 155 virtual gfx::Size GetMinimumSize() const OVERRIDE; 156 virtual gfx::Size GetMaximumSize() const OVERRIDE; 157 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 158 const gfx::Rect& new_bounds) OVERRIDE; 159 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 160 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 161 virtual bool ShouldDescendIntoChildForEventHandling( 162 aura::Window* child, 163 const gfx::Point& location) OVERRIDE; 164 virtual bool CanFocus() OVERRIDE; 165 virtual void OnCaptureLost() OVERRIDE; 166 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 167 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 168 virtual void OnWindowDestroying() OVERRIDE; 169 virtual void OnWindowDestroyed() OVERRIDE; 170 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 171 virtual bool HasHitTestMask() const OVERRIDE; 172 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; 173 virtual void DidRecreateLayer(ui::Layer* old_layer, 174 ui::Layer* new_layer) OVERRIDE; 175 176 // Overridden from ui::EventHandler: 177 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 178 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 179 180 // Overridden from aura::client::DragDropDelegate: 181 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; 182 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 183 virtual void OnDragExited() OVERRIDE; 184 virtual int OnPerformDrop(const ui::DropTargetEvent& event) 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 228 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura); 229 }; 230 231 } // namespace content 232 233 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 234