Changeset 244875 in webkit


Ignore:
Timestamp:
May 2, 2019 10:38:07 AM (5 years ago)
Author:
achristensen@apple.com
Message:

Safe browsing warning should update colors when a user switches between light and dark appearance
https://bugs.webkit.org/show_bug.cgi?id=197443
<rdar://problem/49883917>

Reviewed by Tim Horton.

We draw the WKSafeBrowsingExclamationPoint ourselves, so we need to call setNeedsDisplay when viewDidChangeEffectiveAppearance is called.
Instead of setting NSView.layer.backgroundColor we need to make an NSView subclass I call WKSafeBrowsingBox and we need to set its layer's
backgroundColor in updateLayer, otherwise the CGColor isn't updated from the NSColor.

  • UIProcess/Cocoa/WKSafeBrowsingWarning.h:
  • UIProcess/Cocoa/WKSafeBrowsingWarning.mm:

(colorForItem):
(-[WKSafeBrowsingExclamationPoint viewDidChangeEffectiveAppearance]):
(-[WKSafeBrowsingBox setSafeBrowsingBackgroundColor:]):
(-[WKSafeBrowsingBox updateLayer]):
(-[WKSafeBrowsingWarning initWithFrame:safeBrowsingWarning:completionHandler:]):
(-[WKSafeBrowsingWarning addContent]):
(-[WKSafeBrowsingWarning showDetailsClicked]):
(setBackground): Deleted.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244869 r244875  
     12019-05-02  Alex Christensen  <achristensen@webkit.org>
     2
     3        Safe browsing warning should update colors when a user switches between light and dark appearance
     4        https://bugs.webkit.org/show_bug.cgi?id=197443
     5        <rdar://problem/49883917>
     6
     7        Reviewed by Tim Horton.
     8
     9        We draw the WKSafeBrowsingExclamationPoint ourselves, so we need to call setNeedsDisplay when viewDidChangeEffectiveAppearance is called.
     10        Instead of setting NSView.layer.backgroundColor we need to make an NSView subclass I call WKSafeBrowsingBox and we need to set its layer's
     11        backgroundColor in updateLayer, otherwise the CGColor isn't updated from the NSColor.
     12
     13        * UIProcess/Cocoa/WKSafeBrowsingWarning.h:
     14        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
     15        (colorForItem):
     16        (-[WKSafeBrowsingExclamationPoint viewDidChangeEffectiveAppearance]):
     17        (-[WKSafeBrowsingBox setSafeBrowsingBackgroundColor:]):
     18        (-[WKSafeBrowsingBox updateLayer]):
     19        (-[WKSafeBrowsingWarning initWithFrame:safeBrowsingWarning:completionHandler:]):
     20        (-[WKSafeBrowsingWarning addContent]):
     21        (-[WKSafeBrowsingWarning showDetailsClicked]):
     22        (setBackground): Deleted.
     23
    1242019-05-02  Frederic Wang  <fwang@igalia.com>
    225
  • trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h

    r241125 r244875  
    4646using ViewType = NSView;
    4747using RectType = NSRect;
    48 @interface WKSafeBrowsingWarning : NSView<NSTextViewDelegate>
     48using ColorType = NSColor;
    4949#else
    5050using ViewType = UIView;
    5151using RectType = CGRect;
     52using ColorType = UIColor;
     53#endif
     54
     55@interface WKSafeBrowsingBox : ViewType {
     56@package
     57#if PLATFORM(MAC)
     58    RetainPtr<ColorType> _backgroundColor;
     59#endif
     60}
     61- (void)setSafeBrowsingBackgroundColor:(ColorType *)color;
     62@end
     63
     64#if PLATFORM(MAC)
     65@interface WKSafeBrowsingWarning : WKSafeBrowsingBox<NSTextViewDelegate>
     66#else
    5267@interface WKSafeBrowsingWarning : UIScrollView<UITextViewDelegate>
    5368#endif
     
    5772    RefPtr<const WebKit::SafeBrowsingWarning> _warning;
    5873    WeakObjCPtr<WKSafeBrowsingTextView> _details;
    59     WeakObjCPtr<ViewType> _box;
     74    WeakObjCPtr<WKSafeBrowsingBox> _box;
    6075#if PLATFORM(WATCHOS)
    6176    WeakObjCPtr<UIResponder> _previousFirstResponder;
  • trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm

    r244319 r244875  
    5151
    5252#if PLATFORM(MAC)
    53 using ColorType = NSColor;
    5453using FontType = NSFont;
    5554using TextViewType = NSTextView;
     
    5857using SizeType = NSSize;
    5958#else
    60 using ColorType = UIColor;
    6159using FontType = UIFont;
    6260using TextViewType = UITextView;
     
    201199}
    202200
     201#if PLATFORM(MAC)
     202- (void)viewDidChangeEffectiveAppearance
     203{
     204    [self setNeedsDisplay:YES];
     205}
     206#endif
     207
    203208- (NSSize)intrinsicContentSize
    204209{
     
    255260}
    256261
    257 static void setBackground(ViewType *view, ColorType *color)
    258 {
    259 #if PLATFORM(MAC)
    260     view.wantsLayer = YES;
    261     view.layer.backgroundColor = color.CGColor;
    262 #else
    263     view.backgroundColor = color;
    264 #endif
    265 }
     262@implementation WKSafeBrowsingBox
     263
     264- (void)setSafeBrowsingBackgroundColor:(ColorType *)color
     265{
     266#if PLATFORM(MAC)
     267    _backgroundColor = color;
     268    self.wantsLayer = YES;
     269#else
     270    self.backgroundColor = color;
     271#endif
     272}
     273
     274#if PLATFORM(MAC)
     275- (void)updateLayer
     276{
     277    self.layer.backgroundColor = [_backgroundColor CGColor];
     278}
     279#endif
     280
     281@end
    266282
    267283@interface WKSafeBrowsingTextView : TextViewType {
     
    288304    };
    289305    _warning = makeRef(warning);
    290     setBackground(self, colorForItem(WarningItem::Background, self));
    291 #if PLATFORM(MAC)
     306#if PLATFORM(MAC)
     307    [self setSafeBrowsingBackgroundColor:colorForItem(WarningItem::Background, self)];
    292308    [self addContent];
     309#else
     310    [self setBackgroundColor:colorForItem(WarningItem::Background, self)];
    293311#endif
    294312
     
    318336    auto showDetails = makeButton(WarningItem::ShowDetailsButton, self, @selector(showDetailsClicked));
    319337    auto goBack = makeButton(WarningItem::GoBackButton, self, @selector(goBackClicked));
    320     auto box = [[ViewType new] autorelease];
     338    auto box = [[WKSafeBrowsingBox new] autorelease];
    321339    _box = box;
    322     setBackground(box, colorForItem(WarningItem::BoxBackground, self));
     340    [box setSafeBrowsingBackgroundColor:colorForItem(WarningItem::BoxBackground, self)];
    323341    box.layer.cornerRadius = boxCornerRadius;
    324342
     
    393411- (void)showDetailsClicked
    394412{
    395     ViewType *box = _box.get().get();
     413    WKSafeBrowsingBox *box = _box.get().get();
    396414    ButtonType *showDetails = box.subviews.lastObject;
    397415    [showDetails removeFromSuperview];
     
    401419    WKSafeBrowsingTextView *details = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:text forWarning:self] autorelease];
    402420    _details = details;
    403     ViewType *bottom = [[ViewType new] autorelease];
    404     setBackground(bottom, colorForItem(WarningItem::BoxBackground, self));
     421    WKSafeBrowsingBox *bottom = [[WKSafeBrowsingBox new] autorelease];
     422    [bottom setSafeBrowsingBackgroundColor:colorForItem(WarningItem::BoxBackground, self)];
    405423    bottom.layer.cornerRadius = boxCornerRadius;
    406424
     
    417435#endif
    418436
    419     ViewType *line = [[ViewType new] autorelease];
    420     setBackground(line, [ColorType lightGrayColor]);
     437    WKSafeBrowsingBox *line = [[WKSafeBrowsingBox new] autorelease];
     438    [line setSafeBrowsingBackgroundColor:[ColorType lightGrayColor]];
    421439    for (ViewType *view in @[details, bottom, line])
    422440        view.translatesAutoresizingMaskIntoConstraints = NO;
Note: See TracChangeset for help on using the changeset viewer.