Commit c39df9bf authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Remove TabGridAdaptor

The TabGridAdaptor was used for the migration from the old TabSwitcher.

Bug: none
Change-Id: I9d5991bdbcbafad70da6dc856627b738aa1fd885
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341645
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796368}
parent 218c1fd4
......@@ -178,7 +178,7 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal;
// TabSwitcher object -- the tab grid.
@property(nonatomic, strong) id<TabSwitcher> tabSwitcher;
@property(nonatomic, strong, readonly) id<TabSwitcher> tabSwitcher;
// The main coordinator, lazily created the first time it is accessed. Manages
// the main view controller. This property should not be accessed before the
......@@ -270,6 +270,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
self.signinCoordinator.isSettingsViewPresented;
}
- (id<TabSwitcher>)tabSwitcher {
return self.mainCoordinator;
}
#pragma mark - SceneStateObserver
- (void)sceneState:(SceneState*)sceneState
......@@ -584,9 +588,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
// Lazy init of mainCoordinator.
[self.mainCoordinator start];
self.tabSwitcher = self.mainCoordinator.tabSwitcher;
// Call -restoreInternalState so that the grid shows the correct panel.
[_tabSwitcher
[self.tabSwitcher
restoreInternalStateWithMainBrowser:self.mainInterface.browser
otrBrowser:self.incognitoInterface.browser
activeBrowser:self.currentInterface.browser];
......
......@@ -6,8 +6,6 @@ import("//ios/public/provider/chrome/browser/build_config.gni")
source_set("tab_grid") {
sources = [
"tab_grid_adaptor.h",
"tab_grid_adaptor.mm",
"tab_grid_coordinator.h",
"tab_grid_coordinator.mm",
"tab_grid_mediator.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_ADAPTOR_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_ADAPTOR_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/tab_grid/tab_grid_mediator.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
@class TabGridViewController;
// An opaque adaptor for the TabSwitcher protocol into the TabGrid.
// Consuming objects should be passed instances of this object as an
// id<TabSwitcher>.
// All of the methods and properties on this class are internal API fot the
// tab grid, and external code shouldn't depend on them.
@interface TabGridAdaptor : NSObject<TabSwitcher>
@property(nonatomic, weak) TabGridViewController* tabGridViewController;
// The mediator for the incognito grid.
@property(nonatomic, weak) TabGridMediator* incognitoMediator;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_ADAPTOR_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/tab_grid/tab_grid_adaptor.h"
#include "base/check.h"
#import "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/tab_insertion_browser_agent.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/web/public/navigation/navigation_manager.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation TabGridAdaptor
// TabSwitcher properties.
@synthesize delegate = _delegate;
#pragma mark - TabSwitcher
- (void)restoreInternalStateWithMainBrowser:(Browser*)mainBrowser
otrBrowser:(Browser*)otrBrowser
activeBrowser:(Browser*)activeBrowser {
// The only action here is to signal to the tab grid which panel should be
// active.
if (activeBrowser == otrBrowser) {
self.tabGridViewController.activePage = TabGridPageIncognitoTabs;
} else {
self.tabGridViewController.activePage = TabGridPageRegularTabs;
}
}
- (UIViewController*)viewController {
return self.tabGridViewController;
}
- (void)dismissWithNewTabAnimationToBrowser:(Browser*)browser
withUrlLoadParams:(const UrlLoadParams&)urlLoadParams
atIndex:(int)position {
int tabIndex = std::min(position, browser->GetWebStateList()->count());
TabInsertionBrowserAgent::FromBrowser(browser)->InsertWebState(
urlLoadParams.web_params, nil, false, tabIndex, false);
// Tell the delegate to display the tab.
DCHECK(self.delegate);
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:browser
focusOmnibox:NO];
}
- (void)setOtrBrowser:(Browser*)browser {
DCHECK(self.incognitoMediator);
self.incognitoMediator.browser = browser;
}
@end
......@@ -9,14 +9,14 @@
#import "base/ios/block_types.h"
#import "ios/chrome/browser/chrome_root_coordinator.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
@protocol ApplicationCommands;
@protocol BrowsingDataCommands;
@protocol TabSwitcher;
class Browser;
@interface TabGridCoordinator : ChromeRootCoordinator
@interface TabGridCoordinator : ChromeRootCoordinator <TabSwitcher>
- (instancetype)initWithWindow:(UIWindow*)window
applicationCommandEndpoint:
......@@ -27,7 +27,7 @@ class Browser;
- (instancetype)initWithWindow:(UIWindow*)window NS_UNAVAILABLE;
@property(nonatomic, readonly) id<TabSwitcher> tabSwitcher;
@property(nonatomic, weak) id<TabSwitcherDelegate> delegate;
@property(nonatomic, assign) Browser* regularBrowser;
@property(nonatomic, assign) Browser* incognitoBrowser;
......
......@@ -21,7 +21,6 @@
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_presentation_delegate.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_adaptor.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_mediator.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
......@@ -29,6 +28,7 @@
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/tab_insertion_browser_agent.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -43,8 +43,6 @@
// Commad dispatcher used while this coordinator's view controller is active.
// (for compatibility with the TabSwitcher protocol).
@property(nonatomic, strong) CommandDispatcher* dispatcher;
// Object that internally backs the public TabSwitcher
@property(nonatomic, strong) TabGridAdaptor* adaptor;
// Container view controller for the BVC to live in; this class's view
// controller will present this.
@property(nonatomic, strong) BVCContainerViewController* bvcContainer;
......@@ -92,10 +90,6 @@
#pragma mark - Public
- (id<TabSwitcher>)tabSwitcher {
return self.adaptor;
}
- (Browser*)regularBrowser {
// Ensure browser which is actually used by the mediator is returned, as it
// may have been updated.
......@@ -147,9 +141,6 @@
baseViewController.tabPresentationDelegate = self;
_baseViewController = baseViewController;
self.adaptor = [[TabGridAdaptor alloc] init];
self.adaptor.tabGridViewController = self.baseViewController;
self.regularTabsMediator = [[TabGridMediator alloc]
initWithConsumer:baseViewController.regularTabsConsumer];
ChromeBrowserState* regularBrowserState =
......@@ -166,7 +157,6 @@
self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:baseViewController.incognitoTabsConsumer];
self.incognitoTabsMediator.browser = _incognitoBrowser;
self.adaptor.incognitoMediator = self.incognitoTabsMediator;
baseViewController.regularTabsDelegate = self.regularTabsMediator;
baseViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
baseViewController.regularTabsDragDropHandler = self.regularTabsMediator;
......@@ -261,11 +251,7 @@
}
- (void)showTabSwitcher:(id<TabSwitcher>)tabSwitcher {
DCHECK(tabSwitcher);
DCHECK_EQ([tabSwitcher viewController], self.baseViewController);
// It's also expected that |tabSwitcher| will be |self.tabSwitcher|, but that
// may not be worth a DCHECK?
BOOL animated = !self.animationsDisabledForTesting;
// If a BVC is currently being presented, dismiss it. This will trigger any
......@@ -323,8 +309,7 @@
// on top of the tab switcher) transition has completed.
// Finally, the launch mask view should be removed.
ProceduralBlock extendedCompletion = ^{
[self.tabSwitcher.delegate
tabSwitcherDismissTransitionDidEnd:self.tabSwitcher];
[self.delegate tabSwitcherDismissTransitionDidEnd:self];
if (!GetFirstResponder()) {
// It is possible to already have a first responder (for example the
// omnibox). In that case, we don't want to mark BVC as first responder.
......@@ -339,7 +324,7 @@
self.baseViewController.childViewControllerForStatusBarStyle =
self.bvcContainer.currentBVC;
[self.adaptor.tabGridViewController contentWillDisappearAnimated:animated];
[self.baseViewController contentWillDisappearAnimated:animated];
self.transitionHandler = [[TabGridTransitionHandler alloc]
initWithLayoutProvider:self.baseViewController];
......@@ -371,11 +356,11 @@
// Defensively early return instead of continuing.
return;
}
// Trigger the transition through the TabSwitcher delegate. This will in turn
// call back into this coordinator via the ViewControllerSwapping protocol.
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithBrowser:activeBrowser
focusOmnibox:focusOmnibox];
// Trigger the transition through the delegate. This will in turn call back
// into this coordinator via the ViewControllerSwapping protocol.
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:activeBrowser
focusOmnibox:focusOmnibox];
}
#pragma mark - RecentTabsPresentationDelegate
......@@ -399,23 +384,56 @@
}
- (void)showActiveRegularTabFromRecentTabs {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
}
#pragma mark - HistoryPresentationDelegate
- (void)showActiveRegularTabFromHistory {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
}
- (void)showActiveIncognitoTabFromHistory {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithBrowser:self.incognitoBrowser
focusOmnibox:NO];
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:self.incognitoBrowser
focusOmnibox:NO];
}
#pragma mark - TabSwitcher
- (void)restoreInternalStateWithMainBrowser:(Browser*)mainBrowser
otrBrowser:(Browser*)otrBrowser
activeBrowser:(Browser*)activeBrowser {
// The only action here is to signal to the tab grid which panel should be
// active.
if (activeBrowser == otrBrowser) {
self.baseViewController.activePage = TabGridPageIncognitoTabs;
} else {
self.baseViewController.activePage = TabGridPageRegularTabs;
}
}
- (void)dismissWithNewTabAnimationToBrowser:(Browser*)browser
withUrlLoadParams:(const UrlLoadParams&)urlLoadParams
atIndex:(int)position {
int tabIndex = std::min(position, browser->GetWebStateList()->count());
TabInsertionBrowserAgent::FromBrowser(browser)->InsertWebState(
urlLoadParams.web_params, nil, false, tabIndex, false);
// Tell the delegate to display the tab.
[self.delegate tabSwitcher:self
shouldFinishWithBrowser:browser
focusOmnibox:NO];
}
- (void)setOtrBrowser:(Browser*)browser {
DCHECK(self.incognitoTabsMediator);
self.incognitoTabsMediator.browser = browser;
}
@end
......@@ -59,7 +59,7 @@ class TabGridCoordinatorTest : public BlockCleanupTest {
[coordinator_ start];
delegate_ = [[TestTabSwitcherDelegate alloc] init];
coordinator_.tabSwitcher.delegate = delegate_;
coordinator_.delegate = delegate_;
normal_tab_view_controller_ = [[UIViewController alloc] init];
normal_tab_view_controller_.view.frame = CGRectMake(20, 20, 10, 10);
......@@ -115,11 +115,11 @@ TEST_F(TabGridCoordinatorTest, TabViewControllerBeforeTabSwitcher) {
EXPECT_EQ(normal_tab_view_controller_, coordinator_.activeViewController);
// Now setting a TabSwitcher will make the switcher active.
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
[coordinator_ showTabSwitcher:coordinator_];
bool tab_switcher_active = base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, ^bool {
return [coordinator_.tabSwitcher viewController] ==
coordinator_.activeViewController;
return
[coordinator_ viewController] == coordinator_.activeViewController;
});
EXPECT_TRUE(tab_switcher_active);
}
......@@ -127,20 +127,19 @@ TEST_F(TabGridCoordinatorTest, TabViewControllerBeforeTabSwitcher) {
// Tests that it is possible to set a TabViewController after setting a
// TabSwitcher.
TEST_F(TabGridCoordinatorTest, TabViewControllerAfterTabSwitcher) {
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
EXPECT_EQ([coordinator_.tabSwitcher viewController],
coordinator_.activeViewController);
[coordinator_ showTabSwitcher:coordinator_];
EXPECT_EQ([coordinator_ viewController], coordinator_.activeViewController);
[coordinator_ showTabViewController:normal_tab_view_controller_
completion:nil];
EXPECT_EQ(normal_tab_view_controller_, coordinator_.activeViewController);
// Showing the TabSwitcher again will make it active.
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
[coordinator_ showTabSwitcher:coordinator_];
bool tab_switcher_active = base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, ^bool {
return [coordinator_.tabSwitcher viewController] ==
coordinator_.activeViewController;
return
[coordinator_ viewController] == coordinator_.activeViewController;
});
EXPECT_TRUE(tab_switcher_active);
}
......@@ -158,13 +157,11 @@ TEST_F(TabGridCoordinatorTest, SwapTabViewControllers) {
// Tests calling showTabSwitcher twice in a row with the same VC.
TEST_F(TabGridCoordinatorTest, ShowTabSwitcherTwice) {
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
EXPECT_EQ([coordinator_.tabSwitcher viewController],
coordinator_.activeViewController);
[coordinator_ showTabSwitcher:coordinator_];
EXPECT_EQ([coordinator_ viewController], coordinator_.activeViewController);
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
EXPECT_EQ([coordinator_.tabSwitcher viewController],
coordinator_.activeViewController);
[coordinator_ showTabSwitcher:coordinator_];
EXPECT_EQ([coordinator_ viewController], coordinator_.activeViewController);
}
// Tests calling showTabViewController twice in a row with the same VC.
......@@ -182,7 +179,7 @@ TEST_F(TabGridCoordinatorTest, ShowTabViewControllerTwice) {
// handlers are called properly after the new view controller is made active.
TEST_F(TabGridCoordinatorTest, CompletionHandlers) {
// Setup: show the switcher.
[coordinator_ showTabSwitcher:coordinator_.tabSwitcher];
[coordinator_ showTabSwitcher:coordinator_];
// Tests that the completion handler is called when showing a tab view
// controller. Tests that the delegate 'didEnd' method is also called.
......
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