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 @@
// The number of tabs to show in the google landing fake toolbar.
- (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
// type property.
// Tells the consumer to that most visited data updated.
......
......@@ -193,6 +193,14 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// The number of tabs to show in the google landing fake toolbar.
@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
// field frame. Returns the proper frame from |frames| based on orientation,
// centered in the view.
......@@ -263,6 +271,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
@synthesize promoCanShow = _promoCanShow;
@synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown;
@synthesize tabCount = _tabCount;
@synthesize canGoForward = _canGoForward;
@synthesize canGoBack = _canGoBack;
@synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled;
- (void)loadView {
......@@ -1000,6 +1010,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// hidden.
[_headerView addToolbarWithDataSource:self.dataSource];
[_headerView setToolbarTabCount:self.tabCount];
[_headerView setCanGoForward:self.canGoForward];
[_headerView setCanGoBack:self.canGoBack];
}
[_supplementaryViews addObject:_headerView];
}
......@@ -1494,4 +1506,13 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
[_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
......@@ -41,6 +41,10 @@ class LargeIconService;
// Called when a what's new promo is tapped.
- (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
// consumer, and converted into types more suitable for a consumer.
// Gets an a most visited NTP tile at |index|.
......@@ -49,7 +53,7 @@ class LargeIconService;
// Gets the number of most visited entries.
- (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
// suitable for a consumer.
......@@ -62,8 +66,6 @@ class LargeIconService;
// Gets the large icon service.
- (favicon::LargeIconService*)largeIconService;
// Gets the toolbar delegate.
- (id<WebToolbarDelegate>)toolbarDelegate;
@end
......
......@@ -35,6 +35,7 @@
#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/voice/voice_search_provider.h"
#include "ios/web/public/web_state/web_state.h"
using base::UserMetricsAction;
......@@ -175,6 +176,12 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
[_consumer
setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]];
[_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.
_templateURLService =
......@@ -278,6 +285,22 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
[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
- (void)addBlacklistedURL:(const GURL&)url {
......@@ -317,10 +340,6 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
return IOSChromeLargeIconServiceFactory::GetForBrowserState(_browserState);
}
- (id<WebToolbarDelegate>)toolbarDelegate {
return _webToolbarDelegate;
}
- (void)promoViewed {
DCHECK(_notification_promo);
_notification_promo->HandleViewed();
......@@ -350,6 +369,10 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
NOTREACHED();
}
- (void)prepareToEnterTabSwitcher:(id)sender {
[_webToolbarDelegate prepareToEnterTabSwitcher:sender];
}
#pragma mark - UrlLoader
- (void)loadURL:(const GURL&)url
......
......@@ -42,6 +42,13 @@
// Updates the toolbar tab count;
- (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
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_HEADER_VIEW_H_
......@@ -69,8 +69,7 @@ const CGFloat kMaxConstraintConstantDiff = 5;
DCHECK(dataSource);
_toolbarController.reset([[NewTabPageToolbarController alloc]
initWithToolbarDelegate:[dataSource toolbarDelegate]
focuser:dataSource]);
initWithToolbarDataSource:dataSource]);
_toolbarController.get().readingListModel = [dataSource readingListModel];
UIView* toolbarView = [_toolbarController view];
......@@ -78,12 +77,21 @@ const CGFloat kMaxConstraintConstantDiff = 5;
toolbarFrame.size.height = ntp_header::kToolbarHeight;
toolbarView.frame = toolbarFrame;
[toolbarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self hideToolbarViewsForNewTabPage];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self addSubview:[_toolbarController view]];
}
- (void)setCanGoForward:(BOOL)canGoForward {
[_toolbarController setCanGoForward:canGoForward];
[self hideToolbarViewsForNewTabPage];
}
- (void)setCanGoBack:(BOOL)canGoBack {
[_toolbarController setCanGoBack:canGoBack];
[self hideToolbarViewsForNewTabPage];
}
- (void)hideToolbarViewsForNewTabPage {
[_toolbarController hideViewsForNewTabPage:YES];
};
......
......@@ -7,8 +7,7 @@
#import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
@protocol OmniboxFocuser;
@protocol WebToolbarDelegate;
@protocol GoogleLandingDataSource;
// 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
......@@ -18,8 +17,14 @@
// Designated initializer. The underlying ToolbarController is initialized with
// ToolbarControllerStyleLightMode.
- (instancetype)initWithToolbarDelegate:(id<WebToolbarDelegate>)delegate
focuser:(id<OmniboxFocuser>)focuser;
- (instancetype)initWithToolbarDataSource:
(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
......
......@@ -13,10 +13,9 @@
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
#import "ios/chrome/browser/ui/commands/generic_chrome_command.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/toolbar/toolbar_model_ios.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"
#include "ui/base/l10n/l10n_util.h"
......@@ -44,22 +43,28 @@ enum {
base::scoped_nsobject<UIButton> _backButton;
base::scoped_nsobject<UIButton> _forwardButton;
base::scoped_nsobject<UIButton> _omniboxFocuser;
id<WebToolbarDelegate> _delegate;
// Delegate to focus and blur the omnibox.
base::WeakNSProtocol<id<OmniboxFocuser>> _focuser;
base::WeakNSProtocol<id<GoogleLandingDataSource>> _dataSource;
}
// |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
@implementation NewTabPageToolbarController
- (instancetype)initWithToolbarDelegate:(id<WebToolbarDelegate>)delegate
focuser:(id<OmniboxFocuser>)focuser {
@synthesize canGoForward = _canGoForward;
@synthesize canGoBack = _canGoBack;
- (instancetype)initWithToolbarDataSource:
(id<GoogleLandingDataSource>)dataSource {
self = [super initWithStyle:ToolbarControllerStyleLightMode];
if (self) {
_delegate = delegate;
_focuser.reset(focuser);
_dataSource.reset(dataSource);
[self.backgroundView setHidden:YES];
CGFloat boundingWidth = self.view.bounds.size.width;
......@@ -205,21 +210,18 @@ enum {
- (void)hideViewsForNewTabPage:(BOOL)hide {
[super hideViewsForNewTabPage:hide];
// Show the back/forward buttons if there is forward history.
ToolbarModelIOS* toolbarModelIOS = [_delegate toolbarModelIOS];
if (toolbarModelIOS) {
BOOL forwardEnabled = toolbarModelIOS->CanGoForward();
[_backButton setHidden:!forwardEnabled && hide];
[_backButton setEnabled:toolbarModelIOS->CanGoBack()];
[_forwardButton setHidden:!forwardEnabled && hide];
}
BOOL forwardEnabled = self.canGoForward;
[_backButton setHidden:!forwardEnabled && hide];
[_backButton setEnabled:self.canGoBack];
[_forwardButton setHidden:!forwardEnabled && hide];
}
- (void)focusOmnibox:(id)sender {
[_focuser focusFakebox];
[_dataSource focusFakebox];
}
- (IBAction)stackButtonTouchDown:(id)sender {
[_delegate prepareToEnterTabSwitcher:self];
[_dataSource prepareToEnterTabSwitcher:self];
}
@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