| 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 <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 12 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/aura/overscroll_window_delegate.h" | 15 #include "content/browser/web_contents/aura/overscroll_window_delegate.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 50 // 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. |
| 51 class OverlayDismissAnimator | 52 class OverlayDismissAnimator |
| 52 : public ui::LayerAnimationObserver { | 53 : public ui::LayerAnimationObserver { |
| 53 public: | 54 public: |
| 54 // Takes ownership of the layer. | 55 // Takes ownership of the layer. |
| 55 explicit OverlayDismissAnimator(scoped_ptr<ui::Layer> layer) | 56 explicit OverlayDismissAnimator(scoped_ptr<ui::Layer> layer) |
| 56 : layer_(layer.Pass()) { | 57 : layer_(std::move(layer)) { |
| 57 CHECK(layer_.get()); | 58 CHECK(layer_.get()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Starts the fadeout animation on the layer. When the animation finishes, | 61 // Starts the fadeout animation on the layer. When the animation finishes, |
| 61 // the object deletes itself along with the layer. | 62 // the object deletes itself along with the layer. |
| 62 void Animate() { | 63 void Animate() { |
| 63 DCHECK(layer_.get()); | 64 DCHECK(layer_.get()); |
| 64 ui::LayerAnimator* animator = layer_->GetAnimator(); | 65 ui::LayerAnimator* animator = layer_->GetAnimator(); |
| 65 // This makes SetOpacity() animate with default duration (which could be | 66 // This makes SetOpacity() animate with default duration (which could be |
| 66 // zero, e.g. when running tests). | 67 // zero, e.g. when running tests). |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // 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. |
| 128 if (!window_ || !(loading_complete_ || received_paint_update_) || | 129 if (!window_ || !(loading_complete_ || received_paint_update_) || |
| 129 owa_->is_active()) { | 130 owa_->is_active()) { |
| 130 return; | 131 return; |
| 131 } | 132 } |
| 132 | 133 |
| 133 // OverlayDismissAnimator deletes the dismiss layer and itself when the | 134 // OverlayDismissAnimator deletes the dismiss layer and itself when the |
| 134 // animation completes. | 135 // animation completes. |
| 135 scoped_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer(); | 136 scoped_ptr<ui::Layer> dismiss_layer = window_->AcquireLayer(); |
| 136 window_.reset(); | 137 window_.reset(); |
| 137 (new OverlayDismissAnimator(dismiss_layer.Pass()))->Animate(); | 138 (new OverlayDismissAnimator(std::move(dismiss_layer)))->Animate(); |
| 138 Observe(nullptr); | 139 Observe(nullptr); |
| 139 received_paint_update_ = false; | 140 received_paint_update_ = false; |
| 140 loading_complete_ = false; | 141 loading_complete_ = false; |
| 141 } | 142 } |
| 142 | 143 |
| 143 scoped_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( | 144 scoped_ptr<aura::Window> OverscrollNavigationOverlay::CreateOverlayWindow( |
| 144 const gfx::Rect& bounds) { | 145 const gfx::Rect& bounds) { |
| 145 UMA_HISTOGRAM_ENUMERATION( | 146 UMA_HISTOGRAM_ENUMERATION( |
| 146 "Overscroll.Started2", direction_, NAVIGATION_COUNT); | 147 "Overscroll.Started2", direction_, NAVIGATION_COUNT); |
| 147 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( | 148 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( |
| 148 owa_.get(), GetImageForDirection(direction_)); | 149 owa_.get(), GetImageForDirection(direction_)); |
| 149 scoped_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); | 150 scoped_ptr<aura::Window> window(new aura::Window(overscroll_delegate)); |
| 150 window->set_owned_by_parent(false); | 151 window->set_owned_by_parent(false); |
| 151 window->SetTransparent(true); | 152 window->SetTransparent(true); |
| 152 window->Init(ui::LAYER_TEXTURED); | 153 window->Init(ui::LAYER_TEXTURED); |
| 153 window->layer()->SetMasksToBounds(false); | 154 window->layer()->SetMasksToBounds(false); |
| 154 window->SetName("OverscrollOverlay"); | 155 window->SetName("OverscrollOverlay"); |
| 155 web_contents_window_->AddChild(window.get()); | 156 web_contents_window_->AddChild(window.get()); |
| 156 aura::Window* event_window = GetMainWindow(); | 157 aura::Window* event_window = GetMainWindow(); |
| 157 if (direction_ == FORWARD) | 158 if (direction_ == FORWARD) |
| 158 web_contents_window_->StackChildAbove(window.get(), event_window); | 159 web_contents_window_->StackChildAbove(window.get(), event_window); |
| 159 else | 160 else |
| 160 web_contents_window_->StackChildBelow(window.get(), event_window); | 161 web_contents_window_->StackChildBelow(window.get(), event_window); |
| 161 window->SetBounds(bounds); | 162 window->SetBounds(bounds); |
| 162 // Set capture on the window that is receiving the overscroll events so that | 163 // Set capture on the window that is receiving the overscroll events so that |
| 163 // trackpad scroll gestures keep targetting it even if the mouse pointer moves | 164 // trackpad scroll gestures keep targetting it even if the mouse pointer moves |
| 164 // off its bounds. | 165 // off its bounds. |
| 165 event_window->SetCapture(); | 166 event_window->SetCapture(); |
| 166 window->Show(); | 167 window->Show(); |
| 167 return window.Pass(); | 168 return window; |
| 168 } | 169 } |
| 169 | 170 |
| 170 const gfx::Image OverscrollNavigationOverlay::GetImageForDirection( | 171 const gfx::Image OverscrollNavigationOverlay::GetImageForDirection( |
| 171 NavigationDirection direction) const { | 172 NavigationDirection direction) const { |
| 172 const NavigationControllerImpl& controller = web_contents_->GetController(); | 173 const NavigationControllerImpl& controller = web_contents_->GetController(); |
| 173 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | 174 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 174 controller.GetEntryAtOffset(direction == FORWARD ? 1 : -1)); | 175 controller.GetEntryAtOffset(direction == FORWARD ? 1 : -1)); |
| 175 | 176 |
| 176 if (entry && entry->screenshot().get()) { | 177 if (entry && entry->screenshot().get()) { |
| 177 std::vector<gfx::ImagePNGRep> image_reps; | 178 std::vector<gfx::ImagePNGRep> image_reps; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 loading_complete_ = true; | 241 loading_complete_ = true; |
| 241 } | 242 } |
| 242 | 243 |
| 243 if (navigated) { | 244 if (navigated) { |
| 244 UMA_HISTOGRAM_ENUMERATION( | 245 UMA_HISTOGRAM_ENUMERATION( |
| 245 "Overscroll.Navigated2", direction_, NAVIGATION_COUNT); | 246 "Overscroll.Navigated2", direction_, NAVIGATION_COUNT); |
| 246 StartObserving(); | 247 StartObserving(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 main_window->SetTransform(gfx::Transform()); | 250 main_window->SetTransform(gfx::Transform()); |
| 250 window_ = window.Pass(); | 251 window_ = std::move(window); |
| 251 // Make sure the window is in its default position. | 252 // Make sure the window is in its default position. |
| 252 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size())); | 253 window_->SetBounds(gfx::Rect(web_contents_window_->bounds().size())); |
| 253 window_->SetTransform(gfx::Transform()); | 254 window_->SetTransform(gfx::Transform()); |
| 254 // Make sure the overlay window is on top. | 255 // Make sure the overlay window is on top. |
| 255 web_contents_window_->StackChildAtTop(window_.get()); | 256 web_contents_window_->StackChildAtTop(window_.get()); |
| 256 direction_ = NONE; | 257 direction_ = NONE; |
| 257 StopObservingIfDone(); | 258 StopObservingIfDone(); |
| 258 } | 259 } |
| 259 | 260 |
| 260 void OverscrollNavigationOverlay::OnOverscrollCancelled() { | 261 void OverscrollNavigationOverlay::OnOverscrollCancelled() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 280 | 281 |
| 281 void OverscrollNavigationOverlay::DidStopLoading() { | 282 void OverscrollNavigationOverlay::DidStopLoading() { |
| 282 // 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 |
| 283 // 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 |
| 284 // navigation (e.g., from a script, or from a bookmark). | 285 // navigation (e.g., from a script, or from a bookmark). |
| 285 loading_complete_ = true; | 286 loading_complete_ = true; |
| 286 StopObservingIfDone(); | 287 StopObservingIfDone(); |
| 287 } | 288 } |
| 288 | 289 |
| 289 } // namespace content | 290 } // namespace content |
| OLD | NEW |