Some more interesting visual state with script button
This commit is contained in:
@@ -194,12 +194,20 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
|
||||
private func updateScriptBlockerButton() {
|
||||
var numBlockedScripts: Int = tab.blockedScriptOrigins.count
|
||||
if tab.javaScriptEnabled == false {
|
||||
if tab.url != nil, tab.javaScriptEnabled == false {
|
||||
// Because the page is blocked too, notify.
|
||||
numBlockedScripts += 1
|
||||
}
|
||||
|
||||
toolbarController.scriptControllerIconView.setBlockedScriptsNumber(numBlockedScripts)
|
||||
var scriptsAllowedForHost = false
|
||||
if let url = webView.url, let host = url.host, policyManager.allowedOriginsForScriptResources().contains(host) {
|
||||
scriptsAllowedForHost = true
|
||||
}
|
||||
|
||||
let iconView = toolbarController.scriptControllerIconView
|
||||
iconView.shieldsDown = tab.javaScriptEnabled
|
||||
iconView.someScriptsAllowed = scriptsAllowedForHost
|
||||
iconView.setBlockedScriptsNumber(numBlockedScripts)
|
||||
}
|
||||
|
||||
// MARK: UIPopoverPresentationControllerDelegate
|
||||
@@ -292,5 +300,6 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
|
||||
func setScriptsEnabledForTab(_ enabled: Bool) {
|
||||
tab.javaScriptEnabled = enabled
|
||||
toolbarController.scriptControllerIconView.shieldsDown = enabled
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,25 @@ import UIKit
|
||||
|
||||
class ScriptControllerIconView: UIButton
|
||||
{
|
||||
public var shieldsDown: Bool = false {
|
||||
didSet { setNeedsLayout() }
|
||||
}
|
||||
|
||||
public var someScriptsAllowed: Bool = false {
|
||||
didSet { setNeedsLayout() }
|
||||
}
|
||||
|
||||
private let labelView = UILabel(frame: .zero)
|
||||
|
||||
private let shieldsDownImage = UIImage(systemName: "shield.slash")
|
||||
private let shieldsUpImage = UIImage(systemName: "shield")
|
||||
private let shieldsPartiallyUpImage = UIImage(systemName: "shield.lefthalf.fill")
|
||||
|
||||
convenience init() {
|
||||
self.init(frame: .zero)
|
||||
|
||||
addSubview(labelView)
|
||||
|
||||
let image = UIImage(systemName: "shield")
|
||||
setImage(image, for: .normal)
|
||||
|
||||
imageView?.contentMode = .scaleAspectFit
|
||||
labelView.backgroundColor = .systemRed
|
||||
labelView.textAlignment = .center
|
||||
@@ -47,5 +56,15 @@ class ScriptControllerIconView: UIButton
|
||||
labelView.sizeToFit()
|
||||
labelView.center = CGPoint(x: bounds.center.x + 10, y: bounds.center.y + 10)
|
||||
labelView.bounds = labelView.bounds.insetBy(dx: -3.0, dy: -2.0)
|
||||
|
||||
if shieldsDown {
|
||||
setImage(shieldsDownImage, for: .normal)
|
||||
} else {
|
||||
if someScriptsAllowed {
|
||||
setImage(shieldsPartiallyUpImage, for: .normal)
|
||||
} else {
|
||||
setImage(shieldsUpImage, for: .normal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user