|
@@ -4,18 +4,14 @@ use crate::events::{
|
|
};
|
|
};
|
|
use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
|
|
use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
|
|
use crate::input_data::{decode_key_location, decode_mouse_button_set, MouseButton};
|
|
use crate::input_data::{decode_key_location, decode_mouse_button_set, MouseButton};
|
|
-use crate::{
|
|
|
|
- DragData, MountedData, MountedError, MountedResult, RenderedElementBacking, ScrollBehavior,
|
|
|
|
-};
|
|
|
|
|
|
+use crate::{DragData, MountedData};
|
|
use keyboard_types::{Code, Key, Modifiers};
|
|
use keyboard_types::{Code, Key, Modifiers};
|
|
use std::convert::TryInto;
|
|
use std::convert::TryInto;
|
|
-use std::future::Future;
|
|
|
|
-use std::pin::Pin;
|
|
|
|
use std::str::FromStr;
|
|
use std::str::FromStr;
|
|
use wasm_bindgen::{JsCast, JsValue};
|
|
use wasm_bindgen::{JsCast, JsValue};
|
|
use web_sys::{
|
|
use web_sys::{
|
|
- AnimationEvent, CompositionEvent, Event, KeyboardEvent, MouseEvent, PointerEvent,
|
|
|
|
- ScrollIntoViewOptions, TouchEvent, TransitionEvent, WheelEvent,
|
|
|
|
|
|
+ AnimationEvent, CompositionEvent, Event, KeyboardEvent, MouseEvent, PointerEvent, TouchEvent,
|
|
|
|
+ TransitionEvent, WheelEvent,
|
|
};
|
|
};
|
|
|
|
|
|
macro_rules! uncheck_convert {
|
|
macro_rules! uncheck_convert {
|
|
@@ -198,16 +194,20 @@ impl From<&TransitionEvent> for TransitionData {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#[cfg(feature = "mounted")]
|
|
impl From<&web_sys::Element> for MountedData {
|
|
impl From<&web_sys::Element> for MountedData {
|
|
fn from(e: &web_sys::Element) -> Self {
|
|
fn from(e: &web_sys::Element) -> Self {
|
|
MountedData::new(e.clone())
|
|
MountedData::new(e.clone())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl RenderedElementBacking for web_sys::Element {
|
|
|
|
|
|
+#[cfg(feature = "mounted")]
|
|
|
|
+impl crate::RenderedElementBacking for web_sys::Element {
|
|
fn get_client_rect(
|
|
fn get_client_rect(
|
|
&self,
|
|
&self,
|
|
- ) -> Pin<Box<dyn Future<Output = MountedResult<euclid::Rect<f64, f64>>>>> {
|
|
|
|
|
|
+ ) -> std::pin::Pin<
|
|
|
|
+ Box<dyn std::future::Future<Output = crate::MountedResult<euclid::Rect<f64, f64>>>>,
|
|
|
|
+ > {
|
|
let rect = self.get_bounding_client_rect();
|
|
let rect = self.get_bounding_client_rect();
|
|
let result = Ok(euclid::Rect::new(
|
|
let result = Ok(euclid::Rect::new(
|
|
euclid::Point2D::new(rect.left(), rect.top()),
|
|
euclid::Point2D::new(rect.left(), rect.top()),
|
|
@@ -216,33 +216,36 @@ impl RenderedElementBacking for web_sys::Element {
|
|
Box::pin(async { result })
|
|
Box::pin(async { result })
|
|
}
|
|
}
|
|
|
|
|
|
- fn get_raw_element(&self) -> MountedResult<&dyn std::any::Any> {
|
|
|
|
|
|
+ fn get_raw_element(&self) -> crate::MountedResult<&dyn std::any::Any> {
|
|
Ok(self)
|
|
Ok(self)
|
|
}
|
|
}
|
|
|
|
|
|
fn scroll_to(
|
|
fn scroll_to(
|
|
&self,
|
|
&self,
|
|
- behavior: ScrollBehavior,
|
|
|
|
- ) -> Pin<Box<dyn Future<Output = MountedResult<()>>>> {
|
|
|
|
|
|
+ behavior: crate::ScrollBehavior,
|
|
|
|
+ ) -> std::pin::Pin<Box<dyn std::future::Future<Output = crate::MountedResult<()>>>> {
|
|
match behavior {
|
|
match behavior {
|
|
- ScrollBehavior::Instant => self.scroll_into_view_with_scroll_into_view_options(
|
|
|
|
- ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Instant),
|
|
|
|
|
|
+ crate::ScrollBehavior::Instant => self.scroll_into_view_with_scroll_into_view_options(
|
|
|
|
+ web_sys::ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Instant),
|
|
),
|
|
),
|
|
- ScrollBehavior::Smooth => self.scroll_into_view_with_scroll_into_view_options(
|
|
|
|
- ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Smooth),
|
|
|
|
|
|
+ crate::ScrollBehavior::Smooth => self.scroll_into_view_with_scroll_into_view_options(
|
|
|
|
+ web_sys::ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Smooth),
|
|
),
|
|
),
|
|
}
|
|
}
|
|
|
|
|
|
Box::pin(async { Ok(()) })
|
|
Box::pin(async { Ok(()) })
|
|
}
|
|
}
|
|
|
|
|
|
- fn set_focus(&self, focus: bool) -> Pin<Box<dyn Future<Output = MountedResult<()>>>> {
|
|
|
|
|
|
+ fn set_focus(
|
|
|
|
+ &self,
|
|
|
|
+ focus: bool,
|
|
|
|
+ ) -> std::pin::Pin<Box<dyn std::future::Future<Output = crate::MountedResult<()>>>> {
|
|
let result = self
|
|
let result = self
|
|
.dyn_ref::<web_sys::HtmlElement>()
|
|
.dyn_ref::<web_sys::HtmlElement>()
|
|
- .ok_or_else(|| MountedError::OperationFailed(Box::new(FocusError(self.into()))))
|
|
|
|
|
|
+ .ok_or_else(|| crate::MountedError::OperationFailed(Box::new(FocusError(self.into()))))
|
|
.and_then(|e| {
|
|
.and_then(|e| {
|
|
(if focus { e.focus() } else { e.blur() })
|
|
(if focus { e.focus() } else { e.blur() })
|
|
- .map_err(|err| MountedError::OperationFailed(Box::new(FocusError(err))))
|
|
|
|
|
|
+ .map_err(|err| crate::MountedError::OperationFailed(Box::new(FocusError(err))))
|
|
});
|
|
});
|
|
Box::pin(async { result })
|
|
Box::pin(async { result })
|
|
}
|
|
}
|