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

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: Checked comments Created 5 years, 9 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 OverscrollNavigationOverlay(WebContentsImpl* web_contents,
37 OverscrollWindowAnimation* owa,
38 aura::Window* web_contents_window);
39
35 ~OverscrollNavigationOverlay() override; 40 ~OverscrollNavigationOverlay() override;
36 41
37 bool has_window() const { return !!window_.get(); } 42 OverscrollWindowAnimation::Direction direction() { return direction_; }
38
39 // Resets state and starts observing |web_contents_| for page load/paint
40 // 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
42 // screenshot window when the page is done loading/painting.
43 // This should be called immediately after initiating the navigation,
44 // otherwise the overlay may be dismissed prematurely.
45 void StartObserving();
46
47 // Sets the screenshot window and the delegate. This takes ownership of
48 // |window|.
49 // Note that aura_extra::ImageWindowDelegate manages its own lifetime, so this
50 // function does not take ownership of |delegate|.
51 void SetOverlayWindow(scoped_ptr<aura::Window> window,
52 aura_extra::ImageWindowDelegate* delegate);
53 43
54 private: 44 private:
55 friend class OverscrollNavigationOverlayTest; 45 friend class OverscrollNavigationOverlayTest;
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 46 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
57 FirstVisuallyNonEmptyPaint_NoImage); 47 FirstVisuallyNonEmptyPaint_NoImage);
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 48 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
59 FirstVisuallyNonEmptyPaint_WithImage); 49 FirstVisuallyNonEmptyPaint_WithImage);
60 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 50 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
61 LoadUpdateWithoutNonEmptyPaint); 51 LoadUpdateWithoutNonEmptyPaint);
62 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 52 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
63 MultiNavigation_LoadingUpdate); 53 MultiNavigation_LoadingUpdate);
64 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 54 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
65 MultiNavigation_PaintUpdate); 55 MultiNavigation_PaintUpdate);
66 56
67 enum SlideDirection { 57 // Resets state and starts observing |web_contents_| for page load/paint
68 SLIDE_UNKNOWN, 58 // updates. This function makes sure that the screenshot window is stacked
69 SLIDE_BACK, 59 // on top, so that it hides the content window behind it, and destroys the
70 SLIDE_FRONT 60 // screenshot window when the page is done loading/painting.
71 }; 61 // This should be called immediately after initiating the navigation,
62 // otherwise the overlay may be dismissed prematurely.
63 void StartObserving();
64
65 // Creates the overlay window.
66 void SetupOverlayWindow();
67
68 // Returns the screenshot for the given direction.
69 const gfx::Image GetImageForDirection(
70 OverscrollWindowAnimation::Direction direction) const;
71
72 // Creates the overscroll window if it does not exist or adds a layer if it
73 // does.
74 // TODO find a better name.
75 scoped_ptr<OverscrollLayerWrapper> CreateLayer();
72 76
73 // Stop observing the page and start the final overlay fade-out animation if 77 // 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 78 // a window-slide isn't in progress and either the page has been painted or
75 // the page-load has completed. 79 // the page-load has completed.
76 void StopObservingIfDone(); 80 void StopObservingIfDone();
77 81
82 // Fades out the overscroll window and dismisses it.
83 void FadeOutOverscrollWindow();
84
78 // Creates a layer to be used for window-slide. |offset| is the offset of the 85 // Creates a layer to be used for window-slide. |offset| is the offset of the
79 // NavigationEntry for the screenshot image to display. 86 // NavigationEntry for the screenshot image to display.
80 ui::Layer* CreateSlideLayer(int offset); 87 ui::Layer* CreateSlideLayer(int offset);
81 88
82 // Overridden from WindowSlider::Delegate: 89 // Overridden from OverscrollWindowAnimation::Delegate:
83 ui::Layer* CreateBackLayer() override; 90 scoped_ptr<OverscrollLayerWrapper> CreateFrontLayer() override;
84 ui::Layer* CreateFrontLayer() override; 91 scoped_ptr<OverscrollLayerWrapper> CreateBackLayer() override;
85 void OnWindowSlideCompleting() override; 92 void OnOverscrollCompleted() override;
86 void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override; 93 void OnOverscrollCompleting() override;
87 void OnWindowSlideAborted() override;
88 void OnWindowSliderDestroyed() override;
89 94
90 // Overridden from WebContentsObserver: 95 // Overridden from WebContentsObserver:
91 void DidFirstVisuallyNonEmptyPaint() override; 96 void DidFirstVisuallyNonEmptyPaint() override;
92 void DidStopLoading(RenderViewHost* host) override; 97 void DidStopLoading(RenderViewHost* host) override;
93 98
94 // The WebContents which is being navigated. 99 // The current overscroll direction.
100 OverscrollWindowAnimation::Direction direction_;
101
102 // The web contents that are being navigated.
95 WebContentsImpl* web_contents_; 103 WebContentsImpl* web_contents_;
96 104
97 // The screenshot overlay window. 105 // The window shown on top of the live window for the animations.
98 scoped_ptr<aura::Window> window_; 106 scoped_ptr<aura::Window> window_;
99 107
100 // This is the WindowDelegate of |window_|. The delegate manages its own 108 // This is the WindowDelegate of |window_|. The delegate manages its own
101 // lifetime (destroys itself when |window_| is destroyed). 109 // lifetime (destroys itself when |window_| is destroyed).
102 aura_extra::ImageWindowDelegate* image_delegate_; 110 aura_extra::ImageWindowDelegate* image_delegate_;
103 111
104 bool loading_complete_; 112 bool loading_complete_;
105 bool received_paint_update_; 113 bool received_paint_update_;
106 114
107 // URL of the NavigationEntry we are navigating to. This is needed to 115 // URL of the NavigationEntry we are navigating to. This is needed to
108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay 116 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
109 // when the relevant page loads and paints. 117 // when the relevant page loads and paints.
110 GURL pending_entry_url_; 118 GURL pending_entry_url_;
111 119
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 120 // Layer to be used for the final overlay fadeout animation when the overlay
117 // is being dismissed. 121 // is being dismissed.
118 scoped_ptr<ui::Layer> overlay_dismiss_layer_; 122 scoped_ptr<ui::Layer> overlay_dismiss_layer_;
119 123
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. 124 // The LayerDelegate used for the back/front layers during a slide.
124 scoped_ptr<ImageLayerDelegate> layer_delegate_; 125 scoped_ptr<ImageLayerDelegate> layer_delegate_;
125 126
127 // We own the mechanism to animate the windows.
128 OverscrollWindowAnimation* owa_;
129
130 // The window that hosts the web contents.
131 aura::Window* web_contents_window_;
132
126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 133 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
127 }; 134 };
128 135
129 } // namespace content 136 } // namespace content
130 137
131 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 138 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698