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