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 { | |
17 class ImageWindowDelegate; | |
18 } | |
19 | |
20 namespace content { | 18 namespace content { |
21 | 19 |
22 class ImageLayerDelegate; | 20 class OverscrollWindowDelegate; |
23 class OverscrollNavigationOverlayTest; | 21 class OverscrollNavigationOverlayTest; |
24 | 22 |
25 // When a history navigation is triggered at the end of an overscroll | 23 // 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 | 24 // 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 | 25 // done navigating and painting. This class accomplishes this by calling the |
28 // screenshot window on top of the page until the page has completed loading and | 26 // navigation and creating, showing and destroying the screenshot window on top |
29 // painting. | 27 // of the page until the page has completed loading and painting. |
30 class CONTENT_EXPORT OverscrollNavigationOverlay | 28 class CONTENT_EXPORT OverscrollNavigationOverlay |
31 : public WebContentsObserver, | 29 : public WebContentsObserver, |
32 public WindowSlider::Delegate { | 30 public OverscrollWindowAnimation::Delegate { |
33 public: | 31 public: |
34 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents); | 32 enum NavigationDirection { FORWARD, BACK, NONE }; |
33 | |
34 OverscrollNavigationOverlay(WebContentsImpl* web_contents, | |
35 aura::Window* web_contents_window); | |
36 | |
35 ~OverscrollNavigationOverlay() override; | 37 ~OverscrollNavigationOverlay() override; |
36 | 38 |
37 bool has_window() const { return !!window_.get(); } | 39 // Returns a pointer to the overscroll window animation we own. |
40 OverscrollWindowAnimation* owa() { return owa_.get(); } | |
41 | |
42 private: | |
43 friend class OverscrollNavigationOverlayTest; | |
44 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithScreenshot); | |
45 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithoutScreenshot); | |
46 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CannotNavigate); | |
47 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, AbortNavigation); | |
48 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
49 AbortAfterSuccessfulNavigation); | |
50 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, OverlayWindowSwap); | |
38 | 51 |
39 // Resets state and starts observing |web_contents_| for page load/paint | 52 // Resets state and starts observing |web_contents_| for page load/paint |
40 // updates. This function makes sure that the screenshot window is stacked | 53 // 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 | 54 // on top, so that it hides the content window behind it, and destroys the |
42 // screenshot window when the page is done loading/painting. | 55 // screenshot window when the page is done loading/painting. |
43 // This should be called immediately after initiating the navigation, | 56 // This should be called immediately after initiating the navigation, |
44 // otherwise the overlay may be dismissed prematurely. | 57 // otherwise the overlay may be dismissed prematurely. |
45 void StartObserving(); | 58 void StartObserving(); |
46 | 59 |
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 | 60 // 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 | 61 // an overscroll slide isn't in progress and either the page has been painted |
mfomitchev
2015/03/31 21:04:06
I don't think "overscroll slide" hasn't been estab
Nina
2015/04/01 18:10:01
Done.
| |
75 // the page-load has completed. | 62 // or the page-load has completed. |
76 void StopObservingIfDone(); | 63 void StopObservingIfDone(); |
77 | 64 |
78 // Creates a layer to be used for window-slide. |offset| is the offset of the | 65 // Creates a window that shows a history-screenshot and is stacked relative to |
79 // NavigationEntry for the screenshot image to display. | 66 // the current overscroll |direction_|. Transfers ownership to the caller. |
mfomitchev
2015/03/31 21:04:06
NO need to talk about the ownership transfer. scop
Nina
2015/04/01 18:10:01
Removed.
| |
80 ui::Layer* CreateSlideLayer(int offset); | 67 scoped_ptr<aura::Window> CreateOverlayWindow(); |
81 | 68 |
82 // Overridden from WindowSlider::Delegate: | 69 // Returns an image with the history-screenshot for the previous or next page, |
83 ui::Layer* CreateBackLayer() override; | 70 // according to the given |direction|. |
84 ui::Layer* CreateFrontLayer() override; | 71 const gfx::Image GetImageForDirection(NavigationDirection direction) const; |
85 void OnWindowSlideCompleting() override; | 72 |
86 void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override; | 73 // Overridden from OverscrollWindowAnimation::Delegate: |
87 void OnWindowSlideAborted() override; | 74 scoped_ptr<aura::Window> CreateFrontWindow() override; |
88 void OnWindowSliderDestroyed() override; | 75 scoped_ptr<aura::Window> CreateBackWindow() override; |
76 aura::Window* GetMainWindow() const override; | |
77 void OnOverscrollCompleting() override; | |
78 void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override; | |
79 void OnOverscrollAborted() override; | |
89 | 80 |
90 // Overridden from WebContentsObserver: | 81 // Overridden from WebContentsObserver: |
91 void DidFirstVisuallyNonEmptyPaint() override; | 82 void DidFirstVisuallyNonEmptyPaint() override; |
92 void DidStopLoading() override; | 83 void DidStopLoading() override; |
93 | 84 |
94 // The WebContents which is being navigated. | 85 // The current overscroll direction. |
86 NavigationDirection direction_; | |
87 | |
88 // The web contents that are being navigated. | |
95 WebContentsImpl* web_contents_; | 89 WebContentsImpl* web_contents_; |
96 | 90 |
97 // The screenshot overlay window. | 91 // The overlay window that shows a screenshot during an overscroll gesture and |
92 // handles overscroll events. | |
98 scoped_ptr<aura::Window> window_; | 93 scoped_ptr<aura::Window> window_; |
mfomitchev
2015/03/31 21:04:06
Now this is actually a bit misleading since this i
Nina
2015/04/01 18:10:01
Explained up there in the class comments.
| |
99 | 94 |
100 // This is the WindowDelegate of |window_|. The delegate manages its own | |
101 // lifetime (destroys itself when |window_| is destroyed). | |
102 aura_extra::ImageWindowDelegate* image_delegate_; | |
103 | |
104 bool loading_complete_; | 95 bool loading_complete_; |
105 bool received_paint_update_; | 96 bool received_paint_update_; |
106 | 97 |
107 // URL of the NavigationEntry we are navigating to. This is needed to | 98 // URL of the NavigationEntry we are navigating to. This is needed to |
108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay | 99 // filter on WebContentsObserver callbacks and is used to dismiss the overlay |
109 // when the relevant page loads and paints. | 100 // when the relevant page loads and paints. |
110 GURL pending_entry_url_; | 101 GURL pending_entry_url_; |
111 | 102 |
112 // The |WindowSlider| that allows sliding history layers while the page is | 103 // Manages the overscroll animations. |
113 // being reloaded. | 104 scoped_ptr<OverscrollWindowAnimation> owa_; |
114 scoped_ptr<WindowSlider> window_slider_; | |
115 | 105 |
116 // Layer to be used for the final overlay fadeout animation when the overlay | 106 // The window that hosts the web contents. |
117 // is being dismissed. | 107 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 | |
123 // The LayerDelegate used for the back/front layers during a slide. | |
124 scoped_ptr<ImageLayerDelegate> layer_delegate_; | |
125 | 108 |
126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); | 109 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
127 }; | 110 }; |
128 | 111 |
129 } // namespace content | 112 } // namespace content |
130 | 113 |
131 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ | 114 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ |
OLD | NEW |