Commit c5201ecc authored by Nazerke's avatar Nazerke Committed by Commit Bot

[ios] Connect a new TabStrip with the current view.

This CL add a new TabStrip view to BVC.

Bug: 1132236, 1128249
Change-Id: Ife191e6de13b8bbf700fb5ae4abe3fcb34a948e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436537Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#816538}
parent 1f194904
...@@ -195,6 +195,9 @@ using base::UserMetricsAction; ...@@ -195,6 +195,9 @@ using base::UserMetricsAction;
namespace { namespace {
// The size of the tab strip view.
const CGFloat kTabStripHeight = 39.0;
const size_t kMaxURLDisplayChars = 32 * 1024; const size_t kMaxURLDisplayChars = 32 * 1024;
typedef NS_ENUM(NSInteger, ContextMenuHistogram) { typedef NS_ENUM(NSInteger, ContextMenuHistogram) {
...@@ -981,7 +984,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -981,7 +984,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
headerBehaviour:Hideable]]; headerBehaviour:Hideable]];
} }
} else { } else {
if (self.tabStripView) { if (self.tabStripView && !base::FeatureList::IsEnabled(kModernTabStrip)) {
[results addObject:[HeaderDefinition definitionWithView:self.tabStripView [results addObject:[HeaderDefinition definitionWithView:self.tabStripView
headerBehaviour:Hideable]]; headerBehaviour:Hideable]];
} }
...@@ -1439,6 +1442,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1439,6 +1442,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[self installFakeStatusBar]; [self installFakeStatusBar];
[self buildToolbarAndTabStrip]; [self buildToolbarAndTabStrip];
[self setUpViewLayout:YES]; [self setUpViewLayout:YES];
[self addConstraintsToTabStrip];
[self addConstraintsToToolbar]; [self addConstraintsToToolbar];
// If the tab model and browser state are valid, finish initialization. // If the tab model and browser state are valid, finish initialization.
...@@ -1626,20 +1630,22 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1626,20 +1630,22 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[self updateToolbar]; [self updateToolbar];
// Update the tab strip visibility. // Update the tab strip visibility.
if (!base::FeatureList::IsEnabled(kModernTabStrip)) { if (self.tabStripView) {
if (self.tabStripView) { [self showTabStripView:self.tabStripView];
[self showTabStripView:self.tabStripView]; [self.tabStripView layoutSubviews];
[self.tabStripView layoutSubviews]; if (base::FeatureList::IsEnabled(kModernTabStrip)) {
[self.tabStripCoordinator hideTabStrip:![self canShowTabStrip]];
} else {
[self.legacyTabStripCoordinator hideTabStrip:![self canShowTabStrip]]; [self.legacyTabStripCoordinator hideTabStrip:![self canShowTabStrip]];
_fakeStatusBarView.hidden = ![self canShowTabStrip]; }
[self addConstraintsToPrimaryToolbar]; _fakeStatusBarView.hidden = ![self canShowTabStrip];
// If tabstrip is coming back due to a window resize or screen rotation, [self addConstraintsToPrimaryToolbar];
// reset the full screen controller to adjust the tabstrip position. // If tabstrip is coming back due to a window resize or screen rotation,
if (ShouldShowCompactToolbar(previousTraitCollection) && // reset the full screen controller to adjust the tabstrip position.
!ShouldShowCompactToolbar(self)) { if (ShouldShowCompactToolbar(previousTraitCollection) &&
[self updateForFullscreenProgress:self.fullscreenController !ShouldShowCompactToolbar(self)) {
->GetProgress()]; [self
} updateForFullscreenProgress:self.fullscreenController->GetProgress()];
} }
} }
...@@ -1820,7 +1826,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1820,7 +1826,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
- (UIStatusBarStyle)preferredStatusBarStyle { - (UIStatusBarStyle)preferredStatusBarStyle {
if ([self canShowTabStrip] && !_isOffTheRecord) { if ([self canShowTabStrip] && !_isOffTheRecord &&
!base::FeatureList::IsEnabled(kModernTabStrip)) {
return self.tabStripView.frame.origin.y < kTabStripAppearanceOffset return self.tabStripView.frame.origin.y < kTabStripAppearanceOffset
? UIStatusBarStyleDefault ? UIStatusBarStyleDefault
: UIStatusBarStyleLightContent; : UIStatusBarStyleLightContent;
...@@ -2035,6 +2042,22 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2035,6 +2042,22 @@ NSString* const kBrowserViewControllerSnackbarCategory =
return secondaryToolbar.intrinsicContentSize.height + unsafeHeight; return secondaryToolbar.intrinsicContentSize.height + unsafeHeight;
} }
- (void)addConstraintsToTabStrip {
if (!base::FeatureList::IsEnabled(kModernTabStrip))
return;
self.tabStripView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[self.view.safeAreaLayoutGuide.topAnchor
constraintEqualToAnchor:self.tabStripView.topAnchor],
[self.view.safeAreaLayoutGuide.leadingAnchor
constraintEqualToAnchor:self.tabStripView.leadingAnchor],
[self.view.safeAreaLayoutGuide.trailingAnchor
constraintEqualToAnchor:self.tabStripView.trailingAnchor],
[self.tabStripView.heightAnchor constraintEqualToConstant:kTabStripHeight],
]];
}
- (void)addConstraintsToPrimaryToolbar { - (void)addConstraintsToPrimaryToolbar {
NSLayoutYAxisAnchor* topAnchor; NSLayoutYAxisAnchor* topAnchor;
// On iPad, the toolbar is underneath the tab strip. // On iPad, the toolbar is underneath the tab strip.
...@@ -2234,6 +2257,12 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2234,6 +2257,12 @@ NSString* const kBrowserViewControllerSnackbarCategory =
UIView* primaryToolbarView = UIView* primaryToolbarView =
self.primaryToolbarCoordinator.viewController.view; self.primaryToolbarCoordinator.viewController.view;
if (IsIPadIdiom()) { if (IsIPadIdiom()) {
if (base::FeatureList::IsEnabled(kModernTabStrip) &&
self.tabStripCoordinator) {
[self addChildViewController:self.tabStripCoordinator.viewController];
self.tabStripView = self.tabStripCoordinator.view;
[self.view addSubview:self.tabStripView];
}
[self.view insertSubview:primaryToolbarView [self.view insertSubview:primaryToolbarView
aboveSubview:self.tabStripView]; aboveSubview:self.tabStripView];
} else { } else {
...@@ -2307,6 +2336,8 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2307,6 +2336,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Complete child UIViewController containment flow now that the views are // Complete child UIViewController containment flow now that the views are
// finished being added. // finished being added.
[self.tabStripCoordinator.viewController
didMoveToParentViewController:self];
[self.primaryToolbarCoordinator.viewController [self.primaryToolbarCoordinator.viewController
didMoveToParentViewController:self]; didMoveToParentViewController:self];
if (self.secondaryToolbarCoordinator) { if (self.secondaryToolbarCoordinator) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
class Browser; class Browser;
@protocol PopupMenuLongPressDelegate; @protocol PopupMenuLongPressDelegate;
@protocol TabStripContaining;
@class TabStripViewController; @class TabStripViewController;
// Coordinator for the tab strip. // Coordinator for the tab strip.
...@@ -24,9 +25,15 @@ class Browser; ...@@ -24,9 +25,15 @@ class Browser;
// The TabStrip view controller owned by this coordinator. // The TabStrip view controller owned by this coordinator.
@property(nonatomic, strong) UIViewController* viewController; @property(nonatomic, strong) UIViewController* viewController;
// The TabStrip view owned by the viewcontroller of this coordinator.
@property(nonatomic, strong, readonly) UIView<TabStripContaining>* view;
// Delegate for the long press gesture recognizer triggering popup menu. // Delegate for the long press gesture recognizer triggering popup menu.
@property(nonatomic, weak) id<PopupMenuLongPressDelegate> longPressDelegate; @property(nonatomic, weak) id<PopupMenuLongPressDelegate> longPressDelegate;
// Hides or shows the tab strip.
- (void)hideTabStrip:(BOOL)hidden;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TAB_STRIP_TAB_STRIP_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_STRIP_TAB_STRIP_COORDINATOR_H_
...@@ -45,4 +45,14 @@ ...@@ -45,4 +45,14 @@
_longPressDelegate = longPressDelegate; _longPressDelegate = longPressDelegate;
} }
- (UIView<TabStripContaining>*)view {
return static_cast<UIView<TabStripContaining>*>(self.viewController.view);
}
#pragma mark - Public
- (void)hideTabStrip:(BOOL)hidden {
self.viewController.view.hidden = hidden;
}
@end @end
...@@ -14,13 +14,15 @@ ...@@ -14,13 +14,15 @@
- (instancetype)init { - (instancetype)init {
TabStripViewLayout* layout = [[TabStripViewLayout alloc] init]; TabStripViewLayout* layout = [[TabStripViewLayout alloc] init];
self = [super initWithCollectionViewLayout:layout]; if (self = [super initWithCollectionViewLayout:layout]) {
}
return self; return self;
} }
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
self.collectionView.alwaysBounceHorizontal = YES;
} }
@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