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

[ios] Removes LegacyBookmark classes and cleans up

-Deletes the following unused classes: BookmarkElevatedToolbar, LegacyBookmarkParentFolderItem,
LegacyBookmarkTextFieldItem.
-Creates a BookmarkUIConstants file.
-Adds a Legacy prefix to BookmarkCells, to prepare for refresh cells.

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I35662f194eaada4f95cbf46b636426cc98767ca4
Reviewed-on: https://chromium-review.googlesource.com/1049064Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557541}
parent 7b703c59
...@@ -7,8 +7,6 @@ source_set("bookmarks") { ...@@ -7,8 +7,6 @@ source_set("bookmarks") {
sources = [ sources = [
"bookmark_edit_view_controller.h", "bookmark_edit_view_controller.h",
"bookmark_edit_view_controller.mm", "bookmark_edit_view_controller.mm",
"bookmark_elevated_toolbar.h",
"bookmark_elevated_toolbar.mm",
"bookmark_empty_background.h", "bookmark_empty_background.h",
"bookmark_empty_background.mm", "bookmark_empty_background.mm",
"bookmark_folder_editor_view_controller.h", "bookmark_folder_editor_view_controller.h",
...@@ -46,6 +44,7 @@ source_set("bookmarks") { ...@@ -46,6 +44,7 @@ source_set("bookmarks") {
"undo_manager_wrapper.mm", "undo_manager_wrapper.mm",
] ]
deps = [ deps = [
":bookmarks_ui",
"resources:bookmark_bar_innershadow", "resources:bookmark_bar_innershadow",
"resources:bookmark_bar_shadow", "resources:bookmark_bar_shadow",
"resources:bookmark_black_delete", "resources:bookmark_black_delete",
...@@ -132,6 +131,15 @@ source_set("bookmarks") { ...@@ -132,6 +131,15 @@ source_set("bookmarks") {
] ]
} }
source_set("bookmarks_ui") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"bookmark_ui_constants.h",
"bookmark_ui_constants.mm",
]
deps = []
}
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
...@@ -164,6 +172,7 @@ source_set("eg_tests") { ...@@ -164,6 +172,7 @@ source_set("eg_tests") {
"bookmarks_egtest.mm", "bookmarks_egtest.mm",
] ]
deps = [ deps = [
":bookmarks_ui",
"//base", "//base",
"//components/bookmarks/browser", "//components/bookmarks/browser",
"//components/prefs", "//components/prefs",
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_mediator.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_mediator.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_parent_folder_item.h" #import "ios/chrome/browser/ui/bookmarks/cells/bookmark_parent_folder_item.h"
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_text_field_item.h" #import "ios/chrome/browser/ui/bookmarks/cells/bookmark_text_field_item.h"
...@@ -230,7 +231,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -230,7 +231,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(deleteBookmark)]; action:@selector(deleteBookmark)];
deleteButton.accessibilityIdentifier = @"Delete_action"; deleteButton.accessibilityIdentifier = kBookmarkEditDeleteButtonIdentifier;
deleteButton.tintColor = [UIColor blackColor]; deleteButton.tintColor = [UIColor blackColor];
UIBarButtonItem* spaceButton = [[UIBarButtonItem alloc] UIBarButtonItem* spaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
...@@ -455,8 +456,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -455,8 +456,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
break; break;
case ItemTypeURL: { case ItemTypeURL: {
BookmarkTextFieldCell* URLCell = LegacyBookmarkTextFieldCell* URLCell =
base::mac::ObjCCastStrict<BookmarkTextFieldCell>(cell); base::mac::ObjCCastStrict<LegacyBookmarkTextFieldCell>(cell);
URLCell.textField.textValidator = self; URLCell.textField.textValidator = self;
URLCell.selectionStyle = UITableViewCellSelectionStyleNone; URLCell.selectionStyle = UITableViewCellSelectionStyleNone;
break; break;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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_BOOKMARKS_BOOKMARK_ELEVATED_TOOLBAR_H_
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_ELEVATED_TOOLBAR_H_
#import <UIKit/UIKit.h>
@class MDCButton;
// A class containing one button that has a Material shadow.
@interface BookmarksElevatedToolbar : UIView
@property(nonatomic, assign) CGFloat shadowElevation;
- (void)setButton:(MDCButton*)button;
@end
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_ELEVATED_TOOLBAR_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/bookmarks/bookmark_elevated_toolbar.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Buttons/src/MDCButton.h"
#import "ios/third_party/material_components_ios/src/components/ShadowElevations/src/MaterialShadowElevations.h"
#import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/MaterialShadowLayer.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kButtonHeight = 48;
}
@interface BookmarksElevatedToolbar ()
@property(nonatomic, readonly) MDCShadowLayer* shadowLayer;
@property(nonatomic, strong) MDCButton* currentButton;
@end
@implementation BookmarksElevatedToolbar
@synthesize currentButton = _currentButton;
@synthesize shadowLayer = _shadowLayer;
- (instancetype)init {
self = [super init];
if (self) {
[self.layer addSublayer:[[MDCShadowLayer alloc] init]];
self.shadowElevation = MDCShadowElevationSearchBarResting;
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
- (void)setButton:(MDCButton*)button {
[self.currentButton removeFromSuperview];
self.currentButton = button;
if (!button)
return;
[self addSubview:button];
button.translatesAutoresizingMaskIntoConstraints = NO;
id<LayoutGuideProvider> safeAreaLayoutGuide =
SafeAreaLayoutGuideForView(self);
[NSLayoutConstraint activateConstraints:@[
[button.leadingAnchor
constraintEqualToAnchor:safeAreaLayoutGuide.leadingAnchor],
[button.topAnchor constraintEqualToAnchor:safeAreaLayoutGuide.topAnchor],
[button.bottomAnchor
constraintEqualToAnchor:safeAreaLayoutGuide.bottomAnchor],
[button.heightAnchor constraintEqualToConstant:kButtonHeight],
]];
}
#pragma mark - Properties
- (MDCShadowLayer*)shadowLayer {
if (!_shadowLayer) {
_shadowLayer = [[MDCShadowLayer alloc] init];
_shadowLayer.elevation = MDCShadowElevationNone;
[self.layer addSublayer:self.shadowLayer];
}
return _shadowLayer;
}
- (void)setShadowElevation:(CGFloat)shadowElevation {
self.shadowLayer.elevation = shadowElevation;
}
- (CGFloat)shadowElevation {
return self.shadowLayer.elevation;
}
#pragma mark - UIView
- (void)layoutSubviews {
[super layoutSubviews];
self.shadowLayer.frame = self.layer.bounds;
}
@end
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/bookmarks/browser/bookmark_node.h" #include "components/bookmarks/browser/bookmark_node.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_parent_folder_item.h" #import "ios/chrome/browser/ui/bookmarks/cells/bookmark_parent_folder_item.h"
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_text_field_item.h" #import "ios/chrome/browser/ui/bookmarks/cells/bookmark_text_field_item.h"
...@@ -456,7 +457,8 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel ...@@ -456,7 +457,8 @@ folderEditorWithBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel
style:UIBarButtonItemStylePlain style:UIBarButtonItemStylePlain
target:self target:self
action:@selector(deleteFolder)]; action:@selector(deleteFolder)];
deleteButton.accessibilityIdentifier = @"Delete Folder"; deleteButton.accessibilityIdentifier =
kBookmarkFolderEditorDeleteButtonIdentifier;
deleteButton.tintColor = [UIColor blackColor]; deleteButton.tintColor = [UIColor blackColor];
UIBarButtonItem* spaceButton = [[UIBarButtonItem alloc] UIBarButtonItem* spaceButton = [[UIBarButtonItem alloc]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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_BOOKMARKS_BOOKMARK_UI_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UI_CONSTANTS_H_
#import <Foundation/Foundation.h>
// Accessibility identifier of the BookmarkEditVC toolbar delete button.
extern NSString* const kBookmarkEditDeleteButtonIdentifier;
// Accessibility identifier of the BookmarkFolderEditorVC toolbar delete button.
extern NSString* const kBookmarkFolderEditorDeleteButtonIdentifier;
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UI_CONSTANTS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/bookmarks/bookmark_ui_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kBookmarkEditDeleteButtonIdentifier =
@"kBookmarkEditDeleteButtonIdentifier";
NSString* const kBookmarkFolderEditorDeleteButtonIdentifier =
@"kBookmarkFolderEditorDeleteButtonIdentifier";
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h" #import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/authentication/signin_promo_view.h" #import "ios/chrome/browser/ui/authentication/signin_promo_view.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_path_cache.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_path_cache.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/toolbar/buttons/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/buttons/toolbar_constants.h"
#import "ios/chrome/browser/ui/toolbar/legacy/toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/legacy/toolbar_controller_constants.h"
...@@ -215,7 +216,8 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -215,7 +216,8 @@ id<GREYMatcher> CloseToolsMenuButton() {
// Clear the bookmark via the UI. // Clear the bookmark via the UI.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarLitLabel)] [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarLitLabel)]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Delete_action")] [[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kBookmarkEditDeleteButtonIdentifier)]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the bookmark is not in the BookmarkModel. // Verify the bookmark is not in the BookmarkModel.
...@@ -1654,7 +1656,9 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -1654,7 +1656,9 @@ id<GREYMatcher> CloseToolsMenuButton() {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder Editor")] [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Folder Editor")]
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Delete Folder")] [[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditorDeleteButtonIdentifier)]
performAction:grey_tap()]; performAction:grey_tap()];
// Wait for Undo toast to go away from screen. // Wait for Undo toast to go away from screen.
...@@ -2068,7 +2072,9 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -2068,7 +2072,9 @@ id<GREYMatcher> CloseToolsMenuButton() {
performAction:grey_tap()]; performAction:grey_tap()];
// Delete it. // Delete it.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Delete Folder")] [[EarlGrey
selectElementWithMatcher:grey_accessibilityID(
kBookmarkFolderEditorDeleteButtonIdentifier)]
performAction:grey_tap()]; performAction:grey_tap()];
// Wait until it's gone. // Wait until it's gone.
......
...@@ -18,10 +18,6 @@ source_set("cells") { ...@@ -18,10 +18,6 @@ source_set("cells") {
"bookmark_table_signin_promo_cell.mm", "bookmark_table_signin_promo_cell.mm",
"bookmark_text_field_item.h", "bookmark_text_field_item.h",
"bookmark_text_field_item.mm", "bookmark_text_field_item.mm",
"legacy_bookmark_parent_folder_item.h",
"legacy_bookmark_parent_folder_item.mm",
"legacy_bookmark_text_field_item.h",
"legacy_bookmark_text_field_item.mm",
] ]
deps = [ deps = [
...@@ -31,7 +27,6 @@ source_set("cells") { ...@@ -31,7 +27,6 @@ source_set("cells") {
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/authentication", "//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/authentication:authentication_ui", "//ios/chrome/browser/ui/authentication:authentication_ui",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors", "//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/icons", "//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/table_view:styler", "//ios/chrome/browser/ui/table_view:styler",
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
@end @end
// Cell class associated to BookmarkParentFolderItem. // Legacy Cell class associated to BookmarkParentFolderItem.
@interface BookmarkParentFolderCell : UITableViewCell @interface LegacyBookmarkParentFolderCell : UITableViewCell
// Label that displays the item's title. // Label that displays the item's title.
@property(nonatomic, readonly, strong) UILabel* parentFolderNameLabel; @property(nonatomic, readonly, strong) UILabel* parentFolderNameLabel;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
self = [super initWithType:type]; self = [super initWithType:type];
if (self) { if (self) {
self.accessibilityIdentifier = @"Change Folder"; self.accessibilityIdentifier = @"Change Folder";
self.cellClass = [BookmarkParentFolderCell class]; self.cellClass = [LegacyBookmarkParentFolderCell class];
} }
return self; return self;
} }
...@@ -34,19 +34,19 @@ ...@@ -34,19 +34,19 @@
- (void)configureCell:(UITableViewCell*)tableCell - (void)configureCell:(UITableViewCell*)tableCell
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:tableCell withStyler:styler]; [super configureCell:tableCell withStyler:styler];
BookmarkParentFolderCell* cell = LegacyBookmarkParentFolderCell* cell =
base::mac::ObjCCastStrict<BookmarkParentFolderCell>(tableCell); base::mac::ObjCCastStrict<LegacyBookmarkParentFolderCell>(tableCell);
cell.parentFolderNameLabel.text = self.title; cell.parentFolderNameLabel.text = self.title;
} }
@end @end
@interface BookmarkParentFolderCell () @interface LegacyBookmarkParentFolderCell ()
@property(nonatomic, readwrite, strong) UILabel* parentFolderNameLabel; @property(nonatomic, readwrite, strong) UILabel* parentFolderNameLabel;
@property(nonatomic, strong) UILabel* decorationLabel; @property(nonatomic, strong) UILabel* decorationLabel;
@end @end
@implementation BookmarkParentFolderCell @implementation LegacyBookmarkParentFolderCell
@synthesize parentFolderNameLabel = _parentFolderNameLabel; @synthesize parentFolderNameLabel = _parentFolderNameLabel;
@synthesize decorationLabel = _decorationLabel; @synthesize decorationLabel = _decorationLabel;
......
...@@ -21,8 +21,8 @@ using BookmarkParentFolderItemTest = PlatformTest; ...@@ -21,8 +21,8 @@ using BookmarkParentFolderItemTest = PlatformTest;
TEST_F(BookmarkParentFolderItemTest, LabelGetsTitle) { TEST_F(BookmarkParentFolderItemTest, LabelGetsTitle) {
BookmarkParentFolderItem* item = BookmarkParentFolderItem* item =
[[BookmarkParentFolderItem alloc] initWithType:0]; [[BookmarkParentFolderItem alloc] initWithType:0];
BookmarkParentFolderCell* cell = LegacyBookmarkParentFolderCell* cell =
[[BookmarkParentFolderCell alloc] initWithFrame:CGRectZero]; [[LegacyBookmarkParentFolderCell alloc] initWithFrame:CGRectZero];
ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init]; ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init];
item.title = @"Foo"; item.title = @"Foo";
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
@end @end
@interface BookmarkTextFieldCell : UITableViewCell @interface LegacyBookmarkTextFieldCell : UITableViewCell
// Text field to display the title or the URL of the bookmark node. // Text field to display the title or the URL of the bookmark node.
@property(nonatomic, readonly, strong) UITextField<TextFieldStyling>* textField; @property(nonatomic, readonly, strong) UITextField<TextFieldStyling>* textField;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type]; self = [super initWithType:type];
if (self) { if (self) {
self.cellClass = [BookmarkTextFieldCell class]; self.cellClass = [LegacyBookmarkTextFieldCell class];
} }
return self; return self;
} }
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:tableCell withStyler:styler]; [super configureCell:tableCell withStyler:styler];
BookmarkTextFieldCell* cell = LegacyBookmarkTextFieldCell* cell =
base::mac::ObjCCastStrict<BookmarkTextFieldCell>(tableCell); base::mac::ObjCCastStrict<LegacyBookmarkTextFieldCell>(tableCell);
cell.textField.text = self.text; cell.textField.text = self.text;
cell.textField.placeholder = self.placeholder; cell.textField.placeholder = self.placeholder;
cell.textField.tag = self.type; cell.textField.tag = self.type;
...@@ -58,12 +58,12 @@ ...@@ -58,12 +58,12 @@
@end @end
@interface BookmarkTextFieldCell () @interface LegacyBookmarkTextFieldCell ()
@property(nonatomic, readwrite, strong) @property(nonatomic, readwrite, strong)
UITextField<TextFieldStyling>* textField; UITextField<TextFieldStyling>* textField;
@end @end
@implementation BookmarkTextFieldCell @implementation LegacyBookmarkTextFieldCell
@synthesize textField = _textField; @synthesize textField = _textField;
......
...@@ -20,8 +20,8 @@ using BookmarkTextFieldItemTest = PlatformTest; ...@@ -20,8 +20,8 @@ using BookmarkTextFieldItemTest = PlatformTest;
TEST_F(BookmarkTextFieldItemTest, DelegateGetsTextFieldEvents) { TEST_F(BookmarkTextFieldItemTest, DelegateGetsTextFieldEvents) {
BookmarkTextFieldItem* item = [[BookmarkTextFieldItem alloc] initWithType:0]; BookmarkTextFieldItem* item = [[BookmarkTextFieldItem alloc] initWithType:0];
BookmarkTextFieldCell* cell = LegacyBookmarkTextFieldCell* cell =
[[BookmarkTextFieldCell alloc] initWithFrame:CGRectZero]; [[LegacyBookmarkTextFieldCell alloc] initWithFrame:CGRectZero];
id mockDelegate = id mockDelegate =
[OCMockObject mockForProtocol:@protocol(BookmarkTextFieldItemDelegate)]; [OCMockObject mockForProtocol:@protocol(BookmarkTextFieldItemDelegate)];
ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init]; ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init];
...@@ -36,8 +36,8 @@ TEST_F(BookmarkTextFieldItemTest, DelegateGetsTextFieldEvents) { ...@@ -36,8 +36,8 @@ TEST_F(BookmarkTextFieldItemTest, DelegateGetsTextFieldEvents) {
TEST_F(BookmarkTextFieldItemTest, TextFieldGetsText) { TEST_F(BookmarkTextFieldItemTest, TextFieldGetsText) {
BookmarkTextFieldItem* item = [[BookmarkTextFieldItem alloc] initWithType:0]; BookmarkTextFieldItem* item = [[BookmarkTextFieldItem alloc] initWithType:0];
BookmarkTextFieldCell* cell = LegacyBookmarkTextFieldCell* cell =
[[BookmarkTextFieldCell alloc] initWithFrame:CGRectZero]; [[LegacyBookmarkTextFieldCell alloc] initWithFrame:CGRectZero];
ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init]; ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init];
item.text = @"Foo"; item.text = @"Foo";
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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_BOOKMARKS_CELLS_LEGACY_BOOKMARK_PARENT_FOLDER_ITEM_H_
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_CELLS_LEGACY_BOOKMARK_PARENT_FOLDER_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
// Item to display the name of the parent folder of a bookmark node.
@interface LegacyBookmarkParentFolderItem : CollectionViewItem
// The title of the bookmark folder it represents.
@property(nonatomic, copy) NSString* title;
@end
// Cell class associated to LegacyBookmarkParentFolderItem.
@interface LegacyBookmarkParentFolderCell : MDCCollectionViewCell
// Label that displays the item's title.
@property(nonatomic, readonly, strong) UILabel* parentFolderNameLabel;
@end
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_CELLS_LEGACY_BOOKMARK_PARENT_FOLDER_ITEM_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/bookmarks/cells/legacy_bookmark_parent_folder_item.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/icons/chrome_icon.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface LegacyBookmarkParentFolderCell ()
@property(nonatomic, readwrite, strong) UILabel* parentFolderNameLabel;
@property(nonatomic, strong) UILabel* decorationLabel;
@end
@implementation LegacyBookmarkParentFolderItem
@synthesize title = _title;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.accessibilityIdentifier = @"Change Folder";
self.cellClass = [LegacyBookmarkParentFolderCell class];
}
return self;
}
#pragma mark CollectionViewItem
- (void)configureCell:(LegacyBookmarkParentFolderCell*)cell {
[super configureCell:cell];
cell.parentFolderNameLabel.text = self.title;
}
@end
@implementation LegacyBookmarkParentFolderCell
@synthesize parentFolderNameLabel = _parentFolderNameLabel;
@synthesize decorationLabel = _decorationLabel;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self)
return nil;
self.isAccessibilityElement = YES;
self.accessibilityTraits |= UIAccessibilityTraitButton;
const CGFloat kHorizontalPadding = 15;
const CGFloat kVerticalPadding = 8;
const CGFloat kParentFolderLabelTopPadding = 7;
_decorationLabel = [[UILabel alloc] init];
_decorationLabel.translatesAutoresizingMaskIntoConstraints = NO;
_decorationLabel.text = l10n_util::GetNSString(IDS_IOS_BOOKMARK_GROUP_BUTTON);
_decorationLabel.font = [[MDCTypography fontLoader] regularFontOfSize:12];
_decorationLabel.textColor = bookmark_utils_ios::lightTextColor();
[self.contentView addSubview:_decorationLabel];
_parentFolderNameLabel = [[UILabel alloc] init];
_parentFolderNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
_parentFolderNameLabel.font =
[[MDCTypography fontLoader] regularFontOfSize:16];
_parentFolderNameLabel.textColor =
[UIColor colorWithWhite:33.0 / 255.0 alpha:1.0];
_parentFolderNameLabel.textAlignment = NSTextAlignmentNatural;
[self.contentView addSubview:_parentFolderNameLabel];
UIImageView* navigationChevronImage = [[UIImageView alloc] init];
UIImage* image = TintImage([ChromeIcon chevronIcon], [UIColor grayColor]);
navigationChevronImage.image = image;
navigationChevronImage.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:navigationChevronImage];
// Set up the constraints.
[NSLayoutConstraint activateConstraints:@[
[_decorationLabel.topAnchor constraintEqualToAnchor:self.topAnchor
constant:kVerticalPadding],
[_decorationLabel.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
constant:kHorizontalPadding],
[_parentFolderNameLabel.topAnchor
constraintEqualToAnchor:_decorationLabel.bottomAnchor
constant:kParentFolderLabelTopPadding],
[_parentFolderNameLabel.leadingAnchor
constraintEqualToAnchor:_decorationLabel.leadingAnchor],
[navigationChevronImage.centerYAnchor
constraintEqualToAnchor:_parentFolderNameLabel.centerYAnchor],
[navigationChevronImage.leadingAnchor
constraintEqualToAnchor:_parentFolderNameLabel.trailingAnchor],
[navigationChevronImage.widthAnchor
constraintEqualToConstant:navigationChevronImage.image.size.width],
[navigationChevronImage.trailingAnchor
constraintEqualToAnchor:self.trailingAnchor
constant:-kHorizontalPadding],
]];
self.shouldHideSeparator = YES;
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.parentFolderNameLabel.text = nil;
}
- (NSString*)accessibilityLabel {
return self.parentFolderNameLabel.text;
}
- (NSString*)accessibilityHint {
return l10n_util::GetNSString(
IDS_IOS_BOOKMARK_EDIT_PARENT_FOLDER_BUTTON_HINT);
}
@end
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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_BOOKMARKS_CELLS_LEGACY_BOOKMARK_TEXT_FIELD_ITEM_H_
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_CELLS_LEGACY_BOOKMARK_TEXT_FIELD_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
@class LegacyBookmarkTextFieldItem;
@protocol TextFieldStyling;
// Delegates the cell's text field's events.
@protocol LegacyBookmarkTextFieldItemDelegate<UITextFieldDelegate>
// Called when the |text| of the item was changed via the textfield. The item's
// |text| is up-to-date when this is called.
- (void)textDidChangeForItem:(LegacyBookmarkTextFieldItem*)item;
@end
@interface LegacyBookmarkTextFieldItem : CollectionViewItem
// The text field content.
@property(nonatomic, copy) NSString* text;
// The text field placeholder.
@property(nonatomic, copy) NSString* placeholder;
// Receives the text field events.
@property(nonatomic, weak) id<LegacyBookmarkTextFieldItemDelegate> delegate;
@end
@interface LegacyBookmarkTextFieldCell : MDCCollectionViewCell
// Text field to display the title or the URL of the bookmark node.
@property(nonatomic, readonly, strong) UITextField<TextFieldStyling>* textField;
@end
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_CELLS_LEGACY_BOOKMARK_TEXT_FIELD_ITEM_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/bookmarks/cells/legacy_bookmark_text_field_item.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/ui/text_field_styling.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface LegacyBookmarkTextFieldCell ()
@property(nonatomic, readwrite, strong)
UITextField<TextFieldStyling>* textField;
@end
@implementation LegacyBookmarkTextFieldItem
@synthesize text = _text;
@synthesize placeholder = _placeholder;
@synthesize delegate = _delegate;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [LegacyBookmarkTextFieldCell class];
}
return self;
}
#pragma mark CollectionViewItem
- (void)configureCell:(LegacyBookmarkTextFieldCell*)cell {
[super configureCell:cell];
cell.textField.text = self.text;
cell.textField.placeholder = self.placeholder;
cell.textField.tag = self.type;
[cell.textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
cell.textField.delegate = self.delegate;
cell.textField.accessibilityLabel = self.text;
cell.textField.accessibilityIdentifier =
[NSString stringWithFormat:@"%@_textField", self.accessibilityIdentifier];
}
#pragma mark UIControlEventEditingChanged
- (void)textFieldDidChange:(UITextField*)textField {
DCHECK_EQ(textField.tag, self.type);
self.text = textField.text;
[self.delegate textDidChangeForItem:self];
}
@end
@implementation LegacyBookmarkTextFieldCell
@synthesize textField = _textField;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_textField =
ios::GetChromeBrowserProvider()->CreateStyledTextField(CGRectZero);
_textField.translatesAutoresizingMaskIntoConstraints = NO;
_textField.textColor = bookmark_utils_ios::darkTextColor();
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
_textField.placeholderStyle =
TextFieldStylingPlaceholderFloatingPlaceholder;
[self.contentView addSubview:_textField];
const CGFloat kHorizontalPadding = 15;
const CGFloat kTopPadding = 8;
[NSLayoutConstraint activateConstraints:@[
[_textField.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
constant:kHorizontalPadding],
[_textField.topAnchor constraintEqualToAnchor:self.topAnchor
constant:kTopPadding],
[_textField.trailingAnchor constraintEqualToAnchor:self.trailingAnchor
constant:-kHorizontalPadding],
]];
self.shouldHideSeparator = YES;
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.textField resignFirstResponder];
[self.textField removeTarget:nil
action:NULL
forControlEvents:UIControlEventAllEvents];
self.textField.delegate = nil;
self.textField.text = nil;
self.textField.textValidator = nil;
}
@end
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