cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / browser / web_contents / aura / overscroll_navigation_overlay.h
blob00cbf12fb009f45e9e8469d47816fc104b5e8feb
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "content/browser/web_contents/aura/window_slider.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h"
14 struct ViewHostMsg_UpdateRect_Params;
16 namespace content {
18 class ImageLayerDelegate;
19 class ImageWindowDelegate;
20 class OverscrollNavigationOverlayTest;
22 // When a history navigation is triggered at the end of an overscroll
23 // navigation, it is necessary to show the history-screenshot until the page is
24 // done navigating and painting. This class accomplishes this by showing the
25 // screenshot window on top of the page until the page has completed loading and
26 // painting.
27 class CONTENT_EXPORT OverscrollNavigationOverlay
28 : public WebContentsObserver,
29 public WindowSlider::Delegate {
30 public:
31 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents);
32 virtual ~OverscrollNavigationOverlay();
34 bool has_window() const { return !!window_.get(); }
36 // Resets state and starts observing |web_contents_| for page load/paint
37 // updates. This function makes sure that the screenshot window is stacked
38 // on top, so that it hides the content window behind it, and destroys the
39 // screenshot window when the page is done loading/painting.
40 // This should be called immediately after initiating the navigation,
41 // otherwise the overlay may be dismissed prematurely.
42 void StartObserving();
44 // Sets the screenshot window and the delegate. This takes ownership of
45 // |window|.
46 // Note that ImageWindowDelegate manages its own lifetime, so this function
47 // does not take ownership of |delegate|.
48 void SetOverlayWindow(scoped_ptr<aura::Window> window,
49 ImageWindowDelegate* delegate);
51 private:
52 friend class OverscrollNavigationOverlayTest;
53 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
54 FirstVisuallyNonEmptyPaint_NoImage);
55 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
56 FirstVisuallyNonEmptyPaint_WithImage);
57 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
58 LoadUpdateWithoutNonEmptyPaint);
59 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
60 MultiNavigation_LoadingUpdate);
61 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
62 MultiNavigation_PaintUpdate);
64 enum SlideDirection {
65 SLIDE_UNKNOWN,
66 SLIDE_BACK,
67 SLIDE_FRONT
70 // Stop observing the page and start the final overlay fade-out animation if
71 // a window-slide isn't in progress and either the page has been painted or
72 // the page-load has completed.
73 void StopObservingIfDone();
75 // Creates a layer to be used for window-slide. |offset| is the offset of the
76 // NavigationEntry for the screenshot image to display.
77 ui::Layer* CreateSlideLayer(int offset);
79 // Overridden from WindowSlider::Delegate:
80 virtual ui::Layer* CreateBackLayer() override;
81 virtual ui::Layer* CreateFrontLayer() override;
82 virtual void OnWindowSlideCompleting() override;
83 virtual void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override;
84 virtual void OnWindowSlideAborted() override;
85 virtual void OnWindowSliderDestroyed() override;
87 // Overridden from WebContentsObserver:
88 virtual void DidFirstVisuallyNonEmptyPaint() override;
89 virtual void DidStopLoading(RenderViewHost* host) override;
91 // The WebContents which is being navigated.
92 WebContentsImpl* web_contents_;
94 // The screenshot overlay window.
95 scoped_ptr<aura::Window> window_;
97 // This is the WindowDelegate of |window_|. The delegate manages its own
98 // lifetime (destroys itself when |window_| is destroyed).
99 ImageWindowDelegate* image_delegate_;
101 bool loading_complete_;
102 bool received_paint_update_;
104 // URL of the NavigationEntry we are navigating to. This is needed to
105 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
106 // when the relevant page loads and paints.
107 GURL pending_entry_url_;
109 // The |WindowSlider| that allows sliding history layers while the page is
110 // being reloaded.
111 scoped_ptr<WindowSlider> window_slider_;
113 // Layer to be used for the final overlay fadeout animation when the overlay
114 // is being dismissed.
115 scoped_ptr<ui::Layer> overlay_dismiss_layer_;
117 // The direction of the in-progress slide (if any).
118 SlideDirection slide_direction_;
120 // The LayerDelegate used for the back/front layers during a slide.
121 scoped_ptr<ImageLayerDelegate> layer_delegate_;
123 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
126 } // namespace content
128 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_