Commit feb4d6bc authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Expose the viewport insets in FullscreenController.

FullscreenModel knows enough information to calculate these insets, so
it makes sense for the calculation to occur there.  Exposing the
viewport insets in FullscreenController will allow chrome/ layer UI
code to easily account for viewport adjustments.

This API will be used to mask non-modal UIAlertController presentation.

Bug: 674649
Change-Id: I469cb133ef5d27bffcd4de5070bd12820514740e
Reviewed-on: https://chromium-review.googlesource.com/c/1339460
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612538}
parent 3455c993
......@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
......@@ -56,6 +56,15 @@ class FullscreenController : public KeyedService {
// 1.0 denotes that the toolbar should be completely visible.
virtual CGFloat GetProgress() const = 0;
// Returns the max and min insets for the visible content area's viewport.
// The max insets correspond to a progress of 1.0, and the min insets are for
// progress 0.0.
virtual UIEdgeInsets GetMinViewportInsets() const = 0;
virtual UIEdgeInsets GetMaxViewportInsets() const = 0;
// Returns the current insets for the visible content area's viewport.
virtual UIEdgeInsets GetCurrentViewportInsets() const = 0;
// Enters fullscreen mode, animating away toolbars and resetting the progress
// to 0.0. Calling this function while fullscreen is disabled has no effect.
virtual void EnterFullscreen() = 0;
......
......@@ -30,6 +30,9 @@ class FullscreenControllerImpl : public FullscreenController {
void IncrementDisabledCounter() override;
void DecrementDisabledCounter() override;
CGFloat GetProgress() const override;
UIEdgeInsets GetMinViewportInsets() const override;
UIEdgeInsets GetMaxViewportInsets() const override;
UIEdgeInsets GetCurrentViewportInsets() const override;
void EnterFullscreen() override;
void ExitFullscreen() override;
......
......@@ -93,6 +93,18 @@ CGFloat FullscreenControllerImpl::GetProgress() const {
return model_.progress();
}
UIEdgeInsets FullscreenControllerImpl::GetMinViewportInsets() const {
return model_.min_toolbar_insets();
}
UIEdgeInsets FullscreenControllerImpl::GetMaxViewportInsets() const {
return model_.max_toolbar_insets();
}
UIEdgeInsets FullscreenControllerImpl::GetCurrentViewportInsets() const {
return model_.current_toolbar_insets();
}
void FullscreenControllerImpl::EnterFullscreen() {
mediator_.EnterFullscreen();
}
......
......@@ -58,6 +58,25 @@ class FullscreenModel : public ChromeBroadcastObserverInterface {
return y_content_offset_ + scroll_view_height_ >= content_height_;
}
// The min, max, and current insets caused by the toolbars.
UIEdgeInsets min_toolbar_insets() const {
return GetToolbarInsetsAtProgress(0.0);
}
UIEdgeInsets max_toolbar_insets() const {
return GetToolbarInsetsAtProgress(1.0);
}
UIEdgeInsets current_toolbar_insets() const {
return GetToolbarInsetsAtProgress(progress_);
}
// Returns the toolbar insets at |progress|.
UIEdgeInsets GetToolbarInsetsAtProgress(CGFloat progress) const {
return UIEdgeInsetsMake(
collapsed_toolbar_height_ +
progress * (expanded_toolbar_height_ - collapsed_toolbar_height_),
0, progress * bottom_toolbar_height_, 0);
}
// Increments and decrements |disabled_counter_| for features that require the
// toolbar be completely visible.
void IncrementDisabledCounter();
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/fullscreen/test/fullscreen_model_test_util.h"
#import "ios/chrome/browser/ui/fullscreen/test/test_fullscreen_model_observer.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
......@@ -20,6 +21,10 @@ const CGFloat kToolbarHeight = 50.0;
const CGFloat kScrollViewHeight = 400.0;
// The content height used for tests.
const CGFloat kContentHeight = 5000.0;
// Converts |insets| to a string for debugging.
std::string GetStringFromInsets(UIEdgeInsets insets) {
return base::SysNSStringToUTF8(NSStringFromUIEdgeInsets(insets));
}
} // namespace
// Test fixture for FullscreenModel.
......@@ -31,6 +36,7 @@ class FullscreenModelTest : public PlatformTest {
// finishes with a 0.0 y content offset.
model_.SetCollapsedToolbarHeight(0.0);
model_.SetExpandedToolbarHeight(kToolbarHeight);
model_.SetBottomToolbarHeight(kToolbarHeight);
model_.SetScrollViewHeight(kScrollViewHeight);
model_.SetContentHeight(kContentHeight);
model_.ResetForNavigation();
......@@ -218,3 +224,28 @@ TEST_F(FullscreenModelTest, DraggingStarted) {
model().SetScrollViewIsDragging(true);
EXPECT_TRUE(model().has_base_offset());
}
// Tests that toolbar_insets() returns the correct values.
TEST_F(FullscreenModelTest, ToolbarInsets) {
// Checks whether |insets| are equal to the expected insets at |progress|.
void (^check_insets)(UIEdgeInsets insets, CGFloat progress) =
^void(UIEdgeInsets insets, CGFloat progress) {
UIEdgeInsets expected_insets = UIEdgeInsetsMake(
progress * kToolbarHeight, 0, progress * kToolbarHeight, 0);
EXPECT_TRUE(UIEdgeInsetsEqualToEdgeInsets(insets, expected_insets))
<< "Insets " << GetStringFromInsets(insets)
<< " not equal to expected insets "
<< GetStringFromInsets(expected_insets);
};
const CGFloat kFullyVisibleProgress = 1.0;
check_insets(model().max_toolbar_insets(), kFullyVisibleProgress);
check_insets(model().current_toolbar_insets(), kFullyVisibleProgress);
const CGFloat kHalfProgress = 0.5;
SimulateFullscreenUserScrollForProgress(&model(), kHalfProgress);
check_insets(model().current_toolbar_insets(), kHalfProgress);
const CGFloat kHiddenProgress = 0.0;
SimulateFullscreenUserScrollForProgress(&model(), kHiddenProgress);
check_insets(model().current_toolbar_insets(), kHiddenProgress);
check_insets(model().min_toolbar_insets(), kHiddenProgress);
}
......@@ -95,13 +95,7 @@
if (!self.webState || !self.webState->GetView().superview)
return;
UIEdgeInsets newInsets =
UIEdgeInsetsMake(self.model->GetCollapsedToolbarHeight() +
progress * (self.model->GetExpandedToolbarHeight() -
self.model->GetCollapsedToolbarHeight()),
0, progress * self.model->GetBottomToolbarHeight(), 0);
[self updateForInsets:newInsets];
[self updateForInsets:self.model->GetToolbarInsetsAtProgress(progress)];
}
// Updates the WebState view, resizing it such as |insets| is the insets between
......
......@@ -31,6 +31,9 @@ class TestFullscreenController : public FullscreenController {
void IncrementDisabledCounter() override;
void DecrementDisabledCounter() override;
CGFloat GetProgress() const override;
UIEdgeInsets GetMinViewportInsets() const override;
UIEdgeInsets GetMaxViewportInsets() const override;
UIEdgeInsets GetCurrentViewportInsets() const override;
void EnterFullscreen() override;
void ExitFullscreen() override;
......
......@@ -61,6 +61,18 @@ CGFloat TestFullscreenController::GetProgress() const {
return model_ ? model_->progress() : 0.0;
}
UIEdgeInsets TestFullscreenController::GetMinViewportInsets() const {
return model_ ? model_->min_toolbar_insets() : UIEdgeInsetsZero;
}
UIEdgeInsets TestFullscreenController::GetMaxViewportInsets() const {
return model_ ? model_->max_toolbar_insets() : UIEdgeInsetsZero;
}
UIEdgeInsets TestFullscreenController::GetCurrentViewportInsets() const {
return model_ ? model_->current_toolbar_insets() : UIEdgeInsetsZero;
}
void TestFullscreenController::Shutdown() {
for (auto& observer : observers_) {
observer.FullscreenControllerWillShutDown(this);
......
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