Title: [244875] trunk/Source/WebKit
Revision
244875
Author
[email protected]
Date
2019-05-02 10:38:07 -0700 (Thu, 02 May 2019)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (244874 => 244875)


--- trunk/Source/WebKit/ChangeLog	2019-05-02 17:35:23 UTC (rev 244874)
+++ trunk/Source/WebKit/ChangeLog	2019-05-02 17:38:07 UTC (rev 244875)
@@ -1,3 +1,26 @@
+2019-05-02  Alex Christensen  <[email protected]>
+
+        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.
+
 2019-05-02  Frederic Wang  <[email protected]>
 
         [GTK][WPE] Disable "thin", "thick", "medium" values of mfrac@linethickness at runtime

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h (244874 => 244875)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h	2019-05-02 17:35:23 UTC (rev 244874)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h	2019-05-02 17:38:07 UTC (rev 244875)
@@ -45,10 +45,25 @@
 #if PLATFORM(MAC)
 using ViewType = NSView;
 using RectType = NSRect;
-@interface WKSafeBrowsingWarning : NSView<NSTextViewDelegate>
+using ColorType = NSColor;
 #else
 using ViewType = UIView;
 using RectType = CGRect;
+using ColorType = UIColor;
+#endif
+
+@interface WKSafeBrowsingBox : ViewType {
+@package
+#if PLATFORM(MAC)
+    RetainPtr<ColorType> _backgroundColor;
+#endif
+}
+- (void)setSafeBrowsingBackgroundColor:(ColorType *)color;
+@end
+
+#if PLATFORM(MAC)
+@interface WKSafeBrowsingWarning : WKSafeBrowsingBox<NSTextViewDelegate>
+#else
 @interface WKSafeBrowsingWarning : UIScrollView<UITextViewDelegate>
 #endif
 {
@@ -56,7 +71,7 @@
     CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)> _completionHandler;
     RefPtr<const WebKit::SafeBrowsingWarning> _warning;
     WeakObjCPtr<WKSafeBrowsingTextView> _details;
-    WeakObjCPtr<ViewType> _box;
+    WeakObjCPtr<WKSafeBrowsingBox> _box;
 #if PLATFORM(WATCHOS)
     WeakObjCPtr<UIResponder> _previousFirstResponder;
 #endif

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm (244874 => 244875)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2019-05-02 17:35:23 UTC (rev 244874)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2019-05-02 17:38:07 UTC (rev 244875)
@@ -50,7 +50,6 @@
 #endif
 
 #if PLATFORM(MAC)
-using ColorType = NSColor;
 using FontType = NSFont;
 using TextViewType = NSTextView;
 using ButtonType = NSButton;
@@ -57,7 +56,6 @@
 using AlignmentType = NSLayoutAttribute;
 using SizeType = NSSize;
 #else
-using ColorType = UIColor;
 using FontType = UIFont;
 using TextViewType = UITextView;
 using ButtonType = UIButton;
@@ -200,6 +198,13 @@
     [exclamationPoint fill];
 }
 
+#if PLATFORM(MAC)
+- (void)viewDidChangeEffectiveAppearance
+{
+    [self setNeedsDisplay:YES];
+}
+#endif
+
 - (NSSize)intrinsicContentSize
 {
     return { exclamationPointSize, exclamationPointSize };
@@ -254,16 +259,27 @@
 #endif
 }
 
-static void setBackground(ViewType *view, ColorType *color)
+@implementation WKSafeBrowsingBox
+
+- (void)setSafeBrowsingBackgroundColor:(ColorType *)color
 {
 #if PLATFORM(MAC)
-    view.wantsLayer = YES;
-    view.layer.backgroundColor = color.CGColor;
+    _backgroundColor = color;
+    self.wantsLayer = YES;
 #else
-    view.backgroundColor = color;
+    self.backgroundColor = color;
 #endif
 }
 
+#if PLATFORM(MAC)
+- (void)updateLayer
+{
+    self.layer.backgroundColor = [_backgroundColor CGColor];
+}
+#endif
+
+@end
+
 @interface WKSafeBrowsingTextView : TextViewType {
 @package
     WeakObjCPtr<WKSafeBrowsingWarning> _warning;
@@ -287,9 +303,11 @@
         completionHandler(WTFMove(result));
     };
     _warning = makeRef(warning);
-    setBackground(self, colorForItem(WarningItem::Background, self));
 #if PLATFORM(MAC)
+    [self setSafeBrowsingBackgroundColor:colorForItem(WarningItem::Background, self)];
     [self addContent];
+#else
+    [self setBackgroundColor:colorForItem(WarningItem::Background, self)];
 #endif
 
 #if PLATFORM(WATCHOS)
@@ -317,9 +335,9 @@
     }] autorelease]);
     auto showDetails = makeButton(WarningItem::ShowDetailsButton, self, @selector(showDetailsClicked));
     auto goBack = makeButton(WarningItem::GoBackButton, self, @selector(goBackClicked));
-    auto box = [[ViewType new] autorelease];
+    auto box = [[WKSafeBrowsingBox new] autorelease];
     _box = box;
-    setBackground(box, colorForItem(WarningItem::BoxBackground, self));
+    [box setSafeBrowsingBackgroundColor:colorForItem(WarningItem::BoxBackground, self)];
     box.layer.cornerRadius = boxCornerRadius;
 
     for (ViewType *view in @[exclamationPoint, title, warning, goBack, showDetails]) {
@@ -392,7 +410,7 @@
 
 - (void)showDetailsClicked
 {
-    ViewType *box = _box.get().get();
+    WKSafeBrowsingBox *box = _box.get().get();
     ButtonType *showDetails = box.subviews.lastObject;
     [showDetails removeFromSuperview];
 
@@ -400,8 +418,8 @@
     [text addAttributes:@{ NSFontAttributeName:fontOfSize(WarningTextSize::Body) } range:NSMakeRange(0, text.length)];
     WKSafeBrowsingTextView *details = [[[WKSafeBrowsingTextView alloc] initWithAttributedString:text forWarning:self] autorelease];
     _details = details;
-    ViewType *bottom = [[ViewType new] autorelease];
-    setBackground(bottom, colorForItem(WarningItem::BoxBackground, self));
+    WKSafeBrowsingBox *bottom = [[WKSafeBrowsingBox new] autorelease];
+    [bottom setSafeBrowsingBackgroundColor:colorForItem(WarningItem::BoxBackground, self)];
     bottom.layer.cornerRadius = boxCornerRadius;
 
 #if HAVE(SAFE_BROWSING)
@@ -416,8 +434,8 @@
 #endif
 #endif
 
-    ViewType *line = [[ViewType new] autorelease];
-    setBackground(line, [ColorType lightGrayColor]);
+    WKSafeBrowsingBox *line = [[WKSafeBrowsingBox new] autorelease];
+    [line setSafeBrowsingBackgroundColor:[ColorType lightGrayColor]];
     for (ViewType *view in @[details, bottom, line])
         view.translatesAutoresizingMaskIntoConstraints = NO;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to