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/app_list/apps_grid_view.h" | 5 #include "ui/app_list/apps_grid_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/app_list/app_list_item_view.h" | 9 #include "ui/app_list/app_list_item_view.h" |
10 #include "ui/app_list/pagination_model.h" | 10 #include "ui/app_list/pagination_model.h" |
11 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Padding space in pixels for fixed layout. | 15 // Padding space in pixels for fixed layout. |
16 const int kLeftRightPadding = 20; | 16 const int kLeftRightPadding = 20; |
17 const int kTopPadding = 1; | 17 const int kTopPadding = 1; |
18 | 18 |
19 // Padding space in pixels between pages. | 19 // Padding space in pixels between pages. |
20 const int kPagePadding = 40; | 20 const int kPagePadding = 40; |
21 | 21 |
22 // Preferred tile size when showing in fixed layout. | 22 // Preferred tile size when showing in fixed layout. |
23 const int kPreferredTileWidth = 88; | 23 const int kPreferredTileWidth = 88; |
24 const int kPreferredTileHeight = 98; | 24 const int kPreferredTileHeight = 98; |
25 | 25 |
26 // Max extra column padding space in pixels for invalid page transition. | 26 // Max extra column padding space in pixels for invalid page transition. |
27 const int kMaxExtraColPaddingForInvalidTransition = 80; | 27 const int kMaxExtraColPaddingForInvalidTransition = 15; |
| 28 |
| 29 // Extra column padding space in pixels of first column for invalid page |
| 30 // transition. |
| 31 const int kBaseExtraColPaddingForInvalidTransition = 50; |
28 | 32 |
29 } // namespace | 33 } // namespace |
30 | 34 |
31 namespace app_list { | 35 namespace app_list { |
32 | 36 |
33 AppsGridView::AppsGridView(views::ButtonListener* listener, | 37 AppsGridView::AppsGridView(views::ButtonListener* listener, |
34 PaginationModel* pagination_model) | 38 PaginationModel* pagination_model) |
35 : model_(NULL), | 39 : model_(NULL), |
36 listener_(listener), | 40 listener_(listener), |
37 pagination_model_(pagination_model), | 41 pagination_model_(pagination_model), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 const PaginationModel::Transition& transition = | 125 const PaginationModel::Transition& transition = |
122 pagination_model_->transition(); | 126 pagination_model_->transition(); |
123 const bool is_valid = | 127 const bool is_valid = |
124 pagination_model_->is_valid_page(transition.target_page); | 128 pagination_model_->is_valid_page(transition.target_page); |
125 | 129 |
126 // Transition to right means negative offset. | 130 // Transition to right means negative offset. |
127 const int dir = transition.target_page > current_page ? -1 : 1; | 131 const int dir = transition.target_page > current_page ? -1 : 1; |
128 const int transition_offset = is_valid ? | 132 const int transition_offset = is_valid ? |
129 transition.progress * page_width * dir : | 133 transition.progress * page_width * dir : |
130 transition.progress * kMaxExtraColPaddingForInvalidTransition * dir; | 134 transition.progress * kMaxExtraColPaddingForInvalidTransition * dir; |
| 135 const int base_transition_offset = is_valid ? 0 : |
| 136 transition.progress * kBaseExtraColPaddingForInvalidTransition * dir; |
131 | 137 |
132 const int first_visible_index = current_page * tiles_per_page(); | 138 const int first_visible_index = current_page * tiles_per_page(); |
133 const int last_visible_index = (current_page + 1) * tiles_per_page() - 1; | 139 const int last_visible_index = (current_page + 1) * tiles_per_page() - 1; |
134 gfx::Rect tile_slot(grid_rect.origin(), tile_size); | 140 gfx::Rect tile_slot(grid_rect.origin(), tile_size); |
135 for (int i = 0; i < child_count(); ++i) { | 141 for (int i = 0; i < child_count(); ++i) { |
136 views::View* view = child_at(i); | 142 views::View* view = child_at(i); |
137 | 143 |
138 // Decides an x_offset for current item. | 144 // Decides an x_offset for current item. |
139 int x_offset = 0; | 145 int x_offset = 0; |
140 if (i < first_visible_index) | 146 if (i < first_visible_index) |
141 x_offset = -page_width; | 147 x_offset = -page_width; |
142 else if (i > last_visible_index) | 148 else if (i > last_visible_index) |
143 x_offset = page_width; | 149 x_offset = page_width; |
144 | 150 |
145 int page = i / tiles_per_page(); | 151 int page = i / tiles_per_page(); |
146 if (is_valid) { | 152 if (is_valid) { |
147 if (page == current_page || page == transition.target_page) | 153 if (page == current_page || page == transition.target_page) |
148 x_offset += transition_offset; | 154 x_offset += transition_offset; |
149 } else { | 155 } else { |
150 const int col = i % cols_; | 156 const int col = i % cols_; |
| 157 x_offset += base_transition_offset; |
151 if (transition_offset > 0) | 158 if (transition_offset > 0) |
152 x_offset += transition_offset * (col + 1); | 159 x_offset += transition_offset * col; |
153 else | 160 else |
154 x_offset += transition_offset * (cols_ - col); | 161 x_offset += transition_offset * (cols_ - col - 1); |
155 } | 162 } |
156 | 163 |
157 gfx::Rect adjusted_slot(tile_slot); | 164 gfx::Rect adjusted_slot(tile_slot); |
158 adjusted_slot.Offset(x_offset, 0); | 165 adjusted_slot.Offset(x_offset, 0); |
159 view->SetBoundsRect(adjusted_slot); | 166 view->SetBoundsRect(adjusted_slot); |
160 | 167 |
161 tile_slot.Offset(tile_size.width(), 0); | 168 tile_slot.Offset(tile_size.width(), 0); |
162 if ((i + 1) % tiles_per_page() == 0) { | 169 if ((i + 1) % tiles_per_page() == 0) { |
163 tile_slot.set_origin(grid_rect.origin()); | 170 tile_slot.set_origin(grid_rect.origin()); |
164 } else if ((i + 1) % cols_ == 0) { | 171 } else if ((i + 1) % cols_ == 0) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 318 |
312 void AppsGridView::SelectedPageChanged(int old_selected, int new_selected) { | 319 void AppsGridView::SelectedPageChanged(int old_selected, int new_selected) { |
313 Layout(); | 320 Layout(); |
314 } | 321 } |
315 | 322 |
316 void AppsGridView::TransitionChanged() { | 323 void AppsGridView::TransitionChanged() { |
317 Layout(); | 324 Layout(); |
318 } | 325 } |
319 | 326 |
320 } // namespace app_list | 327 } // namespace app_list |
OLD | NEW |