| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_toolbar_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
| 11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 12 #include "components/toolbar/toolbar_model.h" | 12 #include "components/toolbar/toolbar_model.h" |
| 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 16 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" |
| 16 #import "ios/chrome/browser/ui/rtl_geometry.h" | 17 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 17 #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" | |
| 18 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" | 18 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" |
| 19 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | |
| 20 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 19 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 22 | 21 |
| 23 using base::UserMetricsAction; | 22 using base::UserMetricsAction; |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 const CGFloat kButtonYOffset = 4.0; | 26 const CGFloat kButtonYOffset = 4.0; |
| 28 const CGFloat kBackButtonLeading = 0; | 27 const CGFloat kBackButtonLeading = 0; |
| 29 const CGFloat kForwardButtonLeading = 48; | 28 const CGFloat kForwardButtonLeading = 48; |
| 30 const CGFloat kOmniboxFocuserLeading = 96; | 29 const CGFloat kOmniboxFocuserLeading = 96; |
| 31 const CGSize kBackButtonSize = {48, 48}; | 30 const CGSize kBackButtonSize = {48, 48}; |
| 32 const CGSize kForwardButtonSize = {48, 48}; | 31 const CGSize kForwardButtonSize = {48, 48}; |
| 33 const CGSize kOmniboxFocuserSize = {128, 48}; | 32 const CGSize kOmniboxFocuserSize = {128, 48}; |
| 34 | 33 |
| 35 enum { | 34 enum { |
| 36 NTPToolbarButtonNameBack = NumberOfToolbarButtonNames, | 35 NTPToolbarButtonNameBack = NumberOfToolbarButtonNames, |
| 37 NTPToolbarButtonNameForward, | 36 NTPToolbarButtonNameForward, |
| 38 NumberOfNTPToolbarButtonNames, | 37 NumberOfNTPToolbarButtonNames, |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 } // namespace | 40 } // namespace |
| 42 | 41 |
| 43 @interface NewTabPageToolbarController () { | 42 @interface NewTabPageToolbarController () { |
| 44 base::scoped_nsobject<UIButton> _backButton; | 43 base::scoped_nsobject<UIButton> _backButton; |
| 45 base::scoped_nsobject<UIButton> _forwardButton; | 44 base::scoped_nsobject<UIButton> _forwardButton; |
| 46 base::scoped_nsobject<UIButton> _omniboxFocuser; | 45 base::scoped_nsobject<UIButton> _omniboxFocuser; |
| 47 id<WebToolbarDelegate> _delegate; | |
| 48 | 46 |
| 49 // Delegate to focus and blur the omnibox. | 47 base::WeakNSProtocol<id<GoogleLandingDataSource>> _dataSource; |
| 50 base::WeakNSProtocol<id<OmniboxFocuser>> _focuser; | |
| 51 } | 48 } |
| 52 | 49 |
| 50 // |YES| if the google landing toolbar can show the forward arrow. |
| 51 @property(nonatomic, assign) BOOL canGoForward; |
| 52 |
| 53 // |YES| if the google landing toolbar can show the back arrow. |
| 54 @property(nonatomic, assign) BOOL canGoBack; |
| 55 |
| 53 @end | 56 @end |
| 54 | 57 |
| 55 @implementation NewTabPageToolbarController | 58 @implementation NewTabPageToolbarController |
| 56 | 59 |
| 57 - (instancetype)initWithToolbarDelegate:(id<WebToolbarDelegate>)delegate | 60 @synthesize canGoForward = _canGoForward; |
| 58 focuser:(id<OmniboxFocuser>)focuser { | 61 @synthesize canGoBack = _canGoBack; |
| 62 |
| 63 - (instancetype)initWithToolbarDataSource: |
| 64 (id<GoogleLandingDataSource>)dataSource { |
| 59 self = [super initWithStyle:ToolbarControllerStyleLightMode]; | 65 self = [super initWithStyle:ToolbarControllerStyleLightMode]; |
| 60 if (self) { | 66 if (self) { |
| 61 _delegate = delegate; | 67 _dataSource.reset(dataSource); |
| 62 _focuser.reset(focuser); | |
| 63 [self.backgroundView setHidden:YES]; | 68 [self.backgroundView setHidden:YES]; |
| 64 | 69 |
| 65 CGFloat boundingWidth = self.view.bounds.size.width; | 70 CGFloat boundingWidth = self.view.bounds.size.width; |
| 66 LayoutRect backButtonLayout = | 71 LayoutRect backButtonLayout = |
| 67 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, | 72 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, |
| 68 kBackButtonSize.width, kBackButtonSize.height); | 73 kBackButtonSize.width, kBackButtonSize.height); |
| 69 _backButton.reset( | 74 _backButton.reset( |
| 70 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); | 75 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); |
| 71 [_backButton | 76 [_backButton |
| 72 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | | 77 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } else if (gesture.view == _forwardButton.get()) { | 203 } else if (gesture.view == _forwardButton.get()) { |
| 199 base::scoped_nsobject<GenericChromeCommand> command( | 204 base::scoped_nsobject<GenericChromeCommand> command( |
| 200 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]); | 205 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]); |
| 201 [_forwardButton chromeExecuteCommand:command]; | 206 [_forwardButton chromeExecuteCommand:command]; |
| 202 } | 207 } |
| 203 } | 208 } |
| 204 | 209 |
| 205 - (void)hideViewsForNewTabPage:(BOOL)hide { | 210 - (void)hideViewsForNewTabPage:(BOOL)hide { |
| 206 [super hideViewsForNewTabPage:hide]; | 211 [super hideViewsForNewTabPage:hide]; |
| 207 // Show the back/forward buttons if there is forward history. | 212 // Show the back/forward buttons if there is forward history. |
| 208 ToolbarModelIOS* toolbarModelIOS = [_delegate toolbarModelIOS]; | 213 BOOL forwardEnabled = self.canGoForward; |
| 209 if (toolbarModelIOS) { | 214 [_backButton setHidden:!forwardEnabled && hide]; |
| 210 BOOL forwardEnabled = toolbarModelIOS->CanGoForward(); | 215 [_backButton setEnabled:self.canGoBack]; |
| 211 [_backButton setHidden:!forwardEnabled && hide]; | 216 [_forwardButton setHidden:!forwardEnabled && hide]; |
| 212 [_backButton setEnabled:toolbarModelIOS->CanGoBack()]; | |
| 213 [_forwardButton setHidden:!forwardEnabled && hide]; | |
| 214 } | |
| 215 } | 217 } |
| 216 | 218 |
| 217 - (void)focusOmnibox:(id)sender { | 219 - (void)focusOmnibox:(id)sender { |
| 218 [_focuser focusFakebox]; | 220 [_dataSource focusFakebox]; |
| 219 } | 221 } |
| 220 | 222 |
| 221 - (IBAction)stackButtonTouchDown:(id)sender { | 223 - (IBAction)stackButtonTouchDown:(id)sender { |
| 222 [_delegate prepareToEnterTabSwitcher:self]; | 224 [_dataSource prepareToEnterTabSwitcher:self]; |
| 223 } | 225 } |
| 224 | 226 |
| 225 @end | 227 @end |
| OLD | NEW |