|
@@ -27,23 +27,36 @@ const WINDOW_DRAG_ATTR: &str = "data-webruntime-window-drag";
|
|
|
/// Lazily created shared profile; one store for every origin (WebKit partitions internally).
|
|
/// Lazily created shared profile; one store for every origin (WebKit partitions internally).
|
|
|
const APP_NETWORK_SESSION_KEY: &str = "webruntime-network-session";
|
|
const APP_NETWORK_SESSION_KEY: &str = "webruntime-network-session";
|
|
|
|
|
|
|
|
|
|
+/// JS bridge: on mousedown inside a `[data-webruntime-window-drag]` region, we
|
|
|
|
|
+/// wait one animation frame to let the page's own handlers call preventDefault().
|
|
|
|
|
+/// If the event was NOT prevented and no interactive element was the direct
|
|
|
|
|
+/// target, we fire the native drag message. A synthetic pointerup is dispatched
|
|
|
|
|
+/// first so WebKit's pointer state machine stays clean after begin_move steals
|
|
|
|
|
+/// the grab.
|
|
|
fn window_drag_bridge_source() -> String {
|
|
fn window_drag_bridge_source() -> String {
|
|
|
format!(
|
|
format!(
|
|
|
r#"(function () {{
|
|
r#"(function () {{
|
|
|
const attr = "{attr}";
|
|
const attr = "{attr}";
|
|
|
- document.addEventListener(
|
|
|
|
|
- "pointerdown",
|
|
|
|
|
- function (e) {{
|
|
|
|
|
- if (e.button !== 0) return;
|
|
|
|
|
- var el = e.target;
|
|
|
|
|
- if (!el || typeof el.closest !== "function") return;
|
|
|
|
|
- if (!el.closest("[" + attr + "]")) return;
|
|
|
|
|
|
|
+ const interactive = "A,BUTTON,INPUT,TEXTAREA,SELECT,LABEL,SUMMARY,DETAILS,AUDIO,VIDEO";
|
|
|
|
|
+ document.addEventListener("mousedown", function (e) {{
|
|
|
|
|
+ if (e.button !== 0) return;
|
|
|
|
|
+ var el = e.target;
|
|
|
|
|
+ if (!el || typeof el.closest !== "function") return;
|
|
|
|
|
+ if (!el.closest("[" + attr + "]")) return;
|
|
|
|
|
+ if (el.closest(interactive)) return;
|
|
|
|
|
+ if (el.isContentEditable) return;
|
|
|
|
|
+ var ev = e;
|
|
|
|
|
+ requestAnimationFrame(function () {{
|
|
|
|
|
+ if (ev.defaultPrevented) return;
|
|
|
|
|
+ try {{
|
|
|
|
|
+ el.dispatchEvent(new PointerEvent("pointerup", {{bubbles:true}}));
|
|
|
|
|
+ el.dispatchEvent(new MouseEvent("mouseup", {{bubbles:true}}));
|
|
|
|
|
+ }} catch(_) {{}}
|
|
|
try {{
|
|
try {{
|
|
|
window.webkit.messageHandlers.{handler}.postMessage(null);
|
|
window.webkit.messageHandlers.{handler}.postMessage(null);
|
|
|
- }} catch (ex) {{}}
|
|
|
|
|
- }},
|
|
|
|
|
- true
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ }} catch(_) {{}}
|
|
|
|
|
+ }});
|
|
|
|
|
+ }}, false);
|
|
|
}})();"#,
|
|
}})();"#,
|
|
|
attr = WINDOW_DRAG_ATTR,
|
|
attr = WINDOW_DRAG_ATTR,
|
|
|
handler = WINDOW_DRAG_MESSAGE_HANDLER,
|
|
handler = WINDOW_DRAG_MESSAGE_HANDLER,
|
|
@@ -51,7 +64,6 @@ fn window_drag_bridge_source() -> String {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Called when embedded JS reports a press on `[data-webruntime-window-drag]`.
|
|
/// Called when embedded JS reports a press on `[data-webruntime-window-drag]`.
|
|
|
-/// Uses the core pointer position so `begin_move` still matches an in-progress grab.
|
|
|
|
|
fn begin_move_from_pointer_on_window(window: &ApplicationWindow) {
|
|
fn begin_move_from_pointer_on_window(window: &ApplicationWindow) {
|
|
|
let Some(display) = gdk::Display::default() else {
|
|
let Some(display) = gdk::Display::default() else {
|
|
|
return;
|
|
return;
|