OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // Responsible for fading out and deleting the layer of the overlay window. | 51 // Responsible for fading out and deleting the layer of the overlay window. |
52 class OverlayDismissAnimator | 52 class OverlayDismissAnimator |
53 : public ui::LayerAnimationObserver { | 53 : public ui::LayerAnimationObserver { |
54 public: | 54 public: |
55 // Takes ownership of the layer. | 55 // Takes ownership of the layer. |
56 explicit OverlayDismissAnimator(scoped_ptr<ui::Layer> layer) | 56 explicit OverlayDismissAnimator(std::unique_ptr<ui::Layer> layer) |
57 : layer_(std::move(layer)) { | 57 : layer_(std::move(layer)) { |
58 CHECK(layer_.get()); | 58 CHECK(layer_.get()); |
59 } | 59 } |
60 | 60 |
61 // Starts the fadeout animation on the layer. When the animation finishes, | 61 // Starts the fadeout animation on the layer. When the animation finishes, |
62 // the object deletes itself along with the layer. | 62 // the object deletes itself along with the layer. |
63 void Animate() { | 63 void Animate() { |
64 DCHECK(layer_.get()); | 64 DCHECK(layer_.get()); |
65 ui::LayerAnimator* animator = layer_->GetAnimator(); | 65 ui::LayerAnimator* animator = layer_->GetAnimator(); |
66 // This makes SetOpacity() animate with default duration (which could be | 66 // This makes SetOpacity() animate with default duration (which could be |
(...skipping 11 matching lines...) Expand all Loading... |
78 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override { | 78 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override { |
79 delete this; | 79 delete this; |
80 } | 80 } |
81 | 81 |
82 void OnLayerAnimationScheduled( | 82 void OnLayerAnimationScheduled( |
83 ui::LayerAnimationSequence* sequence) override {} | 83 ui::LayerAnimationSequence* sequence) override {} |
84 | 84 |
85 private: | 85 private: |
86 ~OverlayDismissAnimator() override {} | 86 ~OverlayDismissAnimator() override {} |
87 | 87 |
88 scoped_ptr<ui::Layer> layer_; | 88 std::unique_ptr<ui::Layer> layer_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); | 90 DISALLOW_COPY_AND_ASSIGN(OverlayDismissAnimator); |
91 }; | 91 }; |
92 | 92 |
93 OverscrollNavigationOverlay::OverscrollNavigationOverlay( | 93 OverscrollNavigationOverlay::OverscrollNavigationOverlay( |
94 WebContentsImpl* web_contents, | 94 WebContentsImpl* web_contents, |
95 aura::Window* web_contents_window) | 95 aura::Window* web_contents_window) |
96 : direction_(NONE), | 96 : direction_(NONE), |
97 web_contents_(web_contents), | 97 web_contents_(web_contents), |
98 loading_complete_(false), | 98 loading_complete_(false), |
(...skipping 27 matching lines...) Expand all Loading... |
126 // for in-page navigations DidFirstVisuallyNonEmptyPaint() does not get | 126 // for in-page navigations DidFirstVisuallyNonEmptyPaint() does not get |
127 // called, and we rely on loading_complete_ for those cases. | 127 // called, and we rely on loading_complete_ for those cases. |
128 // If an overscroll gesture is in progress, then do not destroy the window. | 128 // If an overscroll gesture is in progress, then do not destroy the window. |
129 if (!window_ || !(loading_complete_ || received_paint_update_) || | 129 if (!window_ || !(loading_complete_ || received_paint_update_) || |
130 owa_->is_active()) { | 130 owa_->is_active()) { |
131 return; | 131 return; |
132 } | 132 } |
133 | 133 |
134 // OverlayDismissAnimator deletes the dismiss layer and itself when the | 134 // OverlayDismissAnimator deletes the dismiss layer and itself when the |
135 // animation completes. | 135 // animation completes. |
136 scoped_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer(); | 136 std::unique_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer(); |
137 window_.reset(); | 137 window_.reset(); |
138 (new OverlayDismissAnimator(std::move(dismiss_layer)))->Animate(); | 138 (new OverlayDismissAnimator(std::move(dismiss_layer)))->Animate(); |
139 Observe(nullptr); | 139 Observe(nullptr); |
140 received_paint_update_ = false; | 140 received_paint_update_ = false; |
141 loading_complete_ = false; | 141 loading_complete_ = false; |
142 } | 142 } |
143 | 143 |
144 scoped_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( | 144 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( |
145 const gfx::Rect& bounds) { | 145 const gfx::Rect& bounds) { |
146 UMA_HISTOGRAM_ENUMERATION( | 146 UMA_HISTOGRAM_ENUMERATION( |
147 "Overscroll.Started2", direction_, NAVIGATION_COUNT); | 147 "Overscroll.Started2", direction_, NAVIGATION_COUNT); |
148 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( | 148 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( |
149 owa_.get(), GetImageForDirection(direction_)); | 149 owa_.get(), GetImageForDirection(direction_)); |
150 scoped_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); | 150 std::unique_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); |
151 window->set_owned_by_parent(false); | 151 window->set_owned_by_parent(false); |
152 window->SetTransparent(true); | 152 window->SetTransparent(true); |
153 window->Init(ui::LAYER_TEXTURED); | 153 window->Init(ui::LAYER_TEXTURED); |
154 window->layer()->SetMasksToBounds(false); | 154 window->layer()->SetMasksToBounds(false); |
155 window->SetName("OverscrollOverlay"); | 155 window->SetName("OverscrollOverlay"); |
156 web_contents_window_->AddChild(window.get()); | 156 web_contents_window_->AddChild(window.get()); |
157 aura::Window* event_window = GetMainWindow(); | 157 aura::Window* event_window = GetMainWindow(); |
158 if (direction_ == FORWARD) | 158 if (direction_ == FORWARD) |
159 web_contents_window_->StackChildAbove(window.get(), event_window); | 159 web_contents_window_->StackChildAbove(window.get(), event_window); |
160 else | 160 else |
(...skipping 14 matching lines...) Expand all Loading... |
175 controller.GetEntryAtOffset(direction == FORWARD ? 1 : -1)); | 175 controller.GetEntryAtOffset(direction == FORWARD ? 1 : -1)); |
176 | 176 |
177 if (entry && entry->screenshot().get()) { | 177 if (entry && entry->screenshot().get()) { |
178 std::vector<gfx::ImagePNGRep> image_reps; | 178 std::vector<gfx::ImagePNGRep> image_reps; |
179 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); | 179 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); |
180 return gfx::Image(image_reps); | 180 return gfx::Image(image_reps); |
181 } | 181 } |
182 return gfx::Image(); | 182 return gfx::Image(); |
183 } | 183 } |
184 | 184 |
185 scoped_ptr<aura::Window> OverscrollNavigationOverlay::CreateFrontWindow( | 185 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateFrontWindow( |
186 const gfx::Rect& bounds) { | 186 const gfx::Rect& bounds) { |
187 if (!web_contents_->GetController().CanGoForward()) | 187 if (!web_contents_->GetController().CanGoForward()) |
188 return nullptr; | 188 return nullptr; |
189 direction_ = FORWARD; | 189 direction_ = FORWARD; |
190 return CreateOverlayWindow(bounds); | 190 return CreateOverlayWindow(bounds); |
191 } | 191 } |
192 | 192 |
193 scoped_ptr<aura::Window> OverscrollNavigationOverlay::CreateBackWindow( | 193 std::unique_ptr<aura::Window> OverscrollNavigationOverlay::CreateBackWindow( |
194 const gfx::Rect& bounds) { | 194 const gfx::Rect& bounds) { |
195 if (!web_contents_->GetController().CanGoBack()) | 195 if (!web_contents_->GetController().CanGoBack()) |
196 return nullptr; | 196 return nullptr; |
197 direction_ = BACK; | 197 direction_ = BACK; |
198 return CreateOverlayWindow(bounds); | 198 return CreateOverlayWindow(bounds); |
199 } | 199 } |
200 | 200 |
201 aura::Window* OverscrollNavigationOverlay::GetMainWindow() const { | 201 aura::Window* OverscrollNavigationOverlay::GetMainWindow() const { |
202 if (window_) | 202 if (window_) |
203 return window_.get(); | 203 return window_.get(); |
204 return web_contents_->IsBeingDestroyed() | 204 return web_contents_->IsBeingDestroyed() |
205 ? nullptr | 205 ? nullptr |
206 : web_contents_->GetContentNativeView(); | 206 : web_contents_->GetContentNativeView(); |
207 } | 207 } |
208 | 208 |
209 void OverscrollNavigationOverlay::OnOverscrollCompleting() { | 209 void OverscrollNavigationOverlay::OnOverscrollCompleting() { |
210 aura::Window* main_window = GetMainWindow(); | 210 aura::Window* main_window = GetMainWindow(); |
211 if (!main_window) | 211 if (!main_window) |
212 return; | 212 return; |
213 main_window->ReleaseCapture(); | 213 main_window->ReleaseCapture(); |
214 } | 214 } |
215 | 215 |
216 void OverscrollNavigationOverlay::OnOverscrollCompleted( | 216 void OverscrollNavigationOverlay::OnOverscrollCompleted( |
217 scoped_ptr<aura::Window> window) { | 217 std::unique_ptr<aura::Window> window) { |
218 DCHECK(direction_ != NONE); | 218 DCHECK(direction_ != NONE); |
219 aura::Window* main_window = GetMainWindow(); | 219 aura::Window* main_window = GetMainWindow(); |
220 if (!main_window) { | 220 if (!main_window) { |
221 UMA_HISTOGRAM_ENUMERATION( | 221 UMA_HISTOGRAM_ENUMERATION( |
222 "Overscroll.Cancelled", direction_, NAVIGATION_COUNT); | 222 "Overscroll.Cancelled", direction_, NAVIGATION_COUNT); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 // Make sure we can navigate first, as other factors can trigger a navigation | 226 // Make sure we can navigate first, as other factors can trigger a navigation |
227 // during an overscroll gesture and navigating without history produces a | 227 // during an overscroll gesture and navigating without history produces a |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 281 |
282 void OverscrollNavigationOverlay::DidStopLoading() { | 282 void OverscrollNavigationOverlay::DidStopLoading() { |
283 // Don't compare URLs in this case - it's possible they won't match if | 283 // Don't compare URLs in this case - it's possible they won't match if |
284 // a gesture-nav initiated navigation was interrupted by some other in-site | 284 // a gesture-nav initiated navigation was interrupted by some other in-site |
285 // navigation (e.g., from a script, or from a bookmark). | 285 // navigation (e.g., from a script, or from a bookmark). |
286 loading_complete_ = true; | 286 loading_complete_ = true; |
287 StopObservingIfDone(); | 287 StopObservingIfDone(); |
288 } | 288 } |
289 | 289 |
290 } // namespace content | 290 } // namespace content |
OLD | NEW |