Title: [239044] trunk/Source/WebKit
Revision
239044
Author
[email protected]
Date
2018-12-10 12:56:52 -0800 (Mon, 10 Dec 2018)

Log Message

Safe browsing warning should layout buttons vertically in narrow WKWebViews
https://bugs.webkit.org/show_bug.cgi?id=192535
<rdar://problem/46308364>

Reviewed by Tim Horton.

They're usually next to each other, but in narrow WKWebViews they currently get clipped.
In order to make it more likely that both buttons are completely visible, put one above
the other if the WKWebView is too narrow to completely show both.  This also helps with
languages where the translations of "Go Back" or "Show Details" are rendered wider than English.

* UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
(buttonWidth):
(-[WKSafeBrowsingWarning addContent]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239043 => 239044)


--- trunk/Source/WebKit/ChangeLog	2018-12-10 20:46:29 UTC (rev 239043)
+++ trunk/Source/WebKit/ChangeLog	2018-12-10 20:56:52 UTC (rev 239044)
@@ -1,3 +1,20 @@
+2018-12-10  Alex Christensen  <[email protected]>
+
+        Safe browsing warning should layout buttons vertically in narrow WKWebViews
+        https://bugs.webkit.org/show_bug.cgi?id=192535
+        <rdar://problem/46308364>
+
+        Reviewed by Tim Horton.
+
+        They're usually next to each other, but in narrow WKWebViews they currently get clipped.
+        In order to make it more likely that both buttons are completely visible, put one above
+        the other if the WKWebView is too narrow to completely show both.  This also helps with
+        languages where the translations of "Go Back" or "Show Details" are rendered wider than English.
+
+        * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+        (buttonWidth):
+        (-[WKSafeBrowsingWarning addContent]):
+
 2018-12-10  Simon Fraser  <[email protected]>
 
         Allow control over child order when adding nodes to the scrolling tree

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm (239043 => 239044)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2018-12-10 20:46:29 UTC (rev 239043)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm	2018-12-10 20:56:52 UTC (rev 239044)
@@ -217,6 +217,17 @@
 #endif
 }
 
+#if HAVE(SAFE_BROWSING)
+static CGFloat buttonWidth(ButtonType *button)
+{
+#if PLATFORM(MAC)
+    return button.frame.size.width;
+#else
+    return button.titleLabel.intrinsicContentSize.width;
+#endif
+}
+#endif
+
 static ViewType *makeLabel(NSAttributedString *attributedString)
 {
 #if PLATFORM(MAC)
@@ -306,14 +317,25 @@
 
         [[title.topAnchor anchorWithOffsetToAnchor:exclamationPoint.topAnchor] constraintEqualToAnchor:[exclamationPoint.bottomAnchor anchorWithOffsetToAnchor:title.bottomAnchor]],
 
-        [goBack.topAnchor constraintEqualToAnchor:showDetails.topAnchor],
-        [[showDetails.trailingAnchor anchorWithOffsetToAnchor:goBack.leadingAnchor] constraintEqualToConstant:marginSize],
-
         [[box.topAnchor anchorWithOffsetToAnchor:title.topAnchor] constraintEqualToConstant:marginSize],
         [[title.bottomAnchor anchorWithOffsetToAnchor:warning.topAnchor] constraintEqualToConstant:marginSize],
         [[warning.bottomAnchor anchorWithOffsetToAnchor:goBack.topAnchor] constraintEqualToConstant:marginSize],
-        [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize]
     ]];
+    
+    bool needsVerticalButtonLayout = buttonWidth(showDetails) + buttonWidth(goBack) + 3 * marginSize > self.frame.size.width;
+    if (needsVerticalButtonLayout) {
+        [NSLayoutConstraint activateConstraints:@[
+            [[showDetails.trailingAnchor anchorWithOffsetToAnchor:box.trailingAnchor] constraintEqualToConstant:marginSize],
+            [[goBack.bottomAnchor anchorWithOffsetToAnchor:showDetails.topAnchor] constraintEqualToConstant:marginSize],
+            [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize * 2 + showDetails.frame.size.height],
+        ]];
+    } else {
+        [NSLayoutConstraint activateConstraints:@[
+            [[showDetails.trailingAnchor anchorWithOffsetToAnchor:goBack.leadingAnchor] constraintEqualToConstant:marginSize],
+            [goBack.topAnchor constraintEqualToAnchor:showDetails.topAnchor],
+            [[goBack.bottomAnchor anchorWithOffsetToAnchor:box.bottomAnchor] constraintEqualToConstant:marginSize],
+        ]];
+    }
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to