From 6fcf2d425b60a499eb65bc7b6ab51bc46057fafb Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 18 Jun 2024 20:53:06 +0200 Subject: [PATCH 1/3] Update and stabilize widely supported parts of the Clipboard API --- CHANGELOG.md | 3 + crates/web-sys/Cargo.toml | 1 - crates/web-sys/src/features/gen_Clipboard.rs | 20 ------ .../web-sys/src/features/gen_ClipboardItem.rs | 38 ------------ .../src/features/gen_ClipboardItemOptions.rs | 13 ---- .../gen_ClipboardPermissionDescriptor.rs | 61 ------------------- crates/web-sys/src/features/gen_Navigator.rs | 20 +++--- .../src/features/gen_PresentationStyle.rs | 4 -- crates/web-sys/src/features/mod.rs | 7 --- .../web-sys/webidls/enabled/Clipboard.webidl | 55 +++++++++++++++++ .../web-sys/webidls/unstable/Clipboard.webidl | 51 ---------------- 11 files changed, 66 insertions(+), 207 deletions(-) delete mode 100644 crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs create mode 100644 crates/web-sys/webidls/enabled/Clipboard.webidl delete mode 100644 crates/web-sys/webidls/unstable/Clipboard.webidl diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c2ef677d7..4c59469e620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,9 @@ * Annotated methods in WebCodecs that throw. [#3970](https://github.com/rustwasm/wasm-bindgen/pull/3970) +* Update and stabilize widely supported parts of the Clipboard API. + [#3992](https://github.com/rustwasm/wasm-bindgen/pull/3992) + ### Fixed * Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`. diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index edb9ff187f0..bf19273f473 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -193,7 +193,6 @@ ClipboardEvent = ["Event"] ClipboardEventInit = [] ClipboardItem = [] ClipboardItemOptions = [] -ClipboardPermissionDescriptor = [] CloseEvent = ["Event"] CloseEventInit = [] CodecState = [] diff --git a/crates/web-sys/src/features/gen_Clipboard.rs b/crates/web-sys/src/features/gen_Clipboard.rs index 66c456dda80..3c997ccdeb4 100644 --- a/crates/web-sys/src/features/gen_Clipboard.rs +++ b/crates/web-sys/src/features/gen_Clipboard.rs @@ -2,7 +2,6 @@ #![allow(clippy::all)] use super::*; use wasm_bindgen::prelude::*; -#[cfg(web_sys_unstable_apis)] #[wasm_bindgen] extern "C" { # [wasm_bindgen (extends = EventTarget , extends = :: js_sys :: Object , js_name = Clipboard , typescript_type = "Clipboard")] @@ -12,52 +11,33 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub type Clipboard; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = read)] #[doc = "The `read()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn read(this: &Clipboard) -> ::js_sys::Promise; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = readText)] #[doc = "The `readText()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/readText)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn read_text(this: &Clipboard) -> ::js_sys::Promise; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = write)] #[doc = "The `write()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn write(this: &Clipboard, data: &::wasm_bindgen::JsValue) -> ::js_sys::Promise; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = writeText)] #[doc = "The `writeText()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn write_text(this: &Clipboard, data: &str) -> ::js_sys::Promise; } diff --git a/crates/web-sys/src/features/gen_ClipboardItem.rs b/crates/web-sys/src/features/gen_ClipboardItem.rs index 435f1a474b3..db2715a32b7 100644 --- a/crates/web-sys/src/features/gen_ClipboardItem.rs +++ b/crates/web-sys/src/features/gen_ClipboardItem.rs @@ -2,7 +2,6 @@ #![allow(clippy::all)] use super::*; use wasm_bindgen::prelude::*; -#[cfg(web_sys_unstable_apis)] #[wasm_bindgen] extern "C" { # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardItem , typescript_type = "ClipboardItem")] @@ -12,11 +11,7 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub type ClipboardItem; - #[cfg(web_sys_unstable_apis)] #[cfg(feature = "PresentationStyle")] # [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = presentationStyle)] #[doc = "Getter for the `presentationStyle` field of this object."] @@ -24,52 +19,19 @@ extern "C" { #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/presentationStyle)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`, `PresentationStyle`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn presentation_style(this: &ClipboardItem) -> PresentationStyle; - #[cfg(web_sys_unstable_apis)] - # [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = lastModified)] - #[doc = "Getter for the `lastModified` field of this object."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/lastModified)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn last_modified(this: &ClipboardItem) -> f64; - #[cfg(web_sys_unstable_apis)] - # [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = delayed)] - #[doc = "Getter for the `delayed` field of this object."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/delayed)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn delayed(this: &ClipboardItem) -> bool; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = types)] #[doc = "Getter for the `types` field of this object."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/types)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn types(this: &ClipboardItem) -> ::js_sys::Array; - #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "ClipboardItem" , js_name = getType)] #[doc = "The `getType()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/getType)"] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn get_type(this: &ClipboardItem, type_: &str) -> ::js_sys::Promise; } diff --git a/crates/web-sys/src/features/gen_ClipboardItemOptions.rs b/crates/web-sys/src/features/gen_ClipboardItemOptions.rs index 5930f6d857a..0f8b5121183 100644 --- a/crates/web-sys/src/features/gen_ClipboardItemOptions.rs +++ b/crates/web-sys/src/features/gen_ClipboardItemOptions.rs @@ -2,7 +2,6 @@ #![allow(clippy::all)] use super::*; use wasm_bindgen::prelude::*; -#[cfg(web_sys_unstable_apis)] #[wasm_bindgen] extern "C" { # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardItemOptions)] @@ -10,41 +9,29 @@ extern "C" { #[doc = "The `ClipboardItemOptions` dictionary."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub type ClipboardItemOptions; #[cfg(feature = "PresentationStyle")] #[wasm_bindgen(method, setter = "presentationStyle")] fn presentation_style_shim(this: &ClipboardItemOptions, val: PresentationStyle); } -#[cfg(web_sys_unstable_apis)] impl ClipboardItemOptions { #[doc = "Construct a new `ClipboardItemOptions`."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn new() -> Self { #[allow(unused_mut)] let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); ret } - #[cfg(web_sys_unstable_apis)] #[cfg(feature = "PresentationStyle")] #[doc = "Change the `presentationStyle` field of this object."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`, `PresentationStyle`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn presentation_style(&mut self, val: PresentationStyle) -> &mut Self { self.presentation_style_shim(val); self } } -#[cfg(web_sys_unstable_apis)] impl Default for ClipboardItemOptions { fn default() -> Self { Self::new() diff --git a/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs b/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs deleted file mode 100644 index 5c8ac6e004d..00000000000 --- a/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(unused_imports)] -#![allow(clippy::all)] -use super::*; -use wasm_bindgen::prelude::*; -#[cfg(web_sys_unstable_apis)] -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardPermissionDescriptor)] - #[derive(Debug, Clone, PartialEq, Eq)] - #[doc = "The `ClipboardPermissionDescriptor` dictionary."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub type ClipboardPermissionDescriptor; - #[cfg(feature = "PermissionName")] - #[wasm_bindgen(method, setter = "name")] - fn name_shim(this: &ClipboardPermissionDescriptor, val: PermissionName); - #[wasm_bindgen(method, setter = "allowWithoutGesture")] - fn allow_without_gesture_shim(this: &ClipboardPermissionDescriptor, val: bool); -} -#[cfg(web_sys_unstable_apis)] -impl ClipboardPermissionDescriptor { - #[cfg(feature = "PermissionName")] - #[doc = "Construct a new `ClipboardPermissionDescriptor`."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`, `PermissionName`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn new(name: PermissionName) -> Self { - #[allow(unused_mut)] - let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); - ret.name(name); - ret - } - #[cfg(web_sys_unstable_apis)] - #[cfg(feature = "PermissionName")] - #[doc = "Change the `name` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`, `PermissionName`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn name(&mut self, val: PermissionName) -> &mut Self { - self.name_shim(val); - self - } - #[cfg(web_sys_unstable_apis)] - #[doc = "Change the `allowWithoutGesture` field of this object."] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn allow_without_gesture(&mut self, val: bool) -> &mut Self { - self.allow_without_gesture_shim(val); - self - } -} diff --git a/crates/web-sys/src/features/gen_Navigator.rs b/crates/web-sys/src/features/gen_Navigator.rs index e148cd27fc5..8b28f73df54 100644 --- a/crates/web-sys/src/features/gen_Navigator.rs +++ b/crates/web-sys/src/features/gen_Navigator.rs @@ -12,6 +12,14 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Navigator`*"] pub type Navigator; + #[cfg(feature = "Clipboard")] + # [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = clipboard)] + #[doc = "Getter for the `clipboard` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Clipboard`, `Navigator`*"] + pub fn clipboard(this: &Navigator) -> Clipboard; #[cfg(feature = "Permissions")] # [wasm_bindgen (structural , catch , method , getter , js_class = "Navigator" , js_name = permissions)] #[doc = "Getter for the `permissions` field of this object."] @@ -126,18 +134,6 @@ extern "C" { #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] pub fn bluetooth(this: &Navigator) -> Option; #[cfg(web_sys_unstable_apis)] - #[cfg(feature = "Clipboard")] - # [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = clipboard)] - #[doc = "Getter for the `clipboard` field of this object."] - #[doc = ""] - #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard)"] - #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Clipboard`, `Navigator`*"] - #[doc = ""] - #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] - #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] - pub fn clipboard(this: &Navigator) -> Option; - #[cfg(web_sys_unstable_apis)] #[cfg(feature = "MediaSession")] # [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = mediaSession)] #[doc = "Getter for the `mediaSession` field of this object."] diff --git a/crates/web-sys/src/features/gen_PresentationStyle.rs b/crates/web-sys/src/features/gen_PresentationStyle.rs index 1c1b92cf56c..2c0573d8553 100644 --- a/crates/web-sys/src/features/gen_PresentationStyle.rs +++ b/crates/web-sys/src/features/gen_PresentationStyle.rs @@ -1,14 +1,10 @@ #![allow(unused_imports)] #![allow(clippy::all)] use wasm_bindgen::prelude::*; -#[cfg(web_sys_unstable_apis)] #[wasm_bindgen] #[doc = "The `PresentationStyle` enum."] #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `PresentationStyle`*"] -#[doc = ""] -#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] -#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PresentationStyle { Unspecified = "unspecified", diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 486e99e0b18..0f03e787157 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -1132,13 +1132,6 @@ mod gen_ClipboardItemOptions; #[allow(unused_imports)] pub use gen_ClipboardItemOptions::*; -#[cfg(feature = "ClipboardPermissionDescriptor")] -#[allow(non_snake_case)] -mod gen_ClipboardPermissionDescriptor; -#[cfg(feature = "ClipboardPermissionDescriptor")] -#[allow(unused_imports)] -pub use gen_ClipboardPermissionDescriptor::*; - #[cfg(feature = "CloseEvent")] #[allow(non_snake_case)] mod gen_CloseEvent; diff --git a/crates/web-sys/webidls/enabled/Clipboard.webidl b/crates/web-sys/webidls/enabled/Clipboard.webidl new file mode 100644 index 00000000000..20e2d5e64ee --- /dev/null +++ b/crates/web-sys/webidls/enabled/Clipboard.webidl @@ -0,0 +1,55 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Clipboard API and events + * Editor’s Draft, 4 June 2024 + * + * The origin of this IDL file is: + * https://w3c.github.io/clipboard-apis/#idl-index + */ + +partial interface Navigator { + [SecureContext, SameObject] readonly attribute Clipboard clipboard; +}; + +typedef Promise<(DOMString or Blob)> ClipboardItemData; + +[SecureContext, Exposed=Window] +interface ClipboardItem { + constructor(record items, + optional ClipboardItemOptions options = {}); + + readonly attribute PresentationStyle presentationStyle; + readonly attribute FrozenArray types; + + Promise getType(DOMString type); + + // Not supported by WebKit + // static boolean supports(DOMString type); +}; + +enum PresentationStyle { "unspecified", "inline", "attachment" }; + +dictionary ClipboardItemOptions { + PresentationStyle presentationStyle = "unspecified"; +}; + +typedef sequence ClipboardItems; + +[SecureContext, Exposed=Window] +interface Clipboard : EventTarget { + Promise read(/* optional ClipboardUnsanitizedFormats formats = {} */); + Promise readText(); + Promise write(ClipboardItems data); + Promise writeText(DOMString data); +}; + +// There is no consensus by browsers to implement this API. +// See https://github.com/w3c/clipboard-apis/pull/197. +// dictionary ClipboardUnsanitizedFormats { +// sequence unsanitized; +// }; + +// Also Chrome-only +// dictionary ClipboardPermissionDescriptor : PermissionDescriptor { +// boolean allowWithoutGesture = false; +// }; diff --git a/crates/web-sys/webidls/unstable/Clipboard.webidl b/crates/web-sys/webidls/unstable/Clipboard.webidl deleted file mode 100644 index c32a6556a06..00000000000 --- a/crates/web-sys/webidls/unstable/Clipboard.webidl +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Clipboard API and events - * W3C Working Draft, 4 June 2021 - * The origin of this IDL file is: - * https://www.w3.org/TR/2021/WD-clipboard-apis-20210604/ - */ - -partial interface Navigator { - [SecureContext, SameObject] readonly attribute Clipboard? clipboard; -}; - -typedef sequence ClipboardItems; - -[SecureContext, Exposed=Window] interface Clipboard : EventTarget { - Promise read(); - Promise readText(); - Promise write(ClipboardItems data); - Promise writeText(DOMString data); -}; - -typedef (DOMString or Blob) ClipboardItemDataType; -typedef Promise ClipboardItemData; - -callback ClipboardItemDelayedCallback = ClipboardItemData (); - -[Exposed=Window] interface ClipboardItem { - constructor(record items, - optional ClipboardItemOptions options = {}); - static ClipboardItem createDelayed( - record items, - optional ClipboardItemOptions options = {}); - - readonly attribute PresentationStyle presentationStyle; - readonly attribute long long lastModified; - readonly attribute boolean delayed; - - readonly attribute FrozenArray types; - - Promise getType(DOMString type); -}; - -enum PresentationStyle { "unspecified", "inline", "attachment" }; - -dictionary ClipboardItemOptions { - PresentationStyle presentationStyle = "unspecified"; -}; - -dictionary ClipboardPermissionDescriptor : PermissionDescriptor { - boolean allowWithoutGesture = false; -}; From 1486214ff747f4baf49fa1ca120887ee007f1970 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 9 Jul 2024 22:37:08 +0200 Subject: [PATCH 2/3] Move `ClipboardEvent` and enable `ClipboardItem.supports()` --- CHANGELOG.md | 2 +- .../web-sys/src/features/gen_ClipboardItem.rs | 7 +++++++ .../web-sys/webidls/enabled/Clipboard.webidl | 18 ++++++++++++++---- .../webidls/enabled/ClipboardEvent.webidl | 18 ------------------ 4 files changed, 22 insertions(+), 23 deletions(-) delete mode 100644 crates/web-sys/webidls/enabled/ClipboardEvent.webidl diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c59469e620..c12cdcf4224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ * Annotated methods in WebCodecs that throw. [#3970](https://github.com/rustwasm/wasm-bindgen/pull/3970) -* Update and stabilize widely supported parts of the Clipboard API. +* Update and stabilize the Clipboard API. [#3992](https://github.com/rustwasm/wasm-bindgen/pull/3992) ### Fixed diff --git a/crates/web-sys/src/features/gen_ClipboardItem.rs b/crates/web-sys/src/features/gen_ClipboardItem.rs index db2715a32b7..879c6308b5e 100644 --- a/crates/web-sys/src/features/gen_ClipboardItem.rs +++ b/crates/web-sys/src/features/gen_ClipboardItem.rs @@ -34,4 +34,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] pub fn get_type(this: &ClipboardItem, type_: &str) -> ::js_sys::Promise; + # [wasm_bindgen (static_method_of = ClipboardItem , js_class = "ClipboardItem" , js_name = supports)] + #[doc = "The `supports()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/supports)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"] + pub fn supports(type_: &str) -> bool; } diff --git a/crates/web-sys/webidls/enabled/Clipboard.webidl b/crates/web-sys/webidls/enabled/Clipboard.webidl index 20e2d5e64ee..2ef1276c44e 100644 --- a/crates/web-sys/webidls/enabled/Clipboard.webidl +++ b/crates/web-sys/webidls/enabled/Clipboard.webidl @@ -7,6 +7,16 @@ * https://w3c.github.io/clipboard-apis/#idl-index */ +dictionary ClipboardEventInit : EventInit { + DataTransfer? clipboardData = null; +}; + +[Exposed=Window] +interface ClipboardEvent : Event { + constructor(DOMString type, optional ClipboardEventInit eventInitDict = {}); + readonly attribute DataTransfer? clipboardData; +}; + partial interface Navigator { [SecureContext, SameObject] readonly attribute Clipboard clipboard; }; @@ -15,6 +25,7 @@ typedef Promise<(DOMString or Blob)> ClipboardItemData; [SecureContext, Exposed=Window] interface ClipboardItem { + [Throws] constructor(record items, optional ClipboardItemOptions options = {}); @@ -23,8 +34,7 @@ interface ClipboardItem { Promise getType(DOMString type); - // Not supported by WebKit - // static boolean supports(DOMString type); + static boolean supports(DOMString type); }; enum PresentationStyle { "unspecified", "inline", "attachment" }; @@ -37,7 +47,7 @@ typedef sequence ClipboardItems; [SecureContext, Exposed=Window] interface Clipboard : EventTarget { - Promise read(/* optional ClipboardUnsanitizedFormats formats = {} */); + Promise read(optional ClipboardUnsanitizedFormats formats = {}); Promise readText(); Promise write(ClipboardItems data); Promise writeText(DOMString data); @@ -49,7 +59,7 @@ interface Clipboard : EventTarget { // sequence unsanitized; // }; -// Also Chrome-only +// Also Chrome-only. // dictionary ClipboardPermissionDescriptor : PermissionDescriptor { // boolean allowWithoutGesture = false; // }; diff --git a/crates/web-sys/webidls/enabled/ClipboardEvent.webidl b/crates/web-sys/webidls/enabled/ClipboardEvent.webidl deleted file mode 100644 index 51ceebfb2e9..00000000000 --- a/crates/web-sys/webidls/enabled/ClipboardEvent.webidl +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * Clipboard API and events - * Editor’s Draft, 21 November 2023 - * - * The origin of this IDL file is: - * https://w3c.github.io/clipboard-apis/#clipboard-event-interfaces - */ - -dictionary ClipboardEventInit : EventInit { - DataTransfer? clipboardData = null; -}; - -[Exposed=Window] -interface ClipboardEvent : Event { - constructor(DOMString type, optional ClipboardEventInit eventInitDict = {}); - readonly attribute DataTransfer? clipboardData; -}; From 0f22913dbfcbe257a207ab1c464745cf77c1a360 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 9 Jul 2024 23:08:09 +0200 Subject: [PATCH 3/3] Add unstable Clipboard API parts --- crates/web-sys/Cargo.toml | 2 + crates/web-sys/src/features/gen_Clipboard.rs | 15 +++++ .../gen_ClipboardPermissionDescriptor.rs | 61 +++++++++++++++++++ .../gen_ClipboardUnsanitizedFormats.rs | 50 +++++++++++++++ crates/web-sys/src/features/mod.rs | 14 +++++ .../web-sys/webidls/enabled/Clipboard.webidl | 11 ---- .../web-sys/webidls/unstable/Clipboard.webidl | 19 ++++++ crates/webidl/src/util.rs | 11 ++-- 8 files changed, 165 insertions(+), 18 deletions(-) create mode 100644 crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs create mode 100644 crates/web-sys/src/features/gen_ClipboardUnsanitizedFormats.rs create mode 100644 crates/web-sys/webidls/unstable/Clipboard.webidl diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index bf19273f473..59db9b49587 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -193,6 +193,8 @@ ClipboardEvent = ["Event"] ClipboardEventInit = [] ClipboardItem = [] ClipboardItemOptions = [] +ClipboardPermissionDescriptor = [] +ClipboardUnsanitizedFormats = [] CloseEvent = ["Event"] CloseEventInit = [] CodecState = [] diff --git a/crates/web-sys/src/features/gen_Clipboard.rs b/crates/web-sys/src/features/gen_Clipboard.rs index 3c997ccdeb4..420f5389fc9 100644 --- a/crates/web-sys/src/features/gen_Clipboard.rs +++ b/crates/web-sys/src/features/gen_Clipboard.rs @@ -19,6 +19,21 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Clipboard`*"] pub fn read(this: &Clipboard) -> ::js_sys::Promise; + #[cfg(web_sys_unstable_apis)] + #[cfg(feature = "ClipboardUnsanitizedFormats")] + # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = read)] + #[doc = "The `read()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Clipboard`, `ClipboardUnsanitizedFormats`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn read_with_formats( + this: &Clipboard, + formats: &ClipboardUnsanitizedFormats, + ) -> ::js_sys::Promise; # [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = readText)] #[doc = "The `readText()` method."] #[doc = ""] diff --git a/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs b/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs new file mode 100644 index 00000000000..5c8ac6e004d --- /dev/null +++ b/crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs @@ -0,0 +1,61 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[cfg(web_sys_unstable_apis)] +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardPermissionDescriptor)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `ClipboardPermissionDescriptor` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub type ClipboardPermissionDescriptor; + #[cfg(feature = "PermissionName")] + #[wasm_bindgen(method, setter = "name")] + fn name_shim(this: &ClipboardPermissionDescriptor, val: PermissionName); + #[wasm_bindgen(method, setter = "allowWithoutGesture")] + fn allow_without_gesture_shim(this: &ClipboardPermissionDescriptor, val: bool); +} +#[cfg(web_sys_unstable_apis)] +impl ClipboardPermissionDescriptor { + #[cfg(feature = "PermissionName")] + #[doc = "Construct a new `ClipboardPermissionDescriptor`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`, `PermissionName`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn new(name: PermissionName) -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret.name(name); + ret + } + #[cfg(web_sys_unstable_apis)] + #[cfg(feature = "PermissionName")] + #[doc = "Change the `name` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`, `PermissionName`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn name(&mut self, val: PermissionName) -> &mut Self { + self.name_shim(val); + self + } + #[cfg(web_sys_unstable_apis)] + #[doc = "Change the `allowWithoutGesture` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardPermissionDescriptor`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn allow_without_gesture(&mut self, val: bool) -> &mut Self { + self.allow_without_gesture_shim(val); + self + } +} diff --git a/crates/web-sys/src/features/gen_ClipboardUnsanitizedFormats.rs b/crates/web-sys/src/features/gen_ClipboardUnsanitizedFormats.rs new file mode 100644 index 00000000000..a4e5fa3251e --- /dev/null +++ b/crates/web-sys/src/features/gen_ClipboardUnsanitizedFormats.rs @@ -0,0 +1,50 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[cfg(web_sys_unstable_apis)] +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardUnsanitizedFormats)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `ClipboardUnsanitizedFormats` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub type ClipboardUnsanitizedFormats; + #[wasm_bindgen(method, setter = "unsanitized")] + fn unsanitized_shim(this: &ClipboardUnsanitizedFormats, val: &::wasm_bindgen::JsValue); +} +#[cfg(web_sys_unstable_apis)] +impl ClipboardUnsanitizedFormats { + #[doc = "Construct a new `ClipboardUnsanitizedFormats`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[cfg(web_sys_unstable_apis)] + #[doc = "Change the `unsanitized` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn unsanitized(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + self.unsanitized_shim(val); + self + } +} +#[cfg(web_sys_unstable_apis)] +impl Default for ClipboardUnsanitizedFormats { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 0f03e787157..593a3f5e0de 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -1132,6 +1132,20 @@ mod gen_ClipboardItemOptions; #[allow(unused_imports)] pub use gen_ClipboardItemOptions::*; +#[cfg(feature = "ClipboardPermissionDescriptor")] +#[allow(non_snake_case)] +mod gen_ClipboardPermissionDescriptor; +#[cfg(feature = "ClipboardPermissionDescriptor")] +#[allow(unused_imports)] +pub use gen_ClipboardPermissionDescriptor::*; + +#[cfg(feature = "ClipboardUnsanitizedFormats")] +#[allow(non_snake_case)] +mod gen_ClipboardUnsanitizedFormats; +#[cfg(feature = "ClipboardUnsanitizedFormats")] +#[allow(unused_imports)] +pub use gen_ClipboardUnsanitizedFormats::*; + #[cfg(feature = "CloseEvent")] #[allow(non_snake_case)] mod gen_CloseEvent; diff --git a/crates/web-sys/webidls/enabled/Clipboard.webidl b/crates/web-sys/webidls/enabled/Clipboard.webidl index 2ef1276c44e..fbf98a2f379 100644 --- a/crates/web-sys/webidls/enabled/Clipboard.webidl +++ b/crates/web-sys/webidls/enabled/Clipboard.webidl @@ -52,14 +52,3 @@ interface Clipboard : EventTarget { Promise write(ClipboardItems data); Promise writeText(DOMString data); }; - -// There is no consensus by browsers to implement this API. -// See https://github.com/w3c/clipboard-apis/pull/197. -// dictionary ClipboardUnsanitizedFormats { -// sequence unsanitized; -// }; - -// Also Chrome-only. -// dictionary ClipboardPermissionDescriptor : PermissionDescriptor { -// boolean allowWithoutGesture = false; -// }; diff --git a/crates/web-sys/webidls/unstable/Clipboard.webidl b/crates/web-sys/webidls/unstable/Clipboard.webidl new file mode 100644 index 00000000000..91ecc637a45 --- /dev/null +++ b/crates/web-sys/webidls/unstable/Clipboard.webidl @@ -0,0 +1,19 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Clipboard API and events + * Editor’s Draft, 4 June 2024 + * + * The origin of this IDL file is: + * https://w3c.github.io/clipboard-apis/#idl-index + */ + +// There is no consensus by browsers to implement this API. +// See https://github.com/w3c/clipboard-apis/pull/197. +dictionary ClipboardUnsanitizedFormats { + sequence unsanitized; +}; + +// Also Chrome-only. +dictionary ClipboardPermissionDescriptor : PermissionDescriptor { + boolean allowWithoutGesture = false; +}; diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 44dffb0af70..0f663978fd3 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -443,14 +443,9 @@ impl<'src> FirstPassRecord<'src> { // If any of the arguments types are `unstable` then this method is downgraded // to be unstable. let has_unstable_args = signature - .orig .args .iter() - .any(|arg| is_type_unstable(arg.ty, unstable_types)) - | signature - .args - .iter() - .any(|arg| is_idl_type_unstable(arg, unstable_types)); + .any(|arg| is_idl_type_unstable(arg, unstable_types)); let unstable = unstable || data.stability.is_unstable() || has_unstable_args; @@ -552,7 +547,9 @@ pub fn is_type_unstable(ty: &weedle::types::Type, unstable_types: &HashSet) -> bool { match ty { - IdlType::Interface(name) => unstable_types.contains(&Identifier(name)), + IdlType::Dictionary(name) | IdlType::Interface(name) => { + unstable_types.contains(&Identifier(name)) + } _ => false, } }