| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_window_animation.h" | 5 #include "content/browser/web_contents/aura/overscroll_window_animation.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() { | 76 void OverscrollWindowAnimation::OnImplicitAnimationsCompleted() { |
| 77 if (overscroll_cancelled_) { | 77 if (overscroll_cancelled_) { |
| 78 slide_window_.reset(); | 78 slide_window_.reset(); |
| 79 delegate_->OnOverscrollCancelled(); | 79 delegate_->OnOverscrollCancelled(); |
| 80 overscroll_cancelled_ = false; | 80 overscroll_cancelled_ = false; |
| 81 } else { | 81 } else { |
| 82 delegate_->OnOverscrollCompleted(std::move(slide_window_)); | 82 delegate_->OnOverscrollCompleted(std::move(slide_window_)); |
| 83 } | 83 } |
| 84 overscroll_source_ = OVERSCROLL_SOURCE_NONE; |
| 84 direction_ = SLIDE_NONE; | 85 direction_ = SLIDE_NONE; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void OverscrollWindowAnimation::OnOverscrollModeChange( | 88 void OverscrollWindowAnimation::OnOverscrollModeChange( |
| 88 OverscrollMode old_mode, | 89 OverscrollMode old_mode, |
| 89 OverscrollMode new_mode) { | 90 OverscrollMode new_mode, |
| 91 OverscrollSource source) { |
| 90 DCHECK_NE(old_mode, new_mode); | 92 DCHECK_NE(old_mode, new_mode); |
| 91 Direction new_direction = GetDirectionForMode(new_mode); | 93 Direction new_direction = GetDirectionForMode(new_mode); |
| 92 if (new_direction == SLIDE_NONE) { | 94 if (new_direction == SLIDE_NONE) { |
| 93 // The user cancelled the in progress animation. | 95 // The user cancelled the in progress animation. |
| 94 if (is_active()) | 96 if (is_active()) |
| 95 CancelSlide(); | 97 CancelSlide(); |
| 96 return; | 98 return; |
| 97 } | 99 } |
| 98 if (is_active()) { | 100 if (is_active()) { |
| 99 slide_window_->layer()->GetAnimator()->StopAnimating(); | 101 slide_window_->layer()->GetAnimator()->StopAnimating(); |
| 100 delegate_->GetMainWindow()->layer()->GetAnimator()->StopAnimating(); | 102 delegate_->GetMainWindow()->layer()->GetAnimator()->StopAnimating(); |
| 101 } | 103 } |
| 102 gfx::Rect slide_window_bounds = gfx::Rect(GetVisibleBounds().size()); | 104 gfx::Rect slide_window_bounds = gfx::Rect(GetVisibleBounds().size()); |
| 103 if (new_direction == SLIDE_FRONT) { | 105 if (new_direction == SLIDE_FRONT) { |
| 104 slide_window_bounds.Offset(base::i18n::IsRTL() | 106 slide_window_bounds.Offset(base::i18n::IsRTL() |
| 105 ? -slide_window_bounds.width() | 107 ? -slide_window_bounds.width() |
| 106 : slide_window_bounds.width(), | 108 : slide_window_bounds.width(), |
| 107 0); | 109 0); |
| 108 } else { | 110 } else { |
| 109 slide_window_bounds.Offset(base::i18n::IsRTL() | 111 slide_window_bounds.Offset(base::i18n::IsRTL() |
| 110 ? slide_window_bounds.width() / 2 | 112 ? slide_window_bounds.width() / 2 |
| 111 : -slide_window_bounds.width() / 2, | 113 : -slide_window_bounds.width() / 2, |
| 112 0); | 114 0); |
| 113 } | 115 } |
| 116 |
| 117 DCHECK_EQ(overscroll_source_, OVERSCROLL_SOURCE_NONE); |
| 118 overscroll_source_ = source; |
| 114 slide_window_ = new_direction == SLIDE_FRONT | 119 slide_window_ = new_direction == SLIDE_FRONT |
| 115 ? delegate_->CreateFrontWindow(slide_window_bounds) | 120 ? delegate_->CreateFrontWindow(slide_window_bounds) |
| 116 : delegate_->CreateBackWindow(slide_window_bounds); | 121 : delegate_->CreateBackWindow(slide_window_bounds); |
| 117 if (!slide_window_) { | 122 if (!slide_window_) { |
| 118 // Cannot navigate, do not start an overscroll gesture. | 123 // Cannot navigate, do not start an overscroll gesture. |
| 119 direction_ = SLIDE_NONE; | 124 direction_ = SLIDE_NONE; |
| 125 overscroll_source_ = OVERSCROLL_SOURCE_NONE; |
| 120 return; | 126 return; |
| 121 } | 127 } |
| 122 overscroll_cancelled_ = false; | 128 overscroll_cancelled_ = false; |
| 123 direction_ = new_direction; | 129 direction_ = new_direction; |
| 124 shadow_.reset(new ShadowLayerDelegate(GetFrontLayer())); | 130 shadow_.reset(new ShadowLayerDelegate(GetFrontLayer())); |
| 125 } | 131 } |
| 126 | 132 |
| 127 void OverscrollWindowAnimation::OnOverscrollComplete( | 133 void OverscrollWindowAnimation::OnOverscrollComplete( |
| 128 OverscrollMode overscroll_mode) { | 134 OverscrollMode overscroll_mode) { |
| 129 if (!is_active()) | 135 if (!is_active()) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ui::Layer* OverscrollWindowAnimation::GetBackLayer() const { | 175 ui::Layer* OverscrollWindowAnimation::GetBackLayer() const { |
| 170 DCHECK(direction_ != SLIDE_NONE); | 176 DCHECK(direction_ != SLIDE_NONE); |
| 171 if (direction_ == SLIDE_BACK) { | 177 if (direction_ == SLIDE_BACK) { |
| 172 DCHECK(slide_window_); | 178 DCHECK(slide_window_); |
| 173 return slide_window_->layer(); | 179 return slide_window_->layer(); |
| 174 } | 180 } |
| 175 return delegate_->GetMainWindow()->layer(); | 181 return delegate_->GetMainWindow()->layer(); |
| 176 } | 182 } |
| 177 | 183 |
| 178 } // namespace content | 184 } // namespace content |
| OLD | NEW |