Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / aura / overscroll_navigation_overlay.h
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.
4
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
7
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"
13
14 struct ViewHostMsg_UpdateRect_Params;
15
16 namespace content {
17
18 class ImageLayerDelegate;
19 class ImageWindowDelegate;
20 class OverscrollNavigationOverlayTest;
21
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();
33
34   bool has_window() const { return !!window_.get(); }
35
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();
43
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);
50
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);
63
64   enum SlideDirection {
65     SLIDE_UNKNOWN,
66     SLIDE_BACK,
67     SLIDE_FRONT
68   };
69
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();
74
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);
78
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;
86
87   // Overridden from WebContentsObserver:
88   virtual void DidFirstVisuallyNonEmptyPaint() OVERRIDE;
89   virtual void DidStopLoading(RenderViewHost* host) OVERRIDE;
90
91   // The WebContents which is being navigated.
92   WebContentsImpl* web_contents_;
93
94   // The screenshot overlay window.
95   scoped_ptr<aura::Window> window_;
96
97   // This is the WindowDelegate of |window_|. The delegate manages its own
98   // lifetime (destroys itself when |window_| is destroyed).
99   ImageWindowDelegate* image_delegate_;
100
101   bool loading_complete_;
102   bool received_paint_update_;
103
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_;
108
109   // The |WindowSlider| that allows sliding history layers while the page is
110   // being reloaded.
111   scoped_ptr<WindowSlider> window_slider_;
112
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_;
116
117   // The direction of the in-progress slide (if any).
118   SlideDirection slide_direction_;
119
120   // The LayerDelegate used for the back/front layers during a slide.
121   scoped_ptr<ImageLayerDelegate> layer_delegate_;
122
123   DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
124 };
125
126 }  // namespace content
127
128 #endif  // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_