diff options
author | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 13:50:17 +0000 |
---|---|---|
committer | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-14 13:50:17 +0000 |
commit | 0b4911c6bf3832d4a3670ccf6e71800fc8d686f5 (patch) | |
tree | d9a556e6c3764eb8cf4bf2d8f7620c6f0e03c1a0 /ui | |
parent | eb5ea3f9fee0b36a040376ea2837fb619daa5e18 (diff) | |
download | chromium_src-0b4911c6bf3832d4a3670ccf6e71800fc8d686f5.zip chromium_src-0b4911c6bf3832d4a3670ccf6e71800fc8d686f5.tar.gz chromium_src-0b4911c6bf3832d4a3670ccf6e71800fc8d686f5.tar.bz2 |
Implement keyboard navigation in OSX app list.
This is done by adding a NSTextField and making AppListViewController a
delegate so that it receives control:textView:doCommandBySelector when
key actions are made on the text field. The key actions are then passed
to a custom handler in AppsGridViewController. The text field is
currently invisible but will later become the search entry field. We
also make GridCollectionView return NO on acceptsFirstResponder to
ensure that the text field is also the only firstResponder.
BUG=138633
TEST=Run with --show-app-list.
Move the selection around using arrow keys and page up/down.
You should be able to move across pages.
[Enter] should launch the selected app.
[Esc] should close the app list.
COLLABORATOR=tapted@chromium.org
Review URL: https://chromiumcodereview.appspot.com/14690008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/cocoa/app_list_view_controller.h | 2 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_controller.mm | 32 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_controller_unittest.mm | 2 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_window_controller.mm | 14 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_window_controller_unittest.mm | 2 | ||||
-rw-r--r-- | ui/app_list/cocoa/apps_collection_view_drag_manager.mm | 4 | ||||
-rw-r--r-- | ui/app_list/cocoa/apps_grid_controller.h | 12 | ||||
-rw-r--r-- | ui/app_list/cocoa/apps_grid_controller.mm | 108 | ||||
-rw-r--r-- | ui/app_list/cocoa/apps_grid_controller_unittest.mm | 158 | ||||
-rw-r--r-- | ui/app_list/cocoa/test/apps_grid_controller_test_helper.h | 4 | ||||
-rw-r--r-- | ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm | 18 |
11 files changed, 286 insertions, 70 deletions
diff --git a/ui/app_list/cocoa/app_list_view_controller.h b/ui/app_list/cocoa/app_list_view_controller.h index 1ec55a5..f18c37c 100644 --- a/ui/app_list/cocoa/app_list_view_controller.h +++ b/ui/app_list/cocoa/app_list_view_controller.h @@ -23,7 +23,7 @@ class AppListViewDelegate; // navigating between pages in the grid. APP_LIST_EXPORT @interface AppListViewController : - NSViewController<AppsPaginationModelObserver> { + NSViewController<AppsPaginationModelObserver, NSTextFieldDelegate> { @private scoped_nsobject<AppsGridController> appsGridController_; scoped_nsobject<NSSegmentedControl> pagerControl_; diff --git a/ui/app_list/cocoa/app_list_view_controller.mm b/ui/app_list/cocoa/app_list_view_controller.mm index 463a571..5d6685f 100644 --- a/ui/app_list/cocoa/app_list_view_controller.mm +++ b/ui/app_list/cocoa/app_list_view_controller.mm @@ -21,6 +21,10 @@ const CGFloat kPagerPreferredHeight = 57; // Padding between the bottom of the grid and the bottom of the view. const CGFloat kViewGridOffsetY = 38; +// Height of the search input. TODO(tapted): Make this visible when the search +// input UI is written. +const CGFloat kSearchInputHeight = 0; + // Minimum margin on either side of the pager. If the pager grows beyond this, // the segment size is reduced. const CGFloat kMinPagerMargin = 40; @@ -104,8 +108,16 @@ const CGFloat kMaxSegmentWidth = 80; scoped_nsobject<BackgroundView> backgroundView( [[BackgroundView alloc] initWithFrame:backgroundRect]); + NSRect searchInputRect = + NSMakeRect(0, NSMaxY(backgroundRect) - kSearchInputHeight, + backgroundRect.size.width, kSearchInputHeight); + scoped_nsobject<NSTextField> searchInput( + [[NSTextField alloc] initWithFrame:searchInputRect]); + [searchInput setDelegate:self]; + [backgroundView addSubview:[appsGridController_ view]]; [backgroundView addSubview:pagerControl_]; + [backgroundView addSubview:searchInput]; [self setView:backgroundView]; } @@ -142,4 +154,24 @@ const CGFloat kMaxSegmentWidth = 80; [pagerControl_ setNeedsDisplay:YES]; } +- (BOOL)control:(NSControl*)control + textView:(NSTextView*)textView + doCommandBySelector:(SEL)command { + // If anything has been written, let the search view handle it. + if ([[control stringValue] length] > 0) + return NO; + + // Handle escape. + if (command == @selector(complete:) || + command == @selector(cancel:) || + command == @selector(cancelOperation:)) { + if (delegate_) + delegate_->Dismiss(); + return YES; + } + + // Possibly handle grid navigation. + return [appsGridController_ handleCommandBySelector:command]; +} + @end diff --git a/ui/app_list/cocoa/app_list_view_controller_unittest.mm b/ui/app_list/cocoa/app_list_view_controller_unittest.mm index d7ecc86..a2f9fa2 100644 --- a/ui/app_list/cocoa/app_list_view_controller_unittest.mm +++ b/ui/app_list/cocoa/app_list_view_controller_unittest.mm @@ -27,6 +27,8 @@ class AppListViewControllerTest : public AppsGridControllerTestHelper { } virtual void TearDown() OVERRIDE { + [app_list_view_controller_ + setDelegate:scoped_ptr<app_list::AppListViewDelegate>(NULL)]; app_list_view_controller_.reset(); AppsGridControllerTestHelper::TearDown(); } diff --git a/ui/app_list/cocoa/app_list_window_controller.mm b/ui/app_list/cocoa/app_list_window_controller.mm index b8f54a6..68f348f 100644 --- a/ui/app_list/cocoa/app_list_window_controller.mm +++ b/ui/app_list/cocoa/app_list_window_controller.mm @@ -40,10 +40,6 @@ [[self window] setFrame:[[appListViewController_ view] bounds] display:NO]; [[self window] setContentView:[appListViewController_ view]]; - [[self window] setDelegate:self]; - [[self window] makeFirstResponder: - [[appListViewController_ appsGridController] - collectionViewAtPageIndex:0]]; } return self; } @@ -52,14 +48,4 @@ return appListViewController_; } -- (void)doCommandBySelector:(SEL)command { - if (command == @selector(cancel:)) { - if ([appListViewController_ delegate]) - [appListViewController_ delegate]->Dismiss(); - } else if (command == @selector(insertNewline:) || - command == @selector(insertLineBreak:)) { - [[appListViewController_ appsGridController] activateSelection]; - } -} - @end diff --git a/ui/app_list/cocoa/app_list_window_controller_unittest.mm b/ui/app_list/cocoa/app_list_window_controller_unittest.mm index 8169f64..12cccdb 100644 --- a/ui/app_list/cocoa/app_list_window_controller_unittest.mm +++ b/ui/app_list/cocoa/app_list_window_controller_unittest.mm @@ -41,6 +41,8 @@ AppListWindowControllerTest::AppListWindowControllerTest() { void AppListWindowControllerTest::TearDown() { EXPECT_TRUE(controller_.get()); [[controller_ window] close]; + [[controller_ appListViewController] + setDelegate:scoped_ptr<app_list::AppListViewDelegate>(NULL)]; controller_.reset(); ui::CocoaTest::TearDown(); } diff --git a/ui/app_list/cocoa/apps_collection_view_drag_manager.mm b/ui/app_list/cocoa/apps_collection_view_drag_manager.mm index d96b283..ba5200f3 100644 --- a/ui/app_list/cocoa/apps_collection_view_drag_manager.mm +++ b/ui/app_list/cocoa/apps_collection_view_drag_manager.mm @@ -233,4 +233,8 @@ const CGFloat kDragThreshold = 5; [factory_ onMouseUp:theEvent]; } +- (BOOL)acceptsFirstResponder { + return NO; +} + @end diff --git a/ui/app_list/cocoa/apps_grid_controller.h b/ui/app_list/cocoa/apps_grid_controller.h index e09354d..0852983 100644 --- a/ui/app_list/cocoa/apps_grid_controller.h +++ b/ui/app_list/cocoa/apps_grid_controller.h @@ -84,6 +84,18 @@ APP_LIST_EXPORT - (void)moveItemWithIndex:(size_t)itemIndex toModelIndex:(size_t)modelIndex; +// Return the index of the selected item. +- (NSUInteger)selectedItemIndex; + +// Moves the selection to the given index. +- (void)selectItemAtIndex:(NSUInteger)index; + +// Handle key actions. Similar to doCommandBySelector from NSResponder but that +// requires this class to be in the responder chain. Instead this method is +// invoked by the AppListViewController. +// Returns YES if this handled navigation or launched an app. +- (BOOL)handleCommandBySelector:(SEL)command; + @end @interface AppsGridController(TestingAPI) diff --git a/ui/app_list/cocoa/apps_grid_controller.mm b/ui/app_list/cocoa/apps_grid_controller.mm index 35d01f5..a2f8481 100644 --- a/ui/app_list/cocoa/apps_grid_controller.mm +++ b/ui/app_list/cocoa/apps_grid_controller.mm @@ -59,7 +59,7 @@ NSTimeInterval g_scroll_duration = 0.18; // Update the model in full, and rebuild subviews. - (void)modelUpdated; -// Return the button selected in first page with a selection. +// Return the button of the selected item. - (NSButton*)selectedButton; // The scroll view holding the grid pages. @@ -83,6 +83,9 @@ NSTimeInterval g_scroll_duration = 0.18; - (void)listItemMovedFromIndex:(size_t)fromIndex toModelIndex:(size_t)toIndex; +// Moves the selection by |indexDelta| items. +- (BOOL)moveSelectionByDelta:(int)indexDelta; + @end namespace app_list { @@ -217,6 +220,12 @@ class AppsGridDelegateBridge : public ui::ListModelObserver { return; } + // Clear any selection on the current page (unless it has been removed). + if (visiblePage_ < [pages_ count]) { + [[self collectionViewAtPageIndex:visiblePage_] + setSelectionIndexes:[NSIndexSet indexSet]]; + } + newOrigin.x = pageIndex * kViewWidth; [NSAnimationContext beginGrouping]; [[NSAnimationContext currentContext] setDuration:g_scroll_duration]; @@ -272,18 +281,14 @@ class AppsGridDelegateBridge : public ui::ListModelObserver { } - (void)boundsDidChange:(NSNotification*)notification { - if ([self nearestPageIndex] == visiblePage_) { + size_t newPage = [self nearestPageIndex]; + if (newPage == visiblePage_) { [paginationObserver_ pageVisibilityChanged]; return; } - // Clear any selection on the previous page (unless it has been removed). - if (visiblePage_ < [pages_ count]) { - [[self collectionViewAtPageIndex:visiblePage_] - setSelectionIndexes:[NSIndexSet indexSet]]; - } - visiblePage_ = [self nearestPageIndex]; - [paginationObserver_ selectedPageChanged:visiblePage_]; + visiblePage_ = newPage; + [paginationObserver_ selectedPageChanged:newPage]; [paginationObserver_ pageVisibilityChanged]; } @@ -315,22 +320,24 @@ class AppsGridDelegateBridge : public ui::ListModelObserver { } else { [self updatePages:0]; } + [self scrollToPage:0]; } -- (NSButton*)selectedButton { - NSIndexSet* selection = nil; - size_t pageIndex = 0; - for (; pageIndex < [self pageCount]; ++pageIndex) { - selection = [[self collectionViewAtPageIndex:pageIndex] selectionIndexes]; - if ([selection count] > 0) - break; - } +- (NSUInteger)selectedItemIndex { + NSCollectionView* page = [self collectionViewAtPageIndex:visiblePage_]; + NSUInteger indexOnPage = [[page selectionIndexes] firstIndex]; + if (indexOnPage == NSNotFound) + return NSNotFound; - if (pageIndex == [self pageCount]) + return indexOnPage + visiblePage_ * kItemsPerPage; +} + +- (NSButton*)selectedButton { + NSUInteger index = [self selectedItemIndex]; + if (index == NSNotFound) return nil; - return [[self itemAtPageIndex:pageIndex - indexInPage:[selection firstIndex]] button]; + return [[self itemAtIndex:index] button]; } - (NSScrollView*)gridScrollView { @@ -502,4 +509,65 @@ class AppsGridDelegateBridge : public ui::ListModelObserver { [self scrollToPage:pageIndex]; } +- (BOOL)moveSelectionByDelta:(int)indexDelta { + if (indexDelta == 0) + return NO; + + NSUInteger oldIndex = [self selectedItemIndex]; + + // If nothing is currently selected, select the first item on the page. + if (oldIndex == NSNotFound) { + [self selectItemAtIndex:visiblePage_ * kItemsPerPage]; + return YES; + } + + if ((indexDelta < 0 && static_cast<NSUInteger>(-indexDelta) > oldIndex) || + oldIndex + indexDelta >= [items_ count]) { + return NO; + } + + [self selectItemAtIndex:oldIndex + indexDelta]; + return YES; +} + +- (void)selectItemAtIndex:(NSUInteger)index { + if (index >= [items_ count]) + return; + + if (index / kItemsPerPage != visiblePage_) + [self scrollToPage:index / kItemsPerPage]; + + [[self itemAtIndex:index] setSelected:YES]; +} + +- (BOOL)handleCommandBySelector:(SEL)command { + if (command == @selector(insertNewline:) || + command == @selector(insertLineBreak:)) { + [self activateSelection]; + return YES; + } + + if (command == @selector(moveLeft:)) + return [self moveSelectionByDelta:-1]; + + if (command == @selector(moveRight:)) + return [self moveSelectionByDelta:1]; + + if (command == @selector(moveUp:)) + return [self moveSelectionByDelta:-kFixedColumns]; + + if (command == @selector(moveDown:)) + return [self moveSelectionByDelta:kFixedColumns]; + + if (command == @selector(pageUp:) || + command == @selector(scrollPageUp:)) + return [self moveSelectionByDelta:-kItemsPerPage]; + + if (command == @selector(pageDown:) || + command == @selector(scrollPageDown:)) + return [self moveSelectionByDelta:kItemsPerPage]; + + return NO; +} + @end diff --git a/ui/app_list/cocoa/apps_grid_controller_unittest.mm b/ui/app_list/cocoa/apps_grid_controller_unittest.mm index 7d49d25..cae0643 100644 --- a/ui/app_list/cocoa/apps_grid_controller_unittest.mm +++ b/ui/app_list/cocoa/apps_grid_controller_unittest.mm @@ -195,35 +195,151 @@ TEST_F(AppsGridControllerTest, Pagination) { EXPECT_EQ(1u, [[GetPageAt(0) content] count]); } -// Tests basic left-right keyboard navigation on the first page, later tests -// will test keyboard navigation across pages and other corner cases. -TEST_F(AppsGridControllerTest, DISABLED_FirstPageKeyboardNavigation) { - model()->PopulateApps(3); - SinkEvents(); - EXPECT_EQ(3u, [[GetPageAt(0) content] count]); +// Tests basic keyboard navigation on the first page. +TEST_F(AppsGridControllerTest, FirstPageKeyboardNavigation) { + model()->PopulateApps(kItemsPerPage - 2); + EXPECT_EQ(kItemsPerPage - 2, [[GetPageAt(0) content] count]); - SimulateKeyPress(NSRightArrowFunctionKey); - SinkEvents(); - EXPECT_EQ(GetSelectedView(), GetItemViewAt(0)); + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); - SimulateKeyPress(NSRightArrowFunctionKey); - SinkEvents(); - EXPECT_EQ(GetSelectedView(), GetItemViewAt(1)); + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(1u, [apps_grid_controller_ selectedItemIndex]); - SimulateKeyPress(NSLeftArrowFunctionKey); - SinkEvents(); - EXPECT_EQ(GetSelectedView(), GetItemViewAt(0)); + SimulateKeyAction(@selector(moveDown:)); + EXPECT_EQ(5u, [apps_grid_controller_ selectedItemIndex]); - // Go to the last item, and launch it. - SimulateKeyPress(NSRightArrowFunctionKey); - SimulateKeyPress(NSRightArrowFunctionKey); - [apps_grid_controller_ activateSelection]; - SinkEvents(); - EXPECT_EQ(GetSelectedView(), GetItemViewAt(2)); + SimulateKeyAction(@selector(moveLeft:)); + EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]); + + SimulateKeyAction(@selector(moveUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); + + // Go to the third item, and launch it. + SimulateKeyAction(@selector(moveRight:)); + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(insertNewline:)); EXPECT_EQ(1, delegate()->activate_count()); EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title()); } +// Tests keyboard navigation across pages. +TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { + [AppsGridController setScrollAnimationDuration:0.0]; + + model()->PopulateApps(2 * kItemsPerPage); + EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); + EXPECT_EQ(kItemsPerPage, [[GetPageAt(1) content] count]); + + // Moving Left, Up, or PageUp from the top-left corner of the first page does + // nothing. + [apps_grid_controller_ selectItemAtIndex:0]; + SimulateKeyAction(@selector(moveLeft:)); + EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(moveUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(scrollPageUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); + + // Moving Right from the right side wraps to the next row. + [apps_grid_controller_ selectItemAtIndex:3]; + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]); + + // Moving Down from the bottom goes to the next page and selects the same + // column. Moving Up again goes back to the first page. + [apps_grid_controller_ selectItemAtIndex:13]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(moveDown:)); + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(moveUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(13u, [apps_grid_controller_ selectedItemIndex]); + + // Moving Right from the bottom-right corner goes to the next page. + // Moving Left again goes back to the first page. + [apps_grid_controller_ selectItemAtIndex:15]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(moveLeft:)); + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(15u, [apps_grid_controller_ selectedItemIndex]); + + // PageDown and PageUp switches pages while maintaining the same selection + // position. + [apps_grid_controller_ selectItemAtIndex:10]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(scrollPageDown:)); + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(kItemsPerPage + 10, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(scrollPageUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); + + // Moving Right, Down, or PageDown from the bottom-right corner of the last + // page does nothing. + [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 1)]; + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(moveRight:)); + EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(moveDown:)); + EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(scrollPageDown:)); + EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); + + // Moving down on the bottom of the last page does nothing. + [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 4)]; + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(moveDown:)); + EXPECT_EQ(kItemsPerPage + 12, [apps_grid_controller_ selectedItemIndex]); + + // Remove some items from the last page. + ReplaceTestModel(kItemsPerPage + 8); + EXPECT_EQ(8u, [[GetPageAt(1) content] count]); + EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); + + // PageUp/Down to an invalid selection does nothing. + [apps_grid_controller_ selectItemAtIndex:10]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + SimulateKeyAction(@selector(scrollPageUp:)); + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(scrollPageDown:)); + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); + + // After page switch, arrow keys select first item on current page. + [apps_grid_controller_ scrollToPage:1]; + EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); + SimulateKeyAction(@selector(moveUp:)); + EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); +} + +// Highlighting an item should cause the page it's on to be visible. +TEST_F(AppsGridControllerTest, EnsureHighlightedVisible) { + model()->PopulateApps(3 * kItemsPerPage); + EXPECT_EQ(kItemsPerPage, [[GetPageAt(2) content] count]); + + // First and last items of first page. + [apps_grid_controller_ selectItemAtIndex:0]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + [apps_grid_controller_ selectItemAtIndex:kItemsPerPage - 1]; + EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); + + // First item of second page. + [apps_grid_controller_ selectItemAtIndex:kItemsPerPage + 1]; + EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); + + // Last item in model. + [apps_grid_controller_ selectItemAtIndex:3 * kItemsPerPage - 1]; + EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]); +} + + // Test runtime updates: adding items, removing items, and moving items (e.g. in // response to app install, uninstall, and chrome sync changes. Also test // changing titles and icons. diff --git a/ui/app_list/cocoa/test/apps_grid_controller_test_helper.h b/ui/app_list/cocoa/test/apps_grid_controller_test_helper.h index 20140b0..90a1014 100644 --- a/ui/app_list/cocoa/test/apps_grid_controller_test_helper.h +++ b/ui/app_list/cocoa/test/apps_grid_controller_test_helper.h @@ -30,8 +30,8 @@ class AppsGridControllerTestHelper : public ui::CocoaTest { // Send a click to the test window in the centre of |view|. void SimulateClick(NSView* view); - // Send a key press to the first responder. - void SimulateKeyPress(unichar c); + // Send a key action using handleCommandBySelector. + void SimulateKeyAction(SEL c); void SimulateMouseEnterItemAt(size_t index); void SimulateMouseExitItemAt(size_t index); diff --git a/ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm b/ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm index e5763ba..19e2790 100644 --- a/ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm +++ b/ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm @@ -40,8 +40,8 @@ void AppsGridControllerTestHelper::SimulateClick(NSView* view) { [NSApp postEvent:events.second atStart:NO]; } -void AppsGridControllerTestHelper::SimulateKeyPress(unichar c) { - [test_window() keyDown:cocoa_test_event_utils::KeyEventWithCharacter(c)]; +void AppsGridControllerTestHelper::SimulateKeyAction(SEL c) { + [apps_grid_controller_ handleCommandBySelector:c]; } void AppsGridControllerTestHelper::SimulateMouseEnterItemAt(size_t index) { @@ -111,6 +111,9 @@ void AppsGridControllerTestHelper::SinkEvents() { } NSButton* AppsGridControllerTestHelper::GetItemViewAt(size_t index) { + if (index == NSNotFound) + return nil; + return [[apps_grid_controller_ itemAtIndex:index] button]; } @@ -119,16 +122,7 @@ NSCollectionView* AppsGridControllerTestHelper::GetPageAt(size_t index) { } NSView* AppsGridControllerTestHelper::GetSelectedView() { - // TODO(tapted): Update this to work for selections on other than the first - // page. - NSIndexSet* selection = [GetPageAt(0) selectionIndexes]; - if ([selection count]) { - AppsGridViewItem* item = base::mac::ObjCCastStrict<AppsGridViewItem>( - [GetPageAt(0) itemAtIndex:[selection firstIndex]]); - return [item button]; - } - - return nil; + return GetItemViewAt([apps_grid_controller_ selectedItemIndex]); } AppListTestViewDelegate* AppsGridControllerTestHelper::delegate() { |