pub struct Node {
pub node_type: NodeType,
pub children: Vec<Node>,
pub node_idx: Option<usize>,
pub features_hash: (u64, u64),
pub children_shape_hash: (u64, u64),
pub subtree_hash: (u64, u64),
}Fields§
§node_type: NodeType§children: Vec<Node>§node_idx: Option<usize>§features_hash: (u64, u64)スタイル計算メモ化(css::style_memo)用の要素単体の特徴ハッシュ(タグ・id・class・属性)。
生成時および属性書き換え時に計算しておき、style_memo::node_features が
1 回の再レイアウトで要素あたり 3〜4 回 BTreeMap を再走査するのを防ぐ(TODO P5a)。
children_shape_hash: (u64, u64)直接の子ノード列の形状(タグ・テキスト空判定・要素数)の 128 ビットハッシュ(TODO P5a)。
subtree_hash: (u64, u64)自身の features_hash と子孫全体の subtree_hash を畳み込んだ 128 ビットハッシュ(TODO P5a)。
:has() や部分木スタイルメモ(SubtreeStyleMemo)の O(1) ルックアップに使用する。
Implementations§
Source§impl Node
impl Node
const MAX_SEARCH_DEPTH: usize = 256
pub fn new_text(text: String) -> Self
Sourcepub fn new_comment(text: String) -> Self
pub fn new_comment(text: String) -> Self
コメントを表すノード(#comment 要素。文字は属性 data)。parse_html_document の木だけに現れる。
Sourcepub fn new_doctype(
name: Option<String>,
public_id: Option<String>,
system_id: Option<String>,
) -> Self
pub fn new_doctype( name: Option<String>, public_id: Option<String>, system_id: Option<String>, ) -> Self
DOCTYPE を表すノード(#doctype 要素。属性 name・publicid・systemid。無いものは属性なし)。
pub fn new_element(name: String, attrs: BTreeMap<String, String>) -> Self
pub fn new_element_direct( name: String, attrs: BTreeMap<String, String>, id: Option<String>, classes: Vec<String>, ) -> Self
Sourcepub fn update_dependent_hashes(&mut self)
pub fn update_dependent_hashes(&mut self)
直接の子ノードが最新ハッシュを持つ前提で自身の children_shape_hash と subtree_hash を O(children.len()) で更新する。
Sourcepub fn refresh_dependent_hashes(&mut self)
pub fn refresh_dependent_hashes(&mut self)
子孫からボトムアップで children_shape_hash と subtree_hash を再計算する。
Sourcepub fn refresh_features_hash(&mut self)
pub fn refresh_features_hash(&mut self)
node_type の属性等を直接書き換えた後に自身と全子孫の features_hash / children_shape_hash / subtree_hash を再計算する。
Sourcepub fn empty_root() -> Self
pub fn empty_root() -> Self
子を持たない html ルート要素を返す。parse_html が返すルートと同じ形状で、
DOM ブリッジを真実源とするインクリメンタル再レイアウト時、HTML パースを
省略するためのプレースホルダとして使う(描画ツリーはブリッジから再構築される)。
Sourcepub fn get_attribute(&self, name: &str) -> Option<&str>
pub fn get_attribute(&self, name: &str) -> Option<&str>
要素の属性値を取得する。
Sourcepub fn dataset(&self) -> BTreeMap<String, String>
pub fn dataset(&self) -> BTreeMap<String, String>
W3C HTML5 §3.2.6.2 / DOMStringMap: data-* 属性から camelCase の dataset マップを抽出する。
Sourcepub fn set_dataset_property(
&mut self,
prop: &str,
value: &str,
) -> Result<String, DatasetError>
pub fn set_dataset_property( &mut self, prop: &str, value: &str, ) -> Result<String, DatasetError>
W3C HTML5 §3.2.6.2: dataset プロパティを設定し、対応する data-* 属性を更新する。
Sourcepub fn remove_dataset_property(
&mut self,
prop: &str,
) -> Result<Option<String>, DatasetError>
pub fn remove_dataset_property( &mut self, prop: &str, ) -> Result<Option<String>, DatasetError>
W3C HTML5 §3.2.6.2: dataset プロパティを削除し、対応する data-* 属性を削除する。
Sourcepub fn get_element_by_id(&self, target_id: &str) -> Option<&Node>
pub fn get_element_by_id(&self, target_id: &str) -> Option<&Node>
ID による要素探索(深さ優先・最初に一致した参照を返す)。
fn get_element_by_id_depth( &self, target_id: &str, depth: usize, ) -> Option<&Node>
Sourcepub fn get_elements_by_class_name<'a>(
&'a self,
target_class: &str,
out: &mut Vec<&'a Node>,
)
pub fn get_elements_by_class_name<'a>( &'a self, target_class: &str, out: &mut Vec<&'a Node>, )
クラス名による要素収集(深さ優先・ゼロアロケーション走査)。
fn get_elements_by_class_name_depth<'a>( &'a self, target_class: &str, out: &mut Vec<&'a Node>, depth: usize, )
Sourcepub fn get_elements_by_tag_name<'a>(
&'a self,
target_tag: &str,
out: &mut Vec<&'a Node>,
)
pub fn get_elements_by_tag_name<'a>( &'a self, target_tag: &str, out: &mut Vec<&'a Node>, )
タグ名による要素収集(大文字小文字無視)。
fn get_elements_by_tag_name_depth<'a>( &'a self, target_tag: &str, out: &mut Vec<&'a Node>, depth: usize, )
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
ツリー内の全テキストを連結して取得する(単一バッファ追記方式)。