Create and use DetailWebViewControllerDelegate.

This commit is contained in:
Brent Simmons 2019-02-12 18:12:12 -08:00
parent 15d682e0ff
commit 2dfec50261
2 changed files with 15 additions and 16 deletions

View File

@ -153,15 +153,20 @@ extension DetailViewController: WKScriptMessageHandler {
mouseDidExit(link) mouseDidExit(link)
} }
} }
}
private func mouseDidEnter(_ link: String) { // MARK: DetailWebViewControllerDelegate
extension DetailViewController: DetailWebViewControllerDelegate {
func mouseDidEnter(_ link: String) {
guard !link.isEmpty else { guard !link.isEmpty else {
return return
} }
statusBarView.mouseoverLink = link statusBarView.mouseoverLink = link
} }
private func mouseDidExit(_ link: String) { func mouseDidExit(_ link: String) {
statusBarView.mouseoverLink = nil statusBarView.mouseoverLink = nil
} }
} }

View File

@ -17,8 +17,14 @@ enum DetailWebViewState: Equatable {
case article(Article) case article(Article)
} }
protocol DetailWebViewControllerDelegate: class {
func mouseDidEnter(_ link: String)
func mouseDidExit(_ link: String)
}
final class DetailWebViewController: NSViewController, WKUIDelegate { final class DetailWebViewController: NSViewController, WKUIDelegate {
weak var delegate: DetailWebViewControllerDelegate?
var webview: DetailWebView! var webview: DetailWebView!
var state: DetailWebViewState = .noSelection { var state: DetailWebViewState = .noSelection {
didSet { didSet {
@ -66,25 +72,13 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
extension DetailWebViewController: WKScriptMessageHandler { extension DetailWebViewController: WKScriptMessageHandler {
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == MessageName.mouseDidEnter, let link = message.body as? String { if message.name == MessageName.mouseDidEnter, let link = message.body as? String {
mouseDidEnter(link) delegate?.mouseDidEnter(link)
} }
else if message.name == MessageName.mouseDidExit, let link = message.body as? String{ else if message.name == MessageName.mouseDidExit, let link = message.body as? String{
mouseDidExit(link) delegate?.mouseDidExit(link)
} }
} }
private func mouseDidEnter(_ link: String) {
guard !link.isEmpty else {
return
}
// statusBarView.mouseoverLink = link
}
private func mouseDidExit(_ link: String) {
// statusBarView.mouseoverLink = nil
}
} }
// MARK: - WKNavigationDelegate // MARK: - WKNavigationDelegate