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

Unified Diff: ui/app_list/cocoa/apps_grid_controller.mm

Issue 12701022: wrongbaseurl OSX App List Pager and root view controller. (Closed) Base URL: http://git.chromium.org/chromium/src.git@20130304-crbug-138633-osx-app-list-demo-polish-macbook
Patch Set: delegate should be owned by viewcontroller, test coverage Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/cocoa/apps_grid_controller.h ('k') | ui/app_list/cocoa/apps_grid_controller_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/cocoa/apps_grid_controller.mm
diff --git a/ui/app_list/cocoa/apps_grid_controller.mm b/ui/app_list/cocoa/apps_grid_controller.mm
index 7eb3f5e23bca89b094faeaf06e1cdb5a1f26586b..f881f96765dcf6128d18ebdbf69a0705d9033fec 100644
--- a/ui/app_list/cocoa/apps_grid_controller.mm
+++ b/ui/app_list/cocoa/apps_grid_controller.mm
@@ -9,6 +9,7 @@
#include "ui/app_list/app_list_model_observer.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/cocoa/apps_grid_view_item.h"
+#import "ui/app_list/cocoa/apps_pagination_model_observer.h"
#include "ui/base/models/list_model_observer.h"
namespace {
@@ -19,8 +20,8 @@ const int kFixedColumns = 4;
const int kItemsPerPage = kFixedRows * kFixedColumns;
// Padding space in pixels for fixed layout.
-const CGFloat kLeftRightPadding = 20;
-const CGFloat kTopPadding = 16;
+const CGFloat kLeftRightPadding = 16;
+const CGFloat kTopPadding = 30;
// Preferred tile size when showing in fixed layout.
const CGFloat kPreferredTileWidth = 88;
@@ -30,6 +31,8 @@ const CGFloat kViewWidth =
kFixedColumns * kPreferredTileWidth + 2 * kLeftRightPadding;
const CGFloat kViewHeight = kFixedRows * kPreferredTileHeight;
+NSTimeInterval g_scroll_duration = 0.18;
+
} // namespace
@interface AppsGridController ()
@@ -46,6 +49,8 @@ const CGFloat kViewHeight = kFixedRows * kPreferredTileHeight;
// Bootstrap the views this class controls.
- (void)loadAndSetView;
+- (void)boundsDidChange:(NSNotification*)notification;
+
// Action for buttons in the grid.
- (void)onItemClicked:(id)sender;
@@ -98,23 +103,25 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
@implementation AppsGridController
-- (id)initWithViewDelegate:
- (scoped_ptr<app_list::AppListViewDelegate>)appListViewDelegate {
++ (void)setScrollAnimationDuration:(NSTimeInterval)duration {
+ g_scroll_duration = duration;
+}
+
+@synthesize paginationObserver = paginationObserver_;
+
+- (id)init {
if ((self = [super init])) {
- scoped_ptr<app_list::AppListModel> model(new app_list::AppListModel);
- delegate_.reset(appListViewDelegate.release());
bridge_.reset(new app_list::AppsGridDelegateBridge(self));
pages_.reset([[NSMutableArray alloc] init]);
items_.reset([[NSMutableArray alloc] init]);
- if (delegate_)
- delegate_->SetModel(model.get());
[self loadAndSetView];
- [self setModel:model.Pass()];
+ [self updatePages:0];
}
return self;
}
- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[self setModel:scoped_ptr<app_list::AppListModel>()];
[super dealloc];
}
@@ -127,11 +134,7 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
return model_.get();
}
-- (app_list::AppListViewDelegate*)delegate {
- return delegate_.get();
-}
-
-- (void)setModel:(scoped_ptr<app_list::AppListModel>)model {
+- (void)setModel:(scoped_ptr<app_list::AppListModel>)newModel {
if (model_) {
model_->apps()->RemoveObserver(bridge_.get());
@@ -142,13 +145,25 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
[[self itemAtIndex:i] setModel:NULL];
}
- model_.reset(model.release());
+ model_.reset(newModel.release());
if (model_)
model_->apps()->AddObserver(bridge_.get());
[self modelUpdated];
}
+- (void)setDelegate:(app_list::AppListViewDelegate*)newDelegate {
+ scoped_ptr<app_list::AppListModel> newModel(new app_list::AppListModel);
+ delegate_ = newDelegate;
+ if (delegate_)
+ delegate_->SetModel(newModel.get()); // Populates items.
+ [self setModel:newModel.Pass()];
+}
+
+- (size_t)visiblePage {
+ return visiblePage_;
+}
+
- (void)activateSelection {
[[self selectedButton] performClick:self];
}
@@ -171,6 +186,7 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
newOrigin.x = pageIndex * kViewWidth;
[NSAnimationContext beginGrouping];
+ [[NSAnimationContext currentContext] setDuration:g_scroll_duration];
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];
animatingScroll_ = YES;
@@ -211,6 +227,8 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
[itemCollectionView setMaxItemSize:itemSize];
[itemCollectionView setSelectable:YES];
[itemCollectionView setFocusRingType:NSFocusRingTypeNone];
+ [itemCollectionView setBackgroundColors:
+ [NSArray arrayWithObject:[NSColor clearColor]]];
scoped_nsobject<AppsGridViewItem> itemPrototype(
[[AppsGridViewItem alloc] initWithSize:itemSize]);
@@ -233,10 +251,33 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
[scrollView setPageScroll:kViewWidth];
[scrollView setDelegate:self];
[scrollView setDocumentView:pagesContainer];
+ [scrollView setDrawsBackground:NO];
+
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(boundsDidChange:)
+ name:NSViewBoundsDidChangeNotification
+ object:[scrollView contentView]];
[self setView:scrollView];
}
+- (void)boundsDidChange:(NSNotification*)notification {
+ if ([self nearestPageIndex] == visiblePage_)
+ return;
+
+ size_t oldPage = visiblePage_;
+ visiblePage_ = [self nearestPageIndex];
+
+ // Clear any selection on the previous page (unless it has been removed).
+ if (oldPage < [pages_ count]) {
+ [[self collectionViewAtPageIndex:oldPage]
+ setSelectionIndexes:[NSIndexSet indexSet]];
+ }
+ [paginationObserver_ selectedPageChanged:oldPage
+ newSelected:visiblePage_];
+}
+
- (void)onItemClicked:(id)sender {
for (size_t i = 0; i < [items_ count]; ++i) {
AppsGridViewItem* item = [self itemAtIndex:i];
@@ -313,6 +354,7 @@ class AppsGridDelegateBridge : public ui::ListModelObserver {
[[self pagesContainerView] setSubviews:pages_];
NSSize pagesSize = NSMakeSize(kViewWidth * targetPages, kViewHeight);
[[self pagesContainerView] setFrameSize:pagesSize];
+ [paginationObserver_ totalPagesChanged];
}
const size_t startPage = startItemIndex / kItemsPerPage;
« no previous file with comments | « ui/app_list/cocoa/apps_grid_controller.h ('k') | ui/app_list/cocoa/apps_grid_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698