overscroll_navigation_overlay.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 14struct ViewHostMsg_UpdateRect_Params; 15 16namespace content { 17 18class ImageLayerDelegate; 19class ImageWindowDelegate; 20class 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. 27class 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 // Starts observing |web_contents_| for page load/paint updates. This function 37 // makes sure that the screenshot window is stacked on top, so that it hides 38 // the content window behind it, and destroys the screenshot window when the 39 // page is done loading/painting. 40 void StartObserving(); 41 42 // Sets the screenshot window and the delegate. This takes ownership of 43 // |window|. 44 // Note that ImageWindowDelegate manages its own lifetime, so this function 45 // does not take ownership of |delegate|. 46 void SetOverlayWindow(scoped_ptr<aura::Window> window, 47 ImageWindowDelegate* delegate); 48 49 // Sets up the overlay for tests. 50 void SetupForTesting(); 51 52 private: 53 friend class OverscrollNavigationOverlayTest; 54 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 55 FirstVisuallyNonEmptyPaint_NoImage); 56 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 57 FirstVisuallyNonEmptyPaint_WithImage); 58 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 59 PaintUpdateWithoutNonEmptyPaint); 60 61 enum SlideDirection { 62 SLIDE_UNKNOWN, 63 SLIDE_BACK, 64 SLIDE_FRONT 65 }; 66 67 // Stop observing the page if the page-load has completed and the page has 68 // been painted, and a window-slide isn't in progress. 69 void StopObservingIfDone(); 70 71 // Creates a layer to be used for window-slide. |offset| is the offset of the 72 // NavigationEntry for the screenshot image to display. 73 ui::Layer* CreateSlideLayer(int offset); 74 75 // IPC message callbacks. 76 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); 77 78 // Overridden from WindowSlider::Delegate: 79 virtual ui::Layer* CreateBackLayer() OVERRIDE; 80 virtual ui::Layer* CreateFrontLayer() OVERRIDE; 81 virtual void OnWindowSlideComplete() OVERRIDE; 82 virtual void OnWindowSlideAborted() OVERRIDE; 83 virtual void OnWindowSliderDestroyed() OVERRIDE; 84 85 // Overridden from WebContentsObserver: 86 virtual void DidFirstVisuallyNonEmptyPaint(int32 page_id) OVERRIDE; 87 virtual void DidStopLoading(RenderViewHost* host) OVERRIDE; 88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 89 90 // The WebContents which is being navigated. 91 WebContentsImpl* web_contents_; 92 93 // The screenshot overlay window. 94 scoped_ptr<aura::Window> window_; 95 96 // This is the WindowDelegate of |window_|. The delegate manages its own 97 // lifetime (destroys itself when |window_| is destroyed). 98 ImageWindowDelegate* image_delegate_; 99 100 bool loading_complete_; 101 bool received_paint_update_; 102 103 // The |WindowSlider| that allows sliding history layers while the page is 104 // being reloaded. 105 scoped_ptr<WindowSlider> window_slider_; 106 107 // The direction of the in-progress slide (if any). 108 SlideDirection slide_direction_; 109 110 // The LayerDelegate used for the back/front layers during a slide. 111 scoped_ptr<ImageLayerDelegate> layer_delegate_; 112 113 // During tests, the aura windows don't get any paint updates. So the overlay 114 // container keeps waiting for a paint update it never receives, causing a 115 // timeout. So during tests, disable the wait for paint updates. 116 bool need_paint_update_; 117 118 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 119}; 120 121} // namespace content 122 123#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 124