Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: content/browser/web_contents/aura/overscroll_navigation_overlay.h

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Following suggestions by Mikhail, rewritten OWA to use a delegate interface (to be implemented) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "content/browser/web_contents/aura/window_slider.h" 10 #include "content/browser/web_contents/aura/overscroll_window_animation.h"
11 #include "content/browser/web_contents/web_contents_view_aura.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
14 #include "ui/gfx/image/image.h"
13 15
14 struct ViewHostMsg_UpdateRect_Params; 16 struct ViewHostMsg_UpdateRect_Params;
15 17
16 namespace aura_extra { 18 namespace aura_extra {
17 class ImageWindowDelegate; 19 class ImageWindowDelegate;
18 } 20 }
19 21
20 namespace content { 22 namespace content {
21 23
22 class ImageLayerDelegate; 24 class ImageLayerDelegate;
23 class OverscrollNavigationOverlayTest; 25 class OverscrollNavigationOverlayTest;
24 26
25 // When a history navigation is triggered at the end of an overscroll 27 // When a history navigation is triggered at the end of an overscroll
26 // navigation, it is necessary to show the history-screenshot until the page is 28 // navigation, it is necessary to show the history-screenshot until the page is
27 // done navigating and painting. This class accomplishes this by showing the 29 // done navigating and painting. This class accomplishes this by showing the
28 // screenshot window on top of the page until the page has completed loading and 30 // screenshot window on top of the page until the page has completed loading and
29 // painting. 31 // painting.
30 class CONTENT_EXPORT OverscrollNavigationOverlay 32 class CONTENT_EXPORT OverscrollNavigationOverlay
31 : public WebContentsObserver, 33 : public WebContentsObserver,
32 public WindowSlider::Delegate { 34 public OverscrollWindowAnimation::Delegate {
33 public: 35 public:
34 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents); 36 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents,
37 WebContentsViewAura* wcva,
38 aura::Window* web_contents_window);
35 ~OverscrollNavigationOverlay() override; 39 ~OverscrollNavigationOverlay() override;
36 40
37 bool has_window() const { return !!window_.get(); } 41 bool has_window() const { return !!window_.get(); }
38 42
39 // Resets state and starts observing |web_contents_| for page load/paint 43 // Resets state and starts observing |web_contents_| for page load/paint
40 // updates. This function makes sure that the screenshot window is stacked 44 // updates. This function makes sure that the screenshot window is stacked
41 // on top, so that it hides the content window behind it, and destroys the 45 // on top, so that it hides the content window behind it, and destroys the
42 // screenshot window when the page is done loading/painting. 46 // screenshot window when the page is done loading/painting.
43 // This should be called immediately after initiating the navigation, 47 // This should be called immediately after initiating the navigation,
44 // otherwise the overlay may be dismissed prematurely. 48 // otherwise the overlay may be dismissed prematurely.
45 void StartObserving(); 49 void StartObserving();
46 50
47 // Sets the screenshot window and the delegate. This takes ownership of 51 // Sets the screenshot window and the delegate. This takes ownership of
48 // |window|. 52 // |window|.
49 // Note that aura_extra::ImageWindowDelegate manages its own lifetime, so this 53 // Note that aura_extra::ImageWindowDelegate manages its own lifetime, so this
50 // function does not take ownership of |delegate|. 54 // function does not take ownership of |delegate|.
51 void SetOverlayWindow(scoped_ptr<aura::Window> window, 55 void SetOverlayWindow(scoped_ptr<aura::Window> window,
52 aura_extra::ImageWindowDelegate* delegate); 56 aura_extra::ImageWindowDelegate* delegate);
53 57
58 const gfx::Image GetImageForDirection(
59 OverscrollWindowAnimation::Direction direction);
60
61 // Creates a layer with a screenshot for a given direction.
62 scoped_ptr<ui::Layer> CreateLayerForDirection(
63 OverscrollWindowAnimation::Direction direction);
64
65 OverscrollWindowAnimation::Direction GetNavigationDirection();
66
54 private: 67 private:
55 friend class OverscrollNavigationOverlayTest; 68 friend class OverscrollNavigationOverlayTest;
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 69 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
57 FirstVisuallyNonEmptyPaint_NoImage); 70 FirstVisuallyNonEmptyPaint_NoImage);
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 71 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
59 FirstVisuallyNonEmptyPaint_WithImage); 72 FirstVisuallyNonEmptyPaint_WithImage);
60 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 73 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
61 LoadUpdateWithoutNonEmptyPaint); 74 LoadUpdateWithoutNonEmptyPaint);
62 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 75 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
63 MultiNavigation_LoadingUpdate); 76 MultiNavigation_LoadingUpdate);
64 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 77 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
65 MultiNavigation_PaintUpdate); 78 MultiNavigation_PaintUpdate);
66 79
67 enum SlideDirection { 80 // Fades out the overscroll window and dismisses it.
68 SLIDE_UNKNOWN, 81 void FadeOutOverscrollWindow();
69 SLIDE_BACK,
70 SLIDE_FRONT
71 };
72 82
73 // Stop observing the page and start the final overlay fade-out animation if 83 // Stop observing the page and start the final overlay fade-out animation if
74 // a window-slide isn't in progress and either the page has been painted or 84 // a window-slide isn't in progress and either the page has been painted or
75 // the page-load has completed. 85 // the page-load has completed.
76 void StopObservingIfDone(); 86 void StopObservingIfDone();
77 87
78 // Creates a layer to be used for window-slide. |offset| is the offset of the 88 // Creates a layer to be used for window-slide. |offset| is the offset of the
79 // NavigationEntry for the screenshot image to display. 89 // NavigationEntry for the screenshot image to display.
80 ui::Layer* CreateSlideLayer(int offset); 90 ui::Layer* CreateSlideLayer(int offset);
81 91
82 // Overridden from WindowSlider::Delegate: 92 aura::Window* GetWindowToAnimateForOverscroll() const;
83 ui::Layer* CreateBackLayer() override; 93
84 ui::Layer* CreateFrontLayer() override; 94 // Overridden from OverscrollWindowAnimation::Delegate:
85 void OnWindowSlideCompleting() override; 95 OverscrollWindowAnimation::Direction
86 void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override; 96 StartNavigation(OverscrollMode mode) override;
87 void OnWindowSlideAborted() override; 97
88 void OnWindowSliderDestroyed() override; 98 void SetTransform(const gfx::Transform& transform) override;
99
100 ui::LayerAnimator* GetAnimator() override;
101
102 gfx::Rect GetContentsBounds() const override;
103
104 void OnAnimationCompleted() override;
105
106 void OnAnimationCompleting() override;
89 107
90 // Overridden from WebContentsObserver: 108 // Overridden from WebContentsObserver:
91 void DidFirstVisuallyNonEmptyPaint() override; 109 void DidFirstVisuallyNonEmptyPaint() override;
92 void DidStopLoading(RenderViewHost* host) override; 110 void DidStopLoading(RenderViewHost* host) override;
93 111
112 // The current overscroll direction.
113 OverscrollWindowAnimation::Direction direction_;
114
94 // The WebContents which is being navigated. 115 // The WebContents which is being navigated.
95 WebContentsImpl* web_contents_; 116 WebContentsImpl* web_contents_;
96 117
97 // The screenshot overlay window. 118 // The window shown on top of the live window for the animations.
98 scoped_ptr<aura::Window> window_; 119 scoped_ptr<aura::Window> window_;
99 120
121 // Shadow shown under the animated window.
122 scoped_ptr<ShadowLayerDelegate> shadow_;
123
100 // This is the WindowDelegate of |window_|. The delegate manages its own 124 // This is the WindowDelegate of |window_|. The delegate manages its own
101 // lifetime (destroys itself when |window_| is destroyed). 125 // lifetime (destroys itself when |window_| is destroyed).
102 aura_extra::ImageWindowDelegate* image_delegate_; 126 aura_extra::ImageWindowDelegate* image_delegate_;
103 127
104 bool loading_complete_; 128 bool loading_complete_;
105 bool received_paint_update_; 129 bool received_paint_update_;
106 130
107 // URL of the NavigationEntry we are navigating to. This is needed to 131 // URL of the NavigationEntry we are navigating to. This is needed to
108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay 132 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
109 // when the relevant page loads and paints. 133 // when the relevant page loads and paints.
110 GURL pending_entry_url_; 134 GURL pending_entry_url_;
111 135
112 // The |WindowSlider| that allows sliding history layers while the page is
113 // being reloaded.
114 scoped_ptr<WindowSlider> window_slider_;
115
116 // Layer to be used for the final overlay fadeout animation when the overlay 136 // Layer to be used for the final overlay fadeout animation when the overlay
117 // is being dismissed. 137 // is being dismissed.
118 scoped_ptr<ui::Layer> overlay_dismiss_layer_; 138 scoped_ptr<ui::Layer> overlay_dismiss_layer_;
119 139
120 // The direction of the in-progress slide (if any).
121 SlideDirection slide_direction_;
122
123 // The LayerDelegate used for the back/front layers during a slide. 140 // The LayerDelegate used for the back/front layers during a slide.
124 scoped_ptr<ImageLayerDelegate> layer_delegate_; 141 scoped_ptr<ImageLayerDelegate> layer_delegate_;
125 142
143 // TODO use a delegate?
144 WebContentsViewAura* wcva_;
145
146 OverscrollWindowAnimation* owa_;
147
148 // The window that hosts the web contents.
149 aura::Window* web_contents_window_;
150
126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 151 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
127 }; 152 };
128 153
129 } // namespace content 154 } // namespace content
130 155
131 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 156 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698