mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Ladybird: Reformat AppKit UI Swift files
This commit is contained in:
parent
1bf4a225bd
commit
cb7402bc69
Notes:
github-actions[bot]
2024-07-31 00:39:26 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/cb7402bc695 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/821
2 changed files with 68 additions and 70 deletions
|
@ -12,53 +12,51 @@ import SwiftUI
|
||||||
|
|
||||||
public class TaskManager: NSWindow {
|
public class TaskManager: NSWindow {
|
||||||
|
|
||||||
private let WINDOW_WIDTH: CGFloat = 600
|
private let WINDOW_WIDTH: CGFloat = 600
|
||||||
private let WINDOW_HEIGHT: CGFloat = 400
|
private let WINDOW_HEIGHT: CGFloat = 400
|
||||||
|
|
||||||
var web_view: LadybirdWebView
|
var web_view: LadybirdWebView
|
||||||
private var timer: Timer?
|
private var timer: Timer?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let tab_rect = NSApplication.shared.keyWindow!.frame
|
let tab_rect = NSApplication.shared.keyWindow!.frame
|
||||||
let position_x = tab_rect.origin.x + (tab_rect.size.width - WINDOW_WIDTH) / 2
|
let position_x = tab_rect.origin.x + (tab_rect.size.width - WINDOW_WIDTH) / 2
|
||||||
let position_y = tab_rect.origin.y + (tab_rect.size.height - WINDOW_HEIGHT) / 2
|
let position_y = tab_rect.origin.y + (tab_rect.size.height - WINDOW_HEIGHT) / 2
|
||||||
|
|
||||||
let window_rect = NSMakeRect(position_x, position_y, WINDOW_WIDTH, WINDOW_HEIGHT)
|
let window_rect = NSMakeRect(position_x, position_y, WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||||
let style_mask = NSWindow.StyleMask.init(arrayLiteral: [
|
let style_mask = NSWindow.StyleMask.init(arrayLiteral: [
|
||||||
NSWindow.StyleMask.titled, NSWindow.StyleMask.closable, NSWindow.StyleMask.miniaturizable,
|
NSWindow.StyleMask.titled, NSWindow.StyleMask.closable, NSWindow.StyleMask.miniaturizable,
|
||||||
NSWindow.StyleMask.resizable,
|
NSWindow.StyleMask.resizable,
|
||||||
])
|
])
|
||||||
|
|
||||||
self.web_view = LadybirdWebView.init(nil)
|
self.web_view = LadybirdWebView.init(nil)
|
||||||
|
|
||||||
super.init(
|
super.init(contentRect: window_rect, styleMask: style_mask, backing: NSWindow.BackingStoreType.buffered, defer: false)
|
||||||
contentRect: window_rect, styleMask: style_mask, backing: NSWindow.BackingStoreType.buffered,
|
|
||||||
defer: false)
|
|
||||||
|
|
||||||
self.timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] timer in
|
self.timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] timer in
|
||||||
if let strong_self = self {
|
if let strong_self = self {
|
||||||
strong_self.updateStatistics()
|
strong_self.updateStatistics()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.web_view.postsBoundsChangedNotifications = true
|
||||||
|
let scroll_view = NSScrollView()
|
||||||
|
scroll_view.hasVerticalScroller = true
|
||||||
|
scroll_view.hasHorizontalScroller = true
|
||||||
|
scroll_view.lineScroll = 24
|
||||||
|
|
||||||
|
scroll_view.contentView = self.web_view
|
||||||
|
scroll_view.documentView = NSView()
|
||||||
|
|
||||||
|
self.contentView = scroll_view
|
||||||
|
self.title = "Task Manager"
|
||||||
|
self.setIsVisible(true)
|
||||||
|
|
||||||
|
self.updateStatistics()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.web_view.postsBoundsChangedNotifications = true
|
func updateStatistics() {
|
||||||
let scroll_view = NSScrollView()
|
WebView.Application.the().update_process_statistics()
|
||||||
scroll_view.hasVerticalScroller = true
|
self.web_view.loadHTML(WebView.Application.the().generate_process_statistics_html().__bytes_as_string_viewUnsafe())
|
||||||
scroll_view.hasHorizontalScroller = true
|
}
|
||||||
scroll_view.lineScroll = 24
|
|
||||||
|
|
||||||
scroll_view.contentView = self.web_view
|
|
||||||
scroll_view.documentView = NSView()
|
|
||||||
|
|
||||||
self.contentView = scroll_view
|
|
||||||
self.title = "Task Manager"
|
|
||||||
self.setIsVisible(true)
|
|
||||||
|
|
||||||
self.updateStatistics()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateStatistics() {
|
|
||||||
WebView.Application.the().update_process_statistics();
|
|
||||||
self.web_view.loadHTML(WebView.Application.the().generate_process_statistics_html().__bytes_as_string_viewUnsafe());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,41 +10,41 @@ import SwiftUI
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public protocol TaskManagerDelegate where Self: NSObject {
|
public protocol TaskManagerDelegate where Self: NSObject {
|
||||||
func onTaskManagerClosed()
|
func onTaskManagerClosed()
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TaskManagerController: NSWindowController, NSWindowDelegate {
|
public class TaskManagerController: NSWindowController, NSWindowDelegate {
|
||||||
|
|
||||||
private weak var delegate: TaskManagerDelegate?
|
private weak var delegate: TaskManagerDelegate?
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
public convenience init(delegate: TaskManagerDelegate) {
|
public convenience init(delegate: TaskManagerDelegate) {
|
||||||
self.init()
|
self.init()
|
||||||
self.delegate = delegate
|
self.delegate = delegate
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction public override func showWindow(_ sender: Any?) {
|
|
||||||
self.window = TaskManager.init()
|
|
||||||
self.window!.delegate = self
|
|
||||||
self.window!.makeKeyAndOrderFront(sender)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func windowWillClose(_ sender: Notification) {
|
|
||||||
self.delegate?.onTaskManagerClosed()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func windowDidResize(_ sender: Notification) {
|
|
||||||
guard self.window != nil else { return }
|
|
||||||
if !self.window!.inLiveResize {
|
|
||||||
self.taskManager().web_view.handleResize()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func windowDidChangeBackingProperties(_ sender: Notification) {
|
@IBAction public override func showWindow(_ sender: Any?) {
|
||||||
self.taskManager().web_view.handleDevicePixelRatioChange()
|
self.window = TaskManager.init()
|
||||||
}
|
self.window!.delegate = self
|
||||||
|
self.window!.makeKeyAndOrderFront(sender)
|
||||||
|
}
|
||||||
|
|
||||||
private func taskManager() -> TaskManager {
|
public func windowWillClose(_ sender: Notification) {
|
||||||
return self.window as! TaskManager
|
self.delegate?.onTaskManagerClosed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func windowDidResize(_ sender: Notification) {
|
||||||
|
guard self.window != nil else { return }
|
||||||
|
if !self.window!.inLiveResize {
|
||||||
|
self.taskManager().web_view.handleResize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func windowDidChangeBackingProperties(_ sender: Notification) {
|
||||||
|
self.taskManager().web_view.handleDevicePixelRatioChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func taskManager() -> TaskManager {
|
||||||
|
return self.window as! TaskManager
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue