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/overscroll_window_animation.h" | 10 #include "content/browser/web_contents/aura/window_slider.h" |
11 #include "content/browser/web_contents/web_contents_view_aura.h" | |
12 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
13 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
14 #include "ui/gfx/image/image.h" | |
15 | 13 |
16 struct ViewHostMsg_UpdateRect_Params; | 14 struct ViewHostMsg_UpdateRect_Params; |
17 | 15 |
| 16 namespace aura_extra { |
| 17 class ImageWindowDelegate; |
| 18 } |
| 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
20 class OverscrollWindowDelegate; | 22 class ImageLayerDelegate; |
21 class OverscrollNavigationOverlayTest; | 23 class OverscrollNavigationOverlayTest; |
22 class ScopedLayerClippingSetting; | |
23 | 24 |
24 // When a history navigation is triggered at the end of an overscroll | 25 // When a history navigation is triggered at the end of an overscroll |
25 // navigation, it is necessary to show the history-screenshot until the page is | 26 // navigation, it is necessary to show the history-screenshot until the page is |
26 // done navigating and painting. This class accomplishes this by calling the | 27 // done navigating and painting. This class accomplishes this by showing the |
27 // navigation and creating, showing and destroying the screenshot window on top | 28 // screenshot window on top of the page until the page has completed loading and |
28 // of the page until the page has completed loading and painting. When the | 29 // painting. |
29 // overscroll completes, this screenshot window is returned by | |
30 // OnOverscrollComplete and |window_| is set to own it. | |
31 // There are two overscroll cases, for the first one the main window is the web | |
32 // contents window. At this stage, |window_| is null. The second case is | |
33 // triggered if the user overscrolls after |window_| is set, before the page | |
34 // finishes loading. When this happens, |window_| is the main window. | |
35 class CONTENT_EXPORT OverscrollNavigationOverlay | 30 class CONTENT_EXPORT OverscrollNavigationOverlay |
36 : public WebContentsObserver, | 31 : public WebContentsObserver, |
37 public OverscrollWindowAnimation::Delegate { | 32 public WindowSlider::Delegate { |
38 public: | 33 public: |
39 enum NavigationDirection { FORWARD, BACK, NONE }; | 34 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents); |
40 | |
41 OverscrollNavigationOverlay(WebContentsImpl* web_contents, | |
42 aura::Window* web_contents_window); | |
43 | |
44 ~OverscrollNavigationOverlay() override; | 35 ~OverscrollNavigationOverlay() override; |
45 | 36 |
46 // Returns a pointer to the relay delegate we own. | 37 bool has_window() const { return !!window_.get(); } |
47 OverscrollControllerDelegate* relay_delegate() { return owa_.get(); } | |
48 | |
49 private: | |
50 class ScopedLayerClippingSetting; | |
51 | |
52 friend class OverscrollNavigationOverlayTest; | |
53 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithScreenshot); | |
54 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithoutScreenshot); | |
55 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CannotNavigate); | |
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CancelNavigation); | |
57 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, | |
58 CancelAfterSuccessfulNavigation); | |
59 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, OverlayWindowSwap); | |
60 | 38 |
61 // Resets state and starts observing |web_contents_| for page load/paint | 39 // Resets state and starts observing |web_contents_| for page load/paint |
62 // updates. This function makes sure that the screenshot window is stacked | 40 // updates. This function makes sure that the screenshot window is stacked |
63 // on top, so that it hides the content window behind it, and destroys the | 41 // on top, so that it hides the content window behind it, and destroys the |
64 // screenshot window when the page is done loading/painting. | 42 // screenshot window when the page is done loading/painting. |
65 // This should be called immediately after initiating the navigation, | 43 // This should be called immediately after initiating the navigation, |
66 // otherwise the overlay may be dismissed prematurely. | 44 // otherwise the overlay may be dismissed prematurely. |
67 void StartObserving(); | 45 void StartObserving(); |
68 | 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 |
| 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 |
69 // Stop observing the page and start the final overlay fade-out animation if | 73 // Stop observing the page and start the final overlay fade-out animation if |
70 // there's no active overscroll window animation. | 74 // a window-slide isn't in progress and either the page has been painted or |
| 75 // the page-load has completed. |
71 void StopObservingIfDone(); | 76 void StopObservingIfDone(); |
72 | 77 |
73 // Creates a window that shows a history-screenshot and is stacked relative to | 78 // Creates a layer to be used for window-slide. |offset| is the offset of the |
74 // the current overscroll |direction_| with the given |bounds|. | 79 // NavigationEntry for the screenshot image to display. |
75 scoped_ptr<aura::Window> CreateOverlayWindow(const gfx::Rect& bounds); | 80 ui::Layer* CreateSlideLayer(int offset); |
76 | 81 |
77 // Returns an image with the history-screenshot for the previous or next page, | 82 // Overridden from WindowSlider::Delegate: |
78 // according to the given |direction|. | 83 ui::Layer* CreateBackLayer() override; |
79 const gfx::Image GetImageForDirection(NavigationDirection direction) const; | 84 ui::Layer* CreateFrontLayer() override; |
80 | 85 void OnWindowSlideCompleting() override; |
81 // Overridden from OverscrollWindowAnimation::Delegate: | 86 void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override; |
82 scoped_ptr<aura::Window> CreateFrontWindow(const gfx::Rect& bounds) override; | 87 void OnWindowSlideAborted() override; |
83 scoped_ptr<aura::Window> CreateBackWindow(const gfx::Rect& bounds) override; | 88 void OnWindowSliderDestroyed() override; |
84 aura::Window* GetMainWindow() const override; | |
85 void OnOverscrollCompleting() override; | |
86 void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override; | |
87 void OnOverscrollCancelled() override; | |
88 | 89 |
89 // Overridden from WebContentsObserver: | 90 // Overridden from WebContentsObserver: |
90 void DidFirstVisuallyNonEmptyPaint() override; | 91 void DidFirstVisuallyNonEmptyPaint() override; |
91 void DidStopLoading() override; | 92 void DidStopLoading() override; |
92 | 93 |
93 // The current overscroll direction. | 94 // The WebContents which is being navigated. |
94 NavigationDirection direction_; | |
95 | |
96 // The web contents that are being navigated. | |
97 WebContentsImpl* web_contents_; | 95 WebContentsImpl* web_contents_; |
98 | 96 |
99 // The overlay window that shows a screenshot during an overscroll gesture and | 97 // The screenshot overlay window. |
100 // handles overscroll events during the second overscroll case. | |
101 scoped_ptr<aura::Window> window_; | 98 scoped_ptr<aura::Window> window_; |
102 | 99 |
| 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 |
103 bool loading_complete_; | 104 bool loading_complete_; |
104 bool received_paint_update_; | 105 bool received_paint_update_; |
105 | 106 |
106 // URL of the NavigationEntry we are navigating to. This is needed to | 107 // URL of the NavigationEntry we are navigating to. This is needed to |
107 // filter on WebContentsObserver callbacks and is used to dismiss the overlay | 108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay |
108 // when the relevant page loads and paints. | 109 // when the relevant page loads and paints. |
109 GURL pending_entry_url_; | 110 GURL pending_entry_url_; |
110 | 111 |
111 // Manages the overscroll animations. | 112 // The |WindowSlider| that allows sliding history layers while the page is |
112 scoped_ptr<OverscrollWindowAnimation> owa_; | 113 // being reloaded. |
| 114 scoped_ptr<WindowSlider> window_slider_; |
113 | 115 |
114 // The window that hosts the web contents. | 116 // Layer to be used for the final overlay fadeout animation when the overlay |
115 aura::Window* web_contents_window_; | 117 // is being dismissed. |
| 118 scoped_ptr<ui::Layer> overlay_dismiss_layer_; |
116 | 119 |
117 // Scoped clipping settings for the contents layer and its parent. | 120 // The direction of the in-progress slide (if any). |
118 scoped_ptr<ScopedLayerClippingSetting> contents_layer_settings_; | 121 SlideDirection slide_direction_; |
119 scoped_ptr<ScopedLayerClippingSetting> contents_layer_parent_settings_; | 122 |
| 123 // The LayerDelegate used for the back/front layers during a slide. |
| 124 scoped_ptr<ImageLayerDelegate> layer_delegate_; |
120 | 125 |
121 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); | 126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
122 }; | 127 }; |
123 | 128 |
124 } // namespace content | 129 } // namespace content |
125 | 130 |
126 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ | 131 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ |
OLD | NEW |