Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: ui/views/view_model_utils.cc

Issue 10388036: Adds the option of aligning the launcher to the left or right. There (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/view_model_utils.h ('k') | ui/views/view_model_utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_model_utils.cc
diff --git a/ui/views/view_model_utils.cc b/ui/views/view_model_utils.cc
index addeee7caff7a42a153cd2e154a7dc9c6f5aa2c6..1d33b141aa1e95229db60f0529fa4a1fe1f3ea67 100644
--- a/ui/views/view_model_utils.cc
+++ b/ui/views/view_model_utils.cc
@@ -11,6 +11,17 @@
namespace views {
+namespace {
+
+// Used in calculating ideal bounds.
+int primary_axis_coordinate(ViewModelUtils::Alignment alignment,
+ int x,
+ int y) {
+ return alignment == ViewModelUtils::HORIZONTAL ? x : y;
+}
+
+} // namespace
+
// static
void ViewModelUtils::SetViewBoundsToIdealBounds(const ViewModel& model) {
for (int i = 0; i < model.view_size(); ++i)
@@ -30,12 +41,18 @@ bool ViewModelUtils::IsAtIdealBounds(const ViewModel& model) {
// static
int ViewModelUtils::DetermineMoveIndex(const ViewModel& model,
View* view,
- int x) {
+ Alignment alignment,
+ int x,
+ int y) {
+ int value = primary_axis_coordinate(alignment, x, y);
int current_index = model.GetIndexOfView(view);
DCHECK_NE(-1, current_index);
for (int i = 0; i < current_index; ++i) {
- int mid_x = model.ideal_bounds(i).x() + model.ideal_bounds(i).width() / 2;
- if (x < mid_x)
+ int mid_point = primary_axis_coordinate(
+ alignment,
+ model.ideal_bounds(i).x() + model.ideal_bounds(i).width() / 2,
+ model.ideal_bounds(i).y() + model.ideal_bounds(i).height() / 2);
+ if (value < mid_point)
return i;
}
@@ -44,12 +61,19 @@ int ViewModelUtils::DetermineMoveIndex(const ViewModel& model,
// For indices after the current index ignore the bounds of the view being
// dragged. This keeps the view from bouncing around as moved.
- int delta = model.ideal_bounds(current_index + 1).x() -
- model.ideal_bounds(current_index).x();
+ int delta = primary_axis_coordinate(
+ alignment,
+ model.ideal_bounds(current_index + 1).x() -
+ model.ideal_bounds(current_index).x(),
+ model.ideal_bounds(current_index + 1).y() -
+ model.ideal_bounds(current_index).y());
for (int i = current_index + 1; i < model.view_size(); ++i) {
const gfx::Rect& bounds(model.ideal_bounds(i));
- int mid_x = bounds.x() + bounds.width() / 2 - delta;
- if (x < mid_x)
+ int mid_point = primary_axis_coordinate(
+ alignment,
+ bounds.x() + bounds.width() / 2 - delta,
+ bounds.y() + bounds.height() / 2 - delta);
+ if (value < mid_point)
return i - 1;
}
return model.view_size() - 1;
« no previous file with comments | « ui/views/view_model_utils.h ('k') | ui/views/view_model_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698