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 missing APIs for InputEvent #2499

Merged
merged 3 commits into from
Mar 25, 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
29 changes: 29 additions & 0 deletions crates/web-sys/src/features/gen_InputEvent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEvent`*"]
pub fn is_composing(this: &InputEvent) -> bool;
# [wasm_bindgen (structural , method , getter , js_class = "InputEvent" , js_name = inputType)]
#[doc = "Getter for the `inputType` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/inputType)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEvent`*"]
pub fn input_type(this: &InputEvent) -> String;
# [wasm_bindgen (structural , method , getter , js_class = "InputEvent" , js_name = data)]
#[doc = "Getter for the `data` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/data)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEvent`*"]
pub fn data(this: &InputEvent) -> Option<String>;
#[cfg(feature = "DataTransfer")]
# [wasm_bindgen (structural , method , getter , js_class = "InputEvent" , js_name = dataTransfer)]
#[doc = "Getter for the `dataTransfer` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/dataTransfer)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `DataTransfer`, `InputEvent`*"]
pub fn data_transfer(this: &InputEvent) -> Option<DataTransfer>;
#[wasm_bindgen(catch, constructor, js_class = "InputEvent")]
#[doc = "The `new InputEvent(..)` constructor, creating a new instance of `InputEvent`."]
#[doc = ""]
Expand All @@ -36,4 +58,11 @@ extern "C" {
type_: &str,
event_init_dict: &InputEventInit,
) -> Result<InputEvent, JsValue>;
# [wasm_bindgen (method , structural , js_class = "InputEvent" , js_name = getTargetRanges)]
#[doc = "The `getTargetRanges()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/getTargetRanges)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEvent`*"]
pub fn get_target_ranges(this: &InputEvent) -> ::js_sys::Array;
}
65 changes: 65 additions & 0 deletions crates/web-sys/src/features/gen_InputEventInit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,54 @@ impl InputEventInit {
let _ = r;
self
}
#[doc = "Change the `data` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEventInit`*"]
pub fn data(&mut self, val: Option<&str>) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("data"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(feature = "DataTransfer")]
#[doc = "Change the `dataTransfer` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `DataTransfer`, `InputEventInit`*"]
pub fn data_transfer(&mut self, val: Option<&DataTransfer>) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("dataTransfer"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[doc = "Change the `inputType` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEventInit`*"]
pub fn input_type(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("inputType"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[doc = "Change the `isComposing` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEventInit`*"]
Expand All @@ -115,4 +163,21 @@ impl InputEventInit {
let _ = r;
self
}
#[doc = "Change the `targetRanges` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `InputEventInit`*"]
pub fn target_ranges(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("targetRanges"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
28 changes: 28 additions & 0 deletions crates/web-sys/webidls/enabled/InputEvent.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,37 @@
interface InputEvent : UIEvent
{
readonly attribute boolean isComposing;
readonly attribute DOMString inputType;
[NeedsCallerType]
readonly attribute DOMString? data;
};

dictionary InputEventInit : UIEventInit
{
boolean isComposing = false;
DOMString inputType = "";
// NOTE: Currently, default value of `data` attribute is declared as empty
// string by UI Events. However, both Chrome and Safari uses `null`,
// and there is a spec issue about this:
// https://github.com/w3c/uievents/issues/139
// So, we take `null` for compatibility with them.
DOMString? data = null;
};

partial interface InputEvent
{
[NeedsCallerType]
readonly attribute DataTransfer? dataTransfer;
// Enable `getTargetRanges()` only when `beforeinput` event is enabled
// because this may be used for feature detection of `beforeinput` event
// support (due to Chrome not supporting `onbeforeinput` attribute).
[Pref="dom.input_events.beforeinput.enabled"]
sequence<StaticRange> getTargetRanges();
};

partial dictionary InputEventInit
{
DataTransfer? dataTransfer = null;
[Pref="dom.input_events.beforeinput.enabled"]
sequence<StaticRange> targetRanges = [];
};