Skip to content
Open
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
6 changes: 6 additions & 0 deletions packages/html/src/events/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl AnimationData {
}
}

impl Default for AnimationData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasAnimationData> From<E> for AnimationData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub struct ClipboardData {
inner: Box<dyn HasClipboardData>,
}

impl Default for ClipboardData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasClipboardData> From<E> for ClipboardData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ impl std::fmt::Debug for CompositionData {
}
}

impl Default for CompositionData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasCompositionData> From<E> for CompositionData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ pub struct DragData {
inner: Box<dyn HasDragData>,
}

impl Default for DragData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasDragData + 'static> From<E> for DragData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub struct FocusData {
inner: Box<dyn HasFocusData>,
}

impl Default for FocusData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasFocusData> From<E> for FocusData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
10 changes: 10 additions & 0 deletions packages/html/src/events/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub struct KeyboardData {
inner: Box<dyn HasKeyboardData>,
}

impl Default for KeyboardData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasKeyboardData> From<E> for KeyboardData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down Expand Up @@ -105,9 +111,13 @@ pub struct SerializedKeyboardData {
key_code: KeyCode,
#[serde(deserialize_with = "resilient_deserialize_code")]
code: Code,
#[serde(default)]
alt_key: bool,
#[serde(default)]
ctrl_key: bool,
#[serde(default)]
meta_key: bool,
#[serde(default)]
shift_key: bool,
location: usize,
repeat: bool,
Expand Down
204 changes: 204 additions & 0 deletions packages/html/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,210 @@ impl From<&PlatformEventData> for WheelData {
}
}

pub(crate) mod empty {
use crate::{
geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint, WheelDelta},
input_data::{MouseButton, MouseButtonSet},
keyboard_types::{Code, Key, Location, Modifiers},
HasDragData, HasFileData, HasFocusData, HasKeyboardData, HasMouseData, HasPointerData,
HasTouchData, HasWheelData, InteractionElementOffset, InteractionLocation,
ModifiersInteraction, PointerInteraction, TouchPoint,
};

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct EmptyEvent;

impl HasDragData for EmptyEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl HasFileData for EmptyEvent {
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
None
}
}
impl HasMouseData for EmptyEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl HasPointerData for EmptyEvent {
fn pointer_id(&self) -> i32 {
0
}

fn width(&self) -> i32 {
0
}

fn height(&self) -> i32 {
0
}

fn pressure(&self) -> f32 {
0.0
}

fn tangential_pressure(&self) -> f32 {
0.0
}

fn tilt_x(&self) -> i32 {
0
}

fn tilt_y(&self) -> i32 {
0
}

fn twist(&self) -> i32 {
0
}

fn pointer_type(&self) -> String {
"mouse".to_string()
}

fn is_primary(&self) -> bool {
false
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl HasTouchData for EmptyEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}

fn touches_changed(&self) -> Vec<TouchPoint> {
Vec::new()
}

fn target_touches(&self) -> Vec<TouchPoint> {
Vec::new()
}

fn touches(&self) -> Vec<TouchPoint> {
Vec::new()
}
}
impl HasWheelData for EmptyEvent {
fn delta(&self) -> WheelDelta {
WheelDelta::lines(0.0, 0.0, 0.0)
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl super::animation::HasAnimationData for EmptyEvent {
fn animation_name(&self) -> String {
String::new()
}
fn pseudo_element(&self) -> String {
String::new()
}
fn elapsed_time(&self) -> f32 {
0.0
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl super::clipboard::HasClipboardData for EmptyEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl super::composition::HasCompositionData for EmptyEvent {
fn data(&self) -> String {
String::new()
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl super::transition::HasTransitionData for EmptyEvent {
fn property_name(&self) -> String {
String::new()
}
fn pseudo_element(&self) -> String {
String::new()
}
fn elapsed_time(&self) -> f32 {
0.0
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl HasKeyboardData for EmptyEvent {
fn key(&self) -> Key {
Key::Unidentified
}

fn code(&self) -> Code {
Code::Unidentified
}

fn location(&self) -> Location {
Location::Standard
}

fn is_auto_repeating(&self) -> bool {
false
}

fn is_composing(&self) -> bool {
false
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl HasFocusData for EmptyEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl InteractionLocation for EmptyEvent {
fn client_coordinates(&self) -> ClientPoint {
Default::default()
}

fn page_coordinates(&self) -> PagePoint {
Default::default()
}

fn screen_coordinates(&self) -> ScreenPoint {
Default::default()
}
}
impl InteractionElementOffset for EmptyEvent {
fn element_coordinates(&self) -> ElementPoint {
Default::default()
}
}
impl ModifiersInteraction for EmptyEvent {
fn modifiers(&self) -> Modifiers {
Modifiers::empty()
}
}
impl PointerInteraction for EmptyEvent {
fn held_buttons(&self) -> MouseButtonSet {
Default::default()
}

fn trigger_button(&self) -> Option<MouseButton> {
None
}
}
}

mod animation;
mod clipboard;
mod composition;
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub struct MouseData {
inner: Box<dyn HasMouseData>,
}

impl Default for MouseData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasMouseData + 'static> From<E> for MouseData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ impl PointerData {
}
}

impl Default for PointerData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasPointerData + 'static> From<E> for PointerData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct TouchData {
inner: Box<dyn HasTouchData>,
}

impl Default for TouchData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasTouchData> From<E> for TouchData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub struct TransitionData {
inner: Box<dyn HasTransitionData>,
}

impl Default for TransitionData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasTransitionData> From<E> for TransitionData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
6 changes: 6 additions & 0 deletions packages/html/src/events/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub struct WheelData {
inner: Box<dyn HasWheelData>,
}

impl Default for WheelData {
fn default() -> Self {
Self::new(crate::events::empty::EmptyEvent)
}
}

impl<E: HasWheelData> From<E> for WheelData {
fn from(e: E) -> Self {
Self { inner: Box::new(e) }
Expand Down
4 changes: 4 additions & 0 deletions packages/html/src/point_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub trait ModifiersInteraction {
#[cfg(feature = "serialize")]
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Default)]
pub struct SerializedPointInteraction {
#[serde(default)]
pub alt_key: bool,

/// The button number that was pressed (if applicable) when the mouse event was fired.
Expand Down Expand Up @@ -78,9 +79,11 @@ pub struct SerializedPointInteraction {
pub client_y: i32,

/// True if the control key was down when the mouse event was fired.
#[serde(default)]
pub ctrl_key: bool,

/// True if the meta key was down when the mouse event was fired.
#[serde(default)]
pub meta_key: bool,

/// The offset in the X coordinate of the mouse pointer between that event and the padding edge of the target node.
Expand All @@ -106,6 +109,7 @@ pub struct SerializedPointInteraction {
pub screen_y: i32,

/// True if the shift key was down when the mouse event was fired.
#[serde(default)]
pub shift_key: bool,
}

Expand Down
Loading
Loading