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/ntp/google_landing_data_source.h" |
17 #import "ios/chrome/browser/ui/rtl_geometry.h" | 17 #import "ios/chrome/browser/ui/rtl_geometry.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" |
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 |
26 const CGFloat kButtonYOffset = 4.0; | 27 const CGFloat kButtonYOffset = 4.0; |
27 const CGFloat kBackButtonLeading = 0; | 28 const CGFloat kBackButtonLeading = 0; |
28 const CGFloat kForwardButtonLeading = 48; | 29 const CGFloat kForwardButtonLeading = 48; |
29 const CGFloat kOmniboxFocuserLeading = 96; | 30 const CGFloat kOmniboxFocuserLeading = 96; |
30 const CGSize kBackButtonSize = {48, 48}; | 31 const CGSize kBackButtonSize = {48, 48}; |
31 const CGSize kForwardButtonSize = {48, 48}; | 32 const CGSize kForwardButtonSize = {48, 48}; |
32 const CGSize kOmniboxFocuserSize = {128, 48}; | 33 const CGSize kOmniboxFocuserSize = {128, 48}; |
33 | 34 |
34 enum { | 35 enum { |
35 NTPToolbarButtonNameBack = NumberOfToolbarButtonNames, | 36 NTPToolbarButtonNameBack = NumberOfToolbarButtonNames, |
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 // |YES| if the google landing toolbar can show the forward arrow. | 49 // |YES| if the google landing toolbar can show the forward arrow. |
51 @property(nonatomic, assign) BOOL canGoForward; | 50 @property(nonatomic, assign) BOOL canGoForward; |
52 | 51 |
53 // |YES| if the google landing toolbar can show the back arrow. | 52 // |YES| if the google landing toolbar can show the back arrow. |
54 @property(nonatomic, assign) BOOL canGoBack; | 53 @property(nonatomic, assign) BOOL canGoBack; |
55 | 54 |
56 @end | 55 @end |
57 | 56 |
58 @implementation NewTabPageToolbarController | 57 @implementation NewTabPageToolbarController |
59 | 58 |
| 59 @synthesize dispatcher = _dispatcher; |
60 @synthesize canGoForward = _canGoForward; | 60 @synthesize canGoForward = _canGoForward; |
61 @synthesize canGoBack = _canGoBack; | 61 @synthesize canGoBack = _canGoBack; |
62 | 62 |
63 - (instancetype)initWithToolbarDataSource: | 63 - (instancetype)init { |
64 (id<GoogleLandingDataSource>)dataSource { | |
65 self = [super initWithStyle:ToolbarControllerStyleLightMode]; | 64 self = [super initWithStyle:ToolbarControllerStyleLightMode]; |
66 if (self) { | 65 if (self) { |
67 _dataSource.reset(dataSource); | |
68 [self.backgroundView setHidden:YES]; | 66 [self.backgroundView setHidden:YES]; |
69 | 67 |
70 CGFloat boundingWidth = self.view.bounds.size.width; | 68 CGFloat boundingWidth = self.view.bounds.size.width; |
71 LayoutRect backButtonLayout = | 69 LayoutRect backButtonLayout = |
72 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, | 70 LayoutRectMake(kBackButtonLeading, boundingWidth, kButtonYOffset, |
73 kBackButtonSize.width, kBackButtonSize.height); | 71 kBackButtonSize.width, kBackButtonSize.height); |
74 _backButton.reset( | 72 _backButton.reset( |
75 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); | 73 [[UIButton alloc] initWithFrame:LayoutRectGetRect(backButtonLayout)]); |
76 [_backButton | 74 [_backButton |
77 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | | 75 setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 - (void)hideViewsForNewTabPage:(BOOL)hide { | 208 - (void)hideViewsForNewTabPage:(BOOL)hide { |
211 [super hideViewsForNewTabPage:hide]; | 209 [super hideViewsForNewTabPage:hide]; |
212 // Show the back/forward buttons if there is forward history. | 210 // Show the back/forward buttons if there is forward history. |
213 BOOL forwardEnabled = self.canGoForward; | 211 BOOL forwardEnabled = self.canGoForward; |
214 [_backButton setHidden:!forwardEnabled && hide]; | 212 [_backButton setHidden:!forwardEnabled && hide]; |
215 [_backButton setEnabled:self.canGoBack]; | 213 [_backButton setEnabled:self.canGoBack]; |
216 [_forwardButton setHidden:!forwardEnabled && hide]; | 214 [_forwardButton setHidden:!forwardEnabled && hide]; |
217 } | 215 } |
218 | 216 |
219 - (void)focusOmnibox:(id)sender { | 217 - (void)focusOmnibox:(id)sender { |
220 [_dataSource focusFakebox]; | 218 [self.dispatcher focusFakebox]; |
221 } | 219 } |
222 | 220 |
223 - (IBAction)stackButtonTouchDown:(id)sender { | 221 - (IBAction)stackButtonTouchDown:(id)sender { |
224 [_dataSource prepareToEnterTabSwitcher:self]; | 222 [self.dispatcher prepareToEnterTabSwitcher:self]; |
225 } | 223 } |
226 | 224 |
227 @end | 225 @end |
OLD | NEW |