| Index: ios/clean/chrome/browser/ui/tools/menu_view_controller.mm
|
| diff --git a/ios/clean/chrome/browser/ui/tools/menu_view_controller.mm b/ios/clean/chrome/browser/ui/tools/menu_view_controller.mm
|
| index 5e74863f48fb5a520a99c57b01ce45c2dd8fd9d0..a62aa7e7fe37b4dc6ce7b6975f8ca0bca4da6937 100644
|
| --- a/ios/clean/chrome/browser/ui/tools/menu_view_controller.mm
|
| +++ b/ios/clean/chrome/browser/ui/tools/menu_view_controller.mm
|
| @@ -9,11 +9,14 @@
|
| #import "base/mac/foundation_util.h"
|
| #import "base/macros.h"
|
| #import "ios/chrome/browser/ui/rtl_geometry.h"
|
| +#import "ios/chrome/browser/ui/uikit_ui_util.h"
|
| +#include "ios/chrome/grit/ios_theme_resources.h"
|
| #import "ios/clean/chrome/browser/ui/commands/find_in_page_visibility_commands.h"
|
| #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
|
| #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h"
|
| #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"
|
| #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
|
| +#import "ios/clean/chrome/browser/ui/toolbar/toolbar_constants.h"
|
| #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h"
|
| #import "ios/clean/chrome/browser/ui/tools/tools_actions.h"
|
| #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h"
|
| @@ -26,8 +29,8 @@
|
| namespace {
|
| const CGFloat kMenuWidth = 250.0;
|
| const CGFloat kMenuItemHeight = 48.0;
|
| -const CGFloat kMenuItemLeadingEdgeInset = 10.0;
|
| -const CGFloat kOverflowControlsMargin = 50.0;
|
| +const CGFloat kMenuItemLeadingEdgeInset = 12.0;
|
| +const CGFloat kOverflowControlsMargin = 58.0;
|
| const CGFloat kCloseButtonHeight = 44.0;
|
| }
|
|
|
| @@ -39,6 +42,7 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| MenuOverflowControlsStackView* toolbarOverflowStackView;
|
| @property(nonatomic, assign) BOOL displayOverflowControls;
|
| @property(nonatomic, strong) ToolbarButton* closeMenuButton;
|
| +@property(nonatomic, assign) BOOL currentPageLoading;
|
|
|
| // Sets up the main StackView and creates a button for each Menu item.
|
| - (void)setupMenuStackView;
|
| @@ -56,6 +60,7 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| @synthesize displayOverflowControls = _displayOverflowControls;
|
| @synthesize menuScrollView = _menuScrollView;
|
| @synthesize closeMenuButton = _closeMenuButton;
|
| +@synthesize currentPageLoading = _currentPageLoading;
|
|
|
| #pragma mark - View Lifecycle
|
|
|
| @@ -79,20 +84,42 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| self.menuScrollView.translatesAutoresizingMaskIntoConstraints = NO;
|
| [self.view addSubview:self.menuScrollView];
|
|
|
| + // PLACEHOLDER: Hardcoded value until the mediator observes the Webstate.
|
| + self.currentPageLoading = NO;
|
| +
|
| + [self setupCloseMenuButton];
|
| + [self setupMenuStackView];
|
| + [self setupConstraints];
|
| +}
|
| +
|
| +#pragma mark - UI Setup
|
| +
|
| +- (void)setupCloseMenuButton {
|
| // Add close tools menu button. This button is fixed on the top right corner
|
| // and will always be visible.
|
| - self.closeMenuButton = [ToolbarButton toolsMenuToolbarButton];
|
| + self.closeMenuButton = [ToolbarButton
|
| + toolbarButtonWithImageForNormalState:
|
| + NativeImage(IDR_IOS_TOOLBAR_LIGHT_TOOLS_PRESSED)
|
| + imageForHighlightedState:NativeImage(
|
| + IDR_IOS_TOOLBAR_LIGHT_TOOLS)
|
| + imageForDisabledState:nil];
|
| + [self.closeMenuButton
|
| + setImageEdgeInsets:UIEdgeInsetsMakeDirected(0, -3, 0, 0)];
|
| [self.closeMenuButton addTarget:self.dispatcher
|
| action:@selector(closeToolsMenu)
|
| forControlEvents:UIControlEventTouchUpInside];
|
| - [self.view addSubview:self.closeMenuButton];
|
|
|
| - [self setupMenuStackView];
|
| - [self setupConstraints];
|
| + NSLayoutConstraint* widthConstraint = [self.closeMenuButton.widthAnchor
|
| + constraintEqualToConstant:kToolbarButtonWidth];
|
| + widthConstraint.priority = UILayoutPriorityDefaultHigh;
|
| + NSLayoutConstraint* heightConstraint = [self.closeMenuButton.heightAnchor
|
| + constraintEqualToConstant:kCloseButtonHeight];
|
| + heightConstraint.priority = UILayoutPriorityDefaultHigh;
|
| + [NSLayoutConstraint
|
| + activateConstraints:@[ widthConstraint, heightConstraint ]];
|
| + [self.view addSubview:self.closeMenuButton];
|
| }
|
|
|
| -#pragma mark - UI Setup
|
| -
|
| - (void)setupMenuStackView {
|
| NSMutableArray<UIButton*>* buttons =
|
| [[NSMutableArray alloc] initWithCapacity:_menuItems.count];
|
| @@ -101,6 +128,11 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
| menuButton.translatesAutoresizingMaskIntoConstraints = NO;
|
| menuButton.tintColor = [UIColor blackColor];
|
| + // Button constraints will be changed in order to match the menu width, for
|
| + // this reason the content will be centered if no content alignment is set.
|
| + menuButton.contentHorizontalAlignment =
|
| + UseRTLLayout() ? UIControlContentHorizontalAlignmentRight
|
| + : UIControlContentHorizontalAlignmentLeft;
|
| [menuButton setTitle:item.title forState:UIControlStateNormal];
|
| [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(
|
| 0, kMenuItemLeadingEdgeInset, 0, 0)];
|
| @@ -123,6 +155,21 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| self.menuStackView.distribution = UIStackViewDistributionFillEqually;
|
| self.menuStackView.alignment = UIStackViewAlignmentLeading;
|
|
|
| + // Set button constraints so they have the same width as the StackView that
|
| + // contains them.
|
| + NSMutableArray* buttonConstraints = [[NSMutableArray alloc] init];
|
| + for (UIView* view in self.menuStackView.arrangedSubviews) {
|
| + [buttonConstraints
|
| + addObject:[view.leadingAnchor
|
| + constraintEqualToAnchor:self.menuStackView
|
| + .leadingAnchor]];
|
| + [buttonConstraints
|
| + addObject:[view.trailingAnchor
|
| + constraintEqualToAnchor:self.menuStackView
|
| + .trailingAnchor]];
|
| + }
|
| + [NSLayoutConstraint activateConstraints:buttonConstraints];
|
| +
|
| // Stack view to hold overflow ToolbarButtons.
|
| if (self.traitCollection.horizontalSizeClass ==
|
| UIUserInterfaceSizeClassCompact &&
|
| @@ -133,8 +180,6 @@ const CGFloat kCloseButtonHeight = 44.0;
|
|
|
| - (void)setUpOverFlowControlsStackView {
|
| self.toolbarOverflowStackView = [[MenuOverflowControlsStackView alloc] init];
|
| - // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view
|
| - // instead of the StackView. We are waiting confirmation on this.
|
| for (UIView* view in self.toolbarOverflowStackView.arrangedSubviews) {
|
| if ([view isKindOfClass:[ToolbarButton class]]) {
|
| ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
|
| @@ -143,6 +188,8 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| forControlEvents:UIControlEventTouchUpInside];
|
| }
|
| }
|
| + self.toolbarOverflowStackView.reloadButton.hidden = self.currentPageLoading;
|
| + self.toolbarOverflowStackView.stopButton.hidden = !self.currentPageLoading;
|
| [self.toolbarOverflowStackView.reloadButton
|
| addTarget:self.dispatcher
|
| action:@selector(reloadPage)
|
| @@ -154,13 +201,17 @@ const CGFloat kCloseButtonHeight = 44.0;
|
|
|
| [self.menuStackView insertArrangedSubview:self.toolbarOverflowStackView
|
| atIndex:0];
|
| - [NSLayoutConstraint activateConstraints:@[
|
| - [self.toolbarOverflowStackView.leadingAnchor
|
| - constraintEqualToAnchor:self.menuStackView.leadingAnchor],
|
| - [self.toolbarOverflowStackView.trailingAnchor
|
| - constraintEqualToAnchor:self.menuStackView.trailingAnchor
|
| - constant:-kOverflowControlsMargin],
|
| - ]];
|
| + NSLayoutConstraint* leadingConstraint =
|
| + [self.toolbarOverflowStackView.leadingAnchor
|
| + constraintEqualToAnchor:self.menuStackView.leadingAnchor];
|
| + leadingConstraint.priority = UILayoutPriorityDefaultHigh;
|
| + NSLayoutConstraint* trailingConstraint =
|
| + [self.toolbarOverflowStackView.trailingAnchor
|
| + constraintEqualToAnchor:self.menuStackView.trailingAnchor
|
| + constant:-kOverflowControlsMargin];
|
| + trailingConstraint.priority = UILayoutPriorityDefaultHigh;
|
| + [NSLayoutConstraint
|
| + activateConstraints:@[ leadingConstraint, trailingConstraint ]];
|
| }
|
|
|
| - (void)setupConstraints {
|
| @@ -187,11 +238,9 @@ const CGFloat kCloseButtonHeight = 44.0;
|
| constraintEqualToAnchor:self.menuScrollView.widthAnchor],
|
| [self.menuStackView.heightAnchor
|
| constraintEqualToConstant:kMenuItemHeight * self.menuItems.count],
|
| - // CloseMenu Button Constraints.
|
| + // CloseMenu Button Constraint.
|
| [self.closeMenuButton.trailingAnchor
|
| constraintEqualToAnchor:self.view.trailingAnchor],
|
| - [self.closeMenuButton.heightAnchor
|
| - constraintEqualToConstant:kCloseButtonHeight],
|
| ]];
|
| }
|
|
|
|
|