File: overscroll_navigation_overlay.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (128 lines) | stat: -rw-r--r-- 4,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_
#define CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_

#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "content/browser/web_contents/aura/window_slider.h"
#include "content/common/content_export.h"
#include "content/public/browser/web_contents_observer.h"

struct ViewHostMsg_UpdateRect_Params;

namespace content {

class ImageLayerDelegate;
class ImageWindowDelegate;
class OverscrollNavigationOverlayTest;

// When a history navigation is triggered at the end of an overscroll
// navigation, it is necessary to show the history-screenshot until the page is
// done navigating and painting. This class accomplishes this by showing the
// screenshot window on top of the page until the page has completed loading and
// painting.
class CONTENT_EXPORT OverscrollNavigationOverlay
    : public WebContentsObserver,
      public WindowSlider::Delegate {
 public:
  explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents);
  ~OverscrollNavigationOverlay() override;

  bool has_window() const { return !!window_.get(); }

  // Resets state and starts observing |web_contents_| for page load/paint
  // updates. This function makes sure that the screenshot window is stacked
  // on top, so that it hides the content window behind it, and destroys the
  // screenshot window when the page is done loading/painting.
  // This should be called immediately after initiating the navigation,
  // otherwise the overlay may be dismissed prematurely.
  void StartObserving();

  // Sets the screenshot window and the delegate. This takes ownership of
  // |window|.
  // Note that ImageWindowDelegate manages its own lifetime, so this function
  // does not take ownership of |delegate|.
  void SetOverlayWindow(scoped_ptr<aura::Window> window,
                        ImageWindowDelegate* delegate);

 private:
  friend class OverscrollNavigationOverlayTest;
  FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
                           FirstVisuallyNonEmptyPaint_NoImage);
  FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
                           FirstVisuallyNonEmptyPaint_WithImage);
  FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
                           LoadUpdateWithoutNonEmptyPaint);
  FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
                           MultiNavigation_LoadingUpdate);
  FRIEND_TEST_ALL_PREFIXES(OverscrollNavigationOverlayTest,
                           MultiNavigation_PaintUpdate);

  enum SlideDirection {
    SLIDE_UNKNOWN,
    SLIDE_BACK,
    SLIDE_FRONT
  };

  // Stop observing the page and start the final overlay fade-out animation if
  // a window-slide isn't in progress and either the page has been painted or
  // the page-load has completed.
  void StopObservingIfDone();

  // Creates a layer to be used for window-slide. |offset| is the offset of the
  // NavigationEntry for the screenshot image to display.
  ui::Layer* CreateSlideLayer(int offset);

  // Overridden from WindowSlider::Delegate:
  ui::Layer* CreateBackLayer() override;
  ui::Layer* CreateFrontLayer() override;
  void OnWindowSlideCompleting() override;
  void OnWindowSlideCompleted(scoped_ptr<ui::Layer> layer) override;
  void OnWindowSlideAborted() override;
  void OnWindowSliderDestroyed() override;

  // Overridden from WebContentsObserver:
  void DidFirstVisuallyNonEmptyPaint() override;
  void DidStopLoading(RenderViewHost* host) override;

  // The WebContents which is being navigated.
  WebContentsImpl* web_contents_;

  // The screenshot overlay window.
  scoped_ptr<aura::Window> window_;

  // This is the WindowDelegate of |window_|. The delegate manages its own
  // lifetime (destroys itself when |window_| is destroyed).
  ImageWindowDelegate* image_delegate_;

  bool loading_complete_;
  bool received_paint_update_;

  // URL of the NavigationEntry we are navigating to. This is needed to
  // filter on WebContentsObserver callbacks and is used to dismiss the overlay
  // when the relevant page loads and paints.
  GURL pending_entry_url_;

  // The |WindowSlider| that allows sliding history layers while the page is
  // being reloaded.
  scoped_ptr<WindowSlider> window_slider_;

  // Layer to be used for the final overlay fadeout animation when the overlay
  // is being dismissed.
  scoped_ptr<ui::Layer> overlay_dismiss_layer_;

  // The direction of the in-progress slide (if any).
  SlideDirection slide_direction_;

  // The LayerDelegate used for the back/front layers during a slide.
  scoped_ptr<ImageLayerDelegate> layer_delegate_;

  DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
};

}  // namespace content

#endif  // CONTENT_BROWSER_WEB_CONTENTS_AURA_OVERSCROLL_NAVIGATION_OVERLAY_H_