Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
89 lines
3.5 KiB
Swift
89 lines
3.5 KiB
Swift
import Cocoa
|
|
import FlutterMacOS
|
|
|
|
// The harness exercises a window without initializing plugins or showing it.
|
|
final class HiddenTestWindow: CutdexNativeWindow {
|
|
var emptyDrags = 0
|
|
override var isKeyWindow: Bool { true }
|
|
override func performDrag(with event: NSEvent) {
|
|
if isMovable {
|
|
emptyDrags += 1
|
|
return // Observe the explicit native drag entry without a blocking tracking loop.
|
|
}
|
|
super.performDrag(with: event)
|
|
}
|
|
override func makeKeyAndOrderFront(_ sender: Any?) {}
|
|
}
|
|
|
|
final class BubblingControlView: NSView {
|
|
var downs = 0
|
|
var drags = 0
|
|
var ups = 0
|
|
override func mouseDown(with event: NSEvent) {
|
|
downs += 1
|
|
precondition(window?.isMovable == false)
|
|
// Exercise responder fallback and direct native actions during the gesture.
|
|
window?.mouseDown(with: event)
|
|
window?.performZoom(nil)
|
|
window?.zoom(nil)
|
|
window?.performDrag(with: event)
|
|
}
|
|
override func mouseDragged(with event: NSEvent) {
|
|
drags += 1
|
|
precondition(window?.isMovable == false)
|
|
window?.mouseDragged(with: event)
|
|
window?.performDrag(with: event)
|
|
}
|
|
override func mouseUp(with event: NSEvent) {
|
|
ups += 1
|
|
precondition(window?.isMovable == false)
|
|
window?.mouseUp(with: event)
|
|
}
|
|
}
|
|
|
|
@main
|
|
struct HeaderGestureTest {
|
|
static func main() {
|
|
_ = NSApplication.shared
|
|
let window = HiddenTestWindow(contentRect: NSRect(x: 100, y: 100, width: 640, height: 480),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
|
|
let control = BubblingControlView(frame: NSRect(x: 0, y: 0, width: 640, height: 480))
|
|
let controller = NSViewController()
|
|
controller.view = control
|
|
window.contentViewController = controller
|
|
window.isMovable = true
|
|
window.isMovableByWindowBackground = true
|
|
window.configureChrome(true)
|
|
window.headerControlRegions["control"] = NSRect(x: 88, y: 0, width: 140, height: 40)
|
|
precondition(!window.isMovable && !window.isMovableByWindowBackground)
|
|
let original = window.frame
|
|
func event(_ type: NSEvent.EventType, x: CGFloat, top: CGFloat, clicks: Int = 1) -> NSEvent {
|
|
let view = window.contentView!
|
|
let p = NSPoint(x: x, y: view.isFlipped ? top : view.bounds.height - top)
|
|
return NSEvent.mouseEvent(with: type, location: view.convert(p, to: nil),
|
|
modifierFlags: [], timestamp: ProcessInfo.processInfo.systemUptime,
|
|
windowNumber: window.windowNumber, context: nil, eventNumber: 0,
|
|
clickCount: clicks, pressure: 1)!
|
|
}
|
|
window.sendEvent(event(.leftMouseDown, x: 110, top: 20))
|
|
// A route change caused by the press must not release native protection.
|
|
window.configureChrome(true)
|
|
window.sendEvent(event(.leftMouseDragged, x: 400, top: 150))
|
|
window.sendEvent(event(.leftMouseUp, x: 400, top: 150))
|
|
precondition(!window.isMovable)
|
|
precondition(window.frame == original)
|
|
window.sendEvent(event(.leftMouseDown, x: 110, top: 20, clicks: 2))
|
|
window.sendEvent(event(.leftMouseUp, x: 110, top: 20, clicks: 2))
|
|
precondition(!window.isMovable)
|
|
precondition(window.frame == original)
|
|
precondition(control.downs == 2 && control.drags == 1 && control.ups == 2)
|
|
precondition(window.emptyDrags == 0)
|
|
window.sendEvent(event(.leftMouseDown, x: 400, top: 20))
|
|
precondition(window.emptyDrags == 1)
|
|
precondition(!window.isMovable)
|
|
window.configureChrome(false)
|
|
precondition(window.isMovable && window.isMovableByWindowBackground)
|
|
print("Native header control gestures passed")
|
|
}
|
|
}
|