Commit 013d9ac4 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Remove tabModel usage from SideSwipeController/SideSwipeView

SideSwipeController initializer now take a Browser instead of browserState
and tabModel.
SideSwipeView will be initialized with webStateList instead of tabModel.

Bug: 783777, 1043370
Change-Id: I5ed4e20b9bb6f8def9f6fff89a333bdfc142b59d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008003
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734107}
parent 8acb9c1f
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper.h" #import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper.h"
#import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper_delegate.h" #import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper_delegate.h"
#include "ios/chrome/browser/system_flags.h" #include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/translate/chrome_ios_translate_client.h" #import "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h" #import "ios/chrome/browser/ui/activity_services/activity_service_legacy_coordinator.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_presentation.h"
...@@ -844,8 +845,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -844,8 +845,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (SideSwipeController*)sideSwipeController { - (SideSwipeController*)sideSwipeController {
if (!_sideSwipeController) { if (!_sideSwipeController) {
_sideSwipeController = _sideSwipeController =
[[SideSwipeController alloc] initWithTabModel:self.tabModel [[SideSwipeController alloc] initWithBrowser:self.browser];
browserState:self.browserState];
[_sideSwipeController setSnapshotDelegate:self]; [_sideSwipeController setSnapshotDelegate:self];
_sideSwipeController.toolbarInteractionHandler = self.toolbarInterface; _sideSwipeController.toolbarInteractionHandler = self.toolbarInterface;
_sideSwipeController.primaryToolbarSnapshotProvider = _sideSwipeController.primaryToolbarSnapshotProvider =
......
...@@ -25,9 +25,9 @@ source_set("side_swipe") { ...@@ -25,9 +25,9 @@ source_set("side_swipe") {
"//ios/chrome/app/theme", "//ios/chrome/app/theme",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/reading_list", "//ios/chrome/browser/reading_list",
"//ios/chrome/browser/snapshots", "//ios/chrome/browser/snapshots",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/fullscreen", "//ios/chrome/browser/ui/fullscreen",
...@@ -60,6 +60,7 @@ source_set("unit_tests") { ...@@ -60,6 +60,7 @@ source_set("unit_tests") {
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/web/common", "//ios/web/common",
"//ios/web/public/test", "//ios/web/public/test",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
@class SideSwipeGestureRecognizer; @class SideSwipeGestureRecognizer;
@protocol SideSwipeToolbarSnapshotProviding; @protocol SideSwipeToolbarSnapshotProviding;
@class TabModel; class WebStateList;
@interface CardSideSwipeView : UIView @interface CardSideSwipeView : UIView
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
topMargin:(CGFloat)margin topMargin:(CGFloat)margin
model:(TabModel*)model; webStateList:(WebStateList*)webStateList;
- (void)updateViewsForDirection:(UISwipeGestureRecognizerDirection)direction; - (void)updateViewsForDirection:(UISwipeGestureRecognizerDirection)direction;
- (void)handleHorizontalPan:(SideSwipeGestureRecognizer*)gesture; - (void)handleHorizontalPan:(SideSwipeGestureRecognizer*)gesture;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h" #import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/side_swipe/side_swipe_gesture_recognizer.h" #import "ios/chrome/browser/ui/side_swipe/side_swipe_gesture_recognizer.h"
#import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h" #import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h"
#import "ios/chrome/browser/ui/side_swipe/swipe_view.h" #import "ios/chrome/browser/ui/side_swipe/swipe_view.h"
...@@ -72,8 +71,8 @@ const CGFloat kResizeFactor = 4; ...@@ -72,8 +71,8 @@ const CGFloat kResizeFactor = 4;
// Most recent touch location. // Most recent touch location.
CGPoint _currentPoint; CGPoint _currentPoint;
// Tab model. // WebStateList provided from the initializer.
__weak TabModel* _model; WebStateList* _webStateList;
} }
@synthesize backgroundTopConstraint = _backgroundTopConstraint; @synthesize backgroundTopConstraint = _backgroundTopConstraint;
...@@ -84,10 +83,10 @@ const CGFloat kResizeFactor = 4; ...@@ -84,10 +83,10 @@ const CGFloat kResizeFactor = 4;
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
topMargin:(CGFloat)topMargin topMargin:(CGFloat)topMargin
model:(TabModel*)model { webStateList:(WebStateList*)webStateList {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_model = model; _webStateList = webStateList;
_currentPoint = CGPointZero; _currentPoint = CGPointZero;
_topMargin = topMargin; _topMargin = topMargin;
...@@ -142,7 +141,7 @@ const CGFloat kResizeFactor = 4; ...@@ -142,7 +141,7 @@ const CGFloat kResizeFactor = 4;
// direction. // direction.
- (void)updateViewsForDirection:(UISwipeGestureRecognizerDirection)direction { - (void)updateViewsForDirection:(UISwipeGestureRecognizerDirection)direction {
_direction = direction; _direction = direction;
int currentIndex = _model.webStateList->active_index(); int currentIndex = _webStateList->active_index();
CGFloat offset = UseRTLLayout() ? -1 : 1; CGFloat offset = UseRTLLayout() ? -1 : 1;
if (_direction == UISwipeGestureRecognizerDirectionRight) { if (_direction == UISwipeGestureRecognizerDirectionRight) {
[self setupCard:_rightCard withIndex:currentIndex]; [self setupCard:_rightCard withIndex:currentIndex];
...@@ -165,15 +164,15 @@ const CGFloat kResizeFactor = 4; ...@@ -165,15 +164,15 @@ const CGFloat kResizeFactor = 4;
return greyImage; return greyImage;
} }
// Create card view based on TabModel's WebStateList index. // Create card view based on |_webStateList|'s index.
- (void)setupCard:(SwipeView*)card withIndex:(int)index { - (void)setupCard:(SwipeView*)card withIndex:(int)index {
if (index < 0 || index >= (NSInteger)[_model count]) { if (index < 0 || index >= _webStateList->count()) {
[card setHidden:YES]; [card setHidden:YES];
return; return;
} }
[card setHidden:NO]; [card setHidden:NO];
web::WebState* webState = _model.webStateList->GetWebStateAt(index); web::WebState* webState = _webStateList->GetWebStateAt(index);
UIImage* topToolbarSnapshot = [self.topToolbarSnapshotProvider UIImage* topToolbarSnapshot = [self.topToolbarSnapshotProvider
toolbarSideSwipeSnapshotForWebState:webState]; toolbarSideSwipeSnapshotForWebState:webState];
[card setTopToolbarImage:topToolbarSnapshot]; [card setTopToolbarImage:topToolbarSnapshot];
...@@ -260,17 +259,16 @@ const CGFloat kResizeFactor = 4; ...@@ -260,17 +259,16 @@ const CGFloat kResizeFactor = 4;
} }
- (BOOL)isEdgeSwipe { - (BOOL)isEdgeSwipe {
int currentIndex = _model.webStateList->active_index(); int currentIndex = _webStateList->active_index();
return (IsSwipingBack(_direction) && currentIndex == 0) || return (IsSwipingBack(_direction) && currentIndex == 0) ||
(IsSwipingForward(_direction) && (IsSwipingForward(_direction) &&
currentIndex == _model.webStateList->count() - 1); currentIndex == _webStateList->count() - 1);
} }
// Update the current WebState and animate the proper card view if the // Update the current WebState and animate the proper card view if the
// |currentPoint_| is past the center of |bounds|. // |currentPoint_| is past the center of |bounds|.
- (void)finishPan { - (void)finishPan {
WebStateList* webStateList = _model.webStateList; int currentIndex = _webStateList->active_index();
int currentIndex = webStateList->active_index();
// Something happened and now there is not active WebState. End card side let // Something happened and now there is not active WebState. End card side let
// swipe and BVC show no tabs UI. // swipe and BVC show no tabs UI.
if (currentIndex == WebStateList::kInvalidIndex) if (currentIndex == WebStateList::kInvalidIndex)
...@@ -318,7 +316,7 @@ const CGFloat kResizeFactor = 4; ...@@ -318,7 +316,7 @@ const CGFloat kResizeFactor = 4;
if (destinationWebStateIndex != currentIndex) { if (destinationWebStateIndex != currentIndex) {
// The old webstate is now hidden. The new WebState will be inserted once // The old webstate is now hidden. The new WebState will be inserted once
// the animation is complete. // the animation is complete.
webStateList->GetActiveWebState()->WasHidden(); _webStateList->GetActiveWebState()->WasHidden();
} }
// Make sure the dominant card animates on top. // Make sure the dominant card animates on top.
...@@ -342,7 +340,7 @@ const CGFloat kResizeFactor = 4; ...@@ -342,7 +340,7 @@ const CGFloat kResizeFactor = 4;
// because ActivateWebStateAt triggers behavior that depends on the view // because ActivateWebStateAt triggers behavior that depends on the view
// hierarchy being reassembled, which happens in // hierarchy being reassembled, which happens in
// sideSwipeViewDismissAnimationDidEnd. // sideSwipeViewDismissAnimationDidEnd.
webStateList->ActivateWebStateAt(destinationWebStateIndex); _webStateList->ActivateWebStateAt(destinationWebStateIndex);
}]; }];
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/snapshots/snapshot_generator_delegate.h" #import "ios/chrome/browser/snapshots/snapshot_generator_delegate.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
namespace web { namespace web {
...@@ -20,6 +19,7 @@ class WebState; ...@@ -20,6 +19,7 @@ class WebState;
@protocol SideSwipeToolbarInteracting; @protocol SideSwipeToolbarInteracting;
@protocol SideSwipeToolbarSnapshotProviding; @protocol SideSwipeToolbarSnapshotProviding;
@protocol TabStripHighlighting; @protocol TabStripHighlighting;
class Browser;
// Notification sent when the user starts a side swipe (on tablet). // Notification sent when the user starts a side swipe (on tablet).
extern NSString* const kSideSwipeWillStartNotification; extern NSString* const kSideSwipeWillStartNotification;
...@@ -41,7 +41,7 @@ extern NSString* const kSideSwipeDidStopNotification; ...@@ -41,7 +41,7 @@ extern NSString* const kSideSwipeDidStopNotification;
// Controls the visibility of views such as the findbar, infobar and voice // Controls the visibility of views such as the findbar, infobar and voice
// search bar. // search bar.
- (void)updateAccessoryViewsForSideSwipeWithVisibility:(BOOL)visible; - (void)updateAccessoryViewsForSideSwipeWithVisibility:(BOOL)visible;
// Returns the height of the header view for the tab model's current tab. // Returns the height of the header view for the current tab.
- (CGFloat)headerHeightForSideSwipe; - (CGFloat)headerHeightForSideSwipe;
// Returns |YES| if side swipe should be blocked from initiating, such as when // Returns |YES| if side swipe should be blocked from initiating, such as when
// voice search is up, or if the tools menu is enabled. // voice search is up, or if the tools menu is enabled.
...@@ -77,8 +77,7 @@ extern NSString* const kSideSwipeDidStopNotification; ...@@ -77,8 +77,7 @@ extern NSString* const kSideSwipeDidStopNotification;
@property(nonatomic, weak) id<TabStripHighlighting> tabStripDelegate; @property(nonatomic, weak) id<TabStripHighlighting> tabStripDelegate;
// Initializer. // Initializer.
- (id)initWithTabModel:(TabModel*)model - (instancetype)initWithBrowser:(Browser*)browser;
browserState:(ios::ChromeBrowserState*)browserState;
// Set up swipe gesture recognizers. // Set up swipe gesture recognizers.
- (void)addHorizontalGesturesToView:(UIView*)view; - (void)addHorizontalGesturesToView:(UIView*)view;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "base/ios/block_types.h" #import "base/ios/block_types.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#import "ios/chrome/browser/browser_state/chrome_browser_state.h" #import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/snapshots/snapshot_cache.h" #import "ios/chrome/browser/snapshots/snapshot_cache.h"
#import "ios/chrome/browser/snapshots/snapshot_cache_factory.h" #import "ios/chrome/browser/snapshots/snapshot_cache_factory.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h" #import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
...@@ -62,7 +63,8 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -62,7 +63,8 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
WebStateListObserving> { WebStateListObserving> {
@private @private
__weak TabModel* _model; // Browser passed on the initializer.
Browser* _browser;
// Side swipe view for tab navigation. // Side swipe view for tab navigation.
CardSideSwipeView* _tabSideSwipeView; CardSideSwipeView* _tabSideSwipeView;
...@@ -104,9 +106,6 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -104,9 +106,6 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
// The animated disabler displays the toolbar when a side swipe navigation // The animated disabler displays the toolbar when a side swipe navigation
// gesture is being recognized. // gesture is being recognized.
std::unique_ptr<AnimatedScopedFullscreenDisabler> _animatedFullscreenDisabler; std::unique_ptr<AnimatedScopedFullscreenDisabler> _animatedFullscreenDisabler;
// Browser state passed to the initialiser.
ios::ChromeBrowserState* _browserState;
} }
// Whether to allow navigating from the leading edge. // Whether to allow navigating from the leading edge.
...@@ -115,6 +114,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -115,6 +114,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
@property(nonatomic, assign) BOOL trailingEdgeNavigationEnabled; @property(nonatomic, assign) BOOL trailingEdgeNavigationEnabled;
// The current active WebState. // The current active WebState.
@property(nonatomic, readonly) web::WebState* activeWebState; @property(nonatomic, readonly) web::WebState* activeWebState;
// The browser state owning the current browser.
@property(nonatomic, readonly) ios::ChromeBrowserState* browserState;
// The webStateList owned by the current browser.
@property(nonatomic, readonly) WebStateList* webStateList;
// Load grey snapshots for the next |kIpadGreySwipeTabCount| tabs in // Load grey snapshots for the next |kIpadGreySwipeTabCount| tabs in
// |direction|. // |direction|.
...@@ -149,14 +152,13 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -149,14 +152,13 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
@synthesize snapshotDelegate = _snapshotDelegate; @synthesize snapshotDelegate = _snapshotDelegate;
@synthesize tabStripDelegate = _tabStripDelegate; @synthesize tabStripDelegate = _tabStripDelegate;
- (id)initWithTabModel:(TabModel*)model - (instancetype)initWithBrowser:(Browser*)browser {
browserState:(ios::ChromeBrowserState*)browserState { DCHECK(browser);
DCHECK(model);
self = [super init]; self = [super init];
if (self) { if (self) {
_model = model; _browser = browser;
_webStateListObserver = std::make_unique<WebStateListObserverBridge>(self); _webStateListObserver = std::make_unique<WebStateListObserverBridge>(self);
_model.webStateList->AddObserver(_webStateListObserver.get()); _browser->GetWebStateList()->AddObserver(_webStateListObserver.get());
_webStateObserverBridge = _webStateObserverBridge =
std::make_unique<web::WebStateObserverBridge>(self); std::make_unique<web::WebStateObserverBridge>(self);
_scopedWebStateObserver = _scopedWebStateObserver =
...@@ -164,17 +166,13 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -164,17 +166,13 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
_webStateObserverBridge.get()); _webStateObserverBridge.get());
if (self.activeWebState) if (self.activeWebState)
_scopedWebStateObserver->Add(self.activeWebState); _scopedWebStateObserver->Add(self.activeWebState);
_browserState = browserState;
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
if (_model.webStateList) { if (self.webStateList) {
// |model_| is a weak reference which owns |webStateList|. Make sure that self.webStateList->RemoveObserver(_webStateListObserver.get());
// |model_| is still alive before accessing |webStateList|.
_model.webStateList->RemoveObserver(_webStateListObserver.get());
} }
_scopedWebStateObserver.reset(); _scopedWebStateObserver.reset();
...@@ -202,8 +200,15 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -202,8 +200,15 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
} }
- (web::WebState*)activeWebState { - (web::WebState*)activeWebState {
return _model.webStateList ? _model.webStateList->GetActiveWebState() return self.webStateList ? self.webStateList->GetActiveWebState() : nullptr;
: nullptr; }
- (ios::ChromeBrowserState*)browserState {
return _browser->GetBrowserState();
}
- (WebStateList*)webStateList {
return _browser->GetWebStateList();
} }
- (NSSet*)swipeRecognizers { - (NSSet*)swipeRecognizers {
...@@ -299,28 +304,28 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -299,28 +304,28 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
[NSMutableArray arrayWithCapacity:kIpadGreySwipeTabCount]; [NSMutableArray arrayWithCapacity:kIpadGreySwipeTabCount];
for (NSUInteger count = 0; count < kIpadGreySwipeTabCount; count++) { for (NSUInteger count = 0; count < kIpadGreySwipeTabCount; count++) {
// Wrap around edges. // Wrap around edges.
if (index >= (NSInteger)[_model count]) if (index >= self.webStateList->count())
index = 0; index = 0;
else if (index < 0) else if (index < 0)
index = [_model count] - 1; index = self.webStateList->count() - 1;
// Don't wrap past the starting index. // Don't wrap past the starting index.
if (index == (NSInteger)_startingTabIndex) if (index == (NSInteger)_startingTabIndex)
break; break;
web::WebState* webState = _model.webStateList->GetWebStateAt(index); web::WebState* webState = self.webStateList->GetWebStateAt(index);
if (webState && PagePlaceholderTabHelper::FromWebState(webState) if (webState && PagePlaceholderTabHelper::FromWebState(webState)
->will_add_placeholder_for_next_navigation()) { ->will_add_placeholder_for_next_navigation()) {
[sessionIDs addObject:TabIdTabHelper::FromWebState(webState)->tab_id()]; [sessionIDs addObject:TabIdTabHelper::FromWebState(webState)->tab_id()];
} }
index = index + dx; index = index + dx;
} }
[SnapshotCacheFactory::GetForBrowserState(_browserState) [SnapshotCacheFactory::GetForBrowserState(self.browserState)
createGreyCache:sessionIDs]; createGreyCache:sessionIDs];
} }
- (void)deleteGreyCache { - (void)deleteGreyCache {
[SnapshotCacheFactory::GetForBrowserState(_browserState) removeGreyCache]; [SnapshotCacheFactory::GetForBrowserState(self.browserState) removeGreyCache];
} }
- (void)handlePan:(SideSwipeGestureRecognizer*)gesture { - (void)handlePan:(SideSwipeGestureRecognizer*)gesture {
...@@ -348,7 +353,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -348,7 +353,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
- (void)handleiPadTabSwipe:(SideSwipeGestureRecognizer*)gesture { - (void)handleiPadTabSwipe:(SideSwipeGestureRecognizer*)gesture {
// Don't handle swipe when there are no tabs. // Don't handle swipe when there are no tabs.
NSInteger count = [_model count]; int count = self.webStateList->count();
if (count == 0) if (count == 0)
return; return;
...@@ -356,14 +361,14 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -356,14 +361,14 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
// Disable fullscreen while the side swipe gesture is occurring. // Disable fullscreen while the side swipe gesture is occurring.
_fullscreenDisabler = std::make_unique<ScopedFullscreenDisabler>( _fullscreenDisabler = std::make_unique<ScopedFullscreenDisabler>(
FullscreenControllerFactory::GetInstance()->GetForBrowserState( FullscreenControllerFactory::GetInstance()->GetForBrowserState(
_browserState)); self.browserState));
SnapshotTabHelper::FromWebState(self.activeWebState) SnapshotTabHelper::FromWebState(self.activeWebState)
->UpdateSnapshotWithCallback(nil); ->UpdateSnapshotWithCallback(nil);
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationName:kSideSwipeWillStartNotification postNotificationName:kSideSwipeWillStartNotification
object:nil]; object:nil];
[self.tabStripDelegate setHighlightsSelectedTab:YES]; [self.tabStripDelegate setHighlightsSelectedTab:YES];
_startingTabIndex = _model.webStateList->active_index(); _startingTabIndex = self.webStateList->active_index();
[self createGreyCache:gesture.direction]; [self createGreyCache:gesture.direction];
} else if (gesture.state == UIGestureRecognizerStateChanged) { } else if (gesture.state == UIGestureRecognizerStateChanged) {
// Side swipe for iPad involves changing the selected tab as the swipe moves // Side swipe for iPad involves changing the selected tab as the swipe moves
...@@ -385,8 +390,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -385,8 +390,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
indexDelta = 0 - indexDelta; indexDelta = 0 - indexDelta;
web::WebState* currentWebState = self.activeWebState; web::WebState* currentWebState = self.activeWebState;
int currentIndex = int currentIndex = self.webStateList->GetIndexOfWebState(currentWebState);
_model.webStateList->GetIndexOfWebState(currentWebState);
DCHECK_GE(currentIndex, 0); DCHECK_GE(currentIndex, 0);
// Wrap around edges. // Wrap around edges.
int newIndex = (int)(_startingTabIndex + indexDelta) % count; int newIndex = (int)(_startingTabIndex + indexDelta) % count;
...@@ -396,11 +400,11 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -396,11 +400,11 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
newIndex += count; newIndex += count;
if (newIndex != currentIndex) { if (newIndex != currentIndex) {
web::WebState* webState = _model.webStateList->GetWebStateAt(newIndex); web::WebState* webState = self.webStateList->GetWebStateAt(newIndex);
// Toggle overlay preview mode for selected tab. // Toggle overlay preview mode for selected tab.
PagePlaceholderTabHelper::FromWebState(webState) PagePlaceholderTabHelper::FromWebState(webState)
->AddPlaceholderForNextNavigation(); ->AddPlaceholderForNextNavigation();
_model.webStateList->ActivateWebStateAt(newIndex); self.webStateList->ActivateWebStateAt(newIndex);
// And disable overlay preview mode for last selected tab. // And disable overlay preview mode for last selected tab.
PagePlaceholderTabHelper::FromWebState(currentWebState) PagePlaceholderTabHelper::FromWebState(currentWebState)
...@@ -410,10 +414,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -410,10 +414,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
} else { } else {
if (gesture.state == UIGestureRecognizerStateCancelled) { if (gesture.state == UIGestureRecognizerStateCancelled) {
web::WebState* webState = web::WebState* webState =
_model.webStateList->GetWebStateAt(_startingTabIndex); self.webStateList->GetWebStateAt(_startingTabIndex);
PagePlaceholderTabHelper::FromWebState(webState) PagePlaceholderTabHelper::FromWebState(webState)
->CancelPlaceholderForNextNavigation(); ->CancelPlaceholderForNextNavigation();
_model.webStateList->ActivateWebStateAt(_startingTabIndex); self.webStateList->ActivateWebStateAt(_startingTabIndex);
} }
PagePlaceholderTabHelper::FromWebState(self.activeWebState) PagePlaceholderTabHelper::FromWebState(self.activeWebState)
->CancelPlaceholderForNextNavigation(); ->CancelPlaceholderForNextNavigation();
...@@ -450,7 +454,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -450,7 +454,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
_animatedFullscreenDisabler = _animatedFullscreenDisabler =
std::make_unique<AnimatedScopedFullscreenDisabler>( std::make_unique<AnimatedScopedFullscreenDisabler>(
FullscreenControllerFactory::GetInstance()->GetForBrowserState( FullscreenControllerFactory::GetInstance()->GetForBrowserState(
_browserState)); self.browserState));
_animatedFullscreenDisabler->StartAnimation(); _animatedFullscreenDisabler->StartAnimation();
_inSwipe = YES; _inSwipe = YES;
...@@ -522,7 +526,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -522,7 +526,7 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
// Add horizontal stack view controller. // Add horizontal stack view controller.
CGFloat headerHeight = CGFloat headerHeight =
FullscreenControllerFactory::GetForBrowserState(_browserState) FullscreenControllerFactory::GetForBrowserState(self.browserState)
->GetMaxViewportInsets() ->GetMaxViewportInsets()
.top; .top;
...@@ -530,9 +534,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -530,9 +534,10 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
[_tabSideSwipeView setFrame:frame]; [_tabSideSwipeView setFrame:frame];
[_tabSideSwipeView setTopMargin:headerHeight]; [_tabSideSwipeView setTopMargin:headerHeight];
} else { } else {
_tabSideSwipeView = [[CardSideSwipeView alloc] initWithFrame:frame _tabSideSwipeView =
topMargin:headerHeight [[CardSideSwipeView alloc] initWithFrame:frame
model:_model]; topMargin:headerHeight
webStateList:self.webStateList];
_tabSideSwipeView.topToolbarSnapshotProvider = _tabSideSwipeView.topToolbarSnapshotProvider =
self.primaryToolbarSnapshotProvider; self.primaryToolbarSnapshotProvider;
_tabSideSwipeView.bottomToolbarSnapshotProvider = _tabSideSwipeView.bottomToolbarSnapshotProvider =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_delegate.h" #import "ios/chrome/browser/web_state_list/web_state_list_delegate.h"
#import "ios/chrome/browser/web_state_list/web_state_opener.h" #import "ios/chrome/browser/web_state_list/web_state_opener.h"
...@@ -40,8 +41,6 @@ class TestWebStateListDelegate : public WebStateListDelegate { ...@@ -40,8 +41,6 @@ class TestWebStateListDelegate : public WebStateListDelegate {
class SideSwipeControllerTest : public PlatformTest { class SideSwipeControllerTest : public PlatformTest {
public: public:
void SetUp() override { void SetUp() override {
// Create a mock for the TabModel that owns the object under test.
tab_model_ = [OCMockObject niceMockForClass:[TabModel class]];
std::unique_ptr<web::TestWebState> original_web_state( std::unique_ptr<web::TestWebState> original_web_state(
std::make_unique<web::TestWebState>()); std::make_unique<web::TestWebState>());
...@@ -50,16 +49,15 @@ class SideSwipeControllerTest : public PlatformTest { ...@@ -50,16 +49,15 @@ class SideSwipeControllerTest : public PlatformTest {
WebStateList::INSERT_NO_FLAGS, WebStateList::INSERT_NO_FLAGS,
WebStateOpener()); WebStateOpener());
WebStateList* web_state_list = web_state_list_.get();
[[[tab_model_ stub] andReturnValue:OCMOCK_VALUE(web_state_list)]
webStateList];
TestChromeBrowserState::Builder builder; TestChromeBrowserState::Builder builder;
browser_state_ = builder.Build(); browser_state_ = builder.Build();
// Create the object to test. // Create the object to test.
browser_ = std::make_unique<TestBrowser>(browser_state_.get(),
web_state_list_.get());
side_swipe_controller_ = side_swipe_controller_ =
[[SideSwipeController alloc] initWithTabModel:tab_model_ [[SideSwipeController alloc] initWithBrowser:browser_.get()];
browserState:browser_state_.get()];
view_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)]; view_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
...@@ -70,9 +68,9 @@ class SideSwipeControllerTest : public PlatformTest { ...@@ -70,9 +68,9 @@ class SideSwipeControllerTest : public PlatformTest {
std::unique_ptr<TestChromeBrowserState> browser_state_; std::unique_ptr<TestChromeBrowserState> browser_state_;
TestWebStateListDelegate web_state_list_delegate_; TestWebStateListDelegate web_state_list_delegate_;
std::unique_ptr<WebStateList> web_state_list_; std::unique_ptr<WebStateList> web_state_list_;
std::unique_ptr<Browser> browser_;
UIView* view_; UIView* view_;
id tab_model_;
SideSwipeController* side_swipe_controller_; SideSwipeController* side_swipe_controller_;
}; };
......
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