Skip to content

Commit

Permalink
[ios clean] Add overflow buttons for ToolsMenu.
Browse files Browse the repository at this point in the history
-ToolsMenu adds a StackView subclass (MenuOverflowControlsStack) as a first
element when in compact widths.
-ToolsMenu is dismissed everytime the ToolbarLayout changes (Rotation, iPad
multitasking,etc.) this mimics current behavior.
-MenuOverflowControlsStack currently uses ToolbarButtons as a placeholder, but this
is not necessarily how it needs to be.
-MenuOverflowControlsStack UI is not yet ready, this CL is more about the logic of
adding/removing the Stack, and not the contents.

Screenshot:
https://drive.google.com/open?id=0Byo6-Nuda2jgQmFzYXZsNkd2ZlU

BUG=682880

Review-Url: https://codereview.chromium.org/2693043002
Cr-Commit-Position: refs/heads/master@{#451065}
  • Loading branch information
sczs authored and Commit bot committed Feb 16, 2017
1 parent 4b0ea82 commit 7f21fa5
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 14 deletions.
23 changes: 17 additions & 6 deletions ios/clean/chrome/browser/ui/toolbar/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,34 @@ source_set("toolbar") {
}

source_set("toolbar_ui") {
sources = [
"toolbar_view_controller.h",
"toolbar_view_controller.mm",
]
deps = [
":toolbar_components_ui",
"//base",
"//ios/clean/chrome/browser/ui/actions",
"//ios/clean/chrome/browser/ui/animators",
"//ios/clean/chrome/browser/ui/commands",
"//ios/clean/chrome/browser/ui/tools",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}

source_set("toolbar_components_ui") {
sources = [
"toolbar_button+factory.h",
"toolbar_button+factory.mm",
"toolbar_button.h",
"toolbar_button.mm",
"toolbar_component_options.h",
"toolbar_view_controller.h",
"toolbar_view_controller.mm",
]
deps = [
"//base",
"//ios/chrome/app/theme",
"//ios/chrome/browser/ui",
"//ios/clean/chrome/browser/ui/actions",
"//ios/clean/chrome/browser/ui/animators",
"//ios/clean/chrome/browser/ui/commands",
"//ios/clean/chrome/browser/ui/tools",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ - (void)viewDidLoad {
]];
}

- (void)viewWillLayoutSubviews {
// This forces the ToolMenu to close whenever a Device Rotation, iPad
// Multitasking change, etc. happens.
[self.toolbarCommandHandler closeToolsMenu];
}

#pragma mark - Components Setup

- (void)setUpToolbarButtons {
Expand Down
4 changes: 4 additions & 0 deletions ios/clean/chrome/browser/ui/tools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ source_set("tools") {

source_set("tools_ui") {
sources = [
"menu_overflow_controls_stackview.h",
"menu_overflow_controls_stackview.mm",
"menu_view_controller.h",
"menu_view_controller.mm",
]
Expand All @@ -32,7 +34,9 @@ source_set("tools_ui") {
deps = [
"//base",
"//base:i18n",
"//ios/chrome/browser/ui",
"//ios/clean/chrome/browser/ui/actions",
"//ios/clean/chrome/browser/ui/toolbar:toolbar_components_ui",
"//ios/third_party/material_roboto_font_loader_ios",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 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_CLEAN_CHROME_BROWSER_UI_TOOLS_MENU_OVERFLOW_CONTROLS_STACKVIEW_H_
#define IOS_CLEAN_CHROME_BROWSER_UI_TOOLS_MENU_OVERFLOW_CONTROLS_STACKVIEW_H_

#import <UIKit/UIKit.h>

@class ToolbarButton;

// StackView subclass that contains the Overflow Toolbar Buttons that will be
// inserted in the first row of ToolMenu in compact widths.
@interface MenuOverflowControlsStackView : UIStackView
// ToolsMenu ToolbarButton.
@property(nonatomic, strong) ToolbarButton* toolsMenuButton;
// Share ToolbarButton.
@property(nonatomic, strong) ToolbarButton* shareButton;
// Reload ToolbarButton.
@property(nonatomic, strong) ToolbarButton* reloadButton;
// Stop ToolbarButton.
@property(nonatomic, strong) ToolbarButton* stopButton;
@end

#endif // IOS_CLEAN_CHROME_BROWSER_UI_TOOLS_MENU_OVERFLOW_CONTROLS_STACKVIEW_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2017 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/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h"

#import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"

@implementation MenuOverflowControlsStackView
@synthesize toolsMenuButton = _toolsMenuButton;
@synthesize shareButton = _shareButton;
@synthesize reloadButton = _reloadButton;
@synthesize stopButton = _stopButton;

- (instancetype)init {
if ((self = [super init])) {
// PLACEHOLDER: Buttons and UI config is not final and will be improved.
[self setUpToolbarButtons];
[self addArrangedSubview:self.shareButton];
[self addArrangedSubview:self.stopButton];
[self addArrangedSubview:self.reloadButton];
[self addArrangedSubview:self.toolsMenuButton];

self.axis = UILayoutConstraintAxisHorizontal;
self.distribution = UIStackViewDistributionFillEqually;
}
return self;
}

#pragma mark - Components Setup

- (void)setUpToolbarButtons {
// Tools menu button.
self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton];

// Share button.
self.shareButton = [ToolbarButton shareToolbarButton];

// Reload button.
self.reloadButton = [ToolbarButton reloadToolbarButton];

// Stop button.
self.stopButton = [ToolbarButton stopToolbarButton];
}

@end
39 changes: 31 additions & 8 deletions ios/clean/chrome/browser/ui/tools/menu_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#include "base/i18n/rtl.h"
#import "base/logging.h"
#import "base/macros.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/clean/chrome/browser/ui/actions/settings_actions.h"
#import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h"
#import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
#import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h"
#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand All @@ -37,10 +40,13 @@ @implementation MenuItem

@interface MenuViewController ()
@property(nonatomic, readonly) NSArray<MenuItem*>* menuItems;
@property(nonatomic, strong)
MenuOverflowControlsStackView* toolbarOverflowStackView;
@end

@implementation MenuViewController
@synthesize menuItems = _menuItems;
@synthesize toolbarOverflowStackView = _toolbarOverflowStackView;

- (instancetype)init {
if ((self = [super init])) {
Expand Down Expand Up @@ -96,6 +102,7 @@ - (void)viewDidLoad {
menuButton.translatesAutoresizingMaskIntoConstraints = NO;
menuButton.tintColor = [UIColor blackColor];
[menuButton setTitle:item.title forState:UIControlStateNormal];
[menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)];
[menuButton.titleLabel
setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
[menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural];
Expand All @@ -117,16 +124,32 @@ - (void)viewDidLoad {
menu.distribution = UIStackViewDistributionFillEqually;
menu.alignment = UIStackViewAlignmentLeading;

// Stack view to hold overflow ToolbarButtons.
if (self.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassCompact) {
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.
[self.toolbarOverflowStackView.toolsMenuButton
addTarget:nil
action:@selector(closeToolsMenu:)
forControlEvents:UIControlEventTouchUpInside];
[menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0];
[NSLayoutConstraint activateConstraints:@[
[self.toolbarOverflowStackView.leadingAnchor
constraintEqualToAnchor:menu.leadingAnchor],
[self.toolbarOverflowStackView.trailingAnchor
constraintEqualToAnchor:menu.trailingAnchor],
]];
}

[self.view addSubview:menu];
[NSLayoutConstraint activateConstraints:@[
[menu.leadingAnchor
constraintEqualToAnchor:self.view.layoutMarginsGuide.leadingAnchor],
[menu.trailingAnchor
constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor],
[menu.bottomAnchor
constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor],
[menu.topAnchor
constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor],
[menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
[menu.topAnchor constraintEqualToAnchor:self.view.topAnchor],
]];
}

Expand Down

0 comments on commit 7f21fa5

Please sign in to comment.