Commit 27648386 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Hides chevron for Recent Tabs “Show History” Cell.

- Renames TableViewAccessoryItem/Cell to TableViewImageItem/Cell, and
adds a property that makes the chevron optional.
- Adds tests for the new behavior.
- Uses this new property to hide the chevron on Show Full History in
Recent Tabs.

Bug: 910738
Change-Id: I9aeee17ebab52cbfcedb1c56b5e54221a5d7b2dd
Reviewed-on: https://chromium-review.googlesource.com/c/1358967Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613256}
parent d8cd79b9
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
#import "ios/chrome/browser/ui/settings/sync_utils/sync_presenter.h" #import "ios/chrome/browser/ui/settings/sync_utils/sync_presenter.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h" #import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h"
#import "ios/chrome/browser/ui/signin_interaction/public/signin_presenter.h" #import "ios/chrome/browser/ui/signin_interaction/public/signin_presenter.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_accessory_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_activity_indicator_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_activity_indicator_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_disclosure_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_disclosure_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_signin_promo_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_signin_promo_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
...@@ -222,10 +222,11 @@ const int kRecentlyClosedTabsSectionIndex = 0; ...@@ -222,10 +222,11 @@ const int kRecentlyClosedTabsSectionIndex = 0;
[self addRecentlyClosedTabItems]; [self addRecentlyClosedTabItems];
// Add show full history item last. // Add show full history item last.
TableViewAccessoryItem* historyItem = TableViewImageItem* historyItem =
[[TableViewAccessoryItem alloc] initWithType:ItemTypeShowFullHistory]; [[TableViewImageItem alloc] initWithType:ItemTypeShowFullHistory];
historyItem.title = l10n_util::GetNSString(IDS_HISTORY_SHOWFULLHISTORY_LINK); historyItem.title = l10n_util::GetNSString(IDS_HISTORY_SHOWFULLHISTORY_LINK);
historyItem.image = [UIImage imageNamed:@"show_history"]; historyItem.image = [UIImage imageNamed:@"show_history"];
historyItem.hideChevron = YES;
historyItem.cellAccessibilityIdentifier = historyItem.cellAccessibilityIdentifier =
kRecentTabsShowFullHistoryCellAccessibilityIdentifier; kRecentTabsShowFullHistoryCellAccessibilityIdentifier;
[model addItem:historyItem [model addItem:historyItem
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#import "ios/chrome/browser/ui/settings/cells/encryption_item.h" #import "ios/chrome/browser/ui/settings/cells/encryption_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_detail_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_detail_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_accessory_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
...@@ -104,18 +104,22 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -104,18 +104,22 @@ typedef NS_ENUM(NSInteger, ItemType) {
textItem.masked = YES; textItem.masked = YES;
[model addItem:textItem toSectionWithIdentifier:SectionIdentifierText]; [model addItem:textItem toSectionWithIdentifier:SectionIdentifierText];
TableViewAccessoryItem* textAccessoryItem = TableViewImageItem* textImageItem =
[[TableViewAccessoryItem alloc] initWithType:ItemTypeTextAccessoryImage]; [[TableViewImageItem alloc] initWithType:ItemTypeTextAccessoryImage];
textAccessoryItem.title = @"Text Accessory with History Image"; textImageItem.title = @"Image Item with History Image";
textAccessoryItem.image = [UIImage imageNamed:@"show_history"]; textImageItem.image = [UIImage imageNamed:@"show_history"];
[model addItem:textAccessoryItem [model addItem:textImageItem toSectionWithIdentifier:SectionIdentifierText];
toSectionWithIdentifier:SectionIdentifierText];
textImageItem =
textAccessoryItem = [[TableViewAccessoryItem alloc] [[TableViewImageItem alloc] initWithType:ItemTypeTextAccessoryNoImage];
initWithType:ItemTypeTextAccessoryNoImage]; textImageItem.title = @"Image Item with No Image";
textAccessoryItem.title = @"Text Accessory No Image"; [model addItem:textImageItem toSectionWithIdentifier:SectionIdentifierText];
[model addItem:textAccessoryItem
toSectionWithIdentifier:SectionIdentifierText]; textImageItem =
[[TableViewImageItem alloc] initWithType:ItemTypeTextAccessoryNoImage];
textImageItem.title = @"Image Item with No Image and no Chevron";
textImageItem.hideChevron = YES;
[model addItem:textImageItem toSectionWithIdentifier:SectionIdentifierText];
TableViewTextItem* textItemDefault = TableViewTextItem* textItemDefault =
[[TableViewTextItem alloc] initWithType:ItemTypeText]; [[TableViewTextItem alloc] initWithType:ItemTypeText];
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
source_set("cells") { source_set("cells") {
sources = [ sources = [
"table_view_accessory_item.h",
"table_view_accessory_item.mm",
"table_view_activity_indicator_header_footer_item.h", "table_view_activity_indicator_header_footer_item.h",
"table_view_activity_indicator_header_footer_item.mm", "table_view_activity_indicator_header_footer_item.mm",
"table_view_cells_constants.h", "table_view_cells_constants.h",
...@@ -16,6 +14,8 @@ source_set("cells") { ...@@ -16,6 +14,8 @@ source_set("cells") {
"table_view_disclosure_header_footer_item.mm", "table_view_disclosure_header_footer_item.mm",
"table_view_header_footer_item.h", "table_view_header_footer_item.h",
"table_view_header_footer_item.mm", "table_view_header_footer_item.mm",
"table_view_image_item.h",
"table_view_image_item.mm",
"table_view_item.h", "table_view_item.h",
"table_view_item.mm", "table_view_item.mm",
"table_view_link_header_footer_item.h", "table_view_link_header_footer_item.h",
...@@ -62,9 +62,9 @@ source_set("cells") { ...@@ -62,9 +62,9 @@ source_set("cells") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"table_view_accessory_item_unittest.mm",
"table_view_detail_text_item_unittest.mm", "table_view_detail_text_item_unittest.mm",
"table_view_header_footer_item_unittest.mm", "table_view_header_footer_item_unittest.mm",
"table_view_image_item_unittest.mm",
"table_view_item_unittest.mm", "table_view_item_unittest.mm",
"table_view_text_button_item_unittest.mm", "table_view_text_button_item_unittest.mm",
"table_view_text_header_footer_item_unittest.mm", "table_view_text_header_footer_item_unittest.mm",
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_ACCESSORY_ITEM_H_ #ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_IMAGE_ITEM_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_ACCESSORY_ITEM_H_ #define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_IMAGE_ITEM_H_
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
// TableViewAccessoryItem contains the model data for a TableViewAccessoryCell. // TableViewImageItem contains the model data for a TableViewImageCell.
@interface TableViewAccessoryItem : TableViewItem @interface TableViewImageItem : TableViewItem
// The image in the cell. If nil, won't be added to the view hierarchy. // The image in the cell. If nil, won't be added to the view hierarchy.
@property(nonatomic, readwrite, strong) UIImage* image; @property(nonatomic, readwrite, strong) UIImage* image;
...@@ -18,18 +18,21 @@ ...@@ -18,18 +18,21 @@
@property(nonatomic, readwrite, copy) NSString* title; @property(nonatomic, readwrite, copy) NSString* title;
// The accessibility identifier for the cell. // The accessibility identifier for the cell.
@property(nonatomic, readwrite, copy) NSString* cellAccessibilityIdentifier; @property(nonatomic, readwrite, copy) NSString* cellAccessibilityIdentifier;
// If YES the cell's chevron will be hidden.
@property(nonatomic, readwrite, assign) BOOL hideChevron;
@end @end
// TableViewAccessoryCell contains a favicon, a title, and an accessory. // TableViewImageCell contains a favicon, a title, and an optional chevron.
@interface TableViewAccessoryCell : UITableViewCell @interface TableViewImageCell : UITableViewCell
// The cell favicon imageView. // The cell favicon imageView.
@property(nonatomic, readonly, strong) UIImageView* imageView; @property(nonatomic, readonly, strong) UIImageView* imageView;
// The cell title. // The cell title.
@property(nonatomic, readonly, strong) UILabel* titleLabel; @property(nonatomic, readonly, strong) UILabel* titleLabel;
// The chevron ImageView.
@property(nonatomic, readonly, strong) UIImageView* chevronImageView;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_ACCESSORY_ITEM_H_ #endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_IMAGE_ITEM_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/cells/table_view_accessory_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@implementation TableViewAccessoryItem @implementation TableViewImageItem
@synthesize cellAccessibilityIdentifier = _cellAccessibilityIdentifier; @synthesize cellAccessibilityIdentifier = _cellAccessibilityIdentifier;
@synthesize image = _image; @synthesize image = _image;
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type]; self = [super initWithType:type];
if (self) { if (self) {
self.cellClass = [TableViewAccessoryCell class]; self.cellClass = [TableViewImageCell class];
} }
return self; return self;
} }
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:tableCell withStyler:styler]; [super configureCell:tableCell withStyler:styler];
TableViewAccessoryCell* cell = TableViewImageCell* cell =
base::mac::ObjCCastStrict<TableViewAccessoryCell>(tableCell); base::mac::ObjCCastStrict<TableViewImageCell>(tableCell);
if (self.image) { if (self.image) {
cell.imageView.hidden = NO; cell.imageView.hidden = NO;
cell.imageView.image = self.image; cell.imageView.image = self.image;
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
cell.titleLabel.text = self.title; cell.titleLabel.text = self.title;
cell.accessibilityIdentifier = self.cellAccessibilityIdentifier; cell.accessibilityIdentifier = self.cellAccessibilityIdentifier;
cell.chevronImageView.hidden = self.hideChevron;
cell.imageView.backgroundColor = styler.tableViewBackgroundColor; cell.imageView.backgroundColor = styler.tableViewBackgroundColor;
cell.titleLabel.backgroundColor = styler.tableViewBackgroundColor; cell.titleLabel.backgroundColor = styler.tableViewBackgroundColor;
if (styler.cellTitleColor) if (styler.cellTitleColor)
...@@ -51,7 +52,7 @@ ...@@ -51,7 +52,7 @@
@end @end
@implementation TableViewAccessoryCell @implementation TableViewImageCell
@synthesize imageView = _imageView; @synthesize imageView = _imageView;
@synthesize titleLabel = _titleLabel; @synthesize titleLabel = _titleLabel;
...@@ -73,19 +74,19 @@ ...@@ -73,19 +74,19 @@
_titleLabel.adjustsFontForContentSizeCategory = YES; _titleLabel.adjustsFontForContentSizeCategory = YES;
// Disclosure ImageView. // Disclosure ImageView.
UIImageView* disclosureImageView = [[UIImageView alloc] _chevronImageView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"table_view_cell_chevron"]]; initWithImage:[UIImage imageNamed:@"table_view_cell_chevron"]];
[disclosureImageView [_chevronImageView
setContentHuggingPriority:UILayoutPriorityDefaultHigh setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal]; forAxis:UILayoutConstraintAxisHorizontal];
// TODO(crbug.com/870841): Use default accessory type. // TODO(crbug.com/870841): Use default accessory type.
if (base::i18n::IsRTL()) if (base::i18n::IsRTL())
disclosureImageView.transform = CGAffineTransformMakeRotation(M_PI); _chevronImageView.transform = CGAffineTransformMakeRotation(M_PI);
// Horizontal stack view holds imageView, title, and disclosureView. // Horizontal stack view holds imageView, title, and disclosureView.
UIStackView* horizontalStack = UIStackView* horizontalStack =
[[UIStackView alloc] initWithArrangedSubviews:@[ [[UIStackView alloc] initWithArrangedSubviews:@[
_imageView, _titleLabel, disclosureImageView _imageView, _titleLabel, _chevronImageView
]]; ]];
horizontalStack.axis = UILayoutConstraintAxisHorizontal; horizontalStack.axis = UILayoutConstraintAxisHorizontal;
horizontalStack.spacing = kTableViewSubViewHorizontalSpacing; horizontalStack.spacing = kTableViewSubViewHorizontalSpacing;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/cells/table_view_accessory_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
...@@ -15,47 +15,64 @@ ...@@ -15,47 +15,64 @@
#endif #endif
namespace { namespace {
using TableViewAccessoryItemTest = PlatformTest; using TableViewImageItemTest = PlatformTest;
} }
// Tests that the UILabel is set properly after a call to // Tests that the UILabel is set properly after a call to
// |configureCell:| and the image is visible. // |configureCell:| and the image and chevron are visible.
TEST_F(TableViewAccessoryItemTest, ItemProperties) { TEST_F(TableViewImageItemTest, ItemProperties) {
NSString* text = @"Cell text"; NSString* text = @"Cell text";
TableViewAccessoryItem* item = TableViewImageItem* item = [[TableViewImageItem alloc] initWithType:0];
[[TableViewAccessoryItem alloc] initWithType:0];
item.title = text; item.title = text;
item.image = [[UIImage alloc] init]; item.image = [[UIImage alloc] init];
id cell = [[[item cellClass] alloc] init]; id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewAccessoryCell class]]); ASSERT_TRUE([cell isMemberOfClass:[TableViewImageCell class]]);
TableViewAccessoryCell* accessoryCell = TableViewImageCell* imageCell =
base::mac::ObjCCastStrict<TableViewAccessoryCell>(cell); base::mac::ObjCCastStrict<TableViewImageCell>(cell);
EXPECT_FALSE(accessoryCell.textLabel.text); EXPECT_FALSE(imageCell.textLabel.text);
EXPECT_FALSE(accessoryCell.imageView.image); EXPECT_FALSE(imageCell.imageView.image);
[item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]]; [item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
EXPECT_NSEQ(text, accessoryCell.titleLabel.text); EXPECT_NSEQ(text, imageCell.titleLabel.text);
EXPECT_FALSE(accessoryCell.imageView.isHidden); EXPECT_FALSE(imageCell.imageView.isHidden);
EXPECT_FALSE(imageCell.chevronImageView.isHidden);
} }
// Tests that the imageView is not visible if no image is set. // Tests that the imageView is not visible if no image is set.
TEST_F(TableViewAccessoryItemTest, ItemImageViewHidden) { TEST_F(TableViewImageItemTest, ItemImageViewHidden) {
NSString* text = @"Cell text"; NSString* text = @"Cell text";
TableViewAccessoryItem* item = TableViewImageItem* item = [[TableViewImageItem alloc] initWithType:0];
[[TableViewAccessoryItem alloc] initWithType:0];
item.title = text; item.title = text;
id cell = [[[item cellClass] alloc] init]; id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewAccessoryCell class]]); ASSERT_TRUE([cell isMemberOfClass:[TableViewImageCell class]]);
TableViewAccessoryCell* accessoryCell = TableViewImageCell* imageCell =
base::mac::ObjCCastStrict<TableViewAccessoryCell>(cell); base::mac::ObjCCastStrict<TableViewImageCell>(cell);
EXPECT_FALSE(item.image); EXPECT_FALSE(item.image);
[item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]]; [item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
EXPECT_FALSE(item.image); EXPECT_FALSE(item.image);
EXPECT_TRUE(accessoryCell.imageView.isHidden); EXPECT_TRUE(imageCell.imageView.isHidden);
}
// Tests that the chevron is not visible if hideChevron is YES.
TEST_F(TableViewImageItemTest, ItemChevronViewHidden) {
NSString* text = @"Cell text";
TableViewImageItem* item = [[TableViewImageItem alloc] initWithType:0];
item.title = text;
item.hideChevron = YES;
id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewImageCell class]]);
TableViewImageCell* imageCell =
base::mac::ObjCCastStrict<TableViewImageCell>(cell);
EXPECT_FALSE(imageCell.chevronImageView.isHidden);
[item configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
EXPECT_TRUE(imageCell.chevronImageView.isHidden);
} }
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