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

Side by Side Diff: ui/app_list/views/apps_grid_view.cc

Issue 27777002: Implement app list folder management page UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 7 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 | Annotate | Revision Log
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/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
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
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (selected_view_ == details.child) 626 if (selected_view_ == details.child)
619 selected_view_ = NULL; 627 selected_view_ = NULL;
620 628
621 if (drag_view_ == details.child) 629 if (drag_view_ == details.child)
622 EndDrag(true); 630 EndDrag(true);
623 631
624 bounds_animator_.StopAnimatingView(details.child); 632 bounds_animator_.StopAnimatingView(details.child);
625 } 633 }
626 } 634 }
627 635
628 // static
629 AppsGridView* AppsGridView::GetLastGridViewForTest() {
630 return last_created_grid_view_for_test;
631 }
632
633 void AppsGridView::Update() { 636 void AppsGridView::Update() {
634 DCHECK(!selected_view_ && !drag_view_); 637 DCHECK(!selected_view_ && !drag_view_);
638 if (!apps_)
639 return;
635 640
636 view_model_.Clear(); 641 view_model_.Clear();
637 if (model_ && model_->apps()->item_count()) 642 if (apps_ && apps_->item_count())
638 ListItemsAdded(0, model_->apps()->item_count()); 643 ListItemsAdded(0, apps_->item_count());
639 } 644 }
640 645
641 void AppsGridView::UpdatePaging() { 646 void AppsGridView::UpdatePaging() {
642 int total_page = start_page_view_ ? 1 : 0; 647 int total_page = start_page_view_ ? 1 : 0;
643 if (view_model_.view_size() && tiles_per_page()) 648 if (view_model_.view_size() && tiles_per_page())
644 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1; 649 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1;
645 650
646 pagination_model_->SetTotalPages(total_page); 651 pagination_model_->SetTotalPages(total_page);
647 } 652 }
648 653
649 void AppsGridView::UpdatePulsingBlockViews() { 654 void AppsGridView::UpdatePulsingBlockViews() {
650 const int available_slots = 655 const int available_slots =
651 tiles_per_page() - model_->apps()->item_count() % tiles_per_page(); 656 tiles_per_page() - apps_->item_count() % tiles_per_page();
652 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? 657 const int desired = model_->status() == AppListModel::STATUS_SYNCING ?
653 available_slots : 0; 658 available_slots : 0;
654 659
655 if (pulsing_blocks_model_.view_size() == desired) 660 if (pulsing_blocks_model_.view_size() == desired)
656 return; 661 return;
657 662
658 while (pulsing_blocks_model_.view_size() > desired) { 663 while (pulsing_blocks_model_.view_size() > desired) {
659 views::View* view = pulsing_blocks_model_.view_at(0); 664 views::View* view = pulsing_blocks_model_.view_at(0);
660 pulsing_blocks_model_.Remove(0); 665 pulsing_blocks_model_.Remove(0);
661 delete view; 666 delete view;
662 } 667 }
663 668
664 while (pulsing_blocks_model_.view_size() < desired) { 669 while (pulsing_blocks_model_.view_size() < desired) {
665 views::View* view = new PulsingBlockView( 670 views::View* view = new PulsingBlockView(
666 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); 671 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true);
667 pulsing_blocks_model_.Add(view, 0); 672 pulsing_blocks_model_.Add(view, 0);
668 AddChildView(view); 673 AddChildView(view);
669 } 674 }
670 } 675 }
671 676
672 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { 677 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) {
673 DCHECK_LT(index, model_->apps()->item_count()); 678 DCHECK_LT(index, apps_->item_count());
674 AppListItemView* view = new AppListItemView(this, 679 AppListItemView* view = new AppListItemView(this,
675 model_->apps()->GetItemAt(index)); 680 apps_->GetItemAt(index));
676 view->SetIconSize(icon_size_); 681 view->SetIconSize(icon_size_);
677 #if defined(USE_AURA) 682 #if defined(USE_AURA)
678 view->SetPaintToLayer(true); 683 view->SetPaintToLayer(true);
679 view->SetFillsBoundsOpaquely(false); 684 view->SetFillsBoundsOpaquely(false);
680 #endif 685 #endif
681 return view; 686 return view;
682 } 687 }
683 688
684 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( 689 AppsGridView::Index AppsGridView::GetIndexFromModelIndex(
685 int model_index) const { 690 int model_index) const {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 1105
1101 void AppsGridView::MoveItemInModel(views::View* item_view, 1106 void AppsGridView::MoveItemInModel(views::View* item_view,
1102 const Index& target) { 1107 const Index& target) {
1103 int current_model_index = view_model_.GetIndexOfView(item_view); 1108 int current_model_index = view_model_.GetIndexOfView(item_view);
1104 DCHECK_GE(current_model_index, 0); 1109 DCHECK_GE(current_model_index, 0);
1105 1110
1106 int target_model_index = GetModelIndexFromIndex(target); 1111 int target_model_index = GetModelIndexFromIndex(target);
1107 if (target_model_index == current_model_index) 1112 if (target_model_index == current_model_index)
1108 return; 1113 return;
1109 1114
1110 model_->apps()->RemoveObserver(this); 1115 apps_->RemoveObserver(this);
1111 model_->apps()->Move(current_model_index, target_model_index); 1116 apps_->Move(current_model_index, target_model_index);
1112 view_model_.Move(current_model_index, target_model_index); 1117 view_model_.Move(current_model_index, target_model_index);
1113 model_->apps()->AddObserver(this); 1118 apps_->AddObserver(this);
1114 1119
1115 if (pagination_model_->selected_page() != target.page) 1120 if (pagination_model_->selected_page() != target.page)
1116 pagination_model_->SelectPage(target.page, false); 1121 pagination_model_->SelectPage(target.page, false);
1117 } 1122 }
1118 1123
1119 void AppsGridView::CancelContextMenusOnCurrentPage() { 1124 void AppsGridView::CancelContextMenusOnCurrentPage() {
1120 int start = pagination_model_->selected_page() * tiles_per_page(); 1125 int start = pagination_model_->selected_page() * tiles_per_page();
1121 int end = std::min(view_model_.view_size(), start + tiles_per_page()); 1126 int end = std::min(view_model_.view_size(), start + tiles_per_page());
1122 for (int i = start; i < end; ++i) { 1127 for (int i = start; i < end; ++i) {
1123 AppListItemView* view = 1128 AppListItemView* view =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 #if defined(USE_AURA) 1253 #if defined(USE_AURA)
1249 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); 1254 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
1250 animator.SetPreemptionStrategy( 1255 animator.SetPreemptionStrategy(
1251 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : 1256 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET :
1252 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); 1257 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION);
1253 view->layer()->SetOpacity(hide ? 0 : 1); 1258 view->layer()->SetOpacity(hide ? 0 : 1);
1254 #endif 1259 #endif
1255 } 1260 }
1256 1261
1257 } // namespace app_list 1262 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698