Commit 3ab343aa authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Consolidate FullscreenMediator animator setup code.

Now that there is a single FullscreenControllerObserver function for all
fullscreen-driven animations, we can remove duplicated code and
consolidate setup to a single function.

Bug: none
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I25a0b7f9797f2a62f79317f9f1ec8121da5dbf5c
Reviewed-on: https://chromium-review.googlesource.com/1053179
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590445}
parent 409f7278
...@@ -63,12 +63,9 @@ class FullscreenMediator : public FullscreenModelObserver { ...@@ -63,12 +63,9 @@ class FullscreenMediator : public FullscreenModelObserver {
void FullscreenModelScrollEventEnded(FullscreenModel* model) override; void FullscreenModelScrollEventEnded(FullscreenModel* model) override;
void FullscreenModelWasReset(FullscreenModel* model) override; void FullscreenModelWasReset(FullscreenModel* model) override;
// Sets up |animator_| with |style|. // Sets up |animator_| with |style|, notifies FullscreenControllerObservers,
void SetUpAnimator(FullscreenAnimatorStyle style); // and starts the animation.
void AnimateWithStyle(FullscreenAnimatorStyle style);
// Starts |animator+| if it has animations to run. |animator_| will be reset
// if no animations have been added.
void StartAnimator();
// Stops the current scroll end animation if one is in progress. If // Stops the current scroll end animation if one is in progress. If
// |update_model| is true, the FullscreenModel will be updated with the active // |update_model| is true, the FullscreenModel will be updated with the active
......
...@@ -37,50 +37,20 @@ void FullscreenMediator::SetWebState(web::WebState* webState) { ...@@ -37,50 +37,20 @@ void FullscreenMediator::SetWebState(web::WebState* webState) {
} }
void FullscreenMediator::ScrollToTop() { void FullscreenMediator::ScrollToTop() {
FullscreenAnimatorStyle scrollToTopStyle = AnimateWithStyle(FullscreenAnimatorStyle::EXIT_FULLSCREEN);
FullscreenAnimatorStyle::EXIT_FULLSCREEN;
if (animator_ && animator_.style == scrollToTopStyle)
return;
StopAnimating(true);
SetUpAnimator(scrollToTopStyle);
for (auto& observer : observers_) {
observer.FullscreenWillAnimate(controller_, animator_);
}
StartAnimator();
} }
void FullscreenMediator::WillEnterForeground() { void FullscreenMediator::WillEnterForeground() {
FullscreenAnimatorStyle enterForegroundStyle = AnimateWithStyle(FullscreenAnimatorStyle::EXIT_FULLSCREEN);
FullscreenAnimatorStyle::EXIT_FULLSCREEN;
if (animator_ && animator_.style == enterForegroundStyle)
return;
StopAnimating(true);
SetUpAnimator(enterForegroundStyle);
for (auto& observer : observers_) {
observer.FullscreenWillAnimate(controller_, animator_);
}
StartAnimator();
} }
void FullscreenMediator::AnimateModelReset() { void FullscreenMediator::AnimateModelReset() {
FullscreenAnimatorStyle resetStyle = FullscreenAnimatorStyle::EXIT_FULLSCREEN;
if (animator_ && animator_.style == resetStyle)
return;
StopAnimating(true);
SetUpAnimator(resetStyle);
for (auto& observer : observers_) {
observer.FullscreenWillAnimate(controller_, animator_);
}
// Instruct the model to ignore the remainder of the current scroll when // Instruct the model to ignore the remainder of the current scroll when
// starting this animator. This prevents the toolbar from immediately being // starting this animator. This prevents the toolbar from immediately being
// hidden if AnimateModelReset() is called while a scroll view is // hidden if AnimateModelReset() is called while a scroll view is
// decelerating. // decelerating.
model_->IgnoreRemainderOfCurrentScroll(); model_->IgnoreRemainderOfCurrentScroll();
StartAnimator(); AnimateWithStyle(FullscreenAnimatorStyle::EXIT_FULLSCREEN);
} }
void FullscreenMediator::Disconnect() { void FullscreenMediator::Disconnect() {
...@@ -132,18 +102,9 @@ void FullscreenMediator::FullscreenModelScrollEventStarted( ...@@ -132,18 +102,9 @@ void FullscreenMediator::FullscreenModelScrollEventStarted(
void FullscreenMediator::FullscreenModelScrollEventEnded( void FullscreenMediator::FullscreenModelScrollEventEnded(
FullscreenModel* model) { FullscreenModel* model) {
DCHECK_EQ(model_, model); DCHECK_EQ(model_, model);
FullscreenAnimatorStyle scrollEndStyle = AnimateWithStyle(model_->progress() >= 0.5
model_->progress() >= 0.5 ? FullscreenAnimatorStyle::EXIT_FULLSCREEN ? FullscreenAnimatorStyle::EXIT_FULLSCREEN
: FullscreenAnimatorStyle::ENTER_FULLSCREEN; : FullscreenAnimatorStyle::ENTER_FULLSCREEN);
if (animator_ && animator_.style == scrollEndStyle)
return;
StopAnimating(true);
SetUpAnimator(scrollEndStyle);
for (auto& observer : observers_) {
observer.FullscreenWillAnimate(controller_, animator_);
}
StartAnimator();
} }
void FullscreenMediator::FullscreenModelWasReset(FullscreenModel* model) { void FullscreenMediator::FullscreenModelWasReset(FullscreenModel* model) {
...@@ -159,8 +120,13 @@ void FullscreenMediator::FullscreenModelWasReset(FullscreenModel* model) { ...@@ -159,8 +120,13 @@ void FullscreenMediator::FullscreenModelWasReset(FullscreenModel* model) {
[resizer_ updateForFullscreenProgress:model_->progress()]; [resizer_ updateForFullscreenProgress:model_->progress()];
} }
void FullscreenMediator::SetUpAnimator(FullscreenAnimatorStyle style) { void FullscreenMediator::AnimateWithStyle(FullscreenAnimatorStyle style) {
if (animator_ && animator_.style == style)
return;
StopAnimating(true);
DCHECK(!animator_); DCHECK(!animator_);
// Create the animator and set up its completion block.
animator_ = animator_ =
[[FullscreenAnimator alloc] initWithStartProgress:model_->progress() [[FullscreenAnimator alloc] initWithStartProgress:model_->progress()
style:style]; style:style];
...@@ -175,9 +141,12 @@ void FullscreenMediator::SetUpAnimator(FullscreenAnimatorStyle style) { ...@@ -175,9 +141,12 @@ void FullscreenMediator::SetUpAnimator(FullscreenAnimatorStyle style) {
[resizer_ updateForFullscreenProgress:animator_.finalProgress]; [resizer_ updateForFullscreenProgress:animator_.finalProgress];
animator_ = nil; animator_ = nil;
}]; }];
}
void FullscreenMediator::StartAnimator() { // Notify observers that the animation will occur.
for (auto& observer : observers_) {
observer.FullscreenWillAnimate(controller_, animator_);
}
// Only start the animator if animations have been added and it has a non-zero // Only start the animator if animations have been added and it has a non-zero
// progress change. // progress change.
if (animator_.hasAnimations && if (animator_.hasAnimations &&
......
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