Commit 9fe5a3c2 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Use |-updateForFullscreenProgress:| as optional selector fallback.

This CL updates the default behavior of FullscreenUIUpdater to use
|-updateForFullscreenProgress:| as a fallback for when the optional
FullscreenUIElement selectors are not implemented.


Bug: 932215
Change-Id: I4e2e5f0efd2b81e3c946161e45cb75f444510537
Reviewed-on: https://chromium-review.googlesource.com/c/1474092
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632392}
parent c3f69282
......@@ -31,13 +31,15 @@
- (void)updateForFullscreenMinViewportInsets:(UIEdgeInsets)minViewportInsets
maxViewportInsets:(UIEdgeInsets)maxViewportInsets;
// Tells the UI that fullscreen is enabled or disabled. When disabled, the UI
// should immediately be updated to the state corresponding with a progress
// value of 1.0.
// Tells the UI that fullscreen is enabled or disabled. FullscreenUIUpdater's
// default behavior if this selector is not implemented is to call
// |-updateForFullscreenProgress:| with a progress value of 1.0.
- (void)updateForFullscreenEnabled:(BOOL)enabled;
// Called when fullscreen is about to initate an animation. UI elements that
// react to fullscreen events should configure |animator| with animations.
// Called when fullscreen is about to initate an animation.
// FullscreenUIUpdater's default behavior if this selector is not implemented is
// to add an animation block calling |-updateForFullscreenProgress:| with a
// progress value of |animator.finalProgress|.
- (void)animateFullscreenWithAnimator:(FullscreenAnimator*)animator;
@end
......
......@@ -9,7 +9,7 @@
@protocol FullscreenUIElement;
// Observer that updates UI elements for FullscreenController.
// Observer that updates FullscreenUIElements for FullscreenController events.
class FullscreenUIUpdater : public FullscreenControllerObserver {
public:
// Contructor for an observer that updates |ui_element|. |ui_element| is not
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_updater.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_animator.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_element.h"
......@@ -35,14 +36,23 @@ void FullscreenUIUpdater::FullscreenViewportInsetRangeChanged(
void FullscreenUIUpdater::FullscreenEnabledStateChanged(
FullscreenController* controller,
bool enabled) {
if ([ui_element_ respondsToSelector:@selector(updateForFullscreenProgress:)])
if ([ui_element_ respondsToSelector:@selector(updateForFullscreenEnabled:)]) {
[ui_element_ updateForFullscreenEnabled:enabled];
} else if (!enabled) {
[ui_element_ updateForFullscreenProgress:1.0];
}
}
void FullscreenUIUpdater::FullscreenWillAnimate(
FullscreenController* controller,
FullscreenAnimator* animator) {
SEL animator_selector = @selector(animateFullscreenWithAnimator:);
if ([ui_element_ respondsToSelector:animator_selector])
if ([ui_element_ respondsToSelector:animator_selector]) {
[ui_element_ animateFullscreenWithAnimator:animator];
} else {
CGFloat progress = animator.finalProgress;
[animator addAnimations:^{
[ui_element_ updateForFullscreenProgress:progress];
}];
}
}
......@@ -22,10 +22,30 @@
@property(nonatomic, readonly) UIEdgeInsets maxViewportInsets;
@property(nonatomic, readonly, getter=isEnabled) BOOL enabled;
@property(nonatomic, readonly) FullscreenAnimator* animator;
// Whether the UI element should implement optional selectors. Defaults to YES.
@property(nonatomic, assign) BOOL implementsOptionalSelectors;
@end
@implementation TestFullscreenUIElement
- (instancetype)init {
if (self = [super init]) {
_implementsOptionalSelectors = YES;
}
return self;
}
- (BOOL)respondsToSelector:(SEL)aSelector {
if (!self.implementsOptionalSelectors &&
(aSelector == @selector(updateForFullscreenMinViewportInsets:
maxViewportInsets:) ||
aSelector == @selector(updateForFullscreenEnabled:) ||
aSelector == @selector(animateFullscreenWithAnimator:))) {
return NO;
}
return [super respondsToSelector:aSelector];
}
- (void)updateForFullscreenMinViewportInsets:(UIEdgeInsets)minViewportInsets
maxViewportInsets:(UIEdgeInsets)maxViewportInsets {
_minViewportInsets = minViewportInsets;
......@@ -104,3 +124,23 @@ TEST_F(FullscreenUIUpdaterTest, ScrollEnd) {
observer()->FullscreenWillAnimate(nullptr, kAnimator);
EXPECT_EQ(element().animator, kAnimator);
}
// Tests the default behavior of FullscreenUIUpdater when optional
// FullscreenUIElement selectors aren not implemented.
TEST_F(FullscreenUIUpdaterTest, OptionalSelectors) {
element().implementsOptionalSelectors = NO;
// Verify that the fullscreen progress gets reset to 1.0 when the enabled
// state selector is not implemented.
ASSERT_TRUE(AreCGFloatsEqual(element().progress, 0.0));
observer()->FullscreenEnabledStateChanged(nullptr, false);
EXPECT_TRUE(AreCGFloatsEqual(element().progress, 1.0));
// Verify that the fullscreen progress gets reset to 0.0 for an
// ENTER_FULLSCREEN animator when the animation selector is not implemented.
FullscreenAnimator* animator = [[FullscreenAnimator alloc]
initWithStartProgress:0.0
style:FullscreenAnimatorStyle::ENTER_FULLSCREEN];
observer()->FullscreenWillAnimate(nullptr, animator);
[animator startAnimation];
EXPECT_TRUE(AreCGFloatsEqual(element().progress, 0.0));
[animator stopAnimation:YES];
}
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