overscroll_navigation_overlay.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 // 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 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 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 61 MultiNavigation_LoadingUpdate); 62 FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest, 63 MultiNavigation_PaintUpdate); 64 65 enum SlideDirection { 66 SLIDE_UNKNOWN, 67 SLIDE_BACK, 68 SLIDE_FRONT 69 }; 70 71 // Stop observing the page and start the final overlay fade-out animation 72 // if the page-load has completed and the page has been painted, and a 73 // window-slide isn't in progress. 74 void StopObservingIfDone(); 75 76 // Creates a layer to be used for window-slide. |offset| is the offset of the 77 // NavigationEntry for the screenshot image to display. 78 ui::Layer* CreateSlideLayer(int offset); 79 80 // IPC message callbacks. 81 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); 82 83 // Overridden from WindowSlider::Delegate: 84 virtual ui::Layer* CreateBackLayer() OVERRIDE; 85 virtual ui::Layer* CreateFrontLayer() OVERRIDE; 86 virtual void OnWindowSlideCompleting() OVERRIDE; 87 virtual void OnWindowSlideCompleted() OVERRIDE; 88 virtual void OnWindowSlideAborted() OVERRIDE; 89 virtual void OnWindowSliderDestroyed() OVERRIDE; 90 91 // Overridden from WebContentsObserver: 92 virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) OVERRIDE; 93 virtual void DidFirstVisuallyNonEmptyPaint(int32 page_id) OVERRIDE; 94 virtual void DidStopLoading(RenderViewHost* host) OVERRIDE; 95 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 96 97 // The WebContents which is being navigated. 98 WebContentsImpl* web_contents_; 99 100 // The screenshot overlay window. 101 scoped_ptr<aura::Window> window_; 102 103 // This is the WindowDelegate of |window_|. The delegate manages its own 104 // lifetime (destroys itself when |window_| is destroyed). 105 ImageWindowDelegate* image_delegate_; 106 107 bool loading_complete_; 108 bool received_paint_update_; 109 110 // Unique ID of the NavigationEntry we are navigating to. This is needed to 111 // filter on WebContentsObserver callbacks and is used to dismiss the overlay 112 // when the relevant page loads and paints. 113 int pending_entry_id_; 114 115 // The |WindowSlider| that allows sliding history layers while the page is 116 // being reloaded. 117 scoped_ptr<WindowSlider> window_slider_; 118 119 // The direction of the in-progress slide (if any). 120 SlideDirection slide_direction_; 121 122 // The LayerDelegate used for the back/front layers during a slide. 123 scoped_ptr<ImageLayerDelegate> layer_delegate_; 124 125 // During tests, the aura windows don't get any paint updates. So the overlay 126 // container keeps waiting for a paint update it never receives, causing a 127 // timeout. So during tests, disable the wait for paint updates. 128 bool need_paint_update_; 129 130 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 131}; 132 133} // namespace content 134 135#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_ 136