Commit 394a4f2f authored by justincohen's avatar justincohen Committed by Commit bot

Remove WebToolbarDelegate from GoogleLandingDataSource.

BUG=694750

Review-Url: https://codereview.chromium.org/2832573002
Cr-Commit-Position: refs/heads/master@{#467980}
parent 1b2b965b
...@@ -44,6 +44,12 @@ ...@@ -44,6 +44,12 @@
// The number of tabs to show in the google landing fake toolbar. // The number of tabs to show in the google landing fake toolbar.
- (void)setTabCount:(int)tabCount; - (void)setTabCount:(int)tabCount;
// |YES| if the google landing toolbar can show the forward arrow.
- (void)setCanGoForward:(BOOL)canGoForward;
// |YES| if the google landing toolbar can show the back arrow.
- (void)setCanGoBack:(BOOL)canGoBack;
// TODO(crbug.com/694750): This should be replaced with consumer suitable data // TODO(crbug.com/694750): This should be replaced with consumer suitable data
// type property. // type property.
// Tells the consumer to that most visited data updated. // Tells the consumer to that most visited data updated.
......
...@@ -193,6 +193,14 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24; ...@@ -193,6 +193,14 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// The number of tabs to show in the google landing fake toolbar. // The number of tabs to show in the google landing fake toolbar.
@property(nonatomic, assign) int tabCount; @property(nonatomic, assign) int tabCount;
// |YES| if the google landing toolbar can show the forward arrow, cached and
// pushed into the header view.
@property(nonatomic, assign) BOOL canGoForward;
// |YES| if the google landing toolbar can show the back arrow, cached and
// pushed into the header view.
@property(nonatomic, assign) BOOL canGoBack;
// iPhone landscape uses a slightly different layout for the doodle and search // iPhone landscape uses a slightly different layout for the doodle and search
// field frame. Returns the proper frame from |frames| based on orientation, // field frame. Returns the proper frame from |frames| based on orientation,
// centered in the view. // centered in the view.
...@@ -263,6 +271,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24; ...@@ -263,6 +271,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
@synthesize promoCanShow = _promoCanShow; @synthesize promoCanShow = _promoCanShow;
@synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown; @synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown;
@synthesize tabCount = _tabCount; @synthesize tabCount = _tabCount;
@synthesize canGoForward = _canGoForward;
@synthesize canGoBack = _canGoBack;
@synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled; @synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled;
- (void)loadView { - (void)loadView {
...@@ -1000,6 +1010,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24; ...@@ -1000,6 +1010,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// hidden. // hidden.
[_headerView addToolbarWithDataSource:self.dataSource]; [_headerView addToolbarWithDataSource:self.dataSource];
[_headerView setToolbarTabCount:self.tabCount]; [_headerView setToolbarTabCount:self.tabCount];
[_headerView setCanGoForward:self.canGoForward];
[_headerView setCanGoBack:self.canGoBack];
} }
[_supplementaryViews addObject:_headerView]; [_supplementaryViews addObject:_headerView];
} }
...@@ -1494,4 +1506,13 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24; ...@@ -1494,4 +1506,13 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
[_headerView setToolbarTabCount:self.tabCount]; [_headerView setToolbarTabCount:self.tabCount];
} }
- (void)setCanGoForward:(BOOL)canGoForward {
_canGoForward = canGoForward;
[_headerView setCanGoForward:self.canGoForward];
}
- (void)setCanGoBack:(BOOL)canGoBack {
_canGoBack = canGoBack;
[_headerView setCanGoBack:self.canGoBack];
}
@end @end
...@@ -41,6 +41,10 @@ class LargeIconService; ...@@ -41,6 +41,10 @@ class LargeIconService;
// Called when a what's new promo is tapped. // Called when a what's new promo is tapped.
- (void)promoTapped; - (void)promoTapped;
// TODO(crbug.com/694750): This should move to a dispatcher.
// Called before the fake tab switcher icon is tapped to save snapshots.
- (void)prepareToEnterTabSwitcher:(id)sender;
// TODO(crbug.com/694750): The following two methods should be moved to the // TODO(crbug.com/694750): The following two methods should be moved to the
// consumer, and converted into types more suitable for a consumer. // consumer, and converted into types more suitable for a consumer.
// Gets an a most visited NTP tile at |index|. // Gets an a most visited NTP tile at |index|.
...@@ -49,7 +53,7 @@ class LargeIconService; ...@@ -49,7 +53,7 @@ class LargeIconService;
// Gets the number of most visited entries. // Gets the number of most visited entries.
- (NSUInteger)mostVisitedSize; - (NSUInteger)mostVisitedSize;
// TODO(crbug.com/694750): The following five properties will be removed in // TODO(crbug.com/694750): The following three properties will be removed in
// subsequent CLs, with data provided via GoogleDataConsumer into types more // subsequent CLs, with data provided via GoogleDataConsumer into types more
// suitable for a consumer. // suitable for a consumer.
...@@ -62,8 +66,6 @@ class LargeIconService; ...@@ -62,8 +66,6 @@ class LargeIconService;
// Gets the large icon service. // Gets the large icon service.
- (favicon::LargeIconService*)largeIconService; - (favicon::LargeIconService*)largeIconService;
// Gets the toolbar delegate.
- (id<WebToolbarDelegate>)toolbarDelegate;
@end @end
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
#include "ios/web/public/web_state/web_state.h"
using base::UserMetricsAction; using base::UserMetricsAction;
...@@ -175,6 +176,12 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() { ...@@ -175,6 +176,12 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
[_consumer [_consumer
setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]]; setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]];
[_consumer setTabCount:self.webStateList->count()]; [_consumer setTabCount:self.webStateList->count()];
web::WebState* webState = _webStateList->GetActiveWebState();
if (webState) {
web::NavigationManager* nav = webState->GetNavigationManager();
[_consumer setCanGoForward:nav->CanGoForward()];
[_consumer setCanGoBack:nav->CanGoBack()];
}
// Set up template URL service to listen for default search engine changes. // Set up template URL service to listen for default search engine changes.
_templateURLService = _templateURLService =
...@@ -278,6 +285,22 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() { ...@@ -278,6 +285,22 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
[self.consumer setTabCount:self.webStateList->count()]; [self.consumer setTabCount:self.webStateList->count()];
} }
// If the actual webState associated with this mediator were passed in, this
// would not be necessary. However, since the active webstate can change when
// the new tab page is created (and animated in), listen for changes here and
// always display what's active.
- (void)webStateList:(WebStateList*)webStateList
didChangeActiveWebState:(web::WebState*)newWebState
oldWebState:(web::WebState*)oldWebState
atIndex:(int)atIndex
userAction:(BOOL)userAction {
if (newWebState) {
web::NavigationManager* nav = newWebState->GetNavigationManager();
[self.consumer setCanGoForward:nav->CanGoForward()];
[self.consumer setCanGoBack:nav->CanGoBack()];
}
}
#pragma mark - GoogleLandingDataSource #pragma mark - GoogleLandingDataSource
- (void)addBlacklistedURL:(const GURL&)url { - (void)addBlacklistedURL:(const GURL&)url {
...@@ -317,10 +340,6 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() { ...@@ -317,10 +340,6 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
return IOSChromeLargeIconServiceFactory::GetForBrowserState(_browserState); return IOSChromeLargeIconServiceFactory::GetForBrowserState(_browserState);
} }
- (id<WebToolbarDelegate>)toolbarDelegate {
return _webToolbarDelegate;
}
- (void)promoViewed { - (void)promoViewed {
DCHECK(_notification_promo); DCHECK(_notification_promo);
_notification_promo->HandleViewed(); _notification_promo->HandleViewed();
...@@ -350,6 +369,10 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() { ...@@ -350,6 +369,10 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
NOTREACHED(); NOTREACHED();
} }
- (void)prepareToEnterTabSwitcher:(id)sender {
[_webToolbarDelegate prepareToEnterTabSwitcher:sender];
}
#pragma mark - UrlLoader #pragma mark - UrlLoader
- (void)loadURL:(const GURL&)url - (void)loadURL:(const GURL&)url
......
...@@ -42,6 +42,13 @@ ...@@ -42,6 +42,13 @@
// Updates the toolbar tab count; // Updates the toolbar tab count;
- (void)setToolbarTabCount:(int)tabCount; - (void)setToolbarTabCount:(int)tabCount;
// |YES| if the toolbar can show the forward arrow.
- (void)setCanGoForward:(BOOL)canGoForward;
// |YES| if the toolbar can show the back arrow.
- (void)setCanGoBack:(BOOL)canGoBack;
@end @end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_HEADER_VIEW_H_ #endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_HEADER_VIEW_H_
...@@ -69,8 +69,7 @@ const CGFloat kMaxConstraintConstantDiff = 5; ...@@ -69,8 +69,7 @@ const CGFloat kMaxConstraintConstantDiff = 5;
DCHECK(dataSource); DCHECK(dataSource);
_toolbarController.reset([[NewTabPageToolbarController alloc] _toolbarController.reset([[NewTabPageToolbarController alloc]
initWithToolbarDelegate:[dataSource toolbarDelegate] initWithToolbarDataSource:dataSource]);
focuser:dataSource]);
_toolbarController.get().readingListModel = [dataSource readingListModel]; _toolbarController.get().readingListModel = [dataSource readingListModel];
UIView* toolbarView = [_toolbarController view]; UIView* toolbarView = [_toolbarController view];
...@@ -78,12 +77,21 @@ const CGFloat kMaxConstraintConstantDiff = 5; ...@@ -78,12 +77,21 @@ const CGFloat kMaxConstraintConstantDiff = 5;
toolbarFrame.size.height = ntp_header::kToolbarHeight; toolbarFrame.size.height = ntp_header::kToolbarHeight;
toolbarView.frame = toolbarFrame; toolbarView.frame = toolbarFrame;
[toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self hideToolbarViewsForNewTabPage];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self addSubview:[_toolbarController view]]; [self addSubview:[_toolbarController view]];
} }
- (void)setCanGoForward:(BOOL)canGoForward {
[_toolbarController setCanGoForward:canGoForward];
[self hideToolbarViewsForNewTabPage];
}
- (void)setCanGoBack:(BOOL)canGoBack {
[_toolbarController setCanGoBack:canGoBack];
[self hideToolbarViewsForNewTabPage];
}
- (void)hideToolbarViewsForNewTabPage { - (void)hideToolbarViewsForNewTabPage {
[_toolbarController hideViewsForNewTabPage:YES]; [_toolbarController hideViewsForNewTabPage:YES];
}; };
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
@protocol OmniboxFocuser; @protocol GoogleLandingDataSource;
@protocol WebToolbarDelegate;
// New tab page specific toolbar. The background view is hidden and the // New tab page specific toolbar. The background view is hidden and the
// navigation buttons are also hidden if there is no forward history. Does not // navigation buttons are also hidden if there is no forward history. Does not
...@@ -18,8 +17,14 @@ ...@@ -18,8 +17,14 @@
// Designated initializer. The underlying ToolbarController is initialized with // Designated initializer. The underlying ToolbarController is initialized with
// ToolbarControllerStyleLightMode. // ToolbarControllerStyleLightMode.
- (instancetype)initWithToolbarDelegate:(id<WebToolbarDelegate>)delegate - (instancetype)initWithToolbarDataSource:
focuser:(id<OmniboxFocuser>)focuser; (id<GoogleLandingDataSource>)dataSource;
// |YES| if the toolbar can show the forward arrow.
- (void)setCanGoForward:(BOOL)canGoForward;
// |YES| if the toolbar can show the back arrow.
- (void)setCanGoBack:(BOOL)canGoBack;
@end @end
......
...@@ -13,10 +13,9 @@ ...@@ -13,10 +13,9 @@
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h" #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h" #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
#import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
#import "ios/chrome/browser/ui/rtl_geometry.h" #import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
#include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h"
#import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -44,22 +43,28 @@ enum { ...@@ -44,22 +43,28 @@ enum {
base::scoped_nsobject<UIButton> _backButton; base::scoped_nsobject<UIButton> _backButton;
base::scoped_nsobject<UIButton> _forwardButton; base::scoped_nsobject<UIButton> _forwardButton;
base::scoped_nsobject<UIButton> _omniboxFocuser; base::scoped_nsobject<UIButton> _omniboxFocuser;
id<WebToolbarDelegate> _delegate;
// Delegate to focus and blur the omnibox. base::WeakNSProtocol<id<GoogleLandingDataSource>> _dataSource;
base::WeakNSProtocol<id<OmniboxFocuser>> _focuser;
} }
// |YES| if the google landing toolbar can show the forward arrow.
@property(nonatomic, assign) BOOL canGoForward;
// |YES| if the google landing toolbar can show the back arrow.
@property(nonatomic, assign) BOOL canGoBack;
@end @end
@implementation NewTabPageToolbarController @implementation NewTabPageToolbarController
- (instancetype)initWithToolbarDelegate:(id<WebToolbarDelegate>)delegate @synthesize canGoForward = _canGoForward;
focuser:(id<OmniboxFocuser>)focuser { @synthesize canGoBack = _canGoBack;
- (instancetype)initWithToolbarDataSource:
(id<GoogleLandingDataSource>)dataSource {
self = [super initWithStyle:ToolbarControllerStyleLightMode]; self = [super initWithStyle:ToolbarControllerStyleLightMode];
if (self) { if (self) {
_delegate = delegate; _dataSource.reset(dataSource);
_focuser.reset(focuser);
[self.backgroundView setHidden:YES]; [self.backgroundView setHidden:YES];
CGFloat boundingWidth = self.view.bounds.size.width; CGFloat boundingWidth = self.view.bounds.size.width;
...@@ -205,21 +210,18 @@ enum { ...@@ -205,21 +210,18 @@ enum {
- (void)hideViewsForNewTabPage:(BOOL)hide { - (void)hideViewsForNewTabPage:(BOOL)hide {
[super hideViewsForNewTabPage:hide]; [super hideViewsForNewTabPage:hide];
// Show the back/forward buttons if there is forward history. // Show the back/forward buttons if there is forward history.
ToolbarModelIOS* toolbarModelIOS = [_delegate toolbarModelIOS]; BOOL forwardEnabled = self.canGoForward;
if (toolbarModelIOS) {
BOOL forwardEnabled = toolbarModelIOS->CanGoForward();
[_backButton setHidden:!forwardEnabled && hide]; [_backButton setHidden:!forwardEnabled && hide];
[_backButton setEnabled:toolbarModelIOS->CanGoBack()]; [_backButton setEnabled:self.canGoBack];
[_forwardButton setHidden:!forwardEnabled && hide]; [_forwardButton setHidden:!forwardEnabled && hide];
}
} }
- (void)focusOmnibox:(id)sender { - (void)focusOmnibox:(id)sender {
[_focuser focusFakebox]; [_dataSource focusFakebox];
} }
- (IBAction)stackButtonTouchDown:(id)sender { - (IBAction)stackButtonTouchDown:(id)sender {
[_delegate prepareToEnterTabSwitcher:self]; [_dataSource prepareToEnterTabSwitcher:self];
} }
@end @end
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