Commit f125b287 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Use PanelIndentifier instead of Integer for NTPBar

The NewTabPageBarItem was using a NSInteger to store a PanelIdentifier
value. Use directly the enum to avoid conversions.

Bug: 753391
Change-Id: I74e319db566cdb65e93a83b09d1d923b7b446c6f
Reviewed-on: https://chromium-review.googlesource.com/645958Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#499497}
parent ec92099a
...@@ -172,6 +172,7 @@ source_set("ntp_internal") { ...@@ -172,6 +172,7 @@ source_set("ntp_internal") {
"//ios/chrome/browser/ui/bookmarks", "//ios/chrome/browser/ui/bookmarks",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions", "//ios/chrome/browser/ui/content_suggestions",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_util", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_util",
"//ios/chrome/browser/ui/content_suggestions/cells", "//ios/chrome/browser/ui/content_suggestions/cells",
"//ios/chrome/browser/ui/context_menu", "//ios/chrome/browser/ui/context_menu",
...@@ -244,6 +245,7 @@ source_set("unit_tests") { ...@@ -244,6 +245,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/web_state_list:test_support", "//ios/chrome/browser/web_state_list:test_support",
"//ios/chrome/browser/web_state_list:web_state_list", "//ios/chrome/browser/web_state_list:web_state_list",
"//ios/chrome/test:test_support", "//ios/chrome/test:test_support",
......
...@@ -8,17 +8,20 @@ ...@@ -8,17 +8,20 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
// Represents an item on the new tab page bar, similar to a UITabBarItem. // Represents an item on the new tab page bar, similar to a UITabBarItem.
@interface NewTabPageBarItem : NSObject @interface NewTabPageBarItem : NSObject
// Convenience method for creating a tab bar choice. // Convenience method for creating a tab bar choice.
+ (NewTabPageBarItem*)newTabPageBarItemWithTitle:(NSString*)title + (NewTabPageBarItem*)newTabPageBarItemWithTitle:(NSString*)title
identifier:(NSUInteger)identifier identifier:
(ntp_home::PanelIdentifier)identifier
image:(UIImage*)imageName image:(UIImage*)imageName
NS_RETURNS_NOT_RETAINED; NS_RETURNS_NOT_RETAINED;
@property(nonatomic, copy) NSString* title; @property(nonatomic, copy) NSString* title;
@property(nonatomic, assign) NSUInteger identifier; @property(nonatomic, assign) ntp_home::PanelIdentifier identifier;
@property(nonatomic, strong) UIImage* image; @property(nonatomic, strong) UIImage* image;
@property(nonatomic, weak) UIView* view; @property(nonatomic, weak) UIView* view;
@end @end
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
@synthesize view = view_; @synthesize view = view_;
+ (NewTabPageBarItem*)newTabPageBarItemWithTitle:(NSString*)title + (NewTabPageBarItem*)newTabPageBarItemWithTitle:(NSString*)title
identifier:(NSUInteger)identifier identifier:
(ntp_home::PanelIdentifier)identifier
image:(UIImage*)image { image:(UIImage*)image {
NewTabPageBarItem* item = [[NewTabPageBarItem alloc] init]; NewTabPageBarItem* item = [[NewTabPageBarItem alloc] init];
if (item) { if (item) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -32,19 +33,19 @@ class NewTabPageBarTest : public PlatformTest { ...@@ -32,19 +33,19 @@ class NewTabPageBarTest : public PlatformTest {
TEST_F(NewTabPageBarTest, SetItems) { TEST_F(NewTabPageBarTest, SetItems) {
NewTabPageBarItem* firstItem = [NewTabPageBarItem NewTabPageBarItem* firstItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"First" newTabPageBarItemWithTitle:@"Home"
identifier:1 identifier:ntp_home::HOME_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
// Tests that identifier test function can return both true and false. // Tests that identifier test function can return both true and false.
EXPECT_TRUE(firstItem.identifier == 1U); EXPECT_TRUE(firstItem.identifier == ntp_home::HOME_PANEL);
NewTabPageBarItem* secondItem = [NewTabPageBarItem NewTabPageBarItem* secondItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Second" newTabPageBarItemWithTitle:@"Bookmarks"
identifier:2 identifier:ntp_home::BOOKMARKS_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
NewTabPageBarItem* thirdItem = [NewTabPageBarItem NewTabPageBarItem* thirdItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Third" newTabPageBarItemWithTitle:@"RecentTabs"
identifier:3 identifier:ntp_home::RECENT_TABS_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
[bar_ setItems:[NSArray arrayWithObject:firstItem]]; [bar_ setItems:[NSArray arrayWithObject:firstItem]];
...@@ -65,17 +66,16 @@ TEST_F(NewTabPageBarTest, SetSelectedIndex_iPadOnly) { ...@@ -65,17 +66,16 @@ TEST_F(NewTabPageBarTest, SetSelectedIndex_iPadOnly) {
} }
NewTabPageBarItem* firstItem = [NewTabPageBarItem NewTabPageBarItem* firstItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"First" newTabPageBarItemWithTitle:@"Home"
identifier:1 identifier:ntp_home::HOME_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
NewTabPageBarItem* secondItem = [NewTabPageBarItem NewTabPageBarItem* secondItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Second" newTabPageBarItemWithTitle:@"Bookmarks"
identifier:2 identifier:ntp_home::BOOKMARKS_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
NewTabPageBarItem* thirdItem = [NewTabPageBarItem NewTabPageBarItem* thirdItem = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Third" newTabPageBarItemWithTitle:@"RecentTabs"
identifier:3 identifier:ntp_home::RECENT_TABS_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
[bar_ setItems:[NSArray [bar_ setItems:[NSArray
......
...@@ -706,7 +706,7 @@ enum { ...@@ -706,7 +706,7 @@ enum {
NSUInteger index = self.ntpView.tabBar.selectedIndex; NSUInteger index = self.ntpView.tabBar.selectedIndex;
DCHECK(index != NSNotFound); DCHECK(index != NSNotFound);
NewTabPageBarItem* item = self.ntpView.tabBar.items[index]; NewTabPageBarItem* item = self.ntpView.tabBar.items[index];
return static_cast<ntp_home::PanelIdentifier>(item.identifier); return item.identifier;
} }
return ntp_home::HOME_PANEL; return ntp_home::HOME_PANEL;
} }
......
...@@ -156,19 +156,17 @@ ...@@ -156,19 +156,17 @@
return; return;
NewTabPageBarItem* item = self.NTPView.tabBar.items[index]; NewTabPageBarItem* item = self.NTPView.tabBar.items[index];
if (item.identifier == ntp_home::BOOKMARKS_PANEL) { if (item.identifier == ntp_home::BOOKMARKS_PANEL &&
self.selectedNTPPanel = ntp_home::BOOKMARKS_PANEL; !self.bookmarksViewController) {
if (!self.bookmarksViewController) [self.dispatcher showNTPBookmarksPanel];
[self.dispatcher showNTPBookmarksPanel]; } else if (item.identifier == ntp_home::HOME_PANEL &&
} else if (item.identifier == ntp_home::HOME_PANEL) { !self.homeViewController) {
self.selectedNTPPanel = ntp_home::HOME_PANEL; [self.dispatcher showNTPHomePanel];
if (!self.homeViewController) } else if (item.identifier == ntp_home::RECENT_TABS_PANEL &&
[self.dispatcher showNTPHomePanel]; !self.recentTabsViewController) {
} else if (item.identifier == ntp_home::RECENT_TABS_PANEL) { [self.dispatcher showNTPRecentTabsPanel];
self.selectedNTPPanel = ntp_home::RECENT_TABS_PANEL;
if (!self.recentTabsViewController)
[self.dispatcher showNTPRecentTabsPanel];
} }
self.selectedNTPPanel = item.identifier;
// If index changed, follow same path as if a tab bar item was pressed. When // If index changed, follow same path as if a tab bar item was pressed. When
// |index| == |position|, the panel is completely in view. // |index| == |position|, the panel is completely in view.
......
...@@ -8,6 +8,7 @@ source_set("ntp") { ...@@ -8,6 +8,7 @@ source_set("ntp") {
"sc_ntp_coordinator.mm", "sc_ntp_coordinator.mm",
] ]
deps = [ deps = [
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/ntp:ntp_internal", "//ios/chrome/browser/ui/ntp:ntp_internal",
"//ios/clean/chrome/browser/ui/commands", "//ios/clean/chrome/browser/ui/commands",
"//ios/clean/chrome/browser/ui/ntp:ntp_ui", "//ios/clean/chrome/browser/ui/ntp:ntp_ui",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/showcase/ntp/sc_ntp_coordinator.h" #import "ios/showcase/ntp/sc_ntp_coordinator.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h"
#import "ios/clean/chrome/browser/ui/commands/ntp_commands.h" #import "ios/clean/chrome/browser/ui/commands/ntp_commands.h"
#import "ios/clean/chrome/browser/ui/ntp/ntp_view_controller.h" #import "ios/clean/chrome/browser/ui/ntp/ntp_view_controller.h"
...@@ -32,11 +33,11 @@ ...@@ -32,11 +33,11 @@
NewTabPageBarItem* item1 = [NewTabPageBarItem NewTabPageBarItem* item1 = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Item 1" newTabPageBarItemWithTitle:@"Item 1"
identifier:0 identifier:ntp_home::HOME_PANEL
image:[UIImage imageNamed:@"ntp_mv_search"]]; image:[UIImage imageNamed:@"ntp_mv_search"]];
NewTabPageBarItem* item2 = [NewTabPageBarItem NewTabPageBarItem* item2 = [NewTabPageBarItem
newTabPageBarItemWithTitle:@"Item 2" newTabPageBarItemWithTitle:@"Item 2"
identifier:0 identifier:ntp_home::BOOKMARKS_PANEL
image:[UIImage imageNamed:@"ntp_bookmarks"]]; image:[UIImage imageNamed:@"ntp_bookmarks"]];
[ntp setBarItems:@[ item1, item2 ]]; [ntp setBarItems:@[ item1, item2 ]];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment