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/views/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "ui/app_list/app_list_item_model.h" | 10 #include "ui/app_list/app_list_item_model.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool canceled_; | 230 bool canceled_; |
231 | 231 |
232 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); | 232 DISALLOW_COPY_AND_ASSIGN(SynchronousDrag); |
233 }; | 233 }; |
234 #endif // defined(OS_WIN) && !defined(USE_AURA) | 234 #endif // defined(OS_WIN) && !defined(USE_AURA) |
235 | 235 |
236 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, | 236 AppsGridView::AppsGridView(AppsGridViewDelegate* delegate, |
237 PaginationModel* pagination_model, | 237 PaginationModel* pagination_model, |
238 content::WebContents* start_page_contents) | 238 content::WebContents* start_page_contents) |
239 : model_(NULL), | 239 : model_(NULL), |
240 apps_(NULL), | |
241 delegate_(delegate), | 240 delegate_(delegate), |
242 pagination_model_(pagination_model), | 241 pagination_model_(pagination_model), |
243 page_switcher_view_(new PageSwitcher(pagination_model)), | 242 page_switcher_view_(new PageSwitcher(pagination_model)), |
244 start_page_view_(NULL), | 243 start_page_view_(NULL), |
245 cols_(0), | 244 cols_(0), |
246 rows_per_page_(0), | 245 rows_per_page_(0), |
247 selected_view_(NULL), | 246 selected_view_(NULL), |
248 drag_view_(NULL), | 247 drag_view_(NULL), |
249 drag_start_page_(-1), | 248 drag_start_page_(-1), |
250 drag_pointer_(NONE), | 249 drag_pointer_(NONE), |
(...skipping 15 matching lines...) Expand all Loading... |
266 } | 265 } |
267 | 266 |
268 AppsGridView::~AppsGridView() { | 267 AppsGridView::~AppsGridView() { |
269 // Coming here |drag_view_| should already be canceled since otherwise the | 268 // Coming here |drag_view_| should already be canceled since otherwise the |
270 // drag would disappear after the app list got animated away and closed, | 269 // drag would disappear after the app list got animated away and closed, |
271 // which would look odd. | 270 // which would look odd. |
272 DCHECK(!drag_view_); | 271 DCHECK(!drag_view_); |
273 if (drag_view_) | 272 if (drag_view_) |
274 EndDrag(true); | 273 EndDrag(true); |
275 | 274 |
276 if (model_) | 275 if (model_) { |
277 model_->RemoveObserver(this); | 276 model_->RemoveObserver(this); |
| 277 model_->apps()->RemoveObserver(this); |
| 278 } |
278 pagination_model_->RemoveObserver(this); | 279 pagination_model_->RemoveObserver(this); |
279 | |
280 if (apps_) | |
281 apps_->RemoveObserver(this); | |
282 } | 280 } |
283 | 281 |
284 void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { | 282 void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { |
285 icon_size_.SetSize(icon_size, icon_size); | 283 icon_size_.SetSize(icon_size, icon_size); |
286 cols_ = cols; | 284 cols_ = cols; |
287 rows_per_page_ = rows_per_page; | 285 rows_per_page_ = rows_per_page; |
288 | 286 |
289 set_border(views::Border::CreateEmptyBorder(kTopPadding, | 287 set_border(views::Border::CreateEmptyBorder(kTopPadding, |
290 kLeftRightPadding, | 288 kLeftRightPadding, |
291 0, | 289 0, |
292 kLeftRightPadding)); | 290 kLeftRightPadding)); |
293 } | 291 } |
294 | 292 |
295 void AppsGridView::SetModel(AppListModel* model) { | 293 void AppsGridView::SetModel(AppListModel* model) { |
296 if (model_) | 294 if (model_) { |
297 model_->RemoveObserver(this); | 295 model_->RemoveObserver(this); |
| 296 model_->apps()->RemoveObserver(this); |
| 297 } |
298 | 298 |
299 model_ = model; | 299 model_ = model; |
300 if (model_) | 300 if (model_) { |
301 model_->AddObserver(this); | 301 model_->AddObserver(this); |
302 | 302 model_->apps()->AddObserver(this); |
303 Update(); | 303 } |
304 } | |
305 | |
306 void AppsGridView::SetApps(AppListModel::Apps* apps) { | |
307 if (apps_) | |
308 apps_->RemoveObserver(this); | |
309 | |
310 apps_ = apps; | |
311 apps_->AddObserver(this); | |
312 Update(); | 304 Update(); |
313 } | 305 } |
314 | 306 |
315 void AppsGridView::SetSelectedView(views::View* view) { | 307 void AppsGridView::SetSelectedView(views::View* view) { |
316 if (IsSelectedView(view) || IsDraggedView(view)) | 308 if (IsSelectedView(view) || IsDraggedView(view)) |
317 return; | 309 return; |
318 | 310 |
319 Index index = GetIndexOfView(view); | 311 Index index = GetIndexOfView(view); |
320 if (IsValidIndex(index)) | 312 if (IsValidIndex(index)) |
321 SetSelectedItemByIndex(index); | 313 SetSelectedItemByIndex(index); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 if (selected_view_ == details.child) | 618 if (selected_view_ == details.child) |
627 selected_view_ = NULL; | 619 selected_view_ = NULL; |
628 | 620 |
629 if (drag_view_ == details.child) | 621 if (drag_view_ == details.child) |
630 EndDrag(true); | 622 EndDrag(true); |
631 | 623 |
632 bounds_animator_.StopAnimatingView(details.child); | 624 bounds_animator_.StopAnimatingView(details.child); |
633 } | 625 } |
634 } | 626 } |
635 | 627 |
| 628 // static |
| 629 AppsGridView* AppsGridView::GetLastGridViewForTest() { |
| 630 return last_created_grid_view_for_test; |
| 631 } |
| 632 |
636 void AppsGridView::Update() { | 633 void AppsGridView::Update() { |
637 DCHECK(!selected_view_ && !drag_view_); | 634 DCHECK(!selected_view_ && !drag_view_); |
638 if (!apps_) | |
639 return; | |
640 | 635 |
641 view_model_.Clear(); | 636 view_model_.Clear(); |
642 if (apps_ && apps_->item_count()) | 637 if (model_ && model_->apps()->item_count()) |
643 ListItemsAdded(0, apps_->item_count()); | 638 ListItemsAdded(0, model_->apps()->item_count()); |
644 } | 639 } |
645 | 640 |
646 void AppsGridView::UpdatePaging() { | 641 void AppsGridView::UpdatePaging() { |
647 int total_page = start_page_view_ ? 1 : 0; | 642 int total_page = start_page_view_ ? 1 : 0; |
648 if (view_model_.view_size() && tiles_per_page()) | 643 if (view_model_.view_size() && tiles_per_page()) |
649 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1; | 644 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1; |
650 | 645 |
651 pagination_model_->SetTotalPages(total_page); | 646 pagination_model_->SetTotalPages(total_page); |
652 } | 647 } |
653 | 648 |
654 void AppsGridView::UpdatePulsingBlockViews() { | 649 void AppsGridView::UpdatePulsingBlockViews() { |
655 const int available_slots = | 650 const int available_slots = |
656 tiles_per_page() - apps_->item_count() % tiles_per_page(); | 651 tiles_per_page() - model_->apps()->item_count() % tiles_per_page(); |
657 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? | 652 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? |
658 available_slots : 0; | 653 available_slots : 0; |
659 | 654 |
660 if (pulsing_blocks_model_.view_size() == desired) | 655 if (pulsing_blocks_model_.view_size() == desired) |
661 return; | 656 return; |
662 | 657 |
663 while (pulsing_blocks_model_.view_size() > desired) { | 658 while (pulsing_blocks_model_.view_size() > desired) { |
664 views::View* view = pulsing_blocks_model_.view_at(0); | 659 views::View* view = pulsing_blocks_model_.view_at(0); |
665 pulsing_blocks_model_.Remove(0); | 660 pulsing_blocks_model_.Remove(0); |
666 delete view; | 661 delete view; |
667 } | 662 } |
668 | 663 |
669 while (pulsing_blocks_model_.view_size() < desired) { | 664 while (pulsing_blocks_model_.view_size() < desired) { |
670 views::View* view = new PulsingBlockView( | 665 views::View* view = new PulsingBlockView( |
671 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); | 666 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); |
672 pulsing_blocks_model_.Add(view, 0); | 667 pulsing_blocks_model_.Add(view, 0); |
673 AddChildView(view); | 668 AddChildView(view); |
674 } | 669 } |
675 } | 670 } |
676 | 671 |
677 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { | 672 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { |
678 DCHECK_LT(index, apps_->item_count()); | 673 DCHECK_LT(index, model_->apps()->item_count()); |
679 AppListItemView* view = new AppListItemView(this, | 674 AppListItemView* view = new AppListItemView(this, |
680 apps_->GetItemAt(index)); | 675 model_->apps()->GetItemAt(index)); |
681 view->SetIconSize(icon_size_); | 676 view->SetIconSize(icon_size_); |
682 #if defined(USE_AURA) | 677 #if defined(USE_AURA) |
683 view->SetPaintToLayer(true); | 678 view->SetPaintToLayer(true); |
684 view->SetFillsBoundsOpaquely(false); | 679 view->SetFillsBoundsOpaquely(false); |
685 #endif | 680 #endif |
686 return view; | 681 return view; |
687 } | 682 } |
688 | 683 |
689 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( | 684 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( |
690 int model_index) const { | 685 int model_index) const { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 | 1100 |
1106 void AppsGridView::MoveItemInModel(views::View* item_view, | 1101 void AppsGridView::MoveItemInModel(views::View* item_view, |
1107 const Index& target) { | 1102 const Index& target) { |
1108 int current_model_index = view_model_.GetIndexOfView(item_view); | 1103 int current_model_index = view_model_.GetIndexOfView(item_view); |
1109 DCHECK_GE(current_model_index, 0); | 1104 DCHECK_GE(current_model_index, 0); |
1110 | 1105 |
1111 int target_model_index = GetModelIndexFromIndex(target); | 1106 int target_model_index = GetModelIndexFromIndex(target); |
1112 if (target_model_index == current_model_index) | 1107 if (target_model_index == current_model_index) |
1113 return; | 1108 return; |
1114 | 1109 |
1115 apps_->RemoveObserver(this); | 1110 model_->apps()->RemoveObserver(this); |
1116 apps_->Move(current_model_index, target_model_index); | 1111 model_->apps()->Move(current_model_index, target_model_index); |
1117 view_model_.Move(current_model_index, target_model_index); | 1112 view_model_.Move(current_model_index, target_model_index); |
1118 apps_->AddObserver(this); | 1113 model_->apps()->AddObserver(this); |
1119 | 1114 |
1120 if (pagination_model_->selected_page() != target.page) | 1115 if (pagination_model_->selected_page() != target.page) |
1121 pagination_model_->SelectPage(target.page, false); | 1116 pagination_model_->SelectPage(target.page, false); |
1122 } | 1117 } |
1123 | 1118 |
1124 void AppsGridView::CancelContextMenusOnCurrentPage() { | 1119 void AppsGridView::CancelContextMenusOnCurrentPage() { |
1125 int start = pagination_model_->selected_page() * tiles_per_page(); | 1120 int start = pagination_model_->selected_page() * tiles_per_page(); |
1126 int end = std::min(view_model_.view_size(), start + tiles_per_page()); | 1121 int end = std::min(view_model_.view_size(), start + tiles_per_page()); |
1127 for (int i = start; i < end; ++i) { | 1122 for (int i = start; i < end; ++i) { |
1128 AppListItemView* view = | 1123 AppListItemView* view = |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 #if defined(USE_AURA) | 1248 #if defined(USE_AURA) |
1254 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); | 1249 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); |
1255 animator.SetPreemptionStrategy( | 1250 animator.SetPreemptionStrategy( |
1256 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : | 1251 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : |
1257 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); | 1252 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); |
1258 view->layer()->SetOpacity(hide ? 0 : 1); | 1253 view->layer()->SetOpacity(hide ? 0 : 1); |
1259 #endif | 1254 #endif |
1260 } | 1255 } |
1261 | 1256 |
1262 } // namespace app_list | 1257 } // namespace app_list |
OLD | NEW |