Skip to content

Commit

Permalink
Rename RendererEvent to DomEvent
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns committed Jan 5, 2025
1 parent 2948274 commit eab1d17
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions packages/blitz-dom/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::events::{handle_event, HitResult, RendererEvent};
use crate::events::{handle_event, DomEvent, HitResult};
use crate::layout::construct::collect_layout_children;
use crate::node::{ImageData, NodeSpecificData, Status, TextBrush};
use crate::stylo_to_cursor_icon::stylo_to_cursor_icon;
Expand Down Expand Up @@ -76,7 +76,7 @@ pub trait DocumentLike: AsRef<Document> + AsMut<Document> + Into<Document> + 'st
false
}

fn handle_event(&mut self, _event: RendererEvent) {
fn handle_event(&mut self, _event: DomEvent) {
// Default implementation does nothing
}

Expand Down Expand Up @@ -174,7 +174,7 @@ fn make_device(viewport: &Viewport) -> Device {
}

impl DocumentLike for Document {
fn handle_event(&mut self, event: RendererEvent) {
fn handle_event(&mut self, event: DomEvent) {
handle_event(self, event)
}
}
Expand Down
34 changes: 17 additions & 17 deletions packages/blitz-dom/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ pub(crate) use mouse::handle_click;
use crate::Document;
use winit::event::{Ime, KeyEvent, Modifiers};

pub(crate) fn handle_event(doc: &mut Document, event: RendererEvent) {
pub(crate) fn handle_event(doc: &mut Document, event: DomEvent) {
let target_node_id = event.target;

match event.data {
EventData::MouseDown { .. } | EventData::MouseUp { .. } => {}
EventData::Hover => {}
EventData::Click { x, y, .. } => {
DomEventData::MouseDown { .. } | DomEventData::MouseUp { .. } => {}
DomEventData::Hover => {}
DomEventData::Click { x, y, .. } => {
handle_click(doc, target_node_id, x, y);
}
EventData::KeyPress { event, mods } => {
DomEventData::KeyPress { event, mods } => {
handle_keypress(doc, target_node_id, event, mods);
}
EventData::Ime(ime_event) => {
DomEventData::Ime(ime_event) => {
handle_ime_event(doc, ime_event);
}
}
Expand All @@ -32,20 +32,20 @@ pub struct EventListener {
}

#[derive(Debug, Clone)]
pub struct RendererEvent {
pub struct DomEvent {
pub target: usize,
pub data: EventData,
pub data: DomEventData,
}

impl RendererEvent {
impl DomEvent {
/// Returns the name of the event ("click", "mouseover", "keypress", etc)
pub fn name(&self) -> &'static str {
self.data.name()
}
}

#[derive(Debug, Clone)]
pub enum EventData {
pub enum DomEventData {
MouseDown { x: f32, y: f32, mods: Modifiers },
MouseUp { x: f32, y: f32, mods: Modifiers },
Click { x: f32, y: f32, mods: Modifiers },
Expand All @@ -54,15 +54,15 @@ pub enum EventData {
Hover,
}

impl EventData {
impl DomEventData {
pub fn name(&self) -> &'static str {
match self {
EventData::MouseDown { .. } => "mousedown",
EventData::MouseUp { .. } => "mouseup",
EventData::Click { .. } => "click",
EventData::KeyPress { .. } => "keypress",
EventData::Ime { .. } => "input",
EventData::Hover => "mouseover",
DomEventData::MouseDown { .. } => "mousedown",
DomEventData::MouseUp { .. } => "mouseup",
DomEventData::Click { .. } => "click",
DomEventData::KeyPress { .. } => "keypress",
DomEventData::Ime { .. } => "input",
DomEventData::Hover => "mouseover",
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/blitz-dom/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use taffy::{
use url::Url;
use winit::event::Modifiers;

use crate::events::{EventData, EventListener, HitResult};
use crate::events::{DomEventData, EventListener, HitResult};
use crate::layout::table::TableContext;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -1070,12 +1070,12 @@ impl Node {
}

/// Creates a synteh
pub fn synthetic_click_event(&self, mods: Modifiers) -> EventData {
pub fn synthetic_click_event(&self, mods: Modifiers) -> DomEventData {
let absolute_position = self.absolute_position(0.0, 0.0);
let x = absolute_position.x + (self.final_layout.size.width / 2.0);
let y = absolute_position.y + (self.final_layout.size.height / 2.0);

EventData::Click { x, y, mods }
DomEventData::Click { x, y, mods }
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-html/src/html_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::DocumentHtmlParser;

use blitz_dom::{
events::RendererEvent, net::Resource, Document, DocumentLike, FontContext, DEFAULT_CSS,
events::DomEvent, net::Resource, Document, DocumentLike, FontContext, DEFAULT_CSS,
};
use blitz_traits::{navigation::NavigationProvider, net::SharedProvider, ColorScheme, Viewport};

Expand All @@ -29,7 +29,7 @@ impl From<HtmlDocument> for Document {
}
}
impl DocumentLike for HtmlDocument {
fn handle_event(&mut self, event: RendererEvent) {
fn handle_event(&mut self, event: DomEvent) {
self.inner.as_mut().handle_event(event)
}
}
Expand Down
20 changes: 10 additions & 10 deletions packages/blitz-shell/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::event::{create_waker, BlitzEvent};
use blitz_dom::events::{EventData, RendererEvent};
use blitz_dom::events::{DomEvent, DomEventData};
use blitz_dom::{DocumentLike, DocumentRenderer};
use blitz_traits::{ColorScheme, Devtools, Viewport};
use winit::keyboard::PhysicalKey;
Expand Down Expand Up @@ -255,9 +255,9 @@ impl<Doc: DocumentLike, Rend: DocumentRenderer> View<Doc, Rend> {

// If we hit a node, then we collect the node to its parents, check for listeners, and then
// call those listeners
self.doc.handle_event(RendererEvent {
self.doc.handle_event(DomEvent {
target: node_id,
data: EventData::MouseDown {
data: DomEventData::MouseDown {
x: self.dom_mouse_pos.0,
y: self.dom_mouse_pos.1,
mods: self.keyboard_modifiers,
Expand All @@ -276,9 +276,9 @@ impl<Doc: DocumentLike, Rend: DocumentRenderer> View<Doc, Rend> {

// If we hit a node, then we collect the node to its parents, check for listeners, and then
// call those listeners
self.doc.handle_event(RendererEvent {
self.doc.handle_event(DomEvent {
target: node_id,
data: EventData::MouseUp {
data: DomEventData::MouseUp {
x: self.dom_mouse_pos.0,
y: self.dom_mouse_pos.1,
mods: self.keyboard_modifiers,
Expand Down Expand Up @@ -309,9 +309,9 @@ impl<Doc: DocumentLike, Rend: DocumentRenderer> View<Doc, Rend> {
if button == "left" {
// If we hit a node, then we collect the node to its parents, check for listeners, and then
// call those listeners
self.doc.handle_event(RendererEvent {
self.doc.handle_event(DomEvent {
target: node_id,
data: EventData::Click {
data: DomEventData::Click {
x: self.dom_mouse_pos.0,
y: self.dom_mouse_pos.1,
mods: self.keyboard_modifiers,
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<Doc: DocumentLike, Rend: DocumentRenderer> View<Doc, Rend> {
// Text / keyboard events
WindowEvent::Ime(ime_event) => {
if let Some(target) = self.doc.as_ref().get_focussed_node_id() {
self.doc.handle_event(RendererEvent { target, data: EventData::Ime(ime_event) });
self.doc.handle_event(DomEvent { target, data: DomEventData::Ime(ime_event) });
self.request_redraw();
}
},
Expand Down Expand Up @@ -424,9 +424,9 @@ impl<Doc: DocumentLike, Rend: DocumentRenderer> View<Doc, Rend> {
}
_ => {
if let Some(focus_node_id) = self.doc.as_ref().get_focussed_node_id() {
self.doc.handle_event(RendererEvent {
self.doc.handle_event(DomEvent {
target: focus_node_id,
data: EventData::KeyPress { event, mods: self.keyboard_modifiers }
data: DomEventData::KeyPress { event, mods: self.keyboard_modifiers }
});
self.request_redraw();
}
Expand Down
28 changes: 14 additions & 14 deletions packages/dioxus-native/src/dioxus_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{any::Any, collections::HashMap, rc::Rc, sync::Arc};

use blitz_dom::{
events::{EventData, RendererEvent},
events::{DomEvent, DomEventData},
local_name, namespace_url,
net::Resource,
node::NodeSpecificData,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl DocumentLike for DioxusDocument {
true
}

fn handle_event(&mut self, event: blitz_dom::events::RendererEvent) {
fn handle_event(&mut self, event: blitz_dom::events::DomEvent) {
// Collect the nodes into a chain by traversing upwards
// This is important so the "capture" phase can be implemented
let mut next_node_id = Some(event.target);
Expand Down Expand Up @@ -105,7 +105,7 @@ impl DocumentLike for DioxusDocument {
let mut stop_propagation = false;

match &event.data {
EventData::MouseDown { .. } => {
DomEventData::MouseDown { .. } => {
let click_event_data = wrap_event_data(NativeClickData);

for &DxNodeIds { node_id, dioxus_id } in chain.iter() {
Expand All @@ -119,7 +119,7 @@ impl DocumentLike for DioxusDocument {
}

if !prevent_default {
let default_event = RendererEvent {
let default_event = DomEvent {
target: node_id,
data: renderer_event.data.clone(),
};
Expand All @@ -131,7 +131,7 @@ impl DocumentLike for DioxusDocument {
}
}
}
EventData::MouseUp { .. } => {
DomEventData::MouseUp { .. } => {
let click_event_data = wrap_event_data(NativeClickData);

for &DxNodeIds {
Expand All @@ -148,7 +148,7 @@ impl DocumentLike for DioxusDocument {
}

if !prevent_default {
let default_event = RendererEvent {
let default_event = DomEvent {
target: node_id,
data: renderer_event.data.clone(),
};
Expand All @@ -160,7 +160,7 @@ impl DocumentLike for DioxusDocument {
}
}
}
EventData::Click { .. } => {
DomEventData::Click { .. } => {
// look for the data-dioxus-id attribute on the element
// todo: we might need to walk upwards to find the first element with a data-dioxus-id attribute

Expand All @@ -179,7 +179,7 @@ impl DocumentLike for DioxusDocument {
stop_propagation |= !click_event.propagates();

if !prevent_default {
let default_event = RendererEvent {
let default_event = DomEvent {
target: node_id,
data: renderer_event.data.clone(),
};
Expand Down Expand Up @@ -214,15 +214,15 @@ impl DocumentLike for DioxusDocument {

// Handle default DOM event
if click_event.default_action_enabled() {
let &EventData::Click { mods, .. } = &renderer_event.data else {
let &DomEventData::Click { mods, .. } = &renderer_event.data else {
unreachable!();
};
let input_click_data = self
.inner
.get_node(node_id)
.unwrap()
.synthetic_click_event(mods);
let default_event = RendererEvent {
let default_event = DomEvent {
target: node_id,
data: input_click_data,
};
Expand Down Expand Up @@ -261,7 +261,7 @@ impl DocumentLike for DioxusDocument {
}
}
}
EventData::KeyPress {
DomEventData::KeyPress {
event: wevent,
mods,
} => {
Expand Down Expand Up @@ -292,7 +292,7 @@ impl DocumentLike for DioxusDocument {

if !prevent_default {
// Handle default DOM event
let default_event = RendererEvent {
let default_event = DomEvent {
target: node_id,
data: renderer_event.data.clone(),
};
Expand Down Expand Up @@ -331,8 +331,8 @@ impl DocumentLike for DioxusDocument {
}
}
// TODO: Implement IME and Hover events handling
EventData::Ime(_) => {}
EventData::Hover => {}
DomEventData::Ime(_) => {}
DomEventData::Hover => {}
}

if !prevent_default {
Expand Down

0 comments on commit eab1d17

Please sign in to comment.