| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/view_model_utils.h" | 5 #include "ui/views/view_model_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/views/view_model.h" | 9 #include "ui/views/view_model.h" |
| 10 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 void ViewModelUtils::SetViewBoundsToIdealBounds(const ViewModel& model) { | 15 void ViewModelUtils::SetViewBoundsToIdealBounds(const ViewModel& model) { |
| 16 for (int i = 0; i < model.view_size(); ++i) | 16 for (int i = 0; i < model.view_size(); ++i) |
| 17 model.view_at(i)->SetBoundsRect(model.ideal_bounds(i)); | 17 model.view_at(i)->SetBoundsRect(model.ideal_bounds(i)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 void ViewModelUtils::SetViewVisibilityToIdealVisibility( |
| 22 const ViewModel& model) { |
| 23 for (int i = 0; i < model.view_size(); ++i) |
| 24 model.view_at(i)->SetVisible(model.ideal_visibility(i)); |
| 25 } |
| 26 |
| 27 // static |
| 21 int ViewModelUtils::DetermineMoveIndex(const ViewModel& model, | 28 int ViewModelUtils::DetermineMoveIndex(const ViewModel& model, |
| 22 View* view, | 29 View* view, |
| 23 int x) { | 30 int x) { |
| 24 int current_index = model.GetIndexOfView(view); | 31 int current_index = model.GetIndexOfView(view); |
| 25 DCHECK_NE(-1, current_index); | 32 DCHECK_NE(-1, current_index); |
| 26 for (int i = 0; i < current_index; ++i) { | 33 for (int i = 0; i < current_index; ++i) { |
| 27 int mid_x = model.ideal_bounds(i).x() + model.ideal_bounds(i).width() / 2; | 34 int mid_x = model.ideal_bounds(i).x() + model.ideal_bounds(i).width() / 2; |
| 28 if (x < mid_x) | 35 if (x < mid_x) |
| 29 return i; | 36 return i; |
| 30 } | 37 } |
| 31 | 38 |
| 32 if (current_index + 1 == model.view_size()) | 39 if (current_index + 1 == model.view_size()) |
| 33 return current_index; | 40 return current_index; |
| 34 | 41 |
| 35 // For indices after the current index ignore the bounds of the view being | 42 // For indices after the current index ignore the bounds of the view being |
| 36 // dragged. This keeps the view from bouncing around as moved. | 43 // dragged. This keeps the view from bouncing around as moved. |
| 37 int delta = model.ideal_bounds(current_index + 1).x() - | 44 int delta = model.ideal_bounds(current_index + 1).x() - |
| 38 model.ideal_bounds(current_index).x(); | 45 model.ideal_bounds(current_index).x(); |
| 39 for (int i = current_index + 1; i < model.view_size(); ++i) { | 46 for (int i = current_index + 1; i < model.view_size(); ++i) { |
| 40 const gfx::Rect& bounds(model.ideal_bounds(i)); | 47 const gfx::Rect& bounds(model.ideal_bounds(i)); |
| 41 int mid_x = bounds.x() + bounds.width() / 2 - delta; | 48 int mid_x = bounds.x() + bounds.width() / 2 - delta; |
| 42 if (x < mid_x) | 49 if (x < mid_x) |
| 43 return i - 1; | 50 return i - 1; |
| 44 } | 51 } |
| 45 return model.view_size() - 1; | 52 return model.view_size() - 1; |
| 46 } | 53 } |
| 47 | 54 |
| 48 } // namespace views | 55 } // namespace views |
| OLD | NEW |