Safe browsing warning should respect text size from settings
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Dec 2018 01:55:52 +0000 (01:55 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Dec 2018 01:55:52 +0000 (01:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192205

Reviewed by Tim Horton.

* UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
(fontWithSize):
(makeButton):
(-[WKSafeBrowsingWarning addContent]):
(-[WKSafeBrowsingWarning showDetailsClicked]):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm

index 99bcac5..07d091f 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-08  Alex Christensen  <achristensen@webkit.org>
+
+        Safe browsing warning should respect text size from settings
+        https://bugs.webkit.org/show_bug.cgi?id=192205
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+        (fontWithSize):
+        (makeButton):
+        (-[WKSafeBrowsingWarning addContent]):
+        (-[WKSafeBrowsingWarning showDetailsClicked]):
+
 2018-12-08  Frederic Wang  <fwang@igalia.com>
 
         Allow control over child order when adding nodes to the scrolling tree
index 6095634..fe21bea 100644 (file)
@@ -34,7 +34,6 @@
 #import <wtf/Language.h>
 
 constexpr CGFloat exclamationPointSize = 30;
-constexpr CGFloat titleSize = 26;
 constexpr CGFloat boxCornerRadius = 6;
 #if HAVE(SAFE_BROWSING)
 constexpr CGFloat marginSize = 20;
@@ -42,7 +41,6 @@ constexpr CGFloat maxWidth = 675;
 #endif
 
 #if PLATFORM(MAC)
-constexpr CGFloat textSize = 14;
 using ColorType = NSColor;
 using FontType = NSFont;
 using TextViewType = NSTextView;
@@ -51,7 +49,6 @@ using AlignmentType = NSLayoutAttribute;
 using ViewType = NSView;
 using SizeType = NSSize;
 #else
-constexpr CGFloat textSize = 20;
 using ColorType = UIColor;
 using FontType = UIFont;
 using TextViewType = UITextView;
@@ -71,6 +68,30 @@ enum class WarningItem : uint8_t {
     GoBackButton
 };
 
+enum class WarningTextSize : uint8_t {
+    Title,
+    Body
+};
+
+static FontType *fontOfSize(WarningTextSize size)
+{
+#if PLATFORM(MAC)
+    switch (size) {
+    case WarningTextSize::Title:
+        return [NSFont boldSystemFontOfSize:26];
+    case WarningTextSize::Body:
+        return [NSFont systemFontOfSize:14];
+    }
+#else
+    switch (size) {
+    case WarningTextSize::Title:
+        return [UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle];
+    case WarningTextSize::Body:
+        return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
+    }
+#endif
+}
+
 static ColorType *colorForItem(WarningItem item, ViewType *warning)
 {
     ASSERT([warning isKindOfClass:[WKSafeBrowsingWarning class]]);
@@ -189,7 +210,7 @@ static ButtonType *makeButton(WarningItem item, WKSafeBrowsingWarning *warning,
         NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),
         NSUnderlineColorAttributeName:[UIColor whiteColor],
         NSForegroundColorAttributeName:colorForItem(item, warning),
-        NSFontAttributeName:[FontType systemFontOfSize:textSize]
+        NSFontAttributeName:fontOfSize(WarningTextSize::Body)
     }] autorelease];
     [button setAttributedTitle:attributedTitle forState:UIControlStateNormal];
     [button addTarget:warning action:action forControlEvents:UIControlEventTouchUpInside];
@@ -248,11 +269,11 @@ static void setBackground(ViewType *view, ColorType *color)
 {
     auto exclamationPoint = [[WKSafeBrowsingExclamationPoint new] autorelease];
     auto title = makeLabel([[[NSAttributedString alloc] initWithString:_warning->title() attributes:@{
-        NSFontAttributeName:[FontType boldSystemFontOfSize:titleSize],
+        NSFontAttributeName:fontOfSize(WarningTextSize::Title),
         NSForegroundColorAttributeName:colorForItem(WarningItem::TitleText, self)
     }] autorelease]);
     auto warning = makeLabel([[[NSAttributedString alloc] initWithString:_warning->warning() attributes:@{
-        NSFontAttributeName:[FontType systemFontOfSize:textSize],
+        NSFontAttributeName:fontOfSize(WarningTextSize::Body),
         NSForegroundColorAttributeName:colorForItem(WarningItem::MessageText, self)
     }] autorelease]);
     auto showDetails = makeButton(WarningItem::ShowDetailsButton, self, @selector(showDetailsClicked));
@@ -304,7 +325,7 @@ static void setBackground(ViewType *view, ColorType *color)
     [showDetails removeFromSuperview];
 
     NSMutableAttributedString *text = [[_warning->details() mutableCopy] autorelease];
-    [text addAttributes:@{ NSFontAttributeName:[FontType systemFontOfSize:textSize] } range:NSMakeRange(0, text.length)];
+    [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];