Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_aura.h
blob2d7df30a122ec8d00fd36c8c264e3e3c688d38ed
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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_
8 #include <vector>
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"
21 namespace aura {
22 class Window;
25 namespace ui {
26 class DropTargetEvent;
29 namespace content {
30 class GestureNavSimple;
31 class OverscrollNavigationOverlay;
32 class RenderWidgetHostImpl;
33 class RenderWidgetHostViewAura;
34 class ShadowLayerDelegate;
35 class TouchEditableImplAura;
36 class WebContentsViewDelegate;
37 class WebContentsImpl;
38 class WebDragDestDelegate;
40 class 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);
52 CONTENT_EXPORT void SetTouchEditableForTest(
53 TouchEditableImplAura* touch_editable);
55 private:
56 class WindowObserver;
58 virtual ~WebContentsViewAura();
60 void SizeChangedCommon(const gfx::Size& size);
62 void EndDrag(blink::WebDragOperationsMask ops);
64 void InstallOverscrollControllerDelegate(RenderWidgetHostViewAura* view);
66 // Creates and sets up the overlay window that will be displayed during the
67 // overscroll gesture.
68 void PrepareOverscrollWindow();
70 // Sets up the content window in preparation for starting an overscroll
71 // gesture.
72 void PrepareContentWindowForOverscroll();
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();
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);
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();
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);
93 // A window showing the screenshot is overlayed during a navigation triggered
94 // by overscroll. This function sets this up.
95 void PrepareOverscrollNavigationOverlay();
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);
101 void AttachTouchEditableToRenderView();
103 void OverscrollUpdateForWebContentsDelegate(int delta_y);
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;
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;
140 // Overridden from OverscrollControllerDelegate:
141 virtual gfx::Rect GetVisibleBounds() const OVERRIDE;
142 virtual bool 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;
147 // Overridden from ui::ImplicitAnimationObserver:
148 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
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;
170 // Overridden from ui::EventHandler:
171 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
172 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
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;
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;
186 // Update the web contents visiblity.
187 void UpdateWebContentsVisibility(bool visible);
189 scoped_ptr<aura::Window> window_;
191 // The window that shows the screenshot of the history page during an
192 // overscroll navigation gesture.
193 scoped_ptr<aura::Window> overscroll_window_;
195 scoped_ptr<WindowObserver> window_observer_;
197 // The WebContentsImpl whose contents we display.
198 WebContentsImpl* web_contents_;
200 scoped_ptr<WebContentsViewDelegate> delegate_;
202 blink::WebDragOperationsMask current_drag_op_;
204 scoped_ptr<DropData> current_drop_data_;
206 WebDragDestDelegate* drag_dest_delegate_;
208 // We keep track of the render view host we're dragging over. If it changes
209 // during a drag, we need to re-send the DragEnter message. WARNING:
210 // this pointer should never be dereferenced. We only use it for comparing
211 // pointers.
212 void* current_rvh_for_drag_;
214 bool overscroll_change_brightness_;
216 // The overscroll gesture currently in progress.
217 OverscrollMode current_overscroll_gesture_;
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_;
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_;
227 scoped_ptr<ShadowLayerDelegate> overscroll_shadow_;
229 scoped_ptr<TouchEditableImplAura> touch_editable_;
230 scoped_ptr<GestureNavSimple> gesture_nav_simple_;
232 // On Windows we can run into problems if resources get released within the
233 // initialization phase while the content (and its dimensions) are not known.
234 bool is_or_was_visible_;
236 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAura);
239 } // namespace content
241 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_AURA_H_