Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings for ResizeObserver #2701

Merged
merged 3 commits into from
Oct 20, 2021
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
5 changes: 5 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ RequestInit = []
RequestMediaKeySystemAccessNotification = []
RequestMode = []
RequestRedirect = []
ResizeObserver = []
ResizeObserverBoxOptions = []
ResizeObserverEntry = []
ResizeObserverOptions = []
ResizeObserverSize = []
Response = []
ResponseInit = []
ResponseType = []
Expand Down
80 changes: 80 additions & 0 deletions crates/web-sys/src/features/gen_ResizeObserver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ResizeObserver , typescript_type = "ResizeObserver")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ResizeObserver` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserver`*"]
#[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 ResizeObserver;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen(catch, constructor, js_class = "ResizeObserver")]
#[doc = "The `new ResizeObserver(..)` constructor, creating a new instance of `ResizeObserver`."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserver`*"]
#[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(callback: &::js_sys::Function) -> Result<ResizeObserver, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ResizeObserver" , js_name = disconnect)]
#[doc = "The `disconnect()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/disconnect)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserver`*"]
#[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 disconnect(this: &ResizeObserver);
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Element")]
# [wasm_bindgen (method , structural , js_class = "ResizeObserver" , js_name = observe)]
#[doc = "The `observe()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Element`, `ResizeObserver`*"]
#[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 observe(this: &ResizeObserver, target: &Element);
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "Element", feature = "ResizeObserverOptions",))]
# [wasm_bindgen (method , structural , js_class = "ResizeObserver" , js_name = observe)]
#[doc = "The `observe()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Element`, `ResizeObserver`, `ResizeObserverOptions`*"]
#[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 observe_with_options(
this: &ResizeObserver,
target: &Element,
options: &ResizeObserverOptions,
);
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Element")]
# [wasm_bindgen (method , structural , js_class = "ResizeObserver" , js_name = unobserve)]
#[doc = "The `unobserve()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/unobserve)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Element`, `ResizeObserver`*"]
#[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 unobserve(this: &ResizeObserver, target: &Element);
}
16 changes: 16 additions & 0 deletions crates/web-sys/src/features/gen_ResizeObserverBoxOptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(unused_imports)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `ResizeObserverBoxOptions` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverBoxOptions`*"]
#[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 ResizeObserverBoxOptions {
BorderBox = "border-box",
ContentBox = "content-box",
DevicePixelContentBox = "device-pixel-content-box",
}
75 changes: 75 additions & 0 deletions crates/web-sys/src/features/gen_ResizeObserverEntry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ResizeObserverEntry , typescript_type = "ResizeObserverEntry")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ResizeObserverEntry` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverEntry`*"]
#[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 ResizeObserverEntry;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Element")]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverEntry" , js_name = target)]
#[doc = "Getter for the `target` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/target)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Element`, `ResizeObserverEntry`*"]
#[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 target(this: &ResizeObserverEntry) -> Element;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "DomRectReadOnly")]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverEntry" , js_name = contentRect)]
#[doc = "Getter for the `contentRect` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/contentRect)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `DomRectReadOnly`, `ResizeObserverEntry`*"]
#[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 content_rect(this: &ResizeObserverEntry) -> DomRectReadOnly;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverEntry" , js_name = borderBoxSize)]
#[doc = "Getter for the `borderBoxSize` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/borderBoxSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverEntry`*"]
#[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 border_box_size(this: &ResizeObserverEntry) -> ::js_sys::Array;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverEntry" , js_name = contentBoxSize)]
#[doc = "Getter for the `contentBoxSize` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/contentBoxSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverEntry`*"]
#[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 content_box_size(this: &ResizeObserverEntry) -> ::js_sys::Array;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverEntry" , js_name = devicePixelContentBoxSize)]
#[doc = "Getter for the `devicePixelContentBoxSize` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry/devicePixelContentBoxSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverEntry`*"]
#[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 device_pixel_content_box_size(this: &ResizeObserverEntry) -> ::js_sys::Array;
}
54 changes: 54 additions & 0 deletions crates/web-sys/src/features/gen_ResizeObserverOptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ResizeObserverOptions)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ResizeObserverOptions` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverOptions`*"]
#[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 ResizeObserverOptions;
}
#[cfg(web_sys_unstable_apis)]
impl ResizeObserverOptions {
#[doc = "Construct a new `ResizeObserverOptions`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverOptions`*"]
#[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 = "ResizeObserverBoxOptions")]
#[doc = "Change the `box` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverBoxOptions`, `ResizeObserverOptions`*"]
#[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 box_(&mut self, val: ResizeObserverBoxOptions) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("box"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for ResizeObserverOptions {
fn default() -> Self {
Self::new()
}
}
40 changes: 40 additions & 0 deletions crates/web-sys/src/features/gen_ResizeObserverSize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![allow(unused_imports)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ResizeObserverSize , typescript_type = "ResizeObserverSize")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ResizeObserverSize` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverSize`*"]
#[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 ResizeObserverSize;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverSize" , js_name = inlineSize)]
#[doc = "Getter for the `inlineSize` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverSize/inlineSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverSize`*"]
#[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 inline_size(this: &ResizeObserverSize) -> f64;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ResizeObserverSize" , js_name = blockSize)]
#[doc = "Getter for the `blockSize` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverSize/blockSize)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ResizeObserverSize`*"]
#[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 block_size(this: &ResizeObserverSize) -> f64;
}
30 changes: 30 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5542,6 +5542,36 @@ mod gen_RequestRedirect;
#[cfg(feature = "RequestRedirect")]
pub use gen_RequestRedirect::*;

