-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bindings for
ResizeObserver
(#2701)
* Add bindings for `ResizeObserver` I had to add a `Constructor` attribute to `ResizeObserver`, since the new constructor syntax isn't supported yet (#1952). * Mark API as unstable * reset ci
- Loading branch information
1 parent
d4b21e7
commit e447729
Showing
8 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
crates/web-sys/src/features/gen_ResizeObserverBoxOptions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |