Use native radiobutton for Default Search Engine picker dialog.
[chromium-blink-merge.git] / content / browser / web_contents / aura / overscroll_navigation_overlay.h
blobcfa5ce8c90883da8f7771d25b78cb6f174e3b7fe
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;
22 class ScopedLayerClippingSetting;
24 // 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 // done navigating and painting. This class accomplishes this by calling the
27 // navigation and creating, showing and destroying the screenshot window on top
28 // of the page until the page has completed loading and painting. When the
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
36 : public WebContentsObserver,
37 public OverscrollWindowAnimation::Delegate {
38 public:
39 // Note that this enum is used to back an UMA histogram, so it should be
40 // treated as append-only.
41 enum NavigationDirection { NONE, FORWARD, BACK, NAVIGATION_COUNT };
43 OverscrollNavigationOverlay(WebContentsImpl* web_contents,
44 aura::Window* web_contents_window);
46 ~OverscrollNavigationOverlay() override;
48 // Returns a pointer to the relay delegate we own.
49 OverscrollControllerDelegate* relay_delegate() { return owa_.get(); }
51 private:
52 class ScopedLayerClippingSetting;
54 friend class OverscrollNavigationOverlayTest;
55 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithScreenshot);
56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, WithoutScreenshot);
57 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CannotNavigate);
58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, CancelNavigation);
59 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
60 CancelAfterSuccessfulNavigation);
61 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, OverlayWindowSwap);
63 // Resets state and starts observing |web_contents_| for page load/paint
64 // updates. This function makes sure that the screenshot window is stacked
65 // on top, so that it hides the content window behind it, and destroys the
66 // screenshot window when the page is done loading/painting.
67 // This should be called immediately after initiating the navigation,
68 // otherwise the overlay may be dismissed prematurely.
69 void StartObserving();
71 // Stop observing the page and start the final overlay fade-out animation if
72 // there's no active overscroll window animation.
73 void StopObservingIfDone();
75 // Creates a window that shows a history-screenshot and is stacked relative to
76 // the current overscroll |direction_| with the given |bounds|.
77 scoped_ptr<aura::Window> CreateOverlayWindow(const gfx::Rect& bounds);
79 // Returns an image with the history-screenshot for the previous or next page,
80 // according to the given |direction|.
81 const gfx::Image GetImageForDirection(NavigationDirection direction) const;
83 // Overridden from OverscrollWindowAnimation::Delegate:
84 scoped_ptr<aura::Window> CreateFrontWindow(const gfx::Rect& bounds) override;
85 scoped_ptr<aura::Window> CreateBackWindow(const gfx::Rect& bounds) override;
86 aura::Window* GetMainWindow() const override;
87 void OnOverscrollCompleting() override;
88 void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override;
89 void OnOverscrollCancelled() override;
91 // Overridden from WebContentsObserver:
92 void DidFirstVisuallyNonEmptyPaint() override;
93 void DidStopLoading() override;
95 // The current overscroll direction.
96 NavigationDirection direction_;
98 // The web contents that are being navigated.
99 WebContentsImpl* web_contents_;
101 // The overlay window that shows a screenshot during an overscroll gesture and
102 // handles overscroll events during the second overscroll case.
103 scoped_ptr<aura::Window> window_;
105 bool loading_complete_;
106 bool received_paint_update_;
108 // URL of the NavigationEntry we are navigating to. This is needed to
109 // filter on WebContentsObserver callbacks and is used to dismiss the overlay
110 // when the relevant page loads and paints.
111 GURL pending_entry_url_;
113 // Manages the overscroll animations.
114 scoped_ptr<OverscrollWindowAnimation> owa_;
116 // The window that hosts the web contents.
117 aura::Window* web_contents_window_;
119 // Scoped clipping settings for the contents layer and its parent.
120 scoped_ptr<ScopedLayerClippingSetting> contents_layer_settings_;
121 scoped_ptr<ScopedLayerClippingSetting> contents_layer_parent_settings_;
123 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
126 } // namespace content
128 #endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_