Replies: 2 comments
-
I like this general approach. Don't use an
Still figuring out how to navigate the Gecko code base. But ultimately I wouldn't be surprised if we end up needing a mutable ref-counted reference to the document in a field that is stored in nodes at some point. There might be a cleaner alternative available in Rust that I'm not aware of. |
Beta Was this translation helpful? Give feedback.
-
While planning out some of my future changes, that's what I think is also needed. Some operations require context that a node by itself doesn't have (the example I keep giving is I'm thinking maybe we require a document pointer whenever creating a node which is passed down to any of its dependencies that also require it (such as an HTML element, in this case.) I have not had time yet to fully explore this but it's the first thing on my "to do" right now |
Beta Was this translation helpful? Give feedback.
-
Right now we have
document.set_named_id
to add a named ID to the DOM to allow for querying (thinkdocument.getElementById()
) and this will also modify the underlying ID attribute in the element.However, it is also possible to directly modify
node.attributes.insert("id", "somevalue")
which does not touch the DOM tree at all and this can cause problems (e.g., trying to query the DOM for the IDsomevalue
would return nothing in this case)To fix this problem, I wanted to modify the
ElementData.ElementAttributes.insert
method to handle the special cases, such asAnd then we can remove the
set_named_id
method from theDocument
. That way there's no possible confusion about how to "properly" modify an attribute and MUST be done via a node's attribute insert method.However, here's where the design problem comes in and want some advice. To implement it like above, we'd be introducing a lot of shared pointers, and ideally I wouldn't want these optional, so you must provide a document when creating a node, and must provide a node when creating an ElementData. But this might complicate things and I'm not sure what some good alternatives are. One other alternative I can think of is having every substruct contain a pointer to the
Document
, at least that would get rid of the huge chain ofself.element_data.node.document
.It's messy because ElementAttribute is deeply nested, however we would eventually need a reference to
Document
within node for some other things coming up anyways (specifically thinking ofinsert_before
) and I think for some things Joshua was working on.Anyways, long rambling aside, does anyone have a good idea how to handle this?
We could avoid this by traversing the tree to find the ID (and soon, class names) but I didn't really like that idea which is why I introduced the
named_id_elements
map in the first place.Beta Was this translation helpful? Give feedback.
All reactions