Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Documentation/Plan.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# WebKit — Plan

**Status:** a draft for review. Phases 2 to 4, URL schemes and replies
to script messages in `WPEWebKit` and `CacaoWebKit`'s API, are merged (#3,
#4, #5). Phase 1 is implemented: `WebView(content:)` here, on
`feature/web-view-content`, and LinuxAppRuntime over this package on its
`feature/pureswift-webkit`. Phase 5 is what's left.
**Status:** a draft for review. Phases 1 to 4 are merged: URL schemes
and replies to script messages in `WPEWebKit` (#3, #4), `CacaoWebKit`'s API
(#5), and LinuxAppRuntime on this package, with `WebView(content:)` here
(#7, PureSwift/LinuxAppRuntime#20). Phase 5 is what's left.

This package has WPE WebKit pages drawn into Cacao's external surfaces
(`WPEWebKit`) and SwiftUI's `WebView` and `WebPage` on Cacao
Expand Down Expand Up @@ -272,7 +271,10 @@ func stopURLSchemeTask(_ content: WebContent, task: Int32)
drag gesture. Done when `ExampleWeb` runs as before under
`Scripts/run-app.sh`, and scrolls with the wheel. `CacaoWebKit` needs
`WebView(content:)`, or `WebPage(content:)`, for a page it didn't make.
Implemented: `WebView(content:)` shows a `WPEWebContent` a host made,
Done: `ExampleWeb` runs in `linux-app-host` as before, loading
swift.org through the guest's `WebPage`, and a wheel notch through
Cacao's view graph scrolls a `WebView(content:)` page by the notch and
back (`WebViewTests`). `WebView(content:)` shows a `WPEWebContent` a host made,
attached while on screen, with the view's input; the page's delegate
stays the host's, so `WebPage(content:)`, which would need it, isn't
needed. A host that set `WPEEngine.onReady` runs the engine's loop, and
Expand Down
27 changes: 27 additions & 0 deletions Tests/CacaoWebKitTests/WebViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,31 @@ struct WebViewTests {
try wait(for: "the script") { host.scripts[1] != nil }
#expect(host.scripts[1] == #""Clicked""#)
}

@Test func scrollsThePageWithTheWheel() throws {
let host = Host()
let content = try #require(WPEWebContent(delegate: host))
content.loadHTML("<body style='margin: 0'><div style='height: 5000px'></div>", baseURL: nil)
try wait(for: "the load") { host.finished }
let graph = ViewGraph(rootView: Root(content: content, shown: true))
graph.layout(in: CGSize(width: 200, height: 100))
_ = graph.displayList()
try wait(for: "a frame") { content.surface.pixelSize == CGSize(width: 200, height: 100) }

var request: Int32 = 0
func scrollY() -> String? {
request += 1
let asked = request
content.evaluateJavaScript("window.scrollY", request: asked)
_ = WPEEngine.dispatch(for: 5) { host.scripts[asked] != nil }
return host.scripts[asked] ?? nil
}
#expect(scrollY() == "0")
let point = CGPoint(x: 100, y: 50)
// A notch toward the user moves down the page by one notch's points.
#expect(graph.externalScroll(x: 0, y: -1, at: point))
try wait(for: "the scroll down") { scrollY() == "\(Int(WebInput.notch))" }
#expect(graph.externalScroll(x: 0, y: 1, at: point))
try wait(for: "the scroll back") { scrollY() == "0" }
}
}