OLD | NEW |
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; |
| 25 class OverscrollWindowDelegate; |
23 class OverscrollNavigationOverlayTest; | 26 class OverscrollNavigationOverlayTest; |
24 | 27 |
25 // When a history navigation is triggered at the end of an overscroll | 28 // 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 | 29 // 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 | 30 // 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 | 31 // screenshot window on top of the page until the page has completed loading and |
29 // painting. | 32 // painting. |
30 class CONTENT_EXPORT OverscrollNavigationOverlay | 33 class CONTENT_EXPORT OverscrollNavigationOverlay |
31 : public WebContentsObserver, | 34 : public WebContentsObserver, |
32 public WindowSlider::Delegate { | 35 public OverscrollWindowAnimation::Delegate { |
33 public: | 36 public: |
34 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents); | 37 enum NavigationDirection { FORWARD, BACK, NONE }; |
| 38 |
| 39 OverscrollNavigationOverlay(WebContentsImpl* web_contents, |
| 40 aura::Window* web_contents_window); |
| 41 |
35 ~OverscrollNavigationOverlay() override; | 42 ~OverscrollNavigationOverlay() override; |
36 | 43 |
37 bool has_window() const { return !!window_.get(); } | 44 // Returns a pointer to the overscroll window animation we own. |
| 45 OverscrollWindowAnimation* owa() { return owa_.get(); } |
| 46 |
| 47 private: |
| 48 friend class OverscrollNavigationOverlayTest; |
| 49 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, |
| 50 WithScreenshot); |
| 51 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, |
| 52 WithoutScreenshot); |
| 53 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, |
| 54 CannotNavigate); |
| 55 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, |
| 56 AbortNavigation); |
| 57 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, |
| 58 AbortAfterSuccessfulNavigation); |
38 | 59 |
39 // Resets state and starts observing |web_contents_| for page load/paint | 60 // Resets state and starts observing |web_contents_| for page load/paint |
40 // updates. This function makes sure that the screenshot window is stacked | 61 // 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 | 62 // on top, so that it hides the content window behind it, and destroys the |
42 // screenshot window when the page is done loading/painting. | 63 // screenshot window when the page is done loading/painting. |
43 // This should be called immediately after initiating the navigation, | 64 // This should be called immediately after initiating the navigation, |
44 // otherwise the overlay may be dismissed prematurely. | 65 // otherwise the overlay may be dismissed prematurely. |
45 void StartObserving(); | 66 void StartObserving(); |
46 | 67 |
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 | |
54 private: | |
55 friend class OverscrollNavigationOverlayTest; | |
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
57 FirstVisuallyNonEmptyPaint_NoImage); | |
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
59 FirstVisuallyNonEmptyPaint_WithImage); | |
60 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
61 LoadUpdateWithoutNonEmptyPaint); | |
62 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
63 MultiNavigation_LoadingUpdate); | |
64 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
65 MultiNavigation_PaintUpdate); | |
66 | |
67 enum SlideDirection { | |
68 SLIDE_UNKNOWN, | |
69 SLIDE_BACK, | |
70 SLIDE_FRONT | |
71 }; | |
72 | |
73 // Stop observing the page and start the final overlay fade-out animation if | 68 // 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 | 69 // a window-slide isn't in progress and either the page has been painted or |
75 // the page-load has completed. | 70 // the page-load has completed. |
76 void StopObservingIfDone(); | 71 void StopObservingIfDone(); |
77 | 72 |
78 // Creates a layer to be used for window-slide. |offset| is the offset of the | 73 // Creates the overscroll window if it does not exist or layer if it does, |
79 // NavigationEntry for the screenshot image to display. | 74 // wraps it and transfers its ownership. |
80 ui::Layer* CreateSlideLayer(int offset); | 75 scoped_ptr<SlidableWrapper> CreateLayerWrapper(); |
81 | 76 |
82 // Overridden from WindowSlider::Delegate: | 77 // Creates a layer to slide on top of the overscroll window. |
83 ui::Layer* CreateBackLayer() override; | 78 scoped_ptr<ui::Layer> CreateSlideLayer(); |
84 ui::Layer* CreateFrontLayer() override; | 79 |
85 void OnWindowSlideCompleting() override; | 80 // Returns the screenshot for the given direction. |
86 void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override; | 81 const gfx::Image GetImageForDirection(NavigationDirection direction) const; |
87 void OnWindowSlideAborted() override; | 82 |
88 void OnWindowSliderDestroyed() override; | 83 // Overridden from OverscrollWindowAnimation::Delegate: |
| 84 scoped_ptr<SlidableWrapper> CreateFrontWrapper() override; |
| 85 scoped_ptr<SlidableWrapper> CreateBackWrapper() override; |
| 86 aura::Window* GetTargetWindow() const override; |
| 87 void OnOverscrollCompleting() override; |
| 88 void OnOverscrollCompleted( |
| 89 scoped_ptr<SlidableWrapper> wrapper) override; |
| 90 void OnOverscrollAborted() override; |
89 | 91 |
90 // Overridden from WebContentsObserver: | 92 // Overridden from WebContentsObserver: |
91 void DidFirstVisuallyNonEmptyPaint() override; | 93 void DidFirstVisuallyNonEmptyPaint() override; |
92 void DidStopLoading(RenderViewHost* host) override; | 94 void DidStopLoading(RenderViewHost* host) override; |
93 | 95 |
94 // The WebContents which is being navigated. | 96 // The current overscroll direction. |
| 97 NavigationDirection direction_; |
| 98 |
| 99 // The web contents that are being navigated. |
95 WebContentsImpl* web_contents_; | 100 WebContentsImpl* web_contents_; |
96 | 101 |
97 // The screenshot overlay window. | 102 // The overlay window that shows a screenshot during an overscroll gesture. |
98 scoped_ptr<aura::Window> window_; | 103 scoped_ptr<aura::Window> window_; |
99 | 104 |
100 // This is the WindowDelegate of |window_|. The delegate manages its own | 105 // This is the WindowDelegate of |window_|. The delegates manages its own |
101 // lifetime (destroys itself when |window_| is destroyed). | 106 // lifetime (destroys itself when |window_| is destroyed). |
102 aura_extra::ImageWindowDelegate* image_delegate_; | 107 aura_extra::ImageWindowDelegate* image_delegate_; |
103 | 108 |
104 bool loading_complete_; | 109 bool loading_complete_; |
105 bool received_paint_update_; | 110 bool received_paint_update_; |
106 | 111 |
107 // URL of the NavigationEntry we are navigating to. This is needed to | 112 // URL of the NavigationEntry we are navigating to. This is needed to |
108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay | 113 // filter on WebContentsObserver callbacks and is used to dismiss the overlay |
109 // when the relevant page loads and paints. | 114 // when the relevant page loads and paints. |
110 GURL pending_entry_url_; | 115 GURL pending_entry_url_; |
111 | 116 |
112 // The |WindowSlider| that allows sliding history layers while the page is | 117 // Manages the overscroll animations. |
113 // being reloaded. | 118 scoped_ptr<OverscrollWindowAnimation> owa_; |
114 scoped_ptr<WindowSlider> window_slider_; | |
115 | 119 |
116 // Layer to be used for the final overlay fadeout animation when the overlay | 120 // The window that hosts the web contents. |
117 // is being dismissed. | 121 aura::Window* web_contents_window_; |
118 scoped_ptr<ui::Layer> overlay_dismiss_layer_; | |
119 | |
120 // The direction of the in-progress slide (if any). | |
121 SlideDirection slide_direction_; | |
122 | 122 |
123 // The LayerDelegate used for the back/front layers during a slide. | 123 // The LayerDelegate used for the back/front layers during a slide. |
124 scoped_ptr<ImageLayerDelegate> layer_delegate_; | 124 scoped_ptr<ImageLayerDelegate> layer_delegate_; |
125 | 125 |
| 126 // The layer scheduled to be dismissed. |
| 127 scoped_ptr<ui::Layer> dismiss_layer_; |
| 128 |
126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); | 129 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
127 }; | 130 }; |
128 | 131 |
129 } // namespace content | 132 } // namespace content |
130 | 133 |
131 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ | 134 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ |
OLD | NEW |