#[cfg(feature = "ResizeObserver")]
#[allow(non_snake_case)]
mod gen_ResizeObserver;
#[cfg(feature = "ResizeObserver")]
pub use gen_ResizeObserver::*;

#[cfg(feature = "ResizeObserverBoxOptions")]
#[allow(non_snake_case)]
mod gen_ResizeObserverBoxOptions;
#[cfg(feature = "ResizeObserverBoxOptions")]
pub use gen_ResizeObserverBoxOptions::*;

#[cfg(feature = "ResizeObserverEntry")]
#[allow(non_snake_case)]
mod gen_ResizeObserverEntry;
#[cfg(feature = "ResizeObserverEntry")]
pub use gen_ResizeObserverEntry::*;

#[cfg(feature = "ResizeObserverOptions")]
#[allow(non_snake_case)]
mod gen_ResizeObserverOptions;
#[cfg(feature = "ResizeObserverOptions")]
pub use gen_ResizeObserverOptions::*;

#[cfg(feature = "ResizeObserverSize")]
#[allow(non_snake_case)]
mod gen_ResizeObserverSize;
#[cfg(feature = "ResizeObserverSize")]
pub use gen_ResizeObserverSize::*;

#[cfg(feature = "Response")]
#[allow(non_snake_case)]
mod gen_Response;
Expand Down
34 changes: 34 additions & 0 deletions crates/web-sys/webidls/unstable/ResizeObserver.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
enum ResizeObserverBoxOptions {
"border-box", "content-box", "device-pixel-content-box"
};

dictionary ResizeObserverOptions {
ResizeObserverBoxOptions box = "content-box";
};

// TODO: remove this once the `constructor()` syntax is supported.
[Constructor(ResizeObserverCallback callback),
Exposed=(Window)]
interface ResizeObserver {
constructor(ResizeObserverCallback callback);
undefined observe(Element target, optional ResizeObserverOptions options = {});
undefined unobserve(Element target);
undefined disconnect();
};

callback ResizeObserverCallback = undefined (sequence<ResizeObserverEntry> entries, ResizeObserver observer);

[Exposed=Window]
interface ResizeObserverEntry {
readonly attribute Element target;
readonly attribute DOMRectReadOnly contentRect;
readonly attribute FrozenArray<ResizeObserverSize> borderBoxSize;
readonly attribute FrozenArray<ResizeObserverSize> contentBoxSize;
readonly attribute FrozenArray<ResizeObserverSize> devicePixelContentBoxSize;
};

[Exposed=Window]
interface ResizeObserverSize {
readonly attribute unrestricted double inlineSize;
readonly attribute unrestricted double blockSize;
};