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