Skip to content

Commit

Permalink
Add id to Document
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 16, 2024
1 parent e4b1369 commit ce50022
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/blitz-dom/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use selectors::{matching::QuirksMode, Element};
use slab::Slab;
use std::any::Any;
use std::collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque};
use std::sync::atomic::{AtomicUsize, Ordering};
use style::selector_parser::ServoElementSnapshot;
use style::servo::media_queries::FontMetricsProvider;
use style::servo_arc::Arc as ServoArc;
Expand Down Expand Up @@ -74,6 +75,8 @@ pub trait DocumentLike: AsRef<Document> + AsMut<Document> + Into<Document> + 'st
}

pub struct Document {
id: usize,

/// A bump-backed tree
///
/// Both taffy and stylo traits are implemented for this.
Expand Down Expand Up @@ -386,6 +389,9 @@ impl Document {
}

pub fn with_font_ctx(viewport: Viewport, mut font_ctx: FontContext) -> Self {
static ID_GENERATOR: AtomicUsize = AtomicUsize::new(1);

let id = ID_GENERATOR.fetch_add(1, Ordering::SeqCst);
let device = viewport.make_device();
let stylist = Stylist::new(device, QuirksMode::NoQuirks);
let snapshots = SnapshotMap::new();
Expand All @@ -404,6 +410,7 @@ impl Document {
.register_fonts(crate::BULLET_FONT.to_vec());

let mut doc = Self {
id,
guard,
nodes,
stylist,
Expand Down Expand Up @@ -442,6 +449,10 @@ impl Document {
&self.nodes
}

pub fn id(&self) -> usize {
self.id
}

pub fn get_node(&self, node_id: usize) -> Option<&Node> {
self.nodes.get(node_id)
}
Expand Down

0 comments on commit ce50022

Please sign in to comment.