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

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 LauncherAppBrowserTest.ClickItem and DragAndDrop. Created 7 years, 1 month 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 LOG(ERROR) << "AppsGridView::SetModel";
xiyuan 2013/10/22 18:15:46 nit: remove this
jennyz 2013/10/22 18:21:31 Done.
297 if (model_)
295 model_->RemoveObserver(this); 298 model_->RemoveObserver(this);
296 model_->apps()->RemoveObserver(this);
297 }
298 299
299 model_ = model; 300 model_ = model;
300 if (model_) { 301 if (model_)
301 model_->AddObserver(this); 302 model_->AddObserver(this);
302 model_->apps()->AddObserver(this); 303
303 }
304 Update(); 304 Update();
305 } 305 }
306 306
307 void AppsGridView::SetApps(AppListModel::Apps* apps) {
308 LOG(ERROR) << "AppsGridView::SetApps";
xiyuan 2013/10/22 18:15:46 nit: remove this
jennyz 2013/10/22 18:21:31 Done.
309 if (apps_)
310 apps_->RemoveObserver(this);
311
312 apps_ = apps;
313 apps_->AddObserver(this);
314 Update();
315 }
316
307 void AppsGridView::SetSelectedView(views::View* view) { 317 void AppsGridView::SetSelectedView(views::View* view) {
308 if (IsSelectedView(view) || IsDraggedView(view)) 318 if (IsSelectedView(view) || IsDraggedView(view))
309 return; 319 return;
310 320
311 Index index = GetIndexOfView(view); 321 Index index = GetIndexOfView(view);
312 if (IsValidIndex(index)) 322 if (IsValidIndex(index))
313 SetSelectedItemByIndex(index); 323 SetSelectedItemByIndex(index);
314 } 324 }
315 325
316 void AppsGridView::ClearSelectedView(views::View* view) { 326 void AppsGridView::ClearSelectedView(views::View* view) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (selected_view_ == details.child) 628 if (selected_view_ == details.child)
619 selected_view_ = NULL; 629 selected_view_ = NULL;
620 630
621 if (drag_view_ == details.child) 631 if (drag_view_ == details.child)
622 EndDrag(true); 632 EndDrag(true);
623 633
624 bounds_animator_.StopAnimatingView(details.child); 634 bounds_animator_.StopAnimatingView(details.child);
625 } 635 }
626 } 636 }
627 637
628 // static
629 AppsGridView* AppsGridView::GetLastGridViewForTest() {
630 return last_created_grid_view_for_test;
631 }
632
633 void AppsGridView::Update() { 638 void AppsGridView::Update() {
634 DCHECK(!selected_view_ && !drag_view_); 639 DCHECK(!selected_view_ && !drag_view_);
640 if (!apps_)
641 return;
635 642
636 view_model_.Clear(); 643 view_model_.Clear();
637 if (model_ && model_->apps()->item_count()) 644 if (apps_ && apps_->item_count())
638 ListItemsAdded(0, model_->apps()->item_count()); 645 ListItemsAdded(0, apps_->item_count());
639 } 646 }
640 647
641 void AppsGridView::UpdatePaging() { 648 void AppsGridView::UpdatePaging() {
642 int total_page = start_page_view_ ? 1 : 0; 649 int total_page = start_page_view_ ? 1 : 0;
643 if (view_model_.view_size() && tiles_per_page()) 650 if (view_model_.view_size() && tiles_per_page())
644 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1; 651 total_page += (view_model_.view_size() - 1) / tiles_per_page() + 1;
645 652
646 pagination_model_->SetTotalPages(total_page); 653 pagination_model_->SetTotalPages(total_page);
647 } 654 }
648 655
649 void AppsGridView::UpdatePulsingBlockViews() { 656 void AppsGridView::UpdatePulsingBlockViews() {
650 const int available_slots = 657 const int available_slots =
651 tiles_per_page() - model_->apps()->item_count() % tiles_per_page(); 658 tiles_per_page() - apps_->item_count() % tiles_per_page();
652 const int desired = model_->status() == AppListModel::STATUS_SYNCING ? 659 const int desired = model_->status() == AppListModel::STATUS_SYNCING ?
653 available_slots : 0; 660 available_slots : 0;
654 661
655 if (pulsing_blocks_model_.view_size() == desired) 662 if (pulsing_blocks_model_.view_size() == desired)
656 return; 663 return;
657 664
658 while (pulsing_blocks_model_.view_size() > desired) { 665 while (pulsing_blocks_model_.view_size() > desired) {
659 views::View* view = pulsing_blocks_model_.view_at(0); 666 views::View* view = pulsing_blocks_model_.view_at(0);
660 pulsing_blocks_model_.Remove(0); 667 pulsing_blocks_model_.Remove(0);
661 delete view; 668 delete view;
662 } 669 }
663 670
664 while (pulsing_blocks_model_.view_size() < desired) { 671 while (pulsing_blocks_model_.view_size() < desired) {
665 views::View* view = new PulsingBlockView( 672 views::View* view = new PulsingBlockView(
666 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true); 673 gfx::Size(kPreferredTileWidth, kPreferredTileHeight), true);
667 pulsing_blocks_model_.Add(view, 0); 674 pulsing_blocks_model_.Add(view, 0);
668 AddChildView(view); 675 AddChildView(view);
669 } 676 }
670 } 677 }
671 678
672 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { 679 views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) {
673 DCHECK_LT(index, model_->apps()->item_count()); 680 DCHECK_LT(index, apps_->item_count());
674 AppListItemView* view = new AppListItemView(this, 681 AppListItemView* view = new AppListItemView(this,
675 model_->apps()->GetItemAt(index)); 682 apps_->GetItemAt(index));
676 view->SetIconSize(icon_size_); 683 view->SetIconSize(icon_size_);
677 #if defined(USE_AURA) 684 #if defined(USE_AURA)
678 view->SetPaintToLayer(true); 685 view->SetPaintToLayer(true);
679 view->SetFillsBoundsOpaquely(false); 686 view->SetFillsBoundsOpaquely(false);
680 #endif 687 #endif
681 return view; 688 return view;
682 } 689 }
683 690
684 AppsGridView::Index AppsGridView::GetIndexFromModelIndex( 691 AppsGridView::Index AppsGridView::GetIndexFromModelIndex(
685 int model_index) const { 692 int model_index) const {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 1107
1101 void AppsGridView::MoveItemInModel(views::View* item_view, 1108 void AppsGridView::MoveItemInModel(views::View* item_view,
1102 const Index& target) { 1109 const Index& target) {
1103 int current_model_index = view_model_.GetIndexOfView(item_view); 1110 int current_model_index = view_model_.GetIndexOfView(item_view);
1104 DCHECK_GE(current_model_index, 0); 1111 DCHECK_GE(current_model_index, 0);
1105 1112
1106 int target_model_index = GetModelIndexFromIndex(target); 1113 int target_model_index = GetModelIndexFromIndex(target);
1107 if (target_model_index == current_model_index) 1114 if (target_model_index == current_model_index)
1108 return; 1115 return;
1109 1116
1110 model_->apps()->RemoveObserver(this); 1117 apps_->RemoveObserver(this);
1111 model_->apps()->Move(current_model_index, target_model_index); 1118 apps_->Move(current_model_index, target_model_index);
1112 view_model_.Move(current_model_index, target_model_index); 1119 view_model_.Move(current_model_index, target_model_index);
1113 model_->apps()->AddObserver(this); 1120 apps_->AddObserver(this);
1114 1121
1115 if (pagination_model_->selected_page() != target.page) 1122 if (pagination_model_->selected_page() != target.page)
1116 pagination_model_->SelectPage(target.page, false); 1123 pagination_model_->SelectPage(target.page, false);
1117 } 1124 }
1118 1125
1119 void AppsGridView::CancelContextMenusOnCurrentPage() { 1126 void AppsGridView::CancelContextMenusOnCurrentPage() {
1120 int start = pagination_model_->selected_page() * tiles_per_page(); 1127 int start = pagination_model_->selected_page() * tiles_per_page();
1121 int end = std::min(view_model_.view_size(), start + tiles_per_page()); 1128 int end = std::min(view_model_.view_size(), start + tiles_per_page());
1122 for (int i = start; i < end; ++i) { 1129 for (int i = start; i < end; ++i) {
1123 AppListItemView* view = 1130 AppListItemView* view =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 #if defined(USE_AURA) 1255 #if defined(USE_AURA)
1249 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator()); 1256 ui::ScopedLayerAnimationSettings animator(view->layer()->GetAnimator());
1250 animator.SetPreemptionStrategy( 1257 animator.SetPreemptionStrategy(
1251 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET : 1258 immediate ? ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET :
1252 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION); 1259 ui::LayerAnimator::BLEND_WITH_CURRENT_ANIMATION);
1253 view->layer()->SetOpacity(hide ? 0 : 1); 1260 view->layer()->SetOpacity(hide ? 0 : 1);
1254 #endif 1261 #endif
1255 } 1262 }
1256 1263
1257 } // namespace app_list 1264 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698