Some fixes for macOS
This commit is contained in:
@@ -18,18 +18,16 @@ class ScriptPolicyControl: UIControl
|
||||
didSet { setNeedsLayout() }
|
||||
}
|
||||
|
||||
private class PolicyButton: UIButton {
|
||||
override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
|
||||
contentRect.insetBy(dx: 8.0, dy: 8.0)
|
||||
}
|
||||
}
|
||||
|
||||
private let allowButton = PolicyButton(frame: .zero)
|
||||
private let denyButton = PolicyButton(frame: .zero)
|
||||
private let allowButton = ReliefButton()
|
||||
private let denyButton = ReliefButton()
|
||||
private let segmentContainer = SegmentedReliefButton(children: [])
|
||||
|
||||
convenience init() {
|
||||
self.init(frame: .zero)
|
||||
|
||||
segmentContainer.children = [ allowButton, denyButton ]
|
||||
addSubview(segmentContainer)
|
||||
|
||||
allowButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
self.policyStatus = .allowed
|
||||
self.sendActions(for: .valueChanged)
|
||||
@@ -52,8 +50,7 @@ class ScriptPolicyControl: UIControl
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
allowButton.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width / 2, height: bounds.height))
|
||||
denyButton.frame = CGRect(origin: CGPoint(x: allowButton.frame.maxX, y: 0), size: allowButton.frame.size)
|
||||
segmentContainer.frame = bounds
|
||||
|
||||
if policyStatus == .allowed {
|
||||
allowButton.tintColor = .blue
|
||||
|
||||
@@ -34,7 +34,13 @@ class ScriptPolicyControlListCell: UICollectionViewListCell
|
||||
|
||||
override func layoutSubviews() {
|
||||
let policyControlWidth = CGFloat(80.0)
|
||||
policyControl.frame = CGRect(x: bounds.maxX - policyControlWidth - layoutMargins.right, y: 0, width: policyControlWidth, height: bounds.height)
|
||||
policyControl.frame = CGRect(
|
||||
x: bounds.maxX - policyControlWidth - layoutMargins.right,
|
||||
y: 0,
|
||||
width: policyControlWidth,
|
||||
height: bounds.height * 0.75
|
||||
)
|
||||
policyControl.frame = policyControl.frame.centeredY(inRect: bounds)
|
||||
bringSubviewToFront(policyControl)
|
||||
|
||||
super.layoutSubviews()
|
||||
@@ -68,7 +74,8 @@ class SwitchListCell: UICollectionViewListCell
|
||||
super.layoutSubviews()
|
||||
|
||||
let switchWidth: CGFloat = switchView.sizeThatFits(bounds.size).width
|
||||
switchView.frame = CGRect(x: bounds.maxX - switchWidth - layoutMargins.right, y: 0, width: switchWidth, height: bounds.height)
|
||||
switchView.frame = CGRect(x: bounds.maxX - switchWidth - layoutMargins.right, y: 0,
|
||||
width: switchWidth, height: bounds.height * 0.85)
|
||||
switchView.frame = switchView.frame.centeredY(inRect: bounds)
|
||||
contentView.frame = CGRect(origin: contentView.frame.origin, size: CGSize(width: switchView.frame.minX, height: contentView.frame.height))
|
||||
}
|
||||
@@ -88,6 +95,19 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
case origins
|
||||
}
|
||||
|
||||
override var traitCollection: UITraitCollection {
|
||||
get {
|
||||
let actualTraits = super.traitCollection
|
||||
if actualTraits.userInterfaceIdiom == .mac {
|
||||
// Override traits to be iPad like on mac. We dont want small list cells here.
|
||||
let desiredTraits = UITraitCollection(userInterfaceIdiom: .pad)
|
||||
return UITraitCollection(traitsFrom: [ actualTraits, desiredTraits ])
|
||||
}
|
||||
|
||||
return actualTraits
|
||||
}
|
||||
}
|
||||
|
||||
private static let enableScriptsForTabItem: String = "enableScriptsForTab"
|
||||
|
||||
convenience init(policyManager: ResourcePolicyManager, hostOrigin: String, loadedScripts: Set<String>, scriptsAllowedForTab: Bool) {
|
||||
@@ -98,13 +118,11 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
let listLayout = UICollectionViewCompositionalLayout.list(using: listConfig)
|
||||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: listLayout)
|
||||
|
||||
// Allowed scripts go to the top
|
||||
let allowedScripts = loadedScripts.filter { policyManager.allowedOriginsForScriptResources().contains($0) }
|
||||
|
||||
// Make sure host origin goes first in the list.
|
||||
let otherOriginScripts = loadedScripts.subtracting([ hostOrigin ]).subtracting(allowedScripts)
|
||||
let otherOriginScripts = loadedScripts.subtracting([ hostOrigin ])
|
||||
let allowedScripts = otherOriginScripts.filter { policyManager.allowedOriginsForScriptResources().contains($0) }
|
||||
|
||||
let originItems = [ hostOrigin ] + allowedScripts + otherOriginScripts
|
||||
let originItems = [ hostOrigin ] + allowedScripts + otherOriginScripts.subtracting(allowedScripts)
|
||||
|
||||
let switchCellRegistry = UICollectionView.CellRegistration<SwitchListCell, String> { [unowned self] (listCell, indexPath, item) in
|
||||
var config = listCell.defaultContentConfiguration()
|
||||
|
||||
Reference in New Issue
Block a user