| 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_commands.h" |
| 16 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" | 17 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" |
| 17 #import "ios/chrome/browser/ui/rtl_geometry.h" | 18 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 18 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" | 19 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" |
| 19 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 20 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| 22 using base::UserMetricsAction; | 23 using base::UserMetricsAction; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 NTPToolbarButtonNameForward, | 37 NTPToolbarButtonNameForward, |
| 37 NumberOfNTPToolbarButtonNames, | 38 NumberOfNTPToolbarButtonNames, |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 @interface NewTabPageToolbarController () { | 43 @interface NewTabPageToolbarController () { |
| 43 base::scoped_nsobject<UIButton> _backButton; | 44 base::scoped_nsobject<UIButton> _backButton; |
| 44 base::scoped_nsobject<UIButton> _forwardButton; | 45 base::scoped_nsobject<UIButton> _forwardButton; |
| 45 base::scoped_nsobject<UIButton> _omniboxFocuser; | 46 base::scoped_nsobject<UIButton> _omniboxFocuser; |
| 46 | |
| 47 base::WeakNSProtocol<id<GoogleLandingDataSource>> _dataSource; | |
| 48 } | 47 } |
| 49 | 48 |
| 50 @end | 49 @end |
| 51 | 50 |
| 52 @implementation NewTabPageToolbarController | 51 @implementation NewTabPageToolbarController |
| 53 | 52 |
| 54 - (instancetype)initWithToolbarDataSource: | 53 @synthesize dispatcher = _dispatcher; |
| 55 (id<GoogleLandingDataSource>)dataSource { | 54 |
| 55 - (instancetype)initWithToolbar { |
| 56 self = [super initWithStyle:ToolbarControllerStyleLightMode]; | 56 self = [super initWithStyle:ToolbarControllerStyleLightMode]; |
| 57 if (self) { | 57 if (self) { |
| 58 _dataSource.reset(dataSource); | |
| 59 [self.backgroundView setHidden:YES]; | 58 [self.backgroundView setHidden:YES]; |
| 60 | 59 |
| 61 CGFloat boundingWidth = self.view.bounds.size.width; | 60 CGFloat boundingWidth = self.view.bounds.size.width; |
| 62 LayoutRect backButtonLayout = | 61 LayoutRect backButtonLayout = |
| 63 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, | 62 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, |
| 64 kBackButtonSize.width, kBackButtonSize.height); | 63 kBackButtonSize.width, kBackButtonSize.height); |
| 65 _backButton.reset( | 64 _backButton.reset( |
| 66 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); | 65 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); |
| 67 [_backButton | 66 [_backButton |
| 68 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | | 67 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } else if (gesture.view == _forwardButton.get()) { | 193 } else if (gesture.view == _forwardButton.get()) { |
| 195 base::scoped_nsobject<GenericChromeCommand> command( | 194 base::scoped_nsobject<GenericChromeCommand> command( |
| 196 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]); | 195 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_FORWARD_HISTORY]); |
| 197 [_forwardButton chromeExecuteCommand:command]; | 196 [_forwardButton chromeExecuteCommand:command]; |
| 198 } | 197 } |
| 199 } | 198 } |
| 200 | 199 |
| 201 - (void)hideViewsForNewTabPage:(BOOL)hide { | 200 - (void)hideViewsForNewTabPage:(BOOL)hide { |
| 202 [super hideViewsForNewTabPage:hide]; | 201 [super hideViewsForNewTabPage:hide]; |
| 203 // Show the back/forward buttons if there is forward history. | 202 // Show the back/forward buttons if there is forward history. |
| 204 BOOL forwardEnabled = [_dataSource canGoForward]; | 203 BOOL forwardEnabled = [self.dispatcher canGoForward]; |
| 205 [_backButton setHidden:!forwardEnabled && hide]; | 204 [_backButton setHidden:!forwardEnabled && hide]; |
| 206 [_backButton setEnabled:[_dataSource canGoBack]]; | 205 [_backButton setEnabled:[self.dispatcher canGoBack]]; |
| 207 [_forwardButton setHidden:!forwardEnabled && hide]; | 206 [_forwardButton setHidden:!forwardEnabled && hide]; |
| 208 } | 207 } |
| 209 | 208 |
| 210 - (void)focusOmnibox:(id)sender { | 209 - (void)focusOmnibox:(id)sender { |
| 211 [_dataSource focusFakebox]; | 210 [self.dispatcher focusFakebox]; |
| 212 } | 211 } |
| 213 | 212 |
| 214 - (IBAction)stackButtonTouchDown:(id)sender { | 213 - (IBAction)stackButtonTouchDown:(id)sender { |
| 215 [_dataSource prepareToEnterTabSwitcher:self]; | 214 [self.dispatcher prepareToEnterTabSwitcher:self]; |
| 216 } | 215 } |
| 217 | 216 |
| 218 @end | 217 @end |
| OLD | NEW |