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 virtual void ShowDisambiguationPopup( 140 const gfx::Rect& target_rect, 141 const SkBitmap& zoomed_bitmap, 142 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, 143 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) OVERRIDE; 144 virtual void HideDisambiguationPopup() OVERRIDE; 145 146 // Overridden from OverscrollControllerDelegate: 147 virtual gfx::Rect GetVisibleBounds() const OVERRIDE; 148 virtual bool OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE; 149 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE; 150 virtual void OnOverscrollModeChange(OverscrollMode old_mode, 151 OverscrollMode new_mode) OVERRIDE; 152 153 // Overridden from ui::ImplicitAnimationObserver: 154 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 155 156 // Overridden from aura::WindowDelegate: 157 virtual gfx::Size GetMinimumSize() const OVERRIDE; 158 virtual gfx::Size GetMaximumSize() const OVERRIDE; 159 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, 160 const gfx::Rect& new_bounds) OVERRIDE; 161 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE; 162 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; 163 virtual bool ShouldDescendIntoChildForEventHandling( 164 aura::Window* child, 165 const gfx::Point& location) OVERRIDE; 166 virtual bool CanFocus() OVERRIDE; 167 virtual void OnCaptureLost() OVERRIDE; 168 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 169 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 170 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 171 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; 172 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE; 173 virtual bool HasHitTestMask() const OVERRIDE; 174 virtual void GetHitTestMask(gfx::Path* mask) const 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 // Overridden from aura::WindowObserver: 187 virtual void OnWindowVisibilityChanged(aura::Window* window, 188 bool visible) OVERRIDE; 189 190 // Update the web contents visiblity. 191 void UpdateWebContentsVisibility(bool visible); 192 193 scoped_ptr<aura::Window> window_; 194 195 // The window that shows the screenshot of the history page during an 196 // overscroll navigation gesture. 197 scoped_ptr<aura::Window> overscroll_window_; 198 199 scoped_ptr<WindowObserver> window_observer_; 200 201 // The WebContentsImpl whose contents we display. 202 WebContentsImpl* web_contents_; 203 204 scoped_ptr<WebContentsViewDelegate> delegate_; 205 206 blink::WebDragOperationsMask current_drag_op_; 207 208 scoped_ptr<DropData> current_drop_data_; 209 210 WebDragDestDelegate* drag_dest_delegate_; 211 212 // We keep track of the render view host we're dragging over. If it changes 213 // during a drag, we need to re-send the DragEnter message. WARNING: 214 // this pointer should never be dereferenced. We only use it for comparing 215 // pointers. 216 void* current_rvh_for_drag_; 217 218 bool overscroll_change_brightness_; 219 220 // The overscroll gesture currently in progress. 221 OverscrollMode current_overscroll_gesture_; 222 223 // This is the completed overscroll gesture. This is used for the animation 224 // callback that happens in response to a completed overscroll gesture. 225 OverscrollMode completed_overscroll_gesture_; 226 227 // This manages the overlay window that shows the screenshot during a history 228 // navigation triggered by the overscroll gesture. 229 scoped_ptr<OverscrollNavigationOverlay> navigation_overlay_; 230 231 scoped_ptr<ShadowLayerDelegate> overscroll_shadow_; 232 233 scoped_ptr<TouchEditableImplAura> touch_editable_; 234 scoped_ptr<GestureNavSimple> gesture_nav_simple_; 235 236 // On Windows we can run into problems if resources get released within the 237 // initialization phase while the content (and its dimensions) are not known. 238 bool is_or_was_visible_; 239 240 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura); 241}; 242 243} // namespace content 244 245#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_ 246