mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Change to use JavaScript to detect scroll events as it will also capture scrollbar events
This commit is contained in:
parent
2c801a388c
commit
de956f9473
@ -10,13 +10,8 @@ import AppKit
|
||||
import WebKit
|
||||
import RSCore
|
||||
|
||||
protocol DetailWebViewDelegate: AnyObject {
|
||||
func didScroll(_ : DetailWebView)
|
||||
}
|
||||
|
||||
final class DetailWebView: WKWebView {
|
||||
|
||||
weak var detailDelegate: DetailWebViewDelegate?
|
||||
weak var keyboardDelegate: KeyboardDelegate?
|
||||
|
||||
override func accessibilityLabel() -> String? {
|
||||
@ -67,11 +62,6 @@ final class DetailWebView: WKWebView {
|
||||
bigSurOffsetFix()
|
||||
}
|
||||
}
|
||||
|
||||
override func scrollWheel(with event: NSEvent) {
|
||||
super.scrollWheel(with: event)
|
||||
detailDelegate?.didScroll(self)
|
||||
}
|
||||
|
||||
private var inBigSurOffsetFix = false
|
||||
|
||||
|
@ -62,7 +62,6 @@ final class DetailWebViewController: NSViewController {
|
||||
private let detailIconSchemeHandler = DetailIconSchemeHandler()
|
||||
private var waitingForFirstReload = false
|
||||
private let keyboardDelegate = DetailKeyboardDelegate()
|
||||
private let scrollPositionQueue = CoalescingQueue(name: "Article Scroll Position", interval: 0.3, maxInterval: 0.3)
|
||||
private var windowScrollY: CGFloat?
|
||||
|
||||
private var isShowingExtractedArticle: Bool {
|
||||
@ -77,6 +76,7 @@ final class DetailWebViewController: NSViewController {
|
||||
private struct MessageName {
|
||||
static let mouseDidEnter = "mouseDidEnter"
|
||||
static let mouseDidExit = "mouseDidExit"
|
||||
static let windowDidScroll = "windowDidScroll"
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
@ -90,6 +90,7 @@ final class DetailWebViewController: NSViewController {
|
||||
configuration.setURLSchemeHandler(detailIconSchemeHandler, forURLScheme: ArticleRenderer.imageIconScheme)
|
||||
|
||||
let userContentController = WKUserContentController()
|
||||
userContentController.add(self, name: MessageName.windowDidScroll)
|
||||
userContentController.add(self, name: MessageName.mouseDidEnter)
|
||||
userContentController.add(self, name: MessageName.mouseDidExit)
|
||||
configuration.userContentController = userContentController
|
||||
@ -97,7 +98,6 @@ final class DetailWebViewController: NSViewController {
|
||||
webView = DetailWebView(frame: NSRect.zero, configuration: configuration)
|
||||
webView.uiDelegate = self
|
||||
webView.navigationDelegate = self
|
||||
webView.detailDelegate = self
|
||||
webView.keyboardDelegate = keyboardDelegate
|
||||
webView.translatesAutoresizingMaskIntoConstraints = false
|
||||
if let userAgent = UserAgent.fromInfoPlist() {
|
||||
@ -204,32 +204,16 @@ final class DetailWebViewController: NSViewController {
|
||||
|
||||
}
|
||||
|
||||
// MARK: DetailWebViewDelegate
|
||||
|
||||
extension DetailWebViewController: DetailWebViewDelegate {
|
||||
|
||||
func didScroll(_: DetailWebView) {
|
||||
|
||||
scrollPositionQueue.add(self, #selector(scrollPositionDidChange))
|
||||
}
|
||||
|
||||
@objc func scrollPositionDidChange() {
|
||||
fetchScrollInfo() { scrollInfo in
|
||||
self.windowScrollY = scrollInfo?.offsetY
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - WKScriptMessageHandler
|
||||
|
||||
extension DetailWebViewController: WKScriptMessageHandler {
|
||||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == MessageName.mouseDidEnter, let link = message.body as? String {
|
||||
if message.name == MessageName.windowDidScroll {
|
||||
windowScrollY = message.body as? CGFloat
|
||||
} else if message.name == MessageName.mouseDidEnter, let link = message.body as? String {
|
||||
delegate?.mouseDidEnter(self, link: link)
|
||||
}
|
||||
else if message.name == MessageName.mouseDidExit {
|
||||
} else if message.name == MessageName.mouseDidExit {
|
||||
delegate?.mouseDidExit(self)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
// Add the mouse listeners for the above functions
|
||||
function scrollDetection() {
|
||||
window.onscroll = function(event) {
|
||||
window.webkit.messageHandlers.windowDidScroll.postMessage(window.scrollY);
|
||||
}
|
||||
}
|
||||
|
||||
function linkHover() {
|
||||
window.onmouseover = function(event) {
|
||||
var closestAnchor = event.target.closest('a')
|
||||
@ -15,5 +20,6 @@ function linkHover() {
|
||||
}
|
||||
|
||||
function postRenderProcessing() {
|
||||
linkHover()
|
||||
scrollDetection();
|
||||
linkHover();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user