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 @@ ...@@ -31,13 +31,15 @@
- (void)updateForFullscreenMinViewportInsets:(UIEdgeInsets)minViewportInsets - (void)updateForFullscreenMinViewportInsets:(UIEdgeInsets)minViewportInsets
maxViewportInsets:(UIEdgeInsets)maxViewportInsets; maxViewportInsets:(UIEdgeInsets)maxViewportInsets;
// Tells the UI that fullscreen is enabled or disabled. When disabled, the UI // Tells the UI that fullscreen is enabled or disabled. FullscreenUIUpdater's
// should immediately be updated to the state corresponding with a progress // default behavior if this selector is not implemented is to call
// value of 1.0. // |-updateForFullscreenProgress:| with a progress value of 1.0.
- (void)updateForFullscreenEnabled:(BOOL)enabled; - (void)updateForFullscreenEnabled:(BOOL)enabled;
// Called when fullscreen is about to initate an animation. UI elements that // Called when fullscreen is about to initate an animation.
// react to fullscreen events should configure |animator| with animations. // 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; - (void)animateFullscreenWithAnimator:(FullscreenAnimator*)animator;
@end @end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
@protocol FullscreenUIElement; @protocol FullscreenUIElement;
// Observer that updates UI elements for FullscreenController. // Observer that updates FullscreenUIElements for FullscreenController events.
class FullscreenUIUpdater : public FullscreenControllerObserver { class FullscreenUIUpdater : public FullscreenControllerObserver {
public: public:
// Contructor for an observer that updates |ui_element|. |ui_element| is not // Contructor for an observer that updates |ui_element|. |ui_element| is not
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_updater.h" #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_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_element.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_element.h"
...@@ -35,14 +36,23 @@ void FullscreenUIUpdater::FullscreenViewportInsetRangeChanged( ...@@ -35,14 +36,23 @@ void FullscreenUIUpdater::FullscreenViewportInsetRangeChanged(
void FullscreenUIUpdater::FullscreenEnabledStateChanged( void FullscreenUIUpdater::FullscreenEnabledStateChanged(
FullscreenController* controller, FullscreenController* controller,
bool enabled) { bool enabled) {
if ([ui_element_ respondsToSelector:@selector(updateForFullscreenProgress:)]) if ([ui_element_ respondsToSelector:@selector(updateForFullscreenEnabled:)]) {
[ui_element_ updateForFullscreenEnabled:enabled]; [ui_element_ updateForFullscreenEnabled:enabled];
} else if (!enabled) {
[ui_element_ updateForFullscreenProgress:1.0];
}
} }
void FullscreenUIUpdater::FullscreenWillAnimate( void FullscreenUIUpdater::FullscreenWillAnimate(
FullscreenController* controller, FullscreenController* controller,
FullscreenAnimator* animator) { FullscreenAnimator* animator) {
SEL animator_selector = @selector(animateFullscreenWithAnimator:); SEL animator_selector = @selector(animateFullscreenWithAnimator:);
if ([ui_element_ respondsToSelector:animator_selector]) if ([ui_element_ respondsToSelector:animator_selector]) {
[ui_element_ animateFullscreenWithAnimator:animator]; [ui_element_ animateFullscreenWithAnimator:animator];
} else {
CGFloat progress = animator.finalProgress;
[animator addAnimations:^{
[ui_element_ updateForFullscreenProgress:progress];
}];
}
} }
...@@ -22,10 +22,30 @@ ...@@ -22,10 +22,30 @@
@property(nonatomic, readonly) UIEdgeInsets maxViewportInsets; @property(nonatomic, readonly) UIEdgeInsets maxViewportInsets;
@property(nonatomic, readonly, getter=isEnabled) BOOL enabled; @property(nonatomic, readonly, getter=isEnabled) BOOL enabled;
@property(nonatomic, readonly) FullscreenAnimator* animator; @property(nonatomic, readonly) FullscreenAnimator* animator;
// Whether the UI element should implement optional selectors. Defaults to YES.
@property(nonatomic, assign) BOOL implementsOptionalSelectors;
@end @end
@implementation TestFullscreenUIElement @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 - (void)updateForFullscreenMinViewportInsets:(UIEdgeInsets)minViewportInsets
maxViewportInsets:(UIEdgeInsets)maxViewportInsets { maxViewportInsets:(UIEdgeInsets)maxViewportInsets {
_minViewportInsets = minViewportInsets; _minViewportInsets = minViewportInsets;
...@@ -104,3 +124,23 @@ TEST_F(FullscreenUIUpdaterTest, ScrollEnd) { ...@@ -104,3 +124,23 @@ TEST_F(FullscreenUIUpdaterTest, ScrollEnd) {
observer()->FullscreenWillAnimate(nullptr, kAnimator); observer()->FullscreenWillAnimate(nullptr, kAnimator);
EXPECT_EQ(element().animator, 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