| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/views/tabs/grid.h" | 5 #include "chrome/browser/views/tabs/grid.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 | 8 |
| 9 using views::View; | 9 using views::View; |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 RemoveChildView(GetChildViewAt(index)); | 56 RemoveChildView(GetChildViewAt(index)); |
| 57 modifying_children_ = false; | 57 modifying_children_ = false; |
| 58 | 58 |
| 59 CalculateTargetBoundsAndStartAnimation(); | 59 CalculateTargetBoundsAndStartAnimation(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void Grid::AnimateToTargetBounds() { | 62 void Grid::AnimateToTargetBounds() { |
| 63 CalculateTargetBoundsAndStartAnimation(); | 63 CalculateTargetBoundsAndStartAnimation(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int Grid::AnimationPosition(int start, int target) { |
| 67 return start + static_cast<int>( |
| 68 static_cast<double>(target - start) * animation_.GetCurrentValue()); |
| 69 } |
| 70 |
| 71 gfx::Rect Grid::AnimationPosition(const gfx::Rect& start_bounds, |
| 72 const gfx::Rect& target_bounds) { |
| 73 return gfx::Rect(AnimationPosition(start_bounds.x(), target_bounds.x()), |
| 74 AnimationPosition(start_bounds.y(), target_bounds.y()), |
| 75 AnimationPosition(start_bounds.width(), |
| 76 target_bounds.width()), |
| 77 AnimationPosition(start_bounds.height(), |
| 78 target_bounds.height())); |
| 79 } |
| 80 |
| 66 void Grid::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 81 void Grid::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 67 if (modifying_children_ || parent != this) | 82 if (modifying_children_ || parent != this) |
| 68 return; | 83 return; |
| 69 | 84 |
| 70 // Our child views changed without us knowing it. Stop the animation and mark | 85 // Our child views changed without us knowing it. Stop the animation and mark |
| 71 // us as dirty (needs_layout_ = true). | 86 // us as dirty (needs_layout_ = true). |
| 72 animation_.Stop(); | 87 animation_.Stop(); |
| 73 needs_layout_ = true; | 88 needs_layout_ = true; |
| 74 } | 89 } |
| 75 | 90 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void Grid::AnimationEnded(const Animation* animation) { | 139 void Grid::AnimationEnded(const Animation* animation) { |
| 125 SetViewBoundsToTarget(); | 140 SetViewBoundsToTarget(); |
| 126 } | 141 } |
| 127 | 142 |
| 128 void Grid::AnimationProgressed(const Animation* animation) { | 143 void Grid::AnimationProgressed(const Animation* animation) { |
| 129 DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size())); | 144 DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size())); |
| 130 for (size_t i = 0; i < target_bounds_.size(); ++i) { | 145 for (size_t i = 0; i < target_bounds_.size(); ++i) { |
| 131 View* view = GetChildViewAt(i); | 146 View* view = GetChildViewAt(i); |
| 132 gfx::Rect start_bounds = start_bounds_[i]; | 147 gfx::Rect start_bounds = start_bounds_[i]; |
| 133 gfx::Rect target_bounds = target_bounds_[i]; | 148 gfx::Rect target_bounds = target_bounds_[i]; |
| 134 if (static_cast<int>(i) != floating_index_) { | 149 if (static_cast<int>(i) != floating_index_) |
| 135 view->SetBounds( | 150 view->SetBounds(AnimationPosition(start_bounds, target_bounds)); |
| 136 gfx::Rect(AnimationPosition(start_bounds.x(), target_bounds.x()), | |
| 137 AnimationPosition(start_bounds.y(), target_bounds.y()), | |
| 138 AnimationPosition(start_bounds.width(), | |
| 139 target_bounds.width()), | |
| 140 AnimationPosition(start_bounds.height(), | |
| 141 target_bounds.height()))); | |
| 142 } | |
| 143 } | 151 } |
| 144 SchedulePaint(); | 152 SchedulePaint(); |
| 145 } | 153 } |
| 146 | 154 |
| 147 void Grid::AnimationCanceled(const Animation* animation) { | 155 void Grid::AnimationCanceled(const Animation* animation) { |
| 148 // Don't do anything when the animation is canceled. Presumably Layout will | 156 // Don't do anything when the animation is canceled. Presumably Layout will |
| 149 // be invoked, and all children will get set to their appropriate position. | 157 // be invoked, and all children will get set to their appropriate position. |
| 150 } | 158 } |
| 151 | 159 |
| 152 void Grid::CalculateCellBounds(std::vector<gfx::Rect>* bounds) { | 160 void Grid::CalculateCellBounds(std::vector<gfx::Rect>* bounds) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Determine the current bounds. | 227 // Determine the current bounds. |
| 220 start_bounds_.clear(); | 228 start_bounds_.clear(); |
| 221 start_bounds_.resize(GetChildViewCount()); | 229 start_bounds_.resize(GetChildViewCount()); |
| 222 for (int i = 0; i < GetChildViewCount(); ++i) | 230 for (int i = 0; i < GetChildViewCount(); ++i) |
| 223 start_bounds_[i] = GetChildViewAt(i)->bounds(); | 231 start_bounds_[i] = GetChildViewAt(i)->bounds(); |
| 224 | 232 |
| 225 // Then the target bounds. | 233 // Then the target bounds. |
| 226 target_bounds_.clear(); | 234 target_bounds_.clear(); |
| 227 CalculateCellBounds(&target_bounds_); | 235 CalculateCellBounds(&target_bounds_); |
| 228 | 236 |
| 229 // And make sure the animation is running. | 237 // And restart the animation. |
| 230 if (!animation_.IsAnimating()) { | 238 animation_.Reset(); |
| 231 animation_.Reset(); | 239 animation_.Show(); |
| 232 animation_.Show(); | |
| 233 } | |
| 234 } | 240 } |
| 235 | 241 |
| 236 void Grid::SetViewBoundsToTarget() { | 242 void Grid::SetViewBoundsToTarget() { |
| 237 DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size())); | 243 DCHECK(GetChildViewCount() == static_cast<int>(target_bounds_.size())); |
| 238 for (size_t i = 0; i < target_bounds_.size(); ++i) { | 244 for (size_t i = 0; i < target_bounds_.size(); ++i) { |
| 239 if (static_cast<int>(i) != floating_index_) | 245 if (static_cast<int>(i) != floating_index_) |
| 240 GetChildViewAt(i)->SetBounds(target_bounds_[i]); | 246 GetChildViewAt(i)->SetBounds(target_bounds_[i]); |
| 241 } | 247 } |
| 242 } | 248 } |
| 243 | |
| 244 int Grid::AnimationPosition(int start, int target) { | |
| 245 return start + static_cast<int>( | |
| 246 static_cast<double>(target - start) * animation_.GetCurrentValue()); | |
| 247 } | |
| OLD | NEW |