wip: fix some event stuff for web and core

This commit is contained in:
Jonathan Kelley committed 2021-09-02 00:37:57 -04:00
1 parent dfe9f86bff
commit 725b4a1d7f
8 files changed
+101 -57

No files matched your search

+24 -26
View File
@@ -5,8 +5,17 @@
//! be heavy or need to interact through FFI, so the events themselves are designed to be lazy.
use crate::innerlude::{ElementId, ScopeId};
use bumpalo::boxed::Box as BumpBox;
use std::{any::Any, cell::RefCell, fmt::Debug, ops::Deref, rc::Rc};
use crate::{
innerlude::NodeFactory,
innerlude::{Attribute, Listener, VNode},
};
use std::cell::Cell;
#[derive(Debug)]
pub struct UiEvent {
pub struct UserEvent {
/// The originator of the event trigger
pub scope: ScopeId,
@@ -23,22 +32,23 @@ pub struct UiEvent {
}
pub enum SyntheticEvent {
KeyboardEvent(on::KeyboardEvent),
TouchEvent(on::TouchEvent),
MouseEvent(on::MouseEvent),
AnimationEvent(on::AnimationEvent),
ClipboardEvent(on::ClipboardEvent),
CompositionEvent(on::CompositionEvent),
FocusEvent(on::FocusEvent),
FormEvent(on::FormEvent),
SelectionEvent(on::SelectionEvent),
WheelEvent(on::WheelEvent),
MediaEvent(on::MediaEvent),
AnimationEvent(on::AnimationEvent),
TransitionEvent(on::TransitionEvent),
KeyboardEvent(on::KeyboardEvent),
GenericEvent(on::GenericEvent),
TouchEvent(on::TouchEvent),
ToggleEvent(on::ToggleEvent),
MediaEvent(on::MediaEvent),
MouseEvent(on::MouseEvent),
WheelEvent(on::WheelEvent),
SelectionEvent(on::SelectionEvent),
TransitionEvent(on::TransitionEvent),
PointerEvent(on::PointerEvent),
// ImageEvent(event_data::ImageEvent),
}
// ImageEvent(event_data::ImageEvent),
impl std::fmt::Debug for SyntheticEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -57,6 +67,7 @@ impl std::fmt::Debug for SyntheticEvent {
SyntheticEvent::ToggleEvent(_) => "ToggleEvent",
SyntheticEvent::MouseEvent(_) => "MouseEvent",
SyntheticEvent::PointerEvent(_) => "PointerEvent",
SyntheticEvent::GenericEvent(_) => "GenericEvent",
};
f.debug_struct("VirtualEvent").field("type", &name).finish()
@@ -71,18 +82,7 @@ pub mod on {
//! Arc allocation through "get_mut"
//!
//! React recently dropped support for re-using event allocation and just passes the real event along.
#![allow(unused)]
use bumpalo::boxed::Box as BumpBox;
use std::{any::Any, cell::RefCell, fmt::Debug, ops::Deref, rc::Rc};
use crate::{
innerlude::NodeFactory,
innerlude::{Attribute, ElementId, Listener, VNode},
};
use std::cell::Cell;
use super::SyntheticEvent;
use super::*;
macro_rules! event_directory {
( $(
@@ -409,12 +409,10 @@ pub mod on {
///
ontoggle
];
GenericEventInner(GenericEvent): [
];
}
pub struct GenericEvent(pub Rc<dyn GenericEventInner>);
pub trait GenericEventInner {
/// Return a reference to the raw event. User will need to downcast the event to the right platform-specific type.
fn raw_event(&self) -> &dyn Any;
+1 -1
View File
@@ -58,7 +58,7 @@ pub(crate) mod innerlude {
pub use crate::innerlude::{
format_args_f, html, rsx, Context, DiffInstruction, DioxusElement, DomEdit, DomTree, ElementId,
EventPriority, LazyNodes, MountType, Mutations, NodeFactory, Properties, ScopeId,
SuspendedContext, SyntheticEvent, TestDom, UiEvent, VNode, VirtualDom, FC,
SuspendedContext, SyntheticEvent, TestDom, UserEvent, VNode, VirtualDom, FC,
};
pub mod prelude {
+2 -17
View File
@@ -1,5 +1,6 @@
//! Instructions returned by the VirtualDOM on how to modify the Real DOM.
//!
//! This module contains an internal API to generate these instructions.
use crate::innerlude::*;
use std::any::Any;
@@ -102,30 +103,14 @@ impl<'a> Mutations<'a> {
let Attribute {
name,
value,
is_static,
is_volatile,
namespace,
} = attribute;
self.edits.push(SetAttribute {
field: name,
value,
ns: *namespace,
});
}
pub(crate) fn set_attribute_ns(&mut self, attribute: &'a Attribute, namespace: &'a str) {
let Attribute {
name,
value,
is_static,
is_volatile,
..
} = attribute;
self.edits.push(SetAttribute {
field: name,
value,
ns: Some(namespace),
ns: *namespace,
});
}
+4 -3
View File
@@ -97,7 +97,7 @@ pub struct EventChannel {
pub enum SchedulerMsg {
Immediate(ScopeId),
UiEvent(UiEvent),
UiEvent(UserEvent),
SubmitTask(FiberTask, u64),
ToggleTask(u64),
PauseTask(u64),
@@ -140,11 +140,11 @@ pub(crate) struct Scheduler {
// scheduler stuff
pub current_priority: EventPriority,
pub ui_events: VecDeque<UiEvent>,
pub ui_events: VecDeque<UserEvent>,
pub pending_immediates: VecDeque<ScopeId>,
pub pending_tasks: VecDeque<UiEvent>,
pub pending_tasks: VecDeque<UserEvent>,
pub garbage_scopes: HashSet<ScopeId>,
@@ -266,6 +266,7 @@ impl Scheduler {
SyntheticEvent::ToggleEvent(_) => {}
SyntheticEvent::MouseEvent(_) => {}
SyntheticEvent::PointerEvent(_) => {}
SyntheticEvent::GenericEvent(_) => {}
};
scope.call_listener(trigger.event, element);