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

Add section separator for the tools menu

This CL adds a section separator for the tools menu, displayed as an
item with a grey line in the middle.

Bug: 804773
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I70d783ee0db85b8889dda5bbbe0d8ab2714a04a6
Reviewed-on: https://chromium-review.googlesource.com/977911Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546070}
parent b123aca0
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
source_set("cells") { source_set("cells") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"popup_menu_footer_item.h",
"popup_menu_footer_item.mm",
"popup_menu_item.h", "popup_menu_item.h",
"popup_menu_navigation_item.h", "popup_menu_navigation_item.h",
"popup_menu_navigation_item.mm", "popup_menu_navigation_item.mm",
......
// 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_POPUP_MENU_CELLS_POPUP_MENU_FOOTER_ITEM_H_
#define IOS_CHROME_BROWSER_UI_POPUP_MENU_CELLS_POPUP_MENU_FOOTER_ITEM_H_
#import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h"
// Item for a popup menu footer.
@interface PopupMenuFooterItem : TableViewHeaderFooterItem
@end
// Associated footer for the PopupMenuFooterItem.
@interface PopupMenuFooterCell : UITableViewHeaderFooterView
@end
#endif // IOS_CHROME_BROWSER_UI_POPUP_MENU_CELLS_POPUP_MENU_FOOTER_ITEM_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/popup_menu/cells/popup_menu_footer_item.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kSeparatorHeight = 2;
const CGFloat kSeparatorMargin = 12;
} // namespace
@implementation PopupMenuFooterItem
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [PopupMenuFooterCell class];
}
return self;
}
- (void)configureHeaderFooterView:(PopupMenuFooterCell*)footer
withStyler:(ChromeTableViewStyler*)styler {
[super configureHeaderFooterView:footer withStyler:styler];
// By default the table view footers have a background view. Remove it so it
// is transparent.
footer.backgroundView = nil;
}
@end
#pragma mark - PopupMenuFooterCell
@implementation PopupMenuFooterCell
- (instancetype)initWithReuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) {
UIView* separator = [[UIView alloc] init];
separator.translatesAutoresizingMaskIntoConstraints = NO;
separator.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubview:separator];
[NSLayoutConstraint activateConstraints:@[
[separator.heightAnchor constraintEqualToConstant:kSeparatorHeight],
[separator.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kSeparatorMargin],
[separator.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kSeparatorMargin],
[separator.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
]];
}
return self;
}
@end
...@@ -79,7 +79,8 @@ ...@@ -79,7 +79,8 @@
- (void)showToolsMenuPopup { - (void)showToolsMenuPopup {
PopupMenuTableViewController* tableViewController = PopupMenuTableViewController* tableViewController =
[[PopupMenuTableViewController alloc] init]; [[PopupMenuTableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
tableViewController.dispatcher = tableViewController.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands>>(self.dispatcher); static_cast<id<ApplicationCommands, BrowserCommands>>(self.dispatcher);
tableViewController.baseViewController = self.baseViewController; tableViewController.baseViewController = self.baseViewController;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
namespace { namespace {
const CGFloat kMinHeight = 200; const CGFloat kMinHeight = 200;
const CGFloat kMinWidth = 200; const CGFloat kMinWidth = 200;
const CGFloat kMaxWidth = 250; const CGFloat kMaxWidth = 300;
const CGFloat kMaxHeight = 400; const CGFloat kMaxHeight = 400;
const CGFloat kMinMargin = 16; const CGFloat kMinMargin = 16;
} // namespace } // namespace
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h" #import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_footer_item.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.h" #import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.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"
...@@ -18,6 +19,10 @@ ...@@ -18,6 +19,10 @@
using base::UserMetricsAction; using base::UserMetricsAction;
namespace {
const CGFloat kFooterHeight = 30;
} // namespace
@implementation PopupMenuTableViewController @implementation PopupMenuTableViewController
@dynamic tableViewModel; @dynamic tableViewModel;
...@@ -31,8 +36,12 @@ using base::UserMetricsAction; ...@@ -31,8 +36,12 @@ using base::UserMetricsAction;
[super viewDidLoad]; [super viewDidLoad];
self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.sectionHeaderHeight = 0; self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 0;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// Adding a tableHeaderView is needed to prevent a wide inset on top of the
// collection.
self.tableView.tableHeaderView = [[UIView alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width,
0.01f)];
} }
- (void)setPopupMenuItems: - (void)setPopupMenuItems:
...@@ -45,6 +54,14 @@ using base::UserMetricsAction; ...@@ -45,6 +54,14 @@ using base::UserMetricsAction;
[self.tableViewModel addItem:item [self.tableViewModel addItem:item
toSectionWithIdentifier:sectionIdentifier]; toSectionWithIdentifier:sectionIdentifier];
} }
if (section != items.count - 1) {
// Add a footer for all sections except the last one.
TableViewHeaderFooterItem* footer =
[[PopupMenuFooterItem alloc] initWithType:kItemTypeEnumZero];
[self.tableViewModel setFooter:footer
forSectionWithIdentifier:sectionIdentifier];
}
} }
[self.tableView reloadData]; [self.tableView reloadData];
} }
...@@ -77,6 +94,13 @@ using base::UserMetricsAction; ...@@ -77,6 +94,13 @@ using base::UserMetricsAction;
[self executeActionForIdentifier:item.actionIdentifier origin:center]; [self executeActionForIdentifier:item.actionIdentifier origin:center];
} }
- (CGFloat)tableView:(UITableView*)tableView
heightForFooterInSection:(NSInteger)section {
if (section == self.tableViewModel.numberOfSections - 1)
return 0;
return kFooterHeight;
}
#pragma mark - Private #pragma mark - Private
// Executes the action associated with |identifier|, using |origin| as the point // Executes the action associated with |identifier|, using |origin| as the point
......
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