[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / web_contents / aura / overscroll_navigation_overlay.h
blob32c9409b70ebf8b31bdf307d91c90a03438a15d0
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/overscroll_window_animation.h"
11 #include "content/browser/web_contents/web_contents_view_aura.h"
12 #include "content/common/content_export.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "ui/gfx/image/image.h"
16 struct ViewHostMsg_UpdateRect_Params;
18 namespace content {
20 class OverscrollWindowDelegate;
21 class OverscrollNavigationOverlayTest;
23 // When a history navigation is triggered at the end of an overscroll
24 // navigation, it is necessary to show the history-screenshot until the page is
25 // done navigating and painting. This class accomplishes this by calling the
26 // navigation and creating, showing and destroying the screenshot window on top
27 // of the page until the page has completed loading and painting. When the
28 // overscroll completes, this screenshot window is returned by
29 // OnOverscrollComplete and |window_| is set to own it.
30 // There are two overscroll cases, for the first one the main window is the web
31 // contents window. At this stage, |window_| is null. The second case is
32 // triggered if the user overscrolls after |window_| is set, before the page
33 // finishes loading. When this happens, |window_| is the main window.
34 class CONTENT_EXPORT OverscrollNavigationOverlay
35 : public WebContentsObserver,
36 public OverscrollWindowAnimation::Delegate {
37 public:
38 // Note that this enum is used to back an UMA histogram, so it should be
39 // treated as append-only.
40 enum NavigationDirection { NONE, FORWARD, BACK, NAVIGATION_COUNT };
42 OverscrollNavigationOverlay(WebContentsImpl* web_contents,
43 aura::Window* web_contents_window);
45 ~OverscrollNavigationOverlay() override;
47 // Returns a pointer to the relay delegate we own.
48 OverscrollControllerDelegate* relay_delegate() { return owa_.get(); }
50 private:
51 friend class OverscrollNavigationOverlayTest;
52 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithScreenshot);
53 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithoutScreenshot);
54 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CannotNavigate);
55 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CancelNavigation);
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
57 CancelAfterSuccessfulNavigation);
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, OverlayWindowSwap);
59 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
60 CloseDuringAnimation);
62 // Resets state and starts observing |web_contents_| for page load/paint
63 // updates. This function makes sure that the screenshot window is stacked
64 // on top, so that it hides the content window behind it, and destroys the
65 // screenshot window when the page is done loading/painting.
66 // This should be called immediately after initiating the navigation,
67 // otherwise the overlay may be dismissed prematurely.
68 void StartObserving();
70 // Stop observing the page and start the final overlay fade-out animation if
71 // there's no active overscroll window animation.
72 void StopObservingIfDone();
74 // Creates a window that shows a history-screenshot and is stacked relative to
75 // the current overscroll |direction_| with the given |bounds|.
76 scoped_ptr<aura::Window> CreateOverlayWindow(const gfx::Rect& bounds);
78 // Returns an image with the history-screenshot for the previous or next page,
79 // according to the given |direction|.
80 const gfx::Image GetImageForDirection(NavigationDirection direction) const;
82 // Overridden from OverscrollWindowAnimation::Delegate:
83 scoped_ptr<aura::Window> CreateFrontWindow(const gfx::Rect& bounds) override;
84 scoped_ptr<aura::Window> CreateBackWindow(const gfx::Rect& bounds) override;
85 aura::Window* GetMainWindow() const override;
86 void OnOverscrollCompleting() override;
87 void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override;
88 void OnOverscrollCancelled() override;
90 // Overridden from WebContentsObserver:
91 void DidFirstVisuallyNonEmptyPaint() override;
92 void DidStopLoading() override;
94 // The current overscroll direction.
95 NavigationDirection direction_;
97 // The web contents that are being navigated.
98 WebContentsImpl* web_contents_;
100 // The overlay window that shows a screenshot during an overscroll gesture and
101 // handles overscroll events during the second overscroll case.
102 scoped_ptr<aura::Window> window_;
104 bool loading_complete_;
105 bool received_paint_update_;
107 // URL of the NavigationEntry we are navigating to. This is needed to
108 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
109 // when the relevant page loads and paints.
110 GURL pending_entry_url_;
112 // Manages the overscroll animations.
113 scoped_ptr<OverscrollWindowAnimation> owa_;
115 // The window that hosts the web contents.
116 aura::Window* web_contents_window_;
118 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
121 } // namespace content
123 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_