Skip to content

Commit

Permalink
Rename raw_dom_data to data
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns committed Jan 20, 2025
1 parent 1893dc8 commit a69bf40
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/blitz-dom/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl BaseDocument {

if node.is_inline_root {
let inline_layout = &node
.raw_dom_data
.data
.downcast_element()
.unwrap()
.inline_layout_data
Expand Down
6 changes: 3 additions & 3 deletions packages/blitz-dom/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl BaseDocument {
pub fn toggle_radio(&mut self, radio_set_name: String, target_radio_id: usize) {
for i in 0..self.nodes.len() {
let node = &mut self.nodes[i];
if let Some(node_data) = node.raw_dom_data.downcast_element_mut() {
if let Some(node_data) = node.data.downcast_element_mut() {
if node_data.attr(local_name!("name")) == Some(&radio_set_name) {
let was_clicked = i == target_radio_id;
let Some(is_checked) = node_data.checkbox_input_checked_mut() else {
Expand Down Expand Up @@ -386,7 +386,7 @@ impl BaseDocument {
pub fn deep_clone_node(&mut self, node_id: usize) -> usize {
// Load existing node
let node = &self.nodes[node_id];
let data = node.raw_dom_data.clone();
let data = node.data.clone();
let children = node.children.clone();

// Create new node
Expand Down Expand Up @@ -1089,7 +1089,7 @@ impl BaseDocument {
return;
};

let is_html_or_body = node.raw_dom_data.downcast_element().is_some_and(|e| {
let is_html_or_body = node.data.downcast_element().is_some_and(|e| {
let tag = &e.name.local;
tag == "html" || tag == "body"
});
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-dom/src/events/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) fn handle_ime_event(doc: &mut BaseDocument, event: BlitzImeEvent) {
if let Some(node_id) = doc.focus_node_id {
let node = &mut doc.nodes[node_id];
let text_input_data = node
.raw_dom_data
.data
.downcast_element_mut()
.and_then(|el| el.text_input_data_mut());
if let Some(input_data) = text_input_data {
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-dom/src/events/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) fn handle_keypress(doc: &mut BaseDocument, target: usize, event: Blit

let node = &mut doc.nodes[node_id];
let text_input_data = node
.raw_dom_data
.data
.downcast_element_mut()
.and_then(|el| el.text_input_data_mut());

Expand Down
6 changes: 3 additions & 3 deletions packages/blitz-dom/src/events/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) fn handle_mousemove(
}

let node = &mut doc.nodes[target];
let Some(el) = node.raw_dom_data.downcast_element_mut() else {
let Some(el) = node.data.downcast_element_mut() else {
return false;
};

Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) fn handle_mousedown(doc: &mut BaseDocument, target: usize, x: f32, y:
}

let node = &mut doc.nodes[target];
let Some(el) = node.raw_dom_data.downcast_element_mut() else {
let Some(el) = node.data.downcast_element_mut() else {
return;
};

Expand Down Expand Up @@ -101,7 +101,7 @@ pub(crate) fn handle_click(doc: &mut BaseDocument, _target: usize, x: f32, y: f3
while let Some(hit) = maybe_hit {
let node = &mut doc.nodes[hit.node_id];

let Some(el) = node.raw_dom_data.downcast_element_mut() else {
let Some(el) = node.data.downcast_element_mut() else {
maybe_hit = parent_hit(node, x, y);
continue;
};
Expand Down
22 changes: 11 additions & 11 deletions packages/blitz-dom/src/layout/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ pub(crate) fn collect_layout_children(

flush_pseudo_elements(doc, container_node_id);

if let Some(el) = doc.nodes[container_node_id].raw_dom_data.downcast_element() {
if let Some(el) = doc.nodes[container_node_id].data.downcast_element() {
// Handle text inputs
let tag_name = el.name.local.as_ref();
if matches!(tag_name, "input" | "textarea") {
let type_attr: Option<&str> = doc.nodes[container_node_id]
.raw_dom_data
.data
.downcast_element()
.and_then(|el| el.attr(local_name!("type")));
if tag_name == "textarea" {
Expand Down Expand Up @@ -134,7 +134,7 @@ pub(crate) fn collect_layout_children(
}

let container_display = doc.nodes[container_node_id].display_style().unwrap_or(
match doc.nodes[container_node_id].raw_dom_data.kind() {
match doc.nodes[container_node_id].data.kind() {
NodeKind::AnonymousBlock => Display::Block,
_ => Display::Inline,
},
Expand Down Expand Up @@ -191,7 +191,7 @@ pub(crate) fn collect_layout_children(
let (inline_layout, ilayout_children) = build_inline_layout(doc, container_node_id);
doc.nodes[container_node_id].is_inline_root = true;
doc.nodes[container_node_id]
.raw_dom_data
.data
.downcast_element_mut()
.unwrap()
.inline_layout_data = Some(Box::new(inline_layout));
Expand Down Expand Up @@ -234,7 +234,7 @@ pub(crate) fn collect_layout_children(
.map(|child_id| &doc.nodes[child_id])
.any(|child| {
let display = child.display_style().unwrap_or(Display::inline());
let node_kind = child.raw_dom_data.kind();
let node_kind = child.data.kind();
display.inside() == DisplayInside::Contents || node_kind == NodeKind::Text
});

Expand Down Expand Up @@ -262,7 +262,7 @@ pub(crate) fn collect_layout_children(
let (table_context, tlayout_children) = build_table_context(doc, container_node_id);
doc.nodes[container_node_id].is_table_root = true;
doc.nodes[container_node_id]
.raw_dom_data
.data
.downcast_element_mut()
.unwrap()
.node_specific_data = NodeSpecificData::TableRoot(Arc::new(table_context));
Expand Down Expand Up @@ -571,7 +571,7 @@ fn collect_complex_layout_children(

doc.iter_children_and_pseudos_mut(container_node_id, |child_id, doc| {
// Get node kind (text, element, comment, etc)
let child_node_kind = doc.nodes[child_id].raw_dom_data.kind();
let child_node_kind = doc.nodes[child_id].data.kind();

// Get Display style. Default to inline because nodes without styles are probably text nodes
let contains_block = doc.nodes[child_id].is_or_contains_block();
Expand All @@ -585,7 +585,7 @@ fn collect_complex_layout_children(
child_display.outside()
};

let is_whitespace_node = match &doc.nodes[child_id].raw_dom_data {
let is_whitespace_node = match &doc.nodes[child_id].data {
NodeData::Text(data) => data.content.chars().all(|c| c.is_ascii_whitespace()),
_ => false,
};
Expand Down Expand Up @@ -671,7 +671,7 @@ fn create_text_editor(doc: &mut BaseDocument, input_element_id: usize, is_multil
.map(|s| stylo_to_parley::style(s))
.unwrap_or_default();

let element = &mut node.raw_dom_data.downcast_element_mut().unwrap();
let element = &mut node.data.downcast_element_mut().unwrap();
if !matches!(element.node_specific_data, NodeSpecificData::TextInput(_)) {
let mut text_input_data = TextInputData::new(is_multiline);
let editor = &mut text_input_data.editor;
Expand All @@ -694,7 +694,7 @@ fn create_text_editor(doc: &mut BaseDocument, input_element_id: usize, is_multil
fn create_checkbox_input(doc: &mut BaseDocument, input_element_id: usize) {
let node = &mut doc.nodes[input_element_id];

let element = &mut node.raw_dom_data.downcast_element_mut().unwrap();
let element = &mut node.data.downcast_element_mut().unwrap();
if !matches!(
element.node_specific_data,
NodeSpecificData::CheckboxInput(_)
Expand Down Expand Up @@ -839,7 +839,7 @@ pub(crate) fn build_inline_layout(
.unwrap_or(collapse_mode);
builder.set_white_space_mode(collapse_mode);

match &node.raw_dom_data {
match &node.data {
NodeData::Element(element_data) | NodeData::AnonymousBlock(element_data) => {
// Hide hidden nodes
if let Some("hidden" | "") = element_data.attr(local_name!("hidden")) {
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-dom/src/layout/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl BaseDocument {

// Take inline layout to satisfy borrow checker
let mut inline_layout = self.nodes[node_id]
.raw_dom_data
.data
.downcast_element_mut()
.unwrap()
.take_inline_layout()
Expand Down Expand Up @@ -230,7 +230,7 @@ impl BaseDocument {

// Put layout back
self.nodes[node_id]
.raw_dom_data
.data
.downcast_element_mut()
.unwrap()
.inline_layout_data = Some(inline_layout);
Expand Down
6 changes: 3 additions & 3 deletions packages/blitz-dom/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl LayoutPartialTree for BaseDocument {
let font_size = font_styles.map(|s| s.0);
let resolved_line_height = font_styles.map(|s| s.1);

match &mut node.raw_dom_data {
match &mut node.data {
NodeData::Text(data) => {
// With the new "inline context" architecture all text nodes should be wrapped in an "inline layout context"
// and should therefore never be measured individually.
Expand Down Expand Up @@ -280,7 +280,7 @@ impl LayoutPartialTree for BaseDocument {

if node.is_table_root {
let NodeSpecificData::TableRoot(context) = &tree.nodes[node_id.into()]
.raw_dom_data
.data
.downcast_element()
.unwrap()
.node_specific_data
Expand Down Expand Up @@ -428,7 +428,7 @@ impl PrintTree for BaseDocument {
let node = &self.node_from_id(node_id);
let style = &node.style;

match node.raw_dom_data {
match node.data {
NodeData::Document => "DOCUMENT",
// NodeData::Doctype { .. } => return "DOCTYPE",
NodeData::Text { .. } => node.node_debug_str().leak(),
Expand Down
30 changes: 15 additions & 15 deletions packages/blitz-dom/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Node {
pub paint_children: RefCell<Option<Vec<usize>>>,

/// Node type (Element, TextNode, etc) specific data
pub raw_dom_data: NodeData,
pub data: NodeData,

// This little bundle of joy is our style data from stylo and a lock guard that allows access to it
// TODO: See if guard can be hoisted to a higher level
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Node {
layout_children: RefCell::new(None),
paint_children: RefCell::new(None),

raw_dom_data: data,
data,
stylo_element_data: Default::default(),
selector_flags: AtomicRefCell::new(ElementSelectorFlags::empty()),
guard,
Expand Down Expand Up @@ -185,7 +185,7 @@ impl Node {
}

pub fn is_focussable(&self) -> bool {
self.raw_dom_data
self.data
.downcast_element()
.map(|el| el.is_focussable)
.unwrap_or(false)
Expand Down Expand Up @@ -793,42 +793,42 @@ impl Node {
}

pub fn is_element(&self) -> bool {
matches!(self.raw_dom_data, NodeData::Element { .. })
matches!(self.data, NodeData::Element { .. })
}

pub fn is_anonymous(&self) -> bool {
matches!(self.raw_dom_data, NodeData::AnonymousBlock { .. })
matches!(self.data, NodeData::AnonymousBlock { .. })
}

pub fn is_text_node(&self) -> bool {
matches!(self.raw_dom_data, NodeData::Text { .. })
matches!(self.data, NodeData::Text { .. })
}

pub fn element_data(&self) -> Option<&ElementNodeData> {
match self.raw_dom_data {
match self.data {
NodeData::Element(ref data) => Some(data),
NodeData::AnonymousBlock(ref data) => Some(data),
_ => None,
}
}

pub fn element_data_mut(&mut self) -> Option<&mut ElementNodeData> {
match self.raw_dom_data {
match self.data {
NodeData::Element(ref mut data) => Some(data),
NodeData::AnonymousBlock(ref mut data) => Some(data),
_ => None,
}
}

pub fn text_data(&self) -> Option<&TextNodeData> {
match self.raw_dom_data {
match self.data {
NodeData::Text(ref data) => Some(data),
_ => None,
}
}

pub fn text_data_mut(&mut self) -> Option<&mut TextNodeData> {
match self.raw_dom_data {
match self.data {
NodeData::Text(ref mut data) => Some(data),
_ => None,
}
Expand All @@ -837,7 +837,7 @@ impl Node {
pub fn node_debug_str(&self) -> String {
let mut s = String::new();

match &self.raw_dom_data {
match &self.data {
NodeData::Document => write!(s, "DOCUMENT"),
// NodeData::Doctype { name, .. } => write!(s, "DOCTYPE {name}"),
NodeData::Text(data) => {
Expand Down Expand Up @@ -886,7 +886,7 @@ impl Node {
.map(|style| style.clone_color())
.map(|color| color.to_css_string());

match &self.raw_dom_data {
match &self.data {
NodeData::Document => {}
NodeData::Comment => {}
NodeData::AnonymousBlock(_) => {}
Expand Down Expand Up @@ -966,7 +966,7 @@ impl Node {
}

fn write_text_content(&self, out: &mut String) {
match &self.raw_dom_data {
match &self.data {
NodeData::Text(data) => {
out.push_str(&data.content);
}
Expand All @@ -980,7 +980,7 @@ impl Node {
}

pub fn flush_style_attribute(&mut self) {
if let NodeData::Element(ref mut elem_data) = self.raw_dom_data {
if let NodeData::Element(ref mut elem_data) = self.data {
elem_data.flush_style_attribute(&self.guard);
}
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl std::fmt::Debug for Node {
.field("children", &self.children)
.field("layout_children", &self.layout_children.borrow())
// .field("style", &self.style)
.field("node", &self.raw_dom_data)
.field("node", &self.data)
.field("stylo_element_data", &self.stylo_element_data)
// .field("unrounded_layout", &self.unrounded_layout)
// .field("final_layout", &self.final_layout)
Expand Down
Loading

0 comments on commit a69bf40

Please sign in to comment.