Commit 959b8436 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Modernize layout of toolbar items for ChromeWebView shell

The manual layout of the toolbar items for ios_web_view_shell is
outdated and no longer works with iOS 11. Update the UIButtons to
UIBarButtonItems and automatically lay them out with setItems: instead
of adding items as subviews to the UIToolbar.

Bug: None
Change-Id: I800ade863253ac244cb8705a4afec0b09a0a2198
Reviewed-on: https://chromium-review.googlesource.com/578239Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488607}
parent 426e08b2
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor darkGrayColor];
ShellViewController* controller = [[ShellViewController alloc] init]; ShellViewController* controller = [[ShellViewController alloc] init];
// Gives a restoration identifier so that state restoration works. // Gives a restoration identifier so that state restoration works.
......
...@@ -27,9 +27,9 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -27,9 +27,9 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
// Text field used for navigating to URLs. // Text field used for navigating to URLs.
@property(nonatomic, strong) UITextField* field; @property(nonatomic, strong) UITextField* field;
// Toolbar button to navigate backwards. // Toolbar button to navigate backwards.
@property(nonatomic, strong) UIButton* backButton; @property(nonatomic, strong) UIBarButtonItem* backButton;
// Toolbar button to navigate forwards. // Toolbar button to navigate forwards.
@property(nonatomic, strong) UIButton* forwardButton; @property(nonatomic, strong) UIBarButtonItem* forwardButton;
// Toolbar containing navigation buttons and |field|. // Toolbar containing navigation buttons and |field|.
@property(nonatomic, strong) UIToolbar* toolbar; @property(nonatomic, strong) UIToolbar* toolbar;
// Handles the translation of the content displayed in |webView|. // Handles the translation of the content displayed in |webView|.
...@@ -97,60 +97,37 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier = ...@@ -97,60 +97,37 @@ NSString* const kWebViewShellJavaScriptDialogTextFieldAccessibiltyIdentifier =
[_field setAccessibilityLabel:kWebViewShellAddressFieldAccessibilityLabel]; [_field setAccessibilityLabel:kWebViewShellAddressFieldAccessibilityLabel];
// Set up the toolbar buttons. // Set up the toolbar buttons.
// Back. self.backButton = [[UIBarButtonItem alloc]
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom]; initWithImage:[UIImage imageNamed:@"toolbar_back"]
[_backButton setImage:[UIImage imageNamed:@"toolbar_back"] style:UIBarButtonItemStylePlain
forState:UIControlStateNormal]; target:self
[_backButton setFrame:CGRectMake(0, 0, kButtonSize, kButtonSize)]; action:@selector(back)];
UIEdgeInsets insets = UIEdgeInsetsMake(5, 5, 4, 4);
[_backButton setImageEdgeInsets:insets];
[_backButton setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[_backButton addTarget:self
action:@selector(back)
forControlEvents:UIControlEventTouchUpInside];
[_backButton setAccessibilityLabel:kWebViewShellBackButtonAccessibilityLabel]; [_backButton setAccessibilityLabel:kWebViewShellBackButtonAccessibilityLabel];
// Forward. self.forwardButton = [[UIBarButtonItem alloc]
self.forwardButton = [UIButton buttonWithType:UIButtonTypeCustom]; initWithImage:[UIImage imageNamed:@"toolbar_forward"]
[_forwardButton setImage:[UIImage imageNamed:@"toolbar_forward"] style:UIBarButtonItemStylePlain
forState:UIControlStateNormal]; target:self
[_forwardButton action:@selector(forward)];
setFrame:CGRectMake(kButtonSize, 0, kButtonSize, kButtonSize)];
[_forwardButton setImageEdgeInsets:insets];
[_forwardButton setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[_forwardButton addTarget:self
action:@selector(forward)
forControlEvents:UIControlEventTouchUpInside];
[_forwardButton [_forwardButton
setAccessibilityLabel:kWebViewShellForwardButtonAccessibilityLabel]; setAccessibilityLabel:kWebViewShellForwardButtonAccessibilityLabel];
// Stop. UIBarButtonItem* stop = [[UIBarButtonItem alloc]
UIButton* stop = [UIButton buttonWithType:UIButtonTypeCustom]; initWithImage:[UIImage imageNamed:@"toolbar_stop"]
[stop setImage:[UIImage imageNamed:@"toolbar_stop"] style:UIBarButtonItemStylePlain
forState:UIControlStateNormal]; target:self
[stop setFrame:CGRectMake(2 * kButtonSize, 0, kButtonSize, kButtonSize)]; action:@selector(stopLoading)];
[stop setImageEdgeInsets:insets];
[stop setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin]; UIBarButtonItem* menu = [[UIBarButtonItem alloc]
[stop addTarget:self initWithImage:[UIImage imageNamed:@"toolbar_more_horiz"]
action:@selector(stopLoading) style:UIBarButtonItemStylePlain
forControlEvents:UIControlEventTouchUpInside]; target:self
action:@selector(showMenu)];
// Menu.
UIButton* menu = [UIButton buttonWithType:UIButtonTypeCustom]; [_toolbar setItems:@[
[menu setImage:[UIImage imageNamed:@"toolbar_more_horiz"] _backButton, _forwardButton, stop, menu,
forState:UIControlStateNormal]; [[UIBarButtonItem alloc] initWithCustomView:_field]
[menu setFrame:CGRectMake(3 * kButtonSize, 0, kButtonSize, kButtonSize)]; ]];
[menu setImageEdgeInsets:insets];
[menu setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[menu addTarget:self
action:@selector(showMenu)
forControlEvents:UIControlEventTouchUpInside];
[_toolbar addSubview:_backButton];
[_toolbar addSubview:_forwardButton];
[_toolbar addSubview:stop];
[_toolbar addSubview:menu];
[_toolbar addSubview:_field];
[CWVWebView setUserAgentProduct:@"Dummy/1.0"]; [CWVWebView setUserAgentProduct:@"Dummy/1.0"];
......
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