[Fullscreen] Use secondary glyph style for fullscreen controls
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jun 2018 18:59:12 +0000 (18:59 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jun 2018 18:59:12 +0000 (18:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186862
<rdar://problem/41212210>

Reviewed by Tim Horton.

Source/WebCore/PAL:

* pal/spi/cocoa/AVKitSPI.h:

Source/WebKit:

Adopt AVBackgroundView, and use its predefined enums to set the material and tint styles for
the fullscreen controls.

* UIProcess/ios/fullscreen/WKFullScreenViewController.mm:
(-[WKFullScreenViewController loadView]):
* UIProcess/ios/fullscreen/WKFullscreenStackView.h:
* UIProcess/ios/fullscreen/WKFullscreenStackView.mm:
(-[WKFullscreenStackView init]):
(-[WKFullscreenStackView dealloc]):
(-[WKFullscreenStackView addArrangedSubview:applyingMaterialStyle:tintEffectStyle:]):
(-[WKFullscreenStackView layoutSubviews]):
(+[WKFullscreenStackView baseEffects]): Deleted.
(+[WKFullscreenStackView configureView:forTintEffectWithColor:filterType:]): Deleted.
(+[WKFullscreenStackView configureView:withBackgroundFillOfColor:opacity:filter:]): Deleted.
(+[WKFullscreenStackView secondaryMaterialOverlayView]): Deleted.
(+[WKFullscreenStackView applyPrimaryGlyphTintToView:]): Deleted.
(+[WKFullscreenStackView applySecondaryGlyphTintToView:]): Deleted.
(-[WKFullscreenStackView initWithArrangedSubviews:axis:]): Deleted.
(-[WKFullscreenStackView setTargetViewForSecondaryMaterialOverlay:]): Deleted.
(-[WKFullscreenStackView contentView]): Deleted.
(-[WKFullscreenStackView _setArrangedSubviews:axis:]): Deleted.
(-[WKFullscreenStackView setBounds:]): Deleted.
(-[WKFullscreenStackView updateConstraints]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233052 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cocoa/AVKitSPI.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenViewController.mm
Source/WebKit/UIProcess/ios/fullscreen/WKFullscreenStackView.h
Source/WebKit/UIProcess/ios/fullscreen/WKFullscreenStackView.mm

index c9954a4..ea1e96b 100644 (file)
@@ -1,3 +1,13 @@
+2018-06-21  Jer Noble  <jer.noble@apple.com>
+
+        [Fullscreen] Use secondary glyph style for fullscreen controls
+        https://bugs.webkit.org/show_bug.cgi?id=186862
+        <rdar://problem/41212210>
+
+        Reviewed by Tim Horton.
+
+        * pal/spi/cocoa/AVKitSPI.h:
+
 2018-06-15  Jonathan Bedard  <jbedard@apple.com>
 
         Complex text handling should opt out of bounded text layout (follow-up fix)
index f1a53b8..bb814fd 100644 (file)
@@ -33,6 +33,7 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
+#import <AVKit/AVBackgroundView.h>
 #import <AVKit/AVPlayerController.h>
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wobjc-property-no-attribute"
@@ -90,6 +91,21 @@ NS_ASSUME_NONNULL_END
 
 #else
 
+NS_ASSUME_NONNULL_BEGIN
+
+@interface AVBackgroundView : UIView
+@property (nonatomic) BOOL automaticallyDrawsRoundedCorners;
+typedef NS_ENUM(NSInteger, AVBackgroundViewMaterialStyle) {
+    AVBackgroundViewMaterialStylePrimary,
+    AVBackgroundViewMaterialStyleSecondary
+};
+typedef NS_ENUM(NSInteger, AVBackgroundViewTintEffectStyle) {
+    AVBackgroundViewTintEffectStylePrimary,
+    AVBackgroundViewTintEffectStyleSecondary
+};
+- (void)addSubview:(UIView *)subview applyingMaterialStyle:(AVBackgroundViewMaterialStyle)materialStyle tintEffectStyle:(AVBackgroundViewTintEffectStyle)tintEffectStyle;
+@end
+
 @interface AVPlayerController : UIResponder
 @end
 
@@ -108,8 +124,6 @@ typedef NS_ENUM(NSInteger, AVPlayerControllerExternalPlaybackType) {
 @property (NS_NONATOMIC_IOSONLY, readonly) AVPlayerControllerStatus status;
 @end
 
-NS_ASSUME_NONNULL_BEGIN
-
 @class AVPlayerLayer;
 
 @interface AVPictureInPicturePlayerLayerView : UIView
index 02ea074..900822d 100644 (file)
@@ -1,5 +1,37 @@
 2018-06-21  Jer Noble  <jer.noble@apple.com>
 
+        [Fullscreen] Use secondary glyph style for fullscreen controls
+        https://bugs.webkit.org/show_bug.cgi?id=186862
+        <rdar://problem/41212210>
+
+        Reviewed by Tim Horton.
+
+        Adopt AVBackgroundView, and use its predefined enums to set the material and tint styles for
+        the fullscreen controls.
+
+        * UIProcess/ios/fullscreen/WKFullScreenViewController.mm:
+        (-[WKFullScreenViewController loadView]):
+        * UIProcess/ios/fullscreen/WKFullscreenStackView.h:
+        * UIProcess/ios/fullscreen/WKFullscreenStackView.mm:
+        (-[WKFullscreenStackView init]):
+        (-[WKFullscreenStackView dealloc]):
+        (-[WKFullscreenStackView addArrangedSubview:applyingMaterialStyle:tintEffectStyle:]):
+        (-[WKFullscreenStackView layoutSubviews]):
+        (+[WKFullscreenStackView baseEffects]): Deleted.
+        (+[WKFullscreenStackView configureView:forTintEffectWithColor:filterType:]): Deleted.
+        (+[WKFullscreenStackView configureView:withBackgroundFillOfColor:opacity:filter:]): Deleted.
+        (+[WKFullscreenStackView secondaryMaterialOverlayView]): Deleted.
+        (+[WKFullscreenStackView applyPrimaryGlyphTintToView:]): Deleted.
+        (+[WKFullscreenStackView applySecondaryGlyphTintToView:]): Deleted.
+        (-[WKFullscreenStackView initWithArrangedSubviews:axis:]): Deleted.
+        (-[WKFullscreenStackView setTargetViewForSecondaryMaterialOverlay:]): Deleted.
+        (-[WKFullscreenStackView contentView]): Deleted.
+        (-[WKFullscreenStackView _setArrangedSubviews:axis:]): Deleted.
+        (-[WKFullscreenStackView setBounds:]): Deleted.
+        (-[WKFullscreenStackView updateConstraints]): Deleted.
+
+2018-06-21  Jer Noble  <jer.noble@apple.com>
+
         [Fullscreen] Suspend page (and pause video) while phishing warning is presented
         https://bugs.webkit.org/show_bug.cgi?id=186856
         <rdar://problem/41212444>
index 472fe3a..3fcbf7b 100644 (file)
@@ -36,6 +36,7 @@
 #import "WebFullScreenManagerProxy.h"
 #import "WebPageProxy.h"
 #import <WebCore/LocalizedStrings.h>
+#import <pal/spi/cocoa/AVKitSPI.h>
 #import <wtf/RetainPtr.h>
 
 using namespace WebCore;
@@ -245,7 +246,6 @@ private:
     [_cancelButton setTranslatesAutoresizingMaskIntoConstraints:NO];
     [_cancelButton setAdjustsImageWhenHighlighted:NO];
     [_cancelButton setExtrinsicContentSize:CGSizeMake(60.0, 47.0)];
-    [WKFullscreenStackView applyPrimaryGlyphTintToView:_cancelButton.get()];
     NSBundle *bundle = [NSBundle bundleForClass:self.class];
     UIImage *doneImage = [UIImage imageNamed:@"Done" inBundle:bundle compatibleWithTraitCollection:nil];
     [_cancelButton setImage:[doneImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
@@ -257,7 +257,6 @@ private:
     [_pipButton setTranslatesAutoresizingMaskIntoConstraints:NO];
     [_pipButton setAdjustsImageWhenHighlighted:NO];
     [_pipButton setExtrinsicContentSize:CGSizeMake(60.0, 47.0)];
-    [WKFullscreenStackView applyPrimaryGlyphTintToView:_pipButton.get()];
     UIImage *startPiPImage = [UIImage imageNamed:@"StartPictureInPictureButton" inBundle:bundle compatibleWithTraitCollection:nil];
     UIImage *stopPiPImage = [UIImage imageNamed:@"StopPictureInPictureButton" inBundle:bundle compatibleWithTraitCollection:nil];
     [_pipButton setImage:[startPiPImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
@@ -266,9 +265,10 @@ private:
     [_pipButton sizeToFit];
     [_pipButton addTarget:self action:@selector(_togglePiPAction:) forControlEvents:UIControlEventTouchUpInside];
 
-    _stackView = adoptNS([[WKFullscreenStackView alloc] initWithArrangedSubviews:@[_cancelButton.get(), _pipButton.get()] axis:UILayoutConstraintAxisHorizontal]);
+    _stackView = adoptNS([[WKFullscreenStackView alloc] init]);
     [_stackView setTranslatesAutoresizingMaskIntoConstraints:NO];
-    [_stackView setTargetViewForSecondaryMaterialOverlay:_cancelButton.get()];
+    [_stackView addArrangedSubview:_cancelButton.get() applyingMaterialStyle:AVBackgroundViewMaterialStyleSecondary tintEffectStyle:AVBackgroundViewTintEffectStyleSecondary];
+    [_stackView addArrangedSubview:_pipButton.get() applyingMaterialStyle:AVBackgroundViewMaterialStylePrimary tintEffectStyle:AVBackgroundViewTintEffectStyleSecondary];
     [[self view] addSubview:_stackView.get()];
 
     UILayoutGuide *safeArea = self.view.safeAreaLayoutGuide;
index f7b82c5..374d4fd 100644 (file)
 #if ENABLE(FULLSCREEN_API) && PLATFORM(IOS)
 
 #import <UIKit/UIView.h>
+#import <pal/spi/cocoa/AVKitSPI.h>
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface WKFullscreenStackView : UIView
-+ (void)applyPrimaryGlyphTintToView:(UIView *)view;
-+ (void)applySecondaryGlyphTintToView:(UIView *)view;
-
-- (instancetype)initWithArrangedSubviews:(NSArray<UIView *> *)arrangedSubviews axis:(UILayoutConstraintAxis)axis;
-
-@property (nonatomic, retain, nullable) UIView *targetViewForSecondaryMaterialOverlay;
-@property (nonatomic, readonly) UIView *contentView;
+@interface WKFullscreenStackView : UIStackView
+- (void)addArrangedSubview:(UIView *)subview applyingMaterialStyle:(AVBackgroundViewMaterialStyle)materialStyle tintEffectStyle:(AVBackgroundViewTintEffectStyle)tintEffectStyle;
 @end
 
 NS_ASSUME_NONNULL_END
index d17a7e8..7d4ab5d 100644 (file)
 #import "UIKitSPI.h"
 #import <QuartzCore/CAFilter.h>
 #import <UIKit/UIVisualEffectView.h>
+#import <pal/cf/CoreMediaSoftLink.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 
-static NSArray<UIVisualEffect *>* reducedTransparencyEffects()
-{
-    static NeverDestroyed<RetainPtr<NSArray<UIVisualEffect *>>> effects;
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        effects.get() = @[[UIVisualEffect effectCompositingColor:[UIColor colorWithRed:(43.0 / 255.0) green:(46.0 / 255.0) blue:(48.0 / 255.0) alpha:1.0] withMode:UICompositingModeNormal alpha:1.0]];
-    });
-    return effects.get().get();
-}
+SOFTLINK_AVKIT_FRAMEWORK()
+SOFT_LINK_CLASS_OPTIONAL(AVKit, AVBackgroundView)
 
-static NSArray<UIVisualEffect *>* normalTransparencyEffects()
-{
-    static NeverDestroyed<RetainPtr<NSArray<UIVisualEffect *>>> effects;
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        effects.get() = @[
-            [UIVisualEffect effectCompositingColor:[UIColor blackColor] withMode:UICompositingModeNormal alpha:0.55],
-            [UIBlurEffect effectWithBlurRadius:UIRoundToScreenScale(17.5, [UIScreen mainScreen])],
-            [UIColorEffect colorEffectSaturate:1.8],
-            [UIVisualEffect effectCompositingColor:[UIColor whiteColor] withMode:UICompositingModeNormal alpha:0.14]
-        ];
-    });
-    return effects.get().get();
+@interface WKFullscreenStackView () {
+    RetainPtr<AVBackgroundView> _backgroundView;
 }
-
-@interface UIVisualEffectView (WebKitPrivate)
-@property (nonatomic, readwrite, copy) NSArray<UIVisualEffect *> *backgroundEffects;
-@end
-
-@interface WKFullscreenStackView ()
-@property (nonatomic, readonly) UIStackView *_stackView;
-@property (nonatomic, readonly) UIVisualEffectView *_visualEffectView;
-@property (nonatomic, assign) UIVisualEffectView *secondaryMaterialOverlayView;
-@property (nonatomic, retain) NSArray<NSLayoutConstraint *> *secondaryMaterialOverlayViewConstraints;
 @end
 
 @implementation WKFullscreenStackView
 
-#pragma mark - Class Methods
-+ (NSArray<UIVisualEffect *> *)baseEffects
-{
-    if (UIAccessibilityIsReduceTransparencyEnabled())
-        return reducedTransparencyEffects();
-    return normalTransparencyEffects();
-}
-
-+ (void)configureView:(UIView *)view forTintEffectWithColor:(UIColor *)tintColor filterType:(NSString *)filterType
-{
-    if ([view isKindOfClass:[UILabel class]]) {
-        [(UILabel *)view setTextColor:tintColor];
-        [view setTintColor:tintColor];
-        [[view layer] setCompositingFilter:[CAFilter filterWithType:kCAFilterPlusL]];
-        return;
-    }
-
-    _UIVisualEffectTintLayerConfig *tintLayerConfig = [_UIVisualEffectTintLayerConfig layerWithTintColor:tintColor filterType:filterType];
-    [[[_UIVisualEffectConfig configWithContentConfig:tintLayerConfig] contentConfig] configureLayerView:view];
-}
-
-+ (void)configureView:(UIView *)view withBackgroundFillOfColor:(UIColor *)fillColor opacity:(CGFloat)opacity filter:(NSString *)filter
-{
-    _UIVisualEffectLayerConfig *baseLayerConfig = [_UIVisualEffectLayerConfig layerWithFillColor:fillColor opacity:opacity filterType:filter];
-    [[[_UIVisualEffectConfig configWithContentConfig:baseLayerConfig] contentConfig] configureLayerView:view];
-}
-
-+ (UIVisualEffectView *)secondaryMaterialOverlayView
-{
-    UIVisualEffectView *secondaryMaterialOverlayView = [[UIVisualEffectView alloc] initWithEffect:nil];
-    [secondaryMaterialOverlayView setUserInteractionEnabled:NO];
-    [secondaryMaterialOverlayView setBackgroundEffects:@[[UIVisualEffect effectCompositingColor:[UIColor blackColor] withMode:UICompositingModePlusDarker alpha:0.06]]];
-    return [secondaryMaterialOverlayView autorelease];
-}
-
 #pragma mark - External Interface
 
-+ (void)applyPrimaryGlyphTintToView:(UIView *)view
+- (instancetype)init
 {
-    [self configureView:view forTintEffectWithColor:[UIColor colorWithWhite:1.0 alpha:0.75] filterType:kCAFilterPlusL];
-}
-
-+ (void)applySecondaryGlyphTintToView:(UIView *)view
-{
-    [self configureView:view forTintEffectWithColor:[UIColor colorWithWhite:1.0 alpha:0.55] filterType:kCAFilterPlusL];
-}
-
-- (instancetype)initWithArrangedSubviews:(NSArray<UIView *> *)arrangedSubviews axis:(UILayoutConstraintAxis)axis
-{
-    self = [self initWithFrame:CGRectMake(0, 0, 100, 100)];
+    CGRect frame = CGRectMake(0, 0, 100, 100);
+    self = [self initWithFrame:frame];
 
     if (!self)
         return nil;
 
     [self setClipsToBounds:YES];
 
-    _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:nil];
-    [self addSubview:_visualEffectView];
-    [_visualEffectView setBackgroundEffects:[[self class] baseEffects]];
-
-    _stackView = [[UIStackView alloc] initWithArrangedSubviews:arrangedSubviews];
-    [_stackView setAxis:axis];
-    [_stackView setLayoutMarginsRelativeArrangement:YES];
-    [_stackView setInsetsLayoutMarginsFromSafeArea:NO];
-    [self insertSubview:_stackView above:_visualEffectView];
-
-    [self _setArrangedSubviews:arrangedSubviews axis:axis];
+    _backgroundView = adoptNS([allocAVBackgroundViewInstance() initWithFrame:frame]);
+    [self addSubview:_backgroundView.get()];
 
     return self;
 }
 
-- (void)dealloc
-{
-    [_targetViewForSecondaryMaterialOverlay release];
-    [_visualEffectView release];
-    [_stackView release];
-    [_secondaryMaterialOverlayViewConstraints release];
-    [super dealloc];
-}
-
-- (void)setTargetViewForSecondaryMaterialOverlay:(UIView *)targetViewForSecondaryMaterialOverlay
-{
-    if (_targetViewForSecondaryMaterialOverlay == targetViewForSecondaryMaterialOverlay)
-        return;
-
-    _targetViewForSecondaryMaterialOverlay = [targetViewForSecondaryMaterialOverlay retain];
-    [self setNeedsUpdateConstraints];
-}
-
-- (UIView *)contentView
-{
-    return [_visualEffectView contentView];
-}
-
-#pragma mark - Internal Interface
-
-@synthesize _stackView=_stackView;
-@synthesize _visualEffectView=_visualEffectView;
-
-- (void)_setArrangedSubviews:(NSArray<UIView *> *)arrangedSubviews axis:(UILayoutConstraintAxis)axis
+- (void)addArrangedSubview:(UIView *)subview applyingMaterialStyle:(AVBackgroundViewMaterialStyle)materialStyle tintEffectStyle:(AVBackgroundViewTintEffectStyle)tintEffectStyle
 {
-    for (UIView *view in [_stackView arrangedSubviews])
-        [view removeFromSuperview];
-
-    for (UIView *view in arrangedSubviews)
-        [_stackView addArrangedSubview:view];
-
-    [_stackView setAxis:axis];
+    [_backgroundView.get() addSubview:subview applyingMaterialStyle:materialStyle tintEffectStyle:tintEffectStyle];
+    [self addArrangedSubview:subview];
 }
 
 #pragma mark - UIView Overrides
 
-- (void)setBounds:(CGRect)bounds
-{
-    CGSize oldSize = [self bounds].size;
-
-    [super setBounds:bounds];
-
-    if (!CGSizeEqualToSize(oldSize, bounds.size))
-        [self _setContinuousCornerRadius:((CGRectGetHeight(bounds) > 40.0) ? 16.0 : 8.0)];
-}
-
-- (void)updateConstraints
+- (void)layoutSubviews
 {
-    if ([_stackView translatesAutoresizingMaskIntoConstraints] || [_visualEffectView translatesAutoresizingMaskIntoConstraints]) {
-        [_visualEffectView setTranslatesAutoresizingMaskIntoConstraints:NO];
-        [_stackView setTranslatesAutoresizingMaskIntoConstraints:NO];
-
-        NSArray<NSLayoutConstraint *> *constraints = @[
-            [[_visualEffectView leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
-            [[_visualEffectView topAnchor] constraintEqualToAnchor:[self topAnchor]],
-            [[_visualEffectView trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
-            [[_visualEffectView bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]],
-            [[_stackView leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
-            [[_stackView topAnchor] constraintEqualToAnchor:[self topAnchor]],
-            [[_stackView trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
-            [[_stackView bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]],
-        ];
-
-        for (NSLayoutConstraint *constraint in constraints)
-            [constraint setPriority:(UILayoutPriorityRequired - 1)];
-
-        [NSLayoutConstraint activateConstraints:constraints];
-    }
-
-    if ([[self targetViewForSecondaryMaterialOverlay] isDescendantOfView:self]) {
-        if (!_secondaryMaterialOverlayView) {
-            [self setSecondaryMaterialOverlayView:[[self class] secondaryMaterialOverlayView]];
-            [self addSubview:[self secondaryMaterialOverlayView]];
-        }
-
-        if ([[self secondaryMaterialOverlayView] isDescendantOfView:self] && !_secondaryMaterialOverlayViewConstraints) {
-            [[self secondaryMaterialOverlayView] setTranslatesAutoresizingMaskIntoConstraints:NO];
-            NSArray<NSLayoutConstraint *> *constraints = @[
-                [[_secondaryMaterialOverlayView centerXAnchor] constraintEqualToAnchor:[_targetViewForSecondaryMaterialOverlay centerXAnchor]],
-                [[_secondaryMaterialOverlayView centerYAnchor] constraintEqualToAnchor:[_targetViewForSecondaryMaterialOverlay centerYAnchor]],
-                [[_secondaryMaterialOverlayView widthAnchor] constraintEqualToAnchor:[_targetViewForSecondaryMaterialOverlay widthAnchor]],
-                [[_secondaryMaterialOverlayView heightAnchor] constraintEqualToAnchor:[_targetViewForSecondaryMaterialOverlay heightAnchor]]
-            ];
-            [self setSecondaryMaterialOverlayViewConstraints:constraints];
-            [NSLayoutConstraint activateConstraints:[self secondaryMaterialOverlayViewConstraints]];
-        }
-    } else
-        [_secondaryMaterialOverlayView removeFromSuperview];
-
-    [super updateConstraints];
+    [_backgroundView.get() setFrame:self.bounds];
+    [super layoutSubviews];
 }
 
 @end