Commit 8a937cfd authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS Fullscreen] Fix MoveContentBelowHeader

This CL fixes MoveContentBelowHeader to have it take into account the
bottom toolbar. This function now moves the content below the header but
also add an inset for the bottom toolbar.

Bug: 851129
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I2b7c5e54e1597bf2779e028381b9d05910c021c7
Reviewed-on: https://chromium-review.googlesource.com/1111845Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570697}
parent a4c3953c
......@@ -62,6 +62,13 @@
// toolbar overlap distance will be reduced to the collapsed height.
- (void)broadcastExpandedToolbarHeight:(CGFloat)height;
// Observer method for objects that care about the height of the bottom toolbar.
// The value broadcast by this method is the distance by which the toolbar
// overlaps the browser content area after the toolbar when the toolbar is fully
// visible (i.e. after a page load). When scrolling occurs, the toolbar overlap
// distance will be reduced to the collapsed height.
- (void)broadcastBottomToolbarHeight:(CGFloat)height;
@end
#endif // IOS_CHROME_BROWSER_UI_BROADCASTER_CHROME_BROADCAST_OBSERVER_H_
......@@ -34,10 +34,13 @@ class ChromeBroadcastObserverInterface {
virtual void OnScrollViewIsDraggingBroadcasted(bool dragging) {}
// Invoked by |-broadcastCollapsedToolbarHeight:|.
virtual void OnCollapsedToolbarHeightBroadcasted(CGFloat min_height) {}
virtual void OnCollapsedToolbarHeightBroadcasted(CGFloat height) {}
// Invoked by |-broadcastExpandedToolbarHeight:|.
virtual void OnExpandedToolbarHeightBroadcasted(CGFloat min_height) {}
virtual void OnExpandedToolbarHeightBroadcasted(CGFloat height) {}
// Invoked by |-broadcastBottomToolbarHeight:|.
virtual void OnBottomToolbarHeightBroadcasted(CGFloat height) {}
};
// Bridge object that forwards broadcasted UI state to objects that subclass
......
......@@ -59,4 +59,8 @@ ChromeBroadcastObserverInterface::~ChromeBroadcastObserverInterface() = default;
self.observer->OnExpandedToolbarHeightBroadcasted(height);
}
- (void)broadcastBottomToolbarHeight:(CGFloat)height {
self.observer->OnBottomToolbarHeightBroadcasted(height);
}
@end
......@@ -3885,6 +3885,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
return self.headerHeight;
}
- (CGFloat)bottomToolbarHeight {
return [self secondaryToolbarHeightWithInset];
}
#pragma mark - Toolbar height helpers
- (CGFloat)nonFullscreenToolbarHeight {
......
......@@ -16,9 +16,11 @@
void MoveContentBelowHeader(id<CRWWebViewProxy> proxy, FullscreenModel* model) {
DCHECK(proxy);
DCHECK(model);
CGFloat padding = model->progress() * model->GetExpandedToolbarHeight();
proxy.scrollViewProxy.contentOffset = CGPointMake(0, -padding);
CGFloat topPadding = model->progress() * model->GetExpandedToolbarHeight();
CGFloat bottomPadding = model->progress() * model->GetBottomToolbarHeight();
proxy.scrollViewProxy.contentOffset = CGPointMake(0, -topPadding);
UIEdgeInsets contentInset = proxy.contentInset;
contentInset.top = padding;
contentInset.top = topPadding;
contentInset.bottom = bottomPadding;
proxy.contentInset = contentInset;
}
......@@ -44,6 +44,8 @@ FullscreenControllerImpl::FullscreenControllerImpl()
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster_ addObserver:bridge_
forSelector:@selector(broadcastExpandedToolbarHeight:)];
[broadcaster_ addObserver:bridge_
forSelector:@selector(broadcastBottomToolbarHeight:)];
}
FullscreenControllerImpl::~FullscreenControllerImpl() = default;
......@@ -116,4 +118,6 @@ void FullscreenControllerImpl::Shutdown() {
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster_ removeObserver:bridge_
forSelector:@selector(broadcastExpandedToolbarHeight:)];
[broadcaster_ removeObserver:bridge_
forSelector:@selector(broadcastBottomToolbarHeight:)];
}
......@@ -59,16 +59,21 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
// progress corresponding to the final state of the aniamtion.
void AnimationEndedWithProgress(CGFloat progress);
// Setter for the minimum toolbar height to use in calculations. Setting this
// Setter for the minimum toolbar height to use in calculations. Setting this
// resets the model to a fully visible state.
void SetCollapsedToolbarHeight(CGFloat height);
CGFloat GetCollapsedToolbarHeight() const;
// Setter for the maximum toolbar height to use in calculations. Setting this
// Setter for the maximum toolbar height to use in calculations. Setting this
// resets the model to a fully visible state.
void SetExpandedToolbarHeight(CGFloat height);
CGFloat GetExpandedToolbarHeight() const;
// Setter for the bottom toolbar height to use in calculations. Setting this
// resets the model to a fully visible state
void SetBottomToolbarHeight(CGFloat height);
CGFloat GetBottomToolbarHeight() const;
// Setter for the height of the scroll view displaying the main content.
void SetScrollViewHeight(CGFloat scroll_view_height);
CGFloat GetScrollViewHeight() const;
......@@ -82,12 +87,12 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
void SetTopContentInset(CGFloat top_inset);
CGFloat GetTopContentInset() const;
// Setter for the current vertical content offset. Setting this will
// Setter for the current vertical content offset. Setting this will
// recalculate the progress value.
void SetYContentOffset(CGFloat y_content_offset);
CGFloat GetYContentOffset() const;
// Setter for whether the scroll view is scrolling. If a scroll event ends
// Setter for whether the scroll view is scrolling. If a scroll event ends
// and the progress value is not 0.0 or 1.0, the model will round to the
// nearest value.
void SetScrollViewIsScrolling(bool scrolling);
......@@ -134,6 +139,7 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
void OnScrollViewIsDraggingBroadcasted(bool dragging) override;
void OnCollapsedToolbarHeightBroadcasted(CGFloat height) override;
void OnExpandedToolbarHeightBroadcasted(CGFloat height) override;
void OnBottomToolbarHeightBroadcasted(CGFloat height) override;
// The observers for this model.
base::ObserverList<FullscreenModelObserver> observers_;
......@@ -143,9 +149,10 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
// The base offset from which to calculate fullscreen state. When |locked_|
// is false, it is reset to the current offset after each scroll event.
CGFloat base_offset_ = NAN;
// The height of the toolbar being shown or hidden by this model.
// The height of the toolbars being shown or hidden by this model.
CGFloat collapsed_toolbar_height_ = 0.0;
CGFloat expanded_toolbar_height_ = 0.0;
CGFloat bottom_toolbar_height_ = 0.0;
// The current vertical content offset of the main content.
CGFloat y_content_offset_ = 0.0;
// The height of the scroll view displaying the current page.
......
......@@ -96,6 +96,18 @@ CGFloat FullscreenModel::GetExpandedToolbarHeight() const {
return expanded_toolbar_height_;
}
void FullscreenModel::SetBottomToolbarHeight(CGFloat height) {
if (AreCGFloatsEqual(bottom_toolbar_height_, height))
return;
DCHECK_GE(height, 0.0);
bottom_toolbar_height_ = height;
ResetForNavigation();
}
CGFloat FullscreenModel::GetBottomToolbarHeight() const {
return bottom_toolbar_height_;
}
void FullscreenModel::SetScrollViewHeight(CGFloat scroll_view_height) {
scroll_view_height_ = scroll_view_height;
}
......@@ -279,3 +291,7 @@ void FullscreenModel::OnCollapsedToolbarHeightBroadcasted(CGFloat height) {
void FullscreenModel::OnExpandedToolbarHeightBroadcasted(CGFloat height) {
SetExpandedToolbarHeight(height);
}
void FullscreenModel::OnBottomToolbarHeightBroadcasted(CGFloat height) {
SetBottomToolbarHeight(height);
}
......@@ -16,6 +16,8 @@ class WebStateList;
// content area.
- (CGFloat)collapsedTopToolbarHeight;
- (CGFloat)expandedTopToolbarHeight;
// Height of the bottom toolbar.
- (CGFloat)bottomToolbarHeight;
@end
// Helper object that uses navigation events to update a ToolbarUIState.
......
......@@ -140,6 +140,7 @@ initWithToolbarUI:(nonnull ToolbarUIState*)toolbarUI
- (void)updateState {
self.toolbarUI.collapsedHeight = [self.owner collapsedTopToolbarHeight];
self.toolbarUI.expandedHeight = [self.owner expandedTopToolbarHeight];
self.toolbarUI.bottomToolbarHeight = [self.owner bottomToolbarHeight];
}
@end
......@@ -26,11 +26,13 @@
// ToolbarHeightProviderForFullscreen.
@property(nonatomic, assign) CGFloat collapsedTopToolbarHeight;
@property(nonatomic, assign) CGFloat expandedTopToolbarHeight;
@property(nonatomic, assign) CGFloat bottomToolbarHeight;
@end
@implementation TestToolbarOwner
@synthesize collapsedTopToolbarHeight = _collapsedTopToolbarHeight;
@synthesize expandedTopToolbarHeight = _expandedTopToolbarHeight;
@synthesize bottomToolbarHeight = _bottomToolbarHeight;
@end
class LegacyToolbarUIUpdaterTest : public PlatformTest {
......@@ -49,7 +51,9 @@ class LegacyToolbarUIUpdaterTest : public PlatformTest {
// Getters.
WebStateList* web_state_list() { return &web_state_list_; }
TestToolbarOwner* toolbar_owner() { return toolbar_owner_; }
CGFloat collapsed_toolbar_height() { return toolbar_ui_.collapsedHeight; }
CGFloat expanded_toolbar_height() { return toolbar_ui_.expandedHeight; }
CGFloat bottom_toolbar_height() { return toolbar_ui_.bottomToolbarHeight; }
// Start or stop updating the state.
void StartUpdating() {
......@@ -89,10 +93,16 @@ class LegacyToolbarUIUpdaterTest : public PlatformTest {
// Tests that |-startUpdating| resets the state's height when starting.
TEST_F(LegacyToolbarUIUpdaterTest, StartUpdating) {
EXPECT_EQ(expanded_toolbar_height(), 0.0);
const CGFloat kHeight = 150.0;
toolbar_owner().expandedTopToolbarHeight = kHeight;
const CGFloat kCollapsedHeight = 140.0;
const CGFloat kExpandedHeight = 150.0;
const CGFloat kBottomHeight = 160.0;
toolbar_owner().collapsedTopToolbarHeight = kCollapsedHeight;
toolbar_owner().expandedTopToolbarHeight = kExpandedHeight;
toolbar_owner().bottomToolbarHeight = kBottomHeight;
StartUpdating();
EXPECT_EQ(expanded_toolbar_height(), kHeight);
EXPECT_EQ(collapsed_toolbar_height(), kCollapsedHeight);
EXPECT_EQ(expanded_toolbar_height(), kExpandedHeight);
EXPECT_EQ(bottom_toolbar_height(), kBottomHeight);
}
// Tests that the state is not updated after calling |-stopUpdating|.
......@@ -115,11 +125,19 @@ TEST_F(LegacyToolbarUIUpdaterTest, StopUpdating) {
// changes.
TEST_F(LegacyToolbarUIUpdaterTest, UpdateActiveWebState) {
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().expandedTopToolbarHeight = kHeight;
const CGFloat kCollapsedHeight = 140.0;
const CGFloat kExpandedHeight = 150.0;
const CGFloat kBottomHeight = 160.0;
toolbar_owner().collapsedTopToolbarHeight = kCollapsedHeight;
toolbar_owner().expandedTopToolbarHeight = kExpandedHeight;
toolbar_owner().bottomToolbarHeight = kBottomHeight;
EXPECT_EQ(collapsed_toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
EXPECT_EQ(bottom_toolbar_height(), 0.0);
InsertActiveWebState();
EXPECT_EQ(expanded_toolbar_height(), kHeight);
EXPECT_EQ(collapsed_toolbar_height(), kCollapsedHeight);
EXPECT_EQ(expanded_toolbar_height(), kExpandedHeight);
EXPECT_EQ(bottom_toolbar_height(), kBottomHeight);
}
// Tests that the updater polls for the new height when the active WebState
......@@ -127,13 +145,21 @@ TEST_F(LegacyToolbarUIUpdaterTest, UpdateActiveWebState) {
TEST_F(LegacyToolbarUIUpdaterTest, UserInitiatedNavigation) {
web::TestWebState* web_state = InsertActiveWebState();
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().expandedTopToolbarHeight = kHeight;
const CGFloat kCollapsedHeight = 140.0;
const CGFloat kExpandedHeight = 150.0;
const CGFloat kBottomHeight = 160.0;
toolbar_owner().collapsedTopToolbarHeight = kCollapsedHeight;
toolbar_owner().expandedTopToolbarHeight = kExpandedHeight;
toolbar_owner().bottomToolbarHeight = kBottomHeight;
EXPECT_EQ(collapsed_toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
EXPECT_EQ(bottom_toolbar_height(), 0.0);
web::FakeNavigationContext context;
context.SetIsRendererInitiated(false);
web_state->OnNavigationStarted(&context);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
EXPECT_EQ(collapsed_toolbar_height(), kCollapsedHeight);
EXPECT_EQ(expanded_toolbar_height(), kExpandedHeight);
EXPECT_EQ(bottom_toolbar_height(), kBottomHeight);
}
// Tests that the updater waits until a render-initiated navigation is committed
......@@ -141,13 +167,23 @@ TEST_F(LegacyToolbarUIUpdaterTest, UserInitiatedNavigation) {
TEST_F(LegacyToolbarUIUpdaterTest, RendererInitiatedNavigation) {
web::TestWebState* web_state = InsertActiveWebState();
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().expandedTopToolbarHeight = kHeight;
const CGFloat kCollapsedHeight = 140.0;
const CGFloat kExpandedHeight = 150.0;
const CGFloat kBottomHeight = 160.0;
toolbar_owner().collapsedTopToolbarHeight = kCollapsedHeight;
toolbar_owner().expandedTopToolbarHeight = kExpandedHeight;
toolbar_owner().bottomToolbarHeight = kBottomHeight;
EXPECT_EQ(collapsed_toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
EXPECT_EQ(bottom_toolbar_height(), 0.0);
web::FakeNavigationContext context;
context.SetIsRendererInitiated(true);
web_state->OnNavigationStarted(&context);
EXPECT_EQ(collapsed_toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
EXPECT_EQ(bottom_toolbar_height(), 0.0);
web_state->OnNavigationFinished(&context);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
EXPECT_EQ(collapsed_toolbar_height(), kCollapsedHeight);
EXPECT_EQ(expanded_toolbar_height(), kExpandedHeight);
EXPECT_EQ(bottom_toolbar_height(), kBottomHeight);
}
......@@ -18,6 +18,7 @@
// The broadcasted UI state observed by this object.
@property(nonatomic, readonly) CGFloat collapsedHeight;
@property(nonatomic, readonly) CGFloat expandedHeight;
@property(nonatomic, readonly) CGFloat bottomToolbarHeight;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TEST_TEST_TOOLBAR_UI_OBSERVER_H_
......@@ -12,17 +12,22 @@
@synthesize broadcaster = _broadcaster;
@synthesize collapsedHeight = _collapsedHeight;
@synthesize expandedHeight = _expandedHeight;
@synthesize bottomToolbarHeight = _bottomToolbarHeight;
- (void)setBroadcaster:(ChromeBroadcaster*)broadcaster {
[_broadcaster removeObserver:self
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[_broadcaster removeObserver:self
forSelector:@selector(broadcastExpandedToolbarHeight:)];
[_broadcaster removeObserver:self
forSelector:@selector(broadcastBottomToolbarHeight:)];
_broadcaster = broadcaster;
[_broadcaster addObserver:self
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[_broadcaster addObserver:self
forSelector:@selector(broadcastExpandedToolbarHeight:)];
[_broadcaster addObserver:self
forSelector:@selector(broadcastBottomToolbarHeight:)];
}
- (void)broadcastCollapsedToolbarHeight:(CGFloat)toolbarHeight {
......@@ -33,4 +38,8 @@
_expandedHeight = toolbarHeight;
}
- (void)broadcastBottomToolbarHeight:(CGFloat)toolbarHeight {
_bottomToolbarHeight = toolbarHeight;
}
@end
......@@ -18,6 +18,10 @@
// This should be broadcast using |-broadcastExpandedToolbarHeight:|.
@property(nonatomic, readonly) CGFloat expandedHeight;
// The height of the bottom toolbar relative to the browser content area.
// This should be broadcast using |-broadcastBottomToolbarHeight:|.
@property(nonatomic, readonly) CGFloat bottomToolbarHeight;
@end
// Simple implementation of ToolbarUI that allows readwrite access to broadcast
......@@ -27,6 +31,7 @@
// Redefine properties as readwrite.
@property(nonatomic, assign) CGFloat collapsedHeight;
@property(nonatomic, assign) CGFloat expandedHeight;
@property(nonatomic, assign) CGFloat bottomToolbarHeight;
@end
......
......@@ -11,4 +11,5 @@
@implementation ToolbarUIState
@synthesize collapsedHeight = _collapsedHeight;
@synthesize expandedHeight = _expandedHeight;
@synthesize bottomToolbarHeight = _bottomToolbarHeight;
@end
......@@ -19,6 +19,9 @@ void StartBroadcastingToolbarUI(id<ToolbarUI> toolbar,
[broadcaster broadcastValue:@"expandedHeight"
ofObject:toolbar
selector:@selector(broadcastExpandedToolbarHeight:)];
[broadcaster broadcastValue:@"bottomToolbarHeight"
ofObject:toolbar
selector:@selector(broadcastBottomToolbarHeight:)];
}
void StopBroadcastingToolbarUI(ChromeBroadcaster* broadcaster) {
......@@ -26,4 +29,6 @@ void StopBroadcastingToolbarUI(ChromeBroadcaster* broadcaster) {
stopBroadcastingForSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster
stopBroadcastingForSelector:@selector(broadcastExpandedToolbarHeight:)];
[broadcaster
stopBroadcastingForSelector:@selector(broadcastBottomToolbarHeight:)];
}
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