Commit 8c6e50ac authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Provide collapsed and expanded toolbar heights to FullscreenModel.

MoveContentBelowHeader() was not working correctly with the UI refresh
flag enabled because it only knew about the height delta, while we
actually needed to inset based on the expanded height.  This CL updates
the broadcaster API to send the collapsed and expanded toolbar heights
so that this information is available for these content adjustments.

This CL also updates CRWWebViewContentView to check against the old
value of self.contentInset rather than the |_contentInset| ivar.  This
fixes the bug where navigating back from a pdf wouldn't correctly
reset WKScrollView.contentInset since the value of |_contentInset| had
not changed from the previous value.

Bug: 849132, 851129
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I1e46e4fc69fc0ac7a7d114b7c463e1f6a90964f9
Reviewed-on: https://chromium-review.googlesource.com/1094480
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569304}
parent 969037e1
......@@ -49,9 +49,18 @@
#pragma mark - Toolbar UI
// Observer method for objects that care about the current height of the
// toolbar.
- (void)broadcastToolbarHeight:(CGFloat)height;
// Observer method for objects that care about the collapsed toolbar height.
// The value broadcast by this method is the distance by which the toolbar
// overlaps the browser content area after the toolbar has been collapsed due
// to scroll events.
- (void)broadcastCollapsedToolbarHeight:(CGFloat)height;
// Observer method for objects that care about the fully expanded toolbar
// height. 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)broadcastExpandedToolbarHeight:(CGFloat)height;
@end
......
......@@ -33,8 +33,11 @@ class ChromeBroadcastObserverInterface {
// Invoked by |-broadcastScrollViewIsDragging:|.
virtual void OnScrollViewIsDraggingBroadcasted(bool dragging) {}
// Invoked by |-broadcastToolbarHeight:|.
virtual void OnToolbarHeightBroadcasted(CGFloat toolbar_height) {}
// Invoked by |-broadcastCollapsedToolbarHeight:|.
virtual void OnCollapsedToolbarHeightBroadcasted(CGFloat min_height) {}
// Invoked by |-broadcastExpandedToolbarHeight:|.
virtual void OnExpandedToolbarHeightBroadcasted(CGFloat min_height) {}
};
// Bridge object that forwards broadcasted UI state to objects that subclass
......
......@@ -51,8 +51,12 @@ ChromeBroadcastObserverInterface::~ChromeBroadcastObserverInterface() = default;
self.observer->OnScrollViewIsDraggingBroadcasted(dragging);
}
- (void)broadcastToolbarHeight:(CGFloat)height {
self.observer->OnToolbarHeightBroadcasted(height);
- (void)broadcastCollapsedToolbarHeight:(CGFloat)height {
self.observer->OnCollapsedToolbarHeightBroadcasted(height);
}
- (void)broadcastExpandedToolbarHeight:(CGFloat)height {
self.observer->OnExpandedToolbarHeightBroadcasted(height);
}
@end
......@@ -17,7 +17,8 @@ class TestChromeBroadcastObserver : public ChromeBroadcastObserverInterface {
CGFloat scroll_offset() const { return scroll_offset_; }
bool scroll_view_scrolling() const { return scroll_view_scrolling_; }
bool scroll_view_dragging() const { return scroll_view_dragging_; }
CGFloat toolbar_height() const { return toolbar_height_; }
CGFloat collapsed_height() const { return collapsed_height_; }
CGFloat expanded_height() const { return expanded_height_; }
private:
// ChromeBroadcastObserverInterface:
......@@ -30,14 +31,19 @@ class TestChromeBroadcastObserver : public ChromeBroadcastObserverInterface {
void OnScrollViewIsDraggingBroadcasted(bool dragging) override {
scroll_view_dragging_ = dragging;
}
void OnToolbarHeightBroadcasted(CGFloat toolbar_height) override {
toolbar_height_ = toolbar_height;
void OnCollapsedToolbarHeightBroadcasted(CGFloat height) override {
collapsed_height_ = height;
;
}
void OnExpandedToolbarHeightBroadcasted(CGFloat height) override {
expanded_height_ = height;
}
CGFloat scroll_offset_ = 0.0;
bool scroll_view_scrolling_ = false;
bool scroll_view_dragging_ = false;
CGFloat toolbar_height_ = 0.0;
CGFloat collapsed_height_ = 0.0;
CGFloat expanded_height_ = 0.0;
};
// Test fixture for ChromeBroadcastOberverBridge.
......@@ -84,8 +90,12 @@ TEST_F(ChromeBroadcastObserverBridgeTest, ScrollViewIsDragging) {
// Tests that |-broadcastToolbarHeight:| is correctly forwarded to the
// observer.
TEST_F(ChromeBroadcastObserverBridgeTest, ToolbarHeight) {
ASSERT_EQ(observer().toolbar_height(), 0.0);
const CGFloat kHeight = 50.0;
[bridge() broadcastToolbarHeight:kHeight];
EXPECT_EQ(observer().toolbar_height(), kHeight);
ASSERT_EQ(observer().collapsed_height(), 0.0);
ASSERT_EQ(observer().expanded_height(), 0.0);
const CGFloat kCollapsedHeight = 10.0;
const CGFloat kExpandedHeight = 50.0;
[bridge() broadcastCollapsedToolbarHeight:kCollapsedHeight];
[bridge() broadcastExpandedToolbarHeight:kExpandedHeight];
EXPECT_EQ(observer().collapsed_height(), kCollapsedHeight);
EXPECT_EQ(observer().expanded_height(), kExpandedHeight);
}
......@@ -2572,8 +2572,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
- (CGFloat)headerHeightForTab:(Tab*)tab {
id nativeController = [self nativeControllerForTab:tab];
if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)] &&
[nativeController respondsToSelector:@selector(toolbarHeight)] &&
[nativeController toolbarHeight] > 0.0 && ![self canShowTabStrip]) {
[nativeController respondsToSelector:@selector(toolbarFrame)] &&
CGRectGetHeight([nativeController toolbarFrame]) > 0.0 &&
![self canShowTabStrip]) {
// On iPhone, don't add any header height for ToolbarOwner native
// controllers when they're displaying their own toolbar.
if (self.usesFullscreenContainer)
......@@ -3152,8 +3153,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
CGFloat headerHeight = [self headerHeightForTab:tab];
id nativeController = [self nativeControllerForTab:tab];
if ([nativeController respondsToSelector:@selector(toolbarHeight)])
headerHeight += [nativeController toolbarHeight];
if ([nativeController respondsToSelector:@selector(toolbarFrame)])
headerHeight += CGRectGetHeight([nativeController toolbarFrame]);
return UIEdgeInsetsMake(headerHeight, 0.0, 0.0, 0.0);
}
......@@ -3866,15 +3867,29 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
#pragma mark - ToolbarHeightProviderForFullscreen
- (CGFloat)collapsedTopToolbarHeight {
// For the legacy UI, the toolbar is completely hidden when in fullscreen
// mode. After the UI refresh, kToolbarHeightFullscreen is still visible
// after scroll events.
CGFloat minHeight =
IsUIRefreshPhase1Enabled() ? kToolbarHeightFullscreen : 0.0;
// |minHeight| describes the distance past the top safe area. If the browser
// container view is laid out using the full screen, it extends past the
// status bar, so that additional overlap is added here.
if (self.usesFullscreenContainer)
minHeight += StatusBarHeight();
return minHeight;
}
- (CGFloat)expandedTopToolbarHeight {
return self.headerHeight;
}
#pragma mark - Toolbar height helpers
- (CGFloat)nonFullscreenToolbarHeight {
CGFloat toolbarHeightFullscreen = 0;
if (IsUIRefreshPhase1Enabled()) {
toolbarHeightFullscreen = kToolbarHeightFullscreen;
}
if (self.usesFullscreenContainer) {
toolbarHeightFullscreen += StatusBarHeight();
}
return MAX(0, self.headerHeight - toolbarHeightFullscreen);
return MAX(
0, [self expandedTopToolbarHeight] - [self collapsedTopToolbarHeight]);
}
#pragma mark - FullscreenUIElement methods
......
......@@ -16,7 +16,7 @@
void MoveContentBelowHeader(id<CRWWebViewProxy> proxy, FullscreenModel* model) {
DCHECK(proxy);
DCHECK(model);
CGFloat padding = model->progress() * model->GetToolbarHeight();
CGFloat padding = model->progress() * model->GetExpandedToolbarHeight();
proxy.scrollViewProxy.contentOffset = CGPointMake(0, -padding);
UIEdgeInsets contentInset = proxy.contentInset;
contentInset.top = padding;
......
......@@ -41,7 +41,9 @@ FullscreenControllerImpl::FullscreenControllerImpl()
[broadcaster_ addObserver:bridge_
forSelector:@selector(broadcastScrollViewIsDragging:)];
[broadcaster_ addObserver:bridge_
forSelector:@selector(broadcastToolbarHeight:)];
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster_ addObserver:bridge_
forSelector:@selector(broadcastExpandedToolbarHeight:)];
}
FullscreenControllerImpl::~FullscreenControllerImpl() = default;
......@@ -111,5 +113,7 @@ void FullscreenControllerImpl::Shutdown() {
[broadcaster_ removeObserver:bridge_
forSelector:@selector(broadcastScrollViewIsDragging:)];
[broadcaster_ removeObserver:bridge_
forSelector:@selector(broadcastToolbarHeight:)];
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster_ removeObserver:bridge_
forSelector:@selector(broadcastExpandedToolbarHeight:)];
}
......@@ -82,10 +82,6 @@ void AssertURLIs(const GURL& expectedURL) {
// Verifies that the content offset of the web view is set up at the correct
// initial value when initially displaying a PDF.
- (void)testLongPDFInitialState {
if (IsUIRefreshPhase1Enabled() && !base::ios::IsRunningOnIOS11OrLater()) {
EARL_GREY_TEST_DISABLED(
@"crbug.com/849132 Test broken in iOS10 with UI refresh.");
}
web::test::SetUpFileBasedHttpServer();
GURL URL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/two_pages.pdf");
......
......@@ -42,6 +42,11 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
// The base offset against which the fullscreen progress is being calculated.
CGFloat base_offset() const { return base_offset_; }
// Returns the difference between the max and min toolbar heights.
CGFloat toolbar_height_delta() const {
return expanded_toolbar_height_ - collapsed_toolbar_height_;
}
// Increments and decrements |disabled_counter_| for features that require the
// toolbar be completely visible.
void IncrementDisabledCounter();
......@@ -54,10 +59,15 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
// progress corresponding to the final state of the aniamtion.
void AnimationEndedWithProgress(CGFloat progress);
// Setter for the toolbar height to use in calculations. Setting this resets
// the model to a fully visible state.
void SetToolbarHeight(CGFloat toolbar_height);
CGFloat GetToolbarHeight() const;
// 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
// resets the model to a fully visible state.
void SetExpandedToolbarHeight(CGFloat height);
CGFloat GetExpandedToolbarHeight() const;
// Setter for the height of the scroll view displaying the main content.
void SetScrollViewHeight(CGFloat scroll_view_height);
......@@ -122,7 +132,8 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
void OnScrollViewIsScrollingBroadcasted(bool scrolling) override;
void OnScrollViewIsZoomingBroadcasted(bool zooming) override;
void OnScrollViewIsDraggingBroadcasted(bool dragging) override;
void OnToolbarHeightBroadcasted(CGFloat toolbar_height) override;
void OnCollapsedToolbarHeightBroadcasted(CGFloat height) override;
void OnExpandedToolbarHeightBroadcasted(CGFloat height) override;
// The observers for this model.
base::ObserverList<FullscreenModelObserver> observers_;
......@@ -133,7 +144,8 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
// 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.
CGFloat toolbar_height_ = 0.0;
CGFloat collapsed_toolbar_height_ = 0.0;
CGFloat expanded_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.
......
......@@ -72,16 +72,28 @@ void FullscreenModel::AnimationEndedWithProgress(CGFloat progress) {
progress_ = progress;
}
void FullscreenModel::SetToolbarHeight(CGFloat toolbar_height) {
if (AreCGFloatsEqual(toolbar_height_, toolbar_height))
void FullscreenModel::SetCollapsedToolbarHeight(CGFloat height) {
if (AreCGFloatsEqual(collapsed_toolbar_height_, height))
return;
DCHECK_GE(toolbar_height, 0.0);
toolbar_height_ = toolbar_height;
DCHECK_GE(height, 0.0);
collapsed_toolbar_height_ = height;
ResetForNavigation();
}
CGFloat FullscreenModel::GetToolbarHeight() const {
return toolbar_height_;
CGFloat FullscreenModel::GetCollapsedToolbarHeight() const {
return collapsed_toolbar_height_;
}
void FullscreenModel::SetExpandedToolbarHeight(CGFloat height) {
if (AreCGFloatsEqual(expanded_toolbar_height_, height))
return;
DCHECK_GE(height, 0.0);
expanded_toolbar_height_ = height;
ResetForNavigation();
}
CGFloat FullscreenModel::GetExpandedToolbarHeight() const {
return expanded_toolbar_height_;
}
void FullscreenModel::SetScrollViewHeight(CGFloat scroll_view_height) {
......@@ -183,7 +195,7 @@ FullscreenModel::ScrollAction FullscreenModel::ActionForScrollFromOffset(
// - there is no toolbar,
// - the scroll offset doesn't change.
if (!enabled() || !scrolling_ || zooming_ || observer_callback_count_ ||
AreCGFloatsEqual(toolbar_height_, 0.0) ||
AreCGFloatsEqual(toolbar_height_delta(), 0.0) ||
AreCGFloatsEqual(y_content_offset_, from_offset)) {
return ScrollAction::kUpdateBaseOffset;
}
......@@ -211,11 +223,11 @@ FullscreenModel::ScrollAction FullscreenModel::ActionForScrollFromOffset(
void FullscreenModel::UpdateProgress() {
CGFloat delta = base_offset_ - y_content_offset_;
SetProgress(1.0 + delta / toolbar_height_);
SetProgress(1.0 + delta / toolbar_height_delta());
}
void FullscreenModel::UpdateBaseOffset() {
base_offset_ = y_content_offset_ - (1.0 - progress_) * toolbar_height_;
base_offset_ = y_content_offset_ - (1.0 - progress_) * toolbar_height_delta();
}
void FullscreenModel::SetProgress(CGFloat progress) {
......@@ -260,6 +272,10 @@ void FullscreenModel::OnScrollViewIsDraggingBroadcasted(bool dragging) {
SetScrollViewIsDragging(dragging);
}
void FullscreenModel::OnToolbarHeightBroadcasted(CGFloat toolbar_height) {
SetToolbarHeight(toolbar_height);
void FullscreenModel::OnCollapsedToolbarHeightBroadcasted(CGFloat height) {
SetCollapsedToolbarHeight(height);
}
void FullscreenModel::OnExpandedToolbarHeightBroadcasted(CGFloat height) {
SetExpandedToolbarHeight(height);
}
......@@ -29,7 +29,8 @@ class FullscreenModelTest : public PlatformTest {
model_.AddObserver(&observer_);
// Set the toolbar height to kToolbarHeight, and simulate a page load that
// finishes with a 0.0 y content offset.
model_.SetToolbarHeight(kToolbarHeight);
model_.SetCollapsedToolbarHeight(0.0);
model_.SetExpandedToolbarHeight(kToolbarHeight);
model_.SetScrollViewHeight(kScrollViewHeight);
model_.SetContentHeight(kContentHeight);
model_.ResetForNavigation();
......@@ -114,7 +115,7 @@ TEST_F(FullscreenModelTest, AnimationEnded) {
TEST_F(FullscreenModelTest, UpdateToolbarHeight) {
// Reset the toolbar height and verify that the base offset is reset and that
// the toolbar is fully visible.
model().SetToolbarHeight(2.0 * kToolbarHeight);
model().SetExpandedToolbarHeight(2.0 * kToolbarHeight);
EXPECT_FALSE(model().has_base_offset());
EXPECT_EQ(observer().progress(), 1.0);
// Simulate a page load to a 0.0 y content offset.
......@@ -173,7 +174,7 @@ TEST_F(FullscreenModelTest, ZoomScroll) {
// Tests that updating the y content offset while the toolbar height is 0 only
// updates the model's base offset.
TEST_F(FullscreenModelTest, NoToolbarScroll) {
model().SetToolbarHeight(0.0);
model().SetExpandedToolbarHeight(0.0);
model().SetYContentOffset(100);
EXPECT_EQ(observer().progress(), 1.0);
EXPECT_EQ(model().base_offset(), 100);
......
......@@ -14,7 +14,8 @@
void SetUpFullscreenModelForTesting(FullscreenModel* model,
CGFloat toolbar_height) {
EXPECT_GE(toolbar_height, 0.0);
model->SetToolbarHeight(toolbar_height);
model->SetCollapsedToolbarHeight(0.0);
model->SetExpandedToolbarHeight(toolbar_height);
model->SetScrollViewHeight(2 * toolbar_height);
model->SetContentHeight(2 * model->GetScrollViewHeight());
model->ResetForNavigation();
......@@ -34,11 +35,11 @@ void SimulateFullscreenUserScrollForProgress(FullscreenModel* model,
CGFloat progress) {
ASSERT_GE(progress, 0.0);
ASSERT_LE(progress, 1.0);
CGFloat toolbar_height = model->GetToolbarHeight();
CGFloat height_delta = model->toolbar_height_delta();
CGFloat base_offset =
GetFullscreenBaseOffsetForProgress(model, model->progress());
CGFloat final_y_content_offset =
base_offset + (1.0 - progress) * toolbar_height;
base_offset + (1.0 - progress) * height_delta;
CGFloat delta = final_y_content_offset - model->GetYContentOffset();
SimulateFullscreenUserScrollWithDelta(model, delta);
}
......@@ -47,5 +48,5 @@ CGFloat GetFullscreenBaseOffsetForProgress(FullscreenModel* model,
CGFloat progress) {
EXPECT_TRUE(model->has_base_offset());
return model->GetYContentOffset() -
(1.0 - progress) * model->GetToolbarHeight();
(1.0 - progress) * model->toolbar_height_delta();
}
......@@ -12,9 +12,10 @@
class WebStateList;
@protocol ToolbarHeightProviderForFullscreen
// Returns the height of the part of the toolbar that is only displayed when not
// in fullscreen.
- (CGFloat)nonFullscreenToolbarHeight;
// The minimum and maximum amount by which the top toolbar overlaps the browser
// content area.
- (CGFloat)collapsedTopToolbarHeight;
- (CGFloat)expandedTopToolbarHeight;
@end
// Helper object that uses navigation events to update a ToolbarUIState.
......
......@@ -138,7 +138,8 @@ initWithToolbarUI:(nonnull ToolbarUIState*)toolbarUI
#pragma mark Private
- (void)updateState {
self.toolbarUI.toolbarHeight = [self.owner nonFullscreenToolbarHeight];
self.toolbarUI.collapsedHeight = [self.owner collapsedTopToolbarHeight];
self.toolbarUI.expandedHeight = [self.owner expandedTopToolbarHeight];
}
@end
......@@ -21,13 +21,16 @@
#endif
@interface TestToolbarOwner : NSObject<ToolbarHeightProviderForFullscreen>
// Define writable property with same name as |-nonFullscreenToolbarHeight|
// getter defined in ToolbarHeightProviderForFullscreen.
@property(nonatomic, assign) CGFloat nonFullscreenToolbarHeight;
// Define writable property with same name as |-collapsedTopToolbarHeight| and
// |-expandedTopToolbarHeight| getters defined in
// ToolbarHeightProviderForFullscreen.
@property(nonatomic, assign) CGFloat collapsedTopToolbarHeight;
@property(nonatomic, assign) CGFloat expandedTopToolbarHeight;
@end
@implementation TestToolbarOwner
@synthesize nonFullscreenToolbarHeight = _nonFullscreenToolbarHeight;
@synthesize collapsedTopToolbarHeight = _collapsedTopToolbarHeight;
@synthesize expandedTopToolbarHeight = _expandedTopToolbarHeight;
@end
class LegacyToolbarUIUpdaterTest : public PlatformTest {
......@@ -46,7 +49,7 @@ class LegacyToolbarUIUpdaterTest : public PlatformTest {
// Getters.
WebStateList* web_state_list() { return &web_state_list_; }
TestToolbarOwner* toolbar_owner() { return toolbar_owner_; }
CGFloat toolbar_height() { return toolbar_ui_.toolbarHeight; }
CGFloat expanded_toolbar_height() { return toolbar_ui_.expandedHeight; }
// Start or stop updating the state.
void StartUpdating() {
......@@ -85,11 +88,11 @@ class LegacyToolbarUIUpdaterTest : public PlatformTest {
// Tests that |-startUpdating| resets the state's height when starting.
TEST_F(LegacyToolbarUIUpdaterTest, StartUpdating) {
EXPECT_EQ(toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
const CGFloat kHeight = 150.0;
toolbar_owner().nonFullscreenToolbarHeight = kHeight;
toolbar_owner().expandedTopToolbarHeight = kHeight;
StartUpdating();
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
}
// Tests that the state is not updated after calling |-stopUpdating|.
......@@ -97,15 +100,15 @@ TEST_F(LegacyToolbarUIUpdaterTest, StopUpdating) {
web::TestWebState* web_state = InsertActiveWebState();
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().nonFullscreenToolbarHeight = kHeight;
toolbar_owner().expandedTopToolbarHeight = kHeight;
web::FakeNavigationContext context;
web_state->OnNavigationFinished(&context);
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
const CGFloat kNonUpdatedHeight = 500.0;
StopUpdating();
toolbar_owner().nonFullscreenToolbarHeight = kNonUpdatedHeight;
toolbar_owner().expandedTopToolbarHeight = kNonUpdatedHeight;
web_state->OnNavigationFinished(&context);
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
}
// Tests that the updater polls for the new height when the active WebState
......@@ -113,10 +116,10 @@ TEST_F(LegacyToolbarUIUpdaterTest, StopUpdating) {
TEST_F(LegacyToolbarUIUpdaterTest, UpdateActiveWebState) {
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().nonFullscreenToolbarHeight = kHeight;
EXPECT_EQ(toolbar_height(), 0.0);
toolbar_owner().expandedTopToolbarHeight = kHeight;
EXPECT_EQ(expanded_toolbar_height(), 0.0);
InsertActiveWebState();
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
}
// Tests that the updater polls for the new height when the active WebState
......@@ -125,12 +128,12 @@ TEST_F(LegacyToolbarUIUpdaterTest, UserInitiatedNavigation) {
web::TestWebState* web_state = InsertActiveWebState();
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().nonFullscreenToolbarHeight = kHeight;
EXPECT_EQ(toolbar_height(), 0.0);
toolbar_owner().expandedTopToolbarHeight = kHeight;
EXPECT_EQ(expanded_toolbar_height(), 0.0);
web::FakeNavigationContext context;
context.SetIsRendererInitiated(false);
web_state->OnNavigationStarted(&context);
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
}
// Tests that the updater waits until a render-initiated navigation is committed
......@@ -139,12 +142,12 @@ TEST_F(LegacyToolbarUIUpdaterTest, RendererInitiatedNavigation) {
web::TestWebState* web_state = InsertActiveWebState();
StartUpdating();
const CGFloat kHeight = 150.0;
toolbar_owner().nonFullscreenToolbarHeight = kHeight;
EXPECT_EQ(toolbar_height(), 0.0);
toolbar_owner().expandedTopToolbarHeight = kHeight;
EXPECT_EQ(expanded_toolbar_height(), 0.0);
web::FakeNavigationContext context;
context.SetIsRendererInitiated(true);
web_state->OnNavigationStarted(&context);
EXPECT_EQ(toolbar_height(), 0.0);
EXPECT_EQ(expanded_toolbar_height(), 0.0);
web_state->OnNavigationFinished(&context);
EXPECT_EQ(toolbar_height(), kHeight);
EXPECT_EQ(expanded_toolbar_height(), kHeight);
}
......@@ -16,7 +16,8 @@
// broadcaster.
@property(nonatomic, strong) ChromeBroadcaster* broadcaster;
// The broadcasted UI state observed by this object.
@property(nonatomic, readonly) CGFloat toolbarHeight;
@property(nonatomic, readonly) CGFloat collapsedHeight;
@property(nonatomic, readonly) CGFloat expandedHeight;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TEST_TEST_TOOLBAR_UI_OBSERVER_H_
......@@ -10,18 +10,27 @@
@implementation TestToolbarUIObserver
@synthesize broadcaster = _broadcaster;
@synthesize toolbarHeight = _toolbarHeight;
@synthesize collapsedHeight = _collapsedHeight;
@synthesize expandedHeight = _expandedHeight;
- (void)setBroadcaster:(ChromeBroadcaster*)broadcaster {
[_broadcaster removeObserver:self
forSelector:@selector(broadcastToolbarHeight:)];
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[_broadcaster removeObserver:self
forSelector:@selector(broadcastExpandedToolbarHeight:)];
_broadcaster = broadcaster;
[_broadcaster addObserver:self
forSelector:@selector(broadcastToolbarHeight:)];
forSelector:@selector(broadcastCollapsedToolbarHeight:)];
[_broadcaster addObserver:self
forSelector:@selector(broadcastExpandedToolbarHeight:)];
}
- (void)broadcastCollapsedToolbarHeight:(CGFloat)toolbarHeight {
_collapsedHeight = toolbarHeight;
}
- (void)broadcastToolbarHeight:(CGFloat)toolbarHeight {
_toolbarHeight = toolbarHeight;
- (void)broadcastExpandedToolbarHeight:(CGFloat)toolbarHeight {
_expandedHeight = toolbarHeight;
}
@end
......@@ -21,19 +21,25 @@ const CGFloat kHeightDelta = 100.0;
class TestToolbarUIStateModifier {
public:
TestToolbarUIStateModifier(ToolbarUIState* toolbar_ui)
: toolbar_ui_(toolbar_ui), original_height_(toolbar_ui_.toolbarHeight) {
toolbar_ui_.toolbarHeight += kHeightDelta;
: toolbar_ui_(toolbar_ui),
original_collapsed_height_(toolbar_ui_.collapsedHeight),
original_expanded_height_(toolbar_ui_.expandedHeight) {
toolbar_ui_.collapsedHeight += kHeightDelta;
toolbar_ui_.expandedHeight += kHeightDelta;
}
~TestToolbarUIStateModifier() {
toolbar_ui_.toolbarHeight = original_height_;
toolbar_ui_.collapsedHeight = original_collapsed_height_;
toolbar_ui_.expandedHeight = original_expanded_height_;
}
// The original values of the UI state.
CGFloat original_height() { return original_height_; }
CGFloat original_collapsed_height() { return original_collapsed_height_; }
CGFloat original_expanded_height() { return original_expanded_height_; }
private:
__strong ToolbarUIState* toolbar_ui_ = nil;
CGFloat original_height_ = 0.0;
CGFloat original_collapsed_height_ = 0.0;
CGFloat original_expanded_height_ = 0.0;
};
} // namespace
......@@ -49,10 +55,14 @@ void VerifyToolbarUIBroadcast(ToolbarUIState* toolbar_ui,
// Verify whether the changed or original UI elements are observed.
if (should_broadcast) {
EXPECT_TRUE(
AreCGFloatsEqual(observer.toolbarHeight, toolbar_ui.toolbarHeight));
} else {
AreCGFloatsEqual(observer.collapsedHeight, toolbar_ui.collapsedHeight));
EXPECT_TRUE(
AreCGFloatsEqual(observer.toolbarHeight, modifier.original_height()));
AreCGFloatsEqual(observer.expandedHeight, toolbar_ui.expandedHeight));
} else {
EXPECT_TRUE(AreCGFloatsEqual(observer.collapsedHeight,
modifier.original_collapsed_height()));
EXPECT_TRUE(AreCGFloatsEqual(observer.expandedHeight,
modifier.original_expanded_height()));
}
// Stop observing |broadcaster|.
observer.broadcaster = nil;
......
......@@ -10,9 +10,13 @@
// Protocol for the UI displaying the toolbar.
@protocol ToolbarUI<NSObject>
// The height of the toolbar, not including the safe area inset.
// This should be broadcast using |-broadcastToolbarHeight:|.
@property(nonatomic, readonly) CGFloat toolbarHeight;
// The minimum height of the toolbar relative to the browser content area.
// This should be broadcast using |-broadcastCollapsedToolbarHeight:|.
@property(nonatomic, readonly) CGFloat collapsedHeight;
// The minimum height of the toolbar relative to the browser content area.
// This should be broadcast using |-broadcastExpandedToolbarHeight:|.
@property(nonatomic, readonly) CGFloat expandedHeight;
@end
......@@ -21,7 +25,8 @@
@interface ToolbarUIState : NSObject<ToolbarUI>
// Redefine properties as readwrite.
@property(nonatomic, assign) CGFloat toolbarHeight;
@property(nonatomic, assign) CGFloat collapsedHeight;
@property(nonatomic, assign) CGFloat expandedHeight;
@end
......
......@@ -9,5 +9,6 @@
#endif
@implementation ToolbarUIState
@synthesize toolbarHeight = _toolbarHeight;
@synthesize collapsedHeight = _collapsedHeight;
@synthesize expandedHeight = _expandedHeight;
@end
......@@ -13,11 +13,17 @@
void StartBroadcastingToolbarUI(id<ToolbarUI> toolbar,
ChromeBroadcaster* broadcaster) {
[broadcaster broadcastValue:@"toolbarHeight"
[broadcaster broadcastValue:@"collapsedHeight"
ofObject:toolbar
selector:@selector(broadcastToolbarHeight:)];
selector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster broadcastValue:@"expandedHeight"
ofObject:toolbar
selector:@selector(broadcastExpandedToolbarHeight:)];
}
void StopBroadcastingToolbarUI(ChromeBroadcaster* broadcaster) {
[broadcaster stopBroadcastingForSelector:@selector(broadcastToolbarHeight:)];
[broadcaster
stopBroadcastingForSelector:@selector(broadcastCollapsedToolbarHeight:)];
[broadcaster
stopBroadcastingForSelector:@selector(broadcastExpandedToolbarHeight:)];
}
......@@ -122,10 +122,11 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
}
- (void)setContentInset:(UIEdgeInsets)contentInset {
CGFloat delta = std::fabs(_contentInset.top - contentInset.top) +
std::fabs(_contentInset.left - contentInset.left) +
std::fabs(_contentInset.bottom - contentInset.bottom) +
std::fabs(_contentInset.right - contentInset.right);
UIEdgeInsets oldInsets = self.contentInset;
CGFloat delta = std::fabs(oldInsets.top - contentInset.top) +
std::fabs(oldInsets.left - contentInset.left) +
std::fabs(oldInsets.bottom - contentInset.bottom) +
std::fabs(oldInsets.right - contentInset.right);
if (delta <= std::numeric_limits<CGFloat>::epsilon())
return;
if (self.shouldUseViewContentInset) {
......
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