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

Side by Side Diff: ui/views/view_model_utils.cc

Issue 598013003: Added views::ViewModelT<T>, a type-safe template version of ViewModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@appsgridview-static-casts
Patch Set: Fix browser_test compile on ChromeOS (missing include). Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « ui/views/view_model_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 9 #include "ui/views/view.h"
10 #include "ui/views/view_model.h" 10 #include "ui/views/view_model.h"
11 11
12 namespace views { 12 namespace views {
13 13
14 namespace { 14 namespace {
15 15
16 // Used in calculating ideal bounds. 16 // Used in calculating ideal bounds.
17 int primary_axis_coordinate(ViewModelUtils::Alignment alignment, 17 int primary_axis_coordinate(ViewModelUtils::Alignment alignment,
18 int x, 18 int x,
19 int y) { 19 int y) {
20 return alignment == ViewModelUtils::HORIZONTAL ? x : y; 20 return alignment == ViewModelUtils::HORIZONTAL ? x : y;
21 } 21 }
22 22
23 } // namespace 23 } // namespace
24 24
25 // static 25 // static
26 void ViewModelUtils::SetViewBoundsToIdealBounds(const ViewModel& model) { 26 void ViewModelUtils::SetViewBoundsToIdealBounds(const ViewModelBase& model) {
27 for (int i = 0; i < model.view_size(); ++i) 27 for (int i = 0; i < model.view_size(); ++i)
28 model.view_at(i)->SetBoundsRect(model.ideal_bounds(i)); 28 model.ViewAtBase(i)->SetBoundsRect(model.ideal_bounds(i));
29 } 29 }
30 30
31 // static 31 // static
32 bool ViewModelUtils::IsAtIdealBounds(const ViewModel& model) { 32 bool ViewModelUtils::IsAtIdealBounds(const ViewModelBase& model) {
33 for (int i = 0; i < model.view_size(); ++i) { 33 for (int i = 0; i < model.view_size(); ++i) {
34 View* view = model.view_at(i); 34 View* view = model.ViewAtBase(i);
35 if (view->bounds() != model.ideal_bounds(i)) 35 if (view->bounds() != model.ideal_bounds(i))
36 return false; 36 return false;
37 } 37 }
38 return true; 38 return true;
39 } 39 }
40 40
41 // static 41 // static
42 int ViewModelUtils::DetermineMoveIndex(const ViewModel& model, 42 int ViewModelUtils::DetermineMoveIndex(const ViewModelBase& model,
43 View* view, 43 View* view,
44 Alignment alignment, 44 Alignment alignment,
45 int x, 45 int x,
46 int y) { 46 int y) {
47 int value = primary_axis_coordinate(alignment, x, y); 47 int value = primary_axis_coordinate(alignment, x, y);
48 int current_index = model.GetIndexOfView(view); 48 int current_index = model.GetIndexOfView(view);
49 DCHECK_NE(-1, current_index); 49 DCHECK_NE(-1, current_index);
50 for (int i = 0; i < current_index; ++i) { 50 for (int i = 0; i < current_index; ++i) {
51 int mid_point = primary_axis_coordinate( 51 int mid_point = primary_axis_coordinate(
52 alignment, 52 alignment,
(...skipping 20 matching lines...) Expand all
73 alignment, 73 alignment,
74 bounds.x() + bounds.width() / 2 - delta, 74 bounds.x() + bounds.width() / 2 - delta,
75 bounds.y() + bounds.height() / 2 - delta); 75 bounds.y() + bounds.height() / 2 - delta);
76 if (value < mid_point) 76 if (value < mid_point)
77 return i - 1; 77 return i - 1;
78 } 78 }
79 return model.view_size() - 1; 79 return model.view_size() - 1;
80 } 80 }
81 81
82 } // namespace views 82 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_model_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698