Skip to main content

DomBridge

Struct DomBridge 

Source
pub struct DomBridge {
Show 73 fields pub nodes: Vec<DomNode>, pub extra_docs: usize, pub attr_nodes: BTreeMap<(usize, String), usize>, pub has_attr_nodes: bool, pub attr_order: BTreeMap<usize, Vec<String>>, pub ns_attrs: BTreeMap<usize, Vec<(String, String, String)>>, pub attr_ns_order: BTreeMap<usize, Vec<(Option<String>, String)>>, pub main_doctype: Option<usize>, pub ranges: BTreeMap<u32, RangeRec>, pub suppress_range_hook: bool, pub next_range_id: u32, pub node_iters: BTreeMap<u32, NiRec>, pub next_ni_id: u32, pub html_collections: Vec<HtmlCollectionKind>, pub html_collection_expandos: BTreeMap<usize, BTreeMap<String, Value>>, pub static_node_lists: Vec<Vec<usize>>, pub has_shells: bool, pub node_doc: BTreeMap<usize, usize>, pub template_owner_docs: BTreeMap<Option<usize>, usize>, pub quirks_mode: bool, pub doc_impls: BTreeMap<usize, Value>, pub listeners: Vec<Listener>, pub dirty: bool, pub id_dirty: bool, pub structural_dirty: bool, pub dirty_causes: BTreeMap<String, u32>, pub pending_style_updates: Vec<(usize, String, String)>, pub pending_text_updates: Vec<(usize, usize, String)>, pub js_created_scripts: BTreeSet<usize>, pub pending_dynamic_scripts: Vec<usize>, pub js_created_links: BTreeSet<usize>, pub pending_dynamic_links: Vec<usize>, pub pending_post_connection: Vec<usize>, pub frames_pending_setup: BTreeSet<usize>, pub frames_dirty: bool, pub frames_check: bool, pub expandos: BTreeMap<usize, BTreeMap<String, Value>>, pub node_accessors: BTreeMap<usize, BTreeMap<String, (Option<Value>, Option<Value>)>>, pub node_protos: BTreeMap<usize, ObjRef>, pub ce_queue: Vec<CeEvent>, pub built: bool, pub rects: BTreeMap<usize, (i32, i32, i32, i32)>, pub measured: BTreeMap<usize, (i32, i32)>, pub border_widths: BTreeMap<usize, (i32, i32, i32, i32)>, pub computed_styles: BTreeMap<usize, Rc<BTreeMap<String, String>>>, pub scroll_tops: BTreeMap<usize, i32>, pub scroll_lefts: BTreeMap<usize, i32>, pub scroll_heights: BTreeMap<usize, i32>, pub scroll_widths: BTreeMap<usize, i32>, pub next_listener_id: u64, pub mut_observers: Vec<MutObsReg>, pub mut_records: Vec<(u32, MutRec)>, pub next_mut_obs_id: u32, pub mut_microtask_pending: bool, pub io_observers: Vec<IntersectionObserverReg>, pub next_io_obs_id: u32, pub ro_observers: Vec<ResizeObserverReg>, pub next_ro_obs_id: u32, pub pointer_captures: BTreeSet<(usize, i32)>, pub focused_idx: Option<usize>, pub pending_scroll_abs_y: Option<i32>, pub pending_scroll_by_y: Option<i32>, pub on_handlers: BTreeMap<(usize, String), Value>, pub selection: Option<Value>, pub custom_elements: CustomElementRegistry, pub shadow_tree: ShadowTreeRegistry, pub pending_parent_messages: Vec<(Value, String)>, pub pending_child_messages: Vec<(String, Value, String)>, pub iframe_content_windows: BTreeMap<usize, Rc<RefCell<Obj>>>, pub iframe_docs: BTreeMap<usize, usize>, pub iframe_doc_to_elem: BTreeMap<usize, usize>, pub builtin_global_names: Vec<String>, pub css_referenced_attrs: Option<BTreeSet<String>>,
}
Expand description

DOM ブリッジ本体。JsRuntime が Rc<RefCell<>> で保持し、レンダラと共有する。

Fields§

§nodes: Vec<DomNode>§extra_docs: usize

#document ノード(new Document()・createHTMLDocument など主文書以外の Document)の数。 0 のあいだは所有文書の管理(node_doc)に一切触れない(主文書だけのページの速い経路を変えない)。

§attr_nodes: BTreeMap<(usize, String), usize>

Attr ノード(#attr。builtins/dom_attr.rs)の表: (要素, 属性の修飾名) → ノード。要素に付いているものだけ。

§has_attr_nodes: bool

#attr ノードを作ったか(作るまで Attr のメンバーの解決へは入らない)。

§attr_order: BTreeMap<usize, Vec<String>>

属性の挿入順(【2026-11-20】仕様は挿入順。attrs は BTreeMap(名前順)のまま、順序が名前順(id・class を先頭)と 食い違うノードだけ別に持つ疎な表。無いノードは既定の並び。描画用の木・CSS の照合・特徴ハッシュは見ない)。

§ns_attrs: BTreeMap<usize, Vec<(String, String, String)>>

名前空間つき属性(ns.is_some() のみ)。要素 → (ns, qname, value) のリスト。 HTML の style・id・class・on* 等の非名前空間属性と完全に分離する。

§attr_ns_order: BTreeMap<usize, Vec<(Option<String>, String)>>

名前空間つき属性を持つ要素の、全属性 (ns, qname) 挿入順リスト(ns_attrs が空でない要素のみ)。

§main_doctype: Option<usize>

主文書の <!DOCTYPE> のノード(親の無い #doctype。ブラウザ用の解析は DOCTYPE を木に入れないので、ふだんは None。 仕様どおりの木で組むホスト実行器(tests/wpt_dom_host)が set_main_doctype で入れる)。

§ranges: BTreeMap<u32, RangeRec>

生きている Range(builtins/range.rs)。DOM の変更のたびに境界点を直す。空のあいだは何もしない。

§suppress_range_hook: bool

replace_data が set_text_content の中の Range の更新を止めるための印。

§next_range_id: u32§node_iters: BTreeMap<u32, NiRec>

生きている NodeIterator(createNodeIterator が作ったものだけ。空のあいだは取り外しの処理に何も足さない)。

§next_ni_id: u32§html_collections: Vec<HtmlCollectionKind>

生きている HTMLCollection の定義(HOST_HTMLCOLLECTION の id が添字)。

§html_collection_expandos: BTreeMap<usize, BTreeMap<String, Value>>

HTMLCollection インスタンスへの expando プロパティ。

§static_node_lists: Vec<Vec<usize>>

静的 NodeList(querySelectorAll 等、HOST_STATIC_NODELIST の id が添字)。

§has_shells: bool

補った <head>/<body> の殻(ensure_shells)を作ったか。描画用の木・走査順では殻を飛ばす(_implicit 属性の要素)。

§node_doc: BTreeMap<usize, usize>

主文書以外の文書が所有するノード → その #document ノードの添字。載っていないノードは主文書のもの。

§template_owner_docs: BTreeMap<Option<usize>, usize>

文書(None は主文書)→ <template>.content 用の所有者 #document ノード。

§quirks_mode: bool

文書が Quirks モードで解析されたか(WPT ホストが設定)。

§doc_impls: BTreeMap<usize, Value>

#document ノード → その document.implementation(同一性を保つためのキャッシュ)。

§listeners: Vec<Listener>§dirty: bool

JS が DOM を変更したフラグ。ホストはこれを見て再レイアウトする。

§id_dirty: bool

id 属性や接続状態が変わったか(window[id] 同期用)。

§structural_dirty: bool

set_style 以外の DOM 変更(ノード追加/削除/クラス/テキスト/属性変更等)や set_css_text があったか

§dirty_causes: BTreeMap<String, u32>

組み直しを招いた変更の、原因ごとの回数(TODO P4 a。note_dirty_cause)。

§pending_style_updates: Vec<(usize, String, String)>

set_style で変更されたプロパティの一覧: (node_idx, prop_kebab, new_val)

§pending_text_updates: Vec<(usize, usize, String)>

単一テキスト子の軽量置換一覧: (elem_node_idx, text_node_idx, new_text)

§js_created_scripts: BTreeSet<usize>

JS が createElement('script') で作った <script>(文書へ挿入されたら実行する)。

§pending_dynamic_scripts: Vec<usize>

文書へ挿入されて実行待ちの <script>(ホストが取得・実行し load/error を発火する)。 【2026-10-17】動的に挿入した script を実行する仕組みが無く、YouTube の埋め込み等 (スクリプトを挿入して onload を待つ)が先へ進まなかった。

§js_created_links: BTreeSet<usize>

JS が createElement('link') で作った <link>(文書へ挿入されたら load を送る)。

§pending_dynamic_links: Vec<usize>

文書へ挿入されて load 待ちの <link rel="stylesheet">。 【2026-11-04】挿入した <link> に load を一度も送っておらず、YouTube の kevlar がプレーヤーの CSS (player-css)の load を Promise.all で待つ所(FXM)で止まった。従来の Promise.all は未決の要素を 即座に完了扱いにしていたので素通りしていた(TODO B0 の調査で判明)。

§pending_post_connection: Vec<usize>

木の操作の後に「post-connection steps」を走らせる要素(ツリー順。<script>・<iframe>・<frame>)。 挿入の DOM 変更をすべて終えてから、JS 側(Interp::run_post_connection_steps)が先頭から 1 つずつ処理する (HTML 標準・DOM 標準 §4.2.3 insert の手順 11。2026-11-27 Wave L)。

§frames_pending_setup: BTreeSet<usize>

接続されたが post-connection steps がまだの <iframe>/<frame>(その間は contentWindow が null)。

§frames_dirty: bool

子フレーム(閲覧コンテキスト)の集合が変わり、window.length・window[i] を直す必要があるか。

§frames_check: bool

子フレームを持ちうる部分木が外れたかもしれない(次の run_post_connection_steps で外れた枠を捨てる)。

§expandos: BTreeMap<usize, BTreeMap<String, Value>>

要素に JS が付けた独自プロパティ(expando。el.foo = 1、組込みメソッドの上書きも含む)。 【2026-10-17】要素のハンドル(Obj::dom)はアクセスのたびに作り直すため、未知の プロパティへの代入は捨てられていた。YouTube の player は API メソッドを要素自身に付け、 埋め込み側は getElementById(...).getApiInterface で準備完了を待つ。

§node_accessors: BTreeMap<usize, BTreeMap<String, (Option<Value>, Option<Value>)>>

Object.defineProperty(element, key, {get, set}) で要素に付けたアクセサ(ハンドルは 毎回作り直されるので要素側に持つ)。キー → (getter, setter)。

§node_protos: BTreeMap<usize, ObjRef>

昇格済みのカスタム要素の原型(要素の添字 → 定義したクラスの prototype)。 【2026-10-20】要素のハンドルはアクセスのたびに作り直すので、原型は要素側に持たせる。

§ce_queue: Vec<CeEvent>

カスタム要素の反応(昇格・connected/disconnected)の待ち行列。 DOM の変更(notify_child_list・複製)が積み、Interp::process_ce_reactions が処理する。

§built: bool

構築済みかどうか(未構築なら getElementById 等は空を返す)。

§rects: BTreeMap<usize, (i32, i32, i32, i32)>

レイアウト後の要素矩形 (x, y, w, h)(ページ座標)。getBoundingClientRect / offsetWidth 等が参照。レンダラが flatten 後に populate する。

§measured: BTreeMap<usize, (i32, i32)>

JS が寸法(clientWidth/offsetWidth/getBoundingClientRect 等)を読んだ要素と、その時の (幅, 高さ)。 次のレイアウトで大きさが変わっていたら、測り直しを促す resize を出す(Runtime::notify_layout_settled)。

§border_widths: BTreeMap<usize, (i32, i32, i32, i32)>

レイアウト後の各要素のborder幅 (top, right, bottom, left)。

§computed_styles: BTreeMap<usize, Rc<BTreeMap<String, String>>>

算出スタイル(カスケード後の specified_values、kebab-case キー)。 getComputedStyle が参照。レンダラがスタイル適用後に populate する。 レイアウトの StyledNode::specified_values を写さずに共有する(2026-11-04)。

§scroll_tops: BTreeMap<usize, i32>

サブスクロールコンテナの現在 scrollTop (node_idx → px)。 JS が el.scrollTop = N で書き込み、レンダラが再レイアウト後に同期する。

§scroll_lefts: BTreeMap<usize, i32>

サブスクロールコンテナの現在 scrollLeft (node_idx → px)。 JS が el.scrollLeft = N で書き込み、レンダラが再レイアウト後に同期する。

§scroll_heights: BTreeMap<usize, i32>

サブスクロールコンテナの scrollHeight (node_idx → px)。 レンダラが parse_and_layout 後に populate する(コンテナ高 + scroll_max_y)。

§scroll_widths: BTreeMap<usize, i32>

サブスクロールコンテナの scrollWidth (node_idx → px)。 レンダラが parse_and_layout 後に populate する(コンテナ幅 + scroll_max_x)。

§next_listener_id: u64

リスナ ID の発番カウンタ(once / removeEventListener 照合用)。

§mut_observers: Vec<MutObsReg>

登録済み MutationObserver。

§mut_records: Vec<(u32, MutRec)>

DOM 変更時に積まれるレコードキュー(observer_id, record)。

§next_mut_obs_id: u32

MutationObserver の ID 発番カウンタ。

§mut_microtask_pending: bool

MutationObserver 通知用マイクロタスクのキュー待ちフラグ。

§io_observers: Vec<IntersectionObserverReg>

登録済み IntersectionObserver。

§next_io_obs_id: u32

IntersectionObserver の ID 発番カウンタ。

§ro_observers: Vec<ResizeObserverReg>

登録済み ResizeObserver。

§next_ro_obs_id: u32

ResizeObserver の ID 発番カウンタ。

§pointer_captures: BTreeSet<(usize, i32)>

setPointerCapture/releasePointerCapture/hasPointerCapture (Pointer Events。丸ごと未対応だった)が捕捉中の (node_idx, pointerId) 集合。 この処理系のイベント配信はヒットテストベースのため、実際にその後の pointer イベントをこの要素へ強制配送するところまでは配線しない (hasPointerCapture が仕様どおりの真偽を返せるようにする状態管理のみの 簡略実装。inert 属性のポインタ操作抑制のみ実装と同種の部分対応)。

§focused_idx: Option<usize>

document.activeElement/element.focus()/.blur()(HTML5。丸ごと 未対応だった)。現在フォーカス中のノード index。WebEngine::focused_id (レンダラ側の文字列キー版フォーカス状態)とは別に、JS 側から直接 読み書きできる node index ベースの状態としてここに持つ。レンダラの 実クリック/autofocus によるフォーカス変更も同期される(詳細は layout.rs/render.rs の focused_id 代入箇所を参照)。id/name 属性を 持たない要素へのレンダラ起点フォーカスは同期対象外(レンダラ自身の 既存の制約と同じ)。

§pending_scroll_abs_y: Option<i32>

window.scrollTo(x, y)/window.scroll(x, y)(丸ごと未対応だった。 実装はあったが SCROLL_Y という孤立した static へ書き込むのみで、 window.scrollY/実際のレンダラ描画位置のどちらにも一切反映されない 死んだ経路だった。2026-07-16 発見)。JS→レンダラの片方向同期用の 「保留中の絶対スクロール先」。focused_idxと同じ「レンダラが毎フレーム 消費する」設計だが、フォーカスと違い同一フレーム内での即時反映が 不要(次の描画で反映されれば十分)なため、render.rsのdraw()冒頭 1箇所でのみ消費すればよく、.focus()のような10箇所以上への配線は 不要(改修規模がずっと小さい)。

§pending_scroll_by_y: Option<i32>

window.scrollBy(x, y)(丸ごと未対応だった。dom_noopのまま)。 複数回呼ばれた場合は加算し、次の描画で一括反映する。

§on_handlers: BTreeMap<(usize, String), Value>

element.onchange = fnのような GlobalEventHandlers IDL 属性(関数値)の 永続的な保管先。以前はObj::dom(idx)(呼び出す度に新規生成される使い捨ての ラッパーオブジェクト)自身の.propsへ書き込んでいたため、代入直後に そのRcが破棄されると値ごと消え、dispatchEvent側が同じObj::dom(idx)を 新規生成して読み直しても常に見つからない(=ハンドラが一切発火しない) 静かなバグだった。listeners(addEventListener系)と同じくDOM構造体側に 持たせることで、どのObj::dom(idx)インスタンス経由でも一貫して読み書き できるようにする。キーは(node_idx, "onchange"等のプロパティ名)。

§selection: Option<Value>

Document に紐づく単一の Selection オブジェクト(W3C Selection API)。

§custom_elements: CustomElementRegistry

Web Components: カスタム要素レジストリ

§shadow_tree: ShadowTreeRegistry

Web Components: Shadow DOM レジストリ

§pending_parent_messages: Vec<(Value, String)>

子 <iframe> から window.parent.postMessage / window.top.postMessage で送られた保留メッセージ列 (data, origin)

§pending_child_messages: Vec<(String, Value, String)>

親ページから <iframe src="..."> の contentWindow.postMessage で送られた保留メッセージ列 (target_src, data, origin)

§iframe_content_windows: BTreeMap<usize, Rc<RefCell<Obj>>>

各 iframe 要素ノードインデックスから生成済み contentWindow オブジェクトへのキャッシュ

§iframe_docs: BTreeMap<usize, usize>

各 iframe 要素ノードインデックス → 子文書の #document ノードインデックス(WPT/接続済みフレーム用)

§iframe_doc_to_elem: BTreeMap<usize, usize>

逆引き: 子文書の #document ノードインデックス → iframe 要素ノードインデックス(doc.defaultView 用)

§builtin_global_names: Vec<String>

組み込みのグローバル名(ページのスクリプトを実行する前に決まっていたもの)。iframe の contentWindow にも置く。

§css_referenced_attrs: Option<BTreeSet<String>>

現在のスタイルシート(RuleIndex)で参照されている属性名(小文字)の集合。 Some のとき、ここに含まれず HTML 固有の表示属性でもない属性の set_attr / remove_attr は レイアウトやスタイルに影響しないため structural_dirty を立てない(TODO P4b)。

Implementations§

Source§

impl DomBridge

Source

pub fn new() -> Self

Source

pub fn ensure_default_document(&mut self)

未初期化の DOM ブリッジに最小限の html/head/body 骨格を遅延生成する。

Source

pub fn set_on_handler(&mut self, node: usize, key: &str, val: Value)

element.onXXX = fn(関数値)の永続的な書き込み。

Source

pub fn get_on_handler(&self, node: usize, key: &str) -> Option<Value>

element.onXXXの読み出し。未設定ならNone。

Source

pub fn set_pointer_capture(&mut self, idx: usize, pointer_id: i32)

element.setPointerCapture(pointerId)。

Source

pub fn release_pointer_capture(&mut self, idx: usize, pointer_id: i32)

element.releasePointerCapture(pointerId)。

Source

pub fn has_pointer_capture(&self, idx: usize, pointer_id: i32) -> bool

element.hasPointerCapture(pointerId)。

Source

fn has_child_list_observer(&self, parent_idx: usize) -> bool

MutationObserver: parent_idx(または subtree: true の祖先)で childList を監視している観察者がいるか。

Source

fn notify_child_list( &mut self, parent_idx: usize, added: Vec<usize>, removed: Vec<usize>, )

MutationObserver: childList 変化を記録するヘルパ(兄弟情報なし版)。

Source

fn notify_child_list_sib( &mut self, parent_idx: usize, added: Vec<usize>, removed: Vec<usize>, prev_sibling: Option<usize>, next_sibling: Option<usize>, )

MutationObserver: childList 変化を previousSibling/nextSibling 付きで記録するヘルパ。

Source

fn siblings_of_child( &self, parent: usize, child: usize, ) -> (Option<usize>, Option<usize>)

idx の直前の兄弟・直後の兄弟を children から取得する(削除・置換の MutationRecord 用)。

Source

fn detach_with_notify(&mut self, idx: usize)

idx が親を持っていれば外し、旧親の childList removal レコード(prev/next 付き)も積む。

Source

fn notify_attribute( &mut self, idx: usize, attr_name: &str, old_value: Option<&str>, )

MutationObserver: 属性変化を記録するヘルパ。attributeFilter が指定された 観察者はその一覧に無い属性名を無視し、attributeOldValue が指定された 観察者にのみ変更前の値をレコードへ積む(以前はどちらのオプションも 読み取られておらず、attributeFilter 指定時も無関係な属性の変化まで 全て通知され、oldValue は常に null 固定だった)。

Source

fn notify_attribute_ns( &mut self, idx: usize, attr_name: &str, attr_ns: Option<&str>, old_value: Option<&str>, )

Source

fn notify_character_data(&mut self, idx: usize, old_value: Option<&str>)

MutationObserver: テキストノードの内容変化を記録するヘルパ(丸ごと 未対応だった。notify_attributeと対になるcharacterData版。 idxは変化したテキストノード自身のインデックス〔仕様上 CharacterDataのmutationはテキストノード自身がtargetになる〕。 2026-07-17 発見・実装)。

Source

pub fn set_rect(&mut self, idx: usize, x: i32, y: i32, w: i32, h: i32)

レンダラがレイアウト後に要素矩形を登録する(getBoundingClientRect 等が参照)。

Source

pub fn get_rect(&self, idx: usize) -> Option<(i32, i32, i32, i32)>

Source

pub fn note_measured(&mut self, idx: usize)

JS が要素 idx の寸法を読んだことを記録する(読んだ時点の大きさ)。

Source

pub fn take_stale_measurements(&mut self) -> bool

記録した測定のうち、今の矩形と大きさが違うものがあるか(記録は消す)。

Source

pub fn set_border_widths( &mut self, idx: usize, top: i32, right: i32, bottom: i32, left: i32, )

Source

pub fn get_border_widths(&self, idx: usize) -> (i32, i32, i32, i32)

Source

pub fn clear_rects(&mut self)

Source

pub fn set_computed_style(&mut self, idx: usize, prop: &str, val: &str)

算出スタイルを登録(kebab-case プロパティ→値)。

Source

pub fn get_computed(&self, idx: usize, prop: &str) -> String

算出スタイルを取得(無ければインライン style → 空)。

Source

fn font_size_px(&self, idx: usize) -> u32

要素の文字サイズ(px)。算出済みの px、無ければインラインの指定を親の大きさで解き、 無ければ親から継承する(ルートの既定は 16px)。

Source

pub fn is_in_display_none_subtree(&self, idx: usize) -> bool

このノードか祖先のどれかが display: none か(直前の配置で決まった値と、その後のインラインの指定で見る)。 文書につながっていないノードも「表示されない」として true。 【2026-11-14】TODO P4: 表示されていない要素のアニメの値を、全体の組み直しの理由にしないため。

Source

pub fn clear_computed(&mut self)

Source

pub fn clear_dirty(&mut self)

ダーティ状態を全クリアする。

Source

pub fn record_text_update( &mut self, elem_idx: usize, text_idx: usize, val: &str, )

単一テキスト子の軽量テキスト更新を記録する(TODO P4c/d)。 空文字・改行入り・style/script/title/textarea/option 要素は対象外とし、通常の構造ダーティへ落とす。

Source

pub fn mark_structural_dirty(&mut self)

構造的な DOM 変更(ノード追加/削除/クラス/テキスト/属性変更等)を記録する。

Source

pub fn mark_structural_dirty_for(&mut self, cause: &str)

構造的な変更を、原因の名前つきで記録する(TODO P4 a、2026-11-14)。

Source

pub fn mark_structural_dirty_attr(&mut self, name: &str)

属性の変更による構造的な変更を記録する(原因は attr:名前)。

Source

fn count_relayout_request()

「組み直しを要求した変更」を 1 件、[PERF][SUMMARY] の数え物へ足す(2026-11-18 TODO P9 (a))。 要求した場所で数えるので、組み直しの間引き(時間で決まる)に左右されない。 同じ試験ページなら実行ごとに同じ数になり、再レイアウトの回数の揺れに代わる比較の物差しになる。

Source

pub fn note_dirty_cause(&mut self, cause: &str)

組み直しを招いた変更を、原因ごとに数える([LAYOUT][CAUSE] で出す。出すたびに 0 へ戻す)。 原因の種類が増えすぎないよう、種類の数に上限を置く(超えた分は … にまとめる)。

Source

pub fn take_dirty_causes(&mut self) -> Vec<(String, u32)>

数えた原因を多い順に取り出して 0 へ戻す。

Source

pub fn build_from(&mut self, root: &Node)

新しいページの DOM 木からブリッジを再構築する(リスナはクリア)。

【2026-11-18 TODO R2 (b) ②】ノードの数だけ回るので、64 個ごとに止める確かめを呼ぶ(bridge_poll)。 このタブだけ止める合図なら途中でやめ、built を偽のままにする(次のレイアウトはブリッジを使わず HTML から組み直す)。

Source

pub fn build_from_ordered(&mut self, root: &Node, order: Option<&AttrOrderNode>)

Source

fn count_nodes(node: &Node) -> usize

木のノードの数(根を含む)。深さは解析の上限(dom::MAX_DOM_DEPTH)で抑えてある。

Source

fn collect( node: &Node, parent: Option<usize>, out: &mut Vec<DomNode>, order: Option<&AttrOrderNode>, attr_order: &mut BTreeMap<usize, Vec<String>>, ) -> usize

木をドキュメント順(プリオーダ)に再帰収集。子インデックスを記録する。

Source

fn special_node_parts( tag: &str, attributes: &BTreeMap<String, String>, ) -> (BTreeMap<String, String>, Option<String>)

仕様どおりの木(parse_html_document)のコメント・DOCTYPE のノードを、ブリッジの表現(#comment はテキスト、 #doctype は _name・_publicId・_systemId)へ直す。ふつうの要素は属性をそのまま返す。

Source

pub fn ensure_shells(&mut self)

補った <head>/<body> の殻を作る(document.head/document.body が null になる問題。2026-11-20 TODO S3)。

ブラウザ用の解析(parse_html)は、<head>/<body> を書かないページの補った殻を外して中身を <html> の直下に並べる (レイアウトがその形を前提にしている)。DOM の仕様では document.head/body は常にあるので、最初に必要になったときだけ 殻を作り、<html> の子を移す。殻は _implicit 属性で印を付け、描画用の木(to_dom_node)・走査順(tree_order)では 飛ばして中身を直接並べる。このため描画の結果は殻が無いときと同じ。変更の通知・再レイアウトは起こさない。

Source

fn flat_kids(&self, parent: usize, out: &mut Vec<usize>)

parent の子を描画用の木の並びで列挙する(補った殻 _implicit は飛ばして中身を並べる)。

Source

fn collect_text(&self, idx: usize) -> String

部分木のテキストを連結(textContent 相当)。現在値(override 優先)で集約。

Source

fn collect_text_into(&self, idx: usize, out: &mut String)

Source

pub fn build_id_index(&self) -> BTreeMap<&str, usize>

id → ノード添字の対応表を 1 回で作る。

【2026-08-05】get_element_by_id は全ノードの線形走査で、 しかも各ノードで is_attached が親を辿る。 レイアウト後の矩形反映では要素 1 個ごとにこれを呼んでおり、 O(要素 × ノード × 深さ) になっていた(実測で要素・ノードとも約 369)。

走査 1 回で表を作れば、引く側は O(log N) で済む。 条件(テキストノードでない・id が空でない・ルートから到達可能)は get_element_by_id と揃えてある。同じ id が複数あれば先勝ち (find と同じ)。

計算量: O(N × D)(N はノード数、D は木の深さ)。

Source

pub fn resolve_element_id( id_map: &BTreeMap<&str, usize>, element_id: &str, ) -> Option<usize>

描画要素の element_id からノードの添字を引く。id の無い要素は to_dom_node が付けた 内部名 _node_idx_<添字> なので、build_id_index の表には載っていない。

Source

pub fn get_element_by_id(&self, id: &str) -> Option<usize>

Source

pub fn is_attached(&self, idx: usize) -> bool

node[0](ルート)から到達可能か。createElement 直後や remove 済みは false。 Shadow DOM の要素は、ShadowRoot の host がルートから到達可能であれば接続中(true)。 node.isConnected(丸ごと未対応だった)向けに公開する。

Source

pub fn query(&self, selector: &str) -> Option<usize>

単純セレクタ(#id / .class / tag、先頭一致)にマッチする最初のノード。

Source

pub fn get_elements_by_class_name( &self, root: Option<usize>, class_names: &str, ) -> Vec<usize>

セレクタにマッチする全ノード(ドキュメント順)。以前は node_matches と同じ 単純セレクタ限定の簡略実装が独立に重複しており、querySelectorAll('div.active') 等のコンパウンドセレクタが常に空になる同型のバグだった。node_matches と 共通の compound_matches/match_selector_chain に統一して解消する。 DOM Standard §4.2.6 getElementsByClassName: ASCII 空白区切りで全クラスを持つ子孫を文書順に返す。

Source

pub fn query_all(&self, selector: &str) -> Vec<usize>

Source

pub fn query_all_scoped( &self, selector: &str, scope_root: Option<usize>, ) -> Vec<usize>

query_all の :scope 対応版。element.querySelectorAll/querySelector の起点要素を scope_root として渡すと、セレクタ中の :scope 疑似クラス (Selectors Level 4。丸ごと未対応だった)がそのノードにのみ一致するように なる(詳細は node_matches_scoped 参照)。

Source

fn query_scoped( &self, selector: &str, scope_root: Option<usize>, first: bool, ) -> Vec<usize>

query_all_scoped の本体。first なら最初の 1 個で止める。

【2026-10-24】従来はノードごとにセレクタの文字列を解析し直し、起点があっても全ノードを 祖先判定しながら走査していた。YouTube の視聴ページの JS 実行で確保の約 3 割が ここだった(document.body 等の参照も query("body") で全ノードを解析していた)。 セレクタは 1 回だけ解析し、起点があればその部分木だけを文書順にたどる。

Source

pub fn set_text_content(&mut self, idx: usize, val: &str)

要素の textContent を設定。子孫テキストノードがあれば最初に値を入れ残りを空に、 無ければ既存の子を捨てて単一テキスト子を作る(createElement したノード等)。

Source

fn set_text_content_raw(&mut self, idx: usize, val: &str)

Source

fn is_exclusive_text(&self, idx: usize) -> bool

node.normalize()(丸ごと未対応だった。DOM 標準メソッドで、連続する隣接テキスト

Source

pub fn normalize_node(&mut self, idx: usize)

ノードを1つに連結し、空のテキストノードを取り除く。textContent を何度も 部分的に書き換えた後などに呼ばれる定番の掃除用メソッド)。子孫を再帰的に処理する。

Source

fn text_of(&self, idx: usize) -> String

テキストノードの実効テキスト(text_override があればそれ、無ければ initial_text)。collect_text_into と同じ参照パターン。

Source

fn new_element_node(&mut self, tag: &str) -> usize

Source

fn new_text_node(&mut self, text: &str) -> usize

Source

pub fn create_element_plain(&mut self, tag: &str) -> usize

document.createElement(tag)。デタッチ状態のノードを返す。 W3C HTML 仕様準拠: <script> 要素は生成時に async = true が初期設定される。 名前空間つきの(HTML 以外の)要素を作る。script・link の特別扱いをしない(createElementNS)。

Source

pub fn create_element(&mut self, tag: &str) -> usize

Source

pub fn script_source(&self, idx: usize) -> (Option<String>, String, String)

<script> の (src 属性, type 属性, 本文)。

Source

pub fn is_connected(&self, idx: usize) -> bool

文書(ノード 0 を根とする木)に繋がっているか。

Source

pub fn is_frame_element(&self, idx: usize) -> bool

<iframe>・<frame>(子の閲覧コンテキストを持つ要素)か。

Source

pub fn browsing_context_doc(&self, idx: usize) -> Option<Option<usize>>

ノードが閲覧コンテキストを持つ文書に(Shadow tree 経由も含めて)繋がっていれば、その文書を返す (Some(None) は主文書、Some(Some(d)) は子フレームの #document ノード d)。 createHTMLDocument() などの閲覧コンテキストの無い文書や、どこにも繋がっていなければ None。

Source

fn queue_post_connection(&mut self, parent: Option<usize>, roots: &[usize])

挿入(または子の変化)の後で、post-connection steps の対象を pending_post_connection へツリー順に積む。 parent が未実行の <script> なら、その「children changed steps」として先に積む(挿入された子より前に走る)。 部分木は前順(Shadow root も含む shadow-including tree order)でたどる。

Source

pub fn script_children_changed(&mut self, idx: usize)

未実行の <script> の子が変わった(HTML の「children changed steps」)。閲覧コンテキストのある文書に 繋がっていれば、post-connection の処理で準備(本文があれば実行)する。テキストノードなら親の script を見る。

Source

pub fn ensure_frame_doc(&mut self, idx: usize) -> bool

<iframe>/<frame> の子文書(about:blank)を作る(既にあれば何もしない)。作ったら true。

Source

pub fn prune_disconnected_frames(&mut self) -> bool

閲覧コンテキストのある文書から外れた <iframe>/<frame> の子文書・contentWindow を捨てる (HTML の removing steps の「destroy a child navigable」。unload/pagehide は同期で送らない)。 何か捨てたら true(frames_dirty も立てる)。

Source

pub fn child_frames_of(&self, root: usize) -> Vec<usize>

部分木 root の子孫のうち、子文書を持つ <iframe>/<frame>(ツリー順。Shadow tree は含めない)。

Source

pub fn create_text_node(&mut self, text: &str) -> usize

document.createTextNode(text)。

Source

pub fn create_comment(&mut self, text: &str) -> usize

document.createComment(text)。

Source

pub fn create_doctype( &mut self, name: &str, public_id: &str, system_id: &str, ) -> usize

document.implementation.createDocumentType(name, publicId, systemId)。#doctype という特殊タグのノード (name・publicId・systemId は内部属性 _name・_publicId・_systemId)。

Source

pub fn create_processing_instruction( &mut self, target: &str, data: &str, ) -> usize

document.createProcessingInstruction(target, data)。#pi という特殊タグのノードで、対象は内部属性 _target、 データは text_override(コメントと同じ CharacterData)。

Source

pub fn create_document_fragment(&mut self) -> usize

document.createDocumentFragment()(丸ごと未対応だった)。仕様どおり、 #fragment という特殊タグの要素として表現する。この要素自身は決して root から到達可能(is_attached)にならず、append_child/insert_before に渡されると自身ではなく子要素群がそのまま挿入先へ移動し、自身は空になる (実 DOM の DocumentFragment の「挿入すると中身だけが移動する」挙動を再現)。

Source

pub fn attr_ns(&self, elem: usize, qname: &str) -> Option<String>

要素 elem の属性 qname の名前空間。

Source

pub fn new_attr_node( &mut self, qname: &str, ns: Option<&str>, value: &str, ) -> usize

孤立した Attr ノードを作る。

Source

pub fn attr_node_for(&mut self, elem: usize, qname: &str) -> Option<usize>

要素 elem の属性 qname の Attr ノード(無ければ作る。属性が無ければ None)。

Source

pub fn attr_node_for_ns( &mut self, elem: usize, ns: Option<&str>, qname: &str, ) -> Option<usize>

名前空間つき属性の Attr ノードを取得または生成する。

Source

pub fn detach_attr_node(&mut self, elem: usize, qname: &str, last_value: &str)

属性 qname が要素から外れるとき、Attr ノードを孤立させて最後の値を持たせる。

Source

pub fn attr_value(&self, attr: usize) -> String

Attr ノードの現在値(持ち主があれば要素の属性)。

Source

pub fn set_attr_ns( &mut self, elem: usize, ns: Option<&str>, qname: &str, value: &str, )

名前空間つきで属性を設定する(setAttributeNS)。 ns.is_some() のときは ns_attrs に分離し、HTML の style/id/class/on* 等に干渉させない。

Source

pub fn find_attr_ns( &self, elem: usize, ns: Option<&str>, local: &str, ) -> Option<String>

名前空間 ns と局所名 local の属性の修飾名。

Source

pub fn get_attr_ns( &self, elem: usize, ns: Option<&str>, local: &str, ) -> Option<String>

名前空間 ns と局所名 local の属性値。

Source

pub fn remove_attr_ns(&mut self, elem: usize, ns: Option<&str>, local: &str)

名前空間 ns と局所名 local の属性を削除する。

Source

pub fn remove_attr_ns_notify( &mut self, elem: usize, ns: Option<&str>, local: &str, qn: &str, old_val: &str, )

Source

fn range_inclusive_descendant(&self, n: usize, anc: usize) -> bool

n は anc の包含的な子孫か。

Source

pub fn ni_register(&mut self, obj: &ObjRef, root: usize) -> u32

NodeIterator を登録する(root が最初の referenceNode)。

Source

pub fn remove_main_doc_child(&mut self, child: usize)

主文書(document)直下の子(doctype 等)を取り除く(NodeIterator-removal 用)。

Source

fn ni_retarget_pos( &self, root: usize, node: usize, pos: usize, before_in: bool, ) -> (usize, bool)

Source

fn iters_pre_remove(&mut self, node: usize)

node を木から取り除く直前の NodeIterator の更新(DOM Standard「NodeIterator pre-removing steps」)。

Source

fn range_prune(&mut self)

弱参照が切れた Range を捨てる。

Source

fn live_ranges(&mut self) -> bool

生きている Range があるか(落ちたものはここで捨てる。DOM の変更のたびに呼ぶので、Range が無ければ即座に偽)。

Source

pub fn ranges_node_removed(&mut self, node: usize, parent: usize, index: usize)

node(親 parent の index 番目)を取り除くとき。

Source

pub fn ranges_children_cleared(&mut self, parent: usize, kids: &[usize])

parent の子が全部取り除かれるとき(innerHTML・textContent・replaceChildren。順に先頭から取り除くのと同じ)。

Source

pub fn ranges_inserted(&mut self, parent: usize, index: usize, count: usize)

parent の index 番目の子の前に count 個挿入したあと。

Source

pub fn ranges_replace_data( &mut self, node: usize, offset: usize, count: usize, new_len: usize, )

CharacterData の replace data(offset から count 個を UTF-16 で new_len 個に)。

Source

pub fn ranges_split( &mut self, node: usize, new_node: usize, parent: Option<usize>, offset: usize, )

Text.splitText: node を offset で分け、後ろを new_node(parent の node の次)にしたとき。

Source

pub fn ranges_normalize_merge( &mut self, node: usize, cur: usize, parent: usize, index: usize, length: usize, )

normalize で cur(parent の index 番目)を直前のテキスト node(取り込み前の長さ length)へ併せるとき。

Source

pub fn set_main_doctype(&mut self, name: &str, public_id: &str, system_id: &str)

主文書の DOCTYPE を設定する(仕様どおりの木で組むホスト実行器用)。

Source

pub fn range_register(&mut self, obj: &ObjRef, node: usize) -> u32

新しい Range を登録して番号を返す。

Source

pub fn replace_data( &mut self, idx: usize, offset: usize, count: usize, new_len: usize, new_text: &str, )

CharacterData の内容を new_text にして、Range の境界点を replace data(offset, count, new_len) どおりに直す。

Source

pub fn create_document_node(&mut self, ctype: &str, html: bool) -> usize

#document ノードを作る。ctype は contentType、html は HTML 文書か(createElement が小文字にするか)。

Source

pub fn is_doc_node(&self, idx: usize) -> bool

idx が主文書以外の #document ノードか。

Source

pub fn doc_is_html(&self, doc: Option<usize>) -> bool

文書(None は主文書)が HTML 文書か。

Source

pub fn node_document(&self, idx: usize) -> Option<usize>

「ノードの文書」。None は主文書。#document ノード自身は自分。

Source

pub fn root_of(&self, idx: usize) -> usize

親をたどった先の根(シャドウ木は越えない)。

Source

pub fn set_owner_subtree(&mut self, idx: usize, doc: Option<usize>)

部分木のノードの所有文書を doc(None は主文書)にする。XML 文書の要素には _xml の印を付け、HTML 文書では外す。

Source

pub fn inherit_owner(&mut self, idx: usize, from: usize)

新しく作った idx が from と同じ文書のものになるようにする(cloneNode・splitText・innerHTML の新ノード)。

Source

fn sync_owner_on_insert(&mut self, parent: usize, kids: &[usize])

挿入された子(部分木)の所有文書を親の文書へ移す(仕様の「adopt」)。

Source

pub fn attach_shadow( &mut self, host_idx: usize, mode: ShadowRootMode, ) -> Result<usize, AttachShadowError>

Web Components: element.attachShadow({ mode: 'open' | 'closed' })

Source

pub fn get_shadow_root(&self, host_idx: usize) -> Option<usize>

ホスト要素の ShadowRoot ノード index を取得(accessible な場合のみ)。

Source

pub fn create_contextual_fragment( &mut self, context_node_idx: Option<usize>, html: &str, ) -> usize

W3C DOM Parsing: Range.prototype.createContextualFragment(fragment)

Source

pub fn template_content(&mut self, idx: usize) -> usize

template.content(<template> が丸ごと未対応だった)。仕様上 <template> の子は「不活性」で通常の DOM ツリーには存在せず、代わりに .content (DocumentFragment)経由でのみアクセスできる。この処理系は HTML パース時に template を特別扱いしないため子が普通にライブツリーへ入ってしまうが、 初回アクセス時にその子を #fragment ノードへ移し替え(内部専用属性 _content_frag にフラグメントの index をキャッシュ)、以後は同じフラグメントを 返すことで「以後 <template> 自身は空、.content だけが中身を持つ」という 仕様どおりの見た目に近づける。

Source

fn expand_fragment(&mut self, child: usize) -> Vec<usize>

child が DocumentFragment(#fragment タグ)なら、その子要素群を 親から切り離して返し、フラグメント自身は空にする。それ以外は [child] を そのまま返す(append_child/insert_before の共通前処理)。

Source

pub fn append_child(&mut self, parent: usize, child: usize)

parent.appendChild(child)。既存の親から外して付け替える。child が DocumentFragment の場合は仕様どおりその子要素群を代わりに追加する。

Source

pub fn replace_children(&mut self, parent: usize, new_child: Option<usize>)

ParentNode.replaceChildren(...): 既存の子を取り外し、新しい子(あれば)を 1 回の MutationRecord で置き換える。

Source

pub fn remove_child(&mut self, parent: usize, child: usize)

parent.removeChild(child) / child.remove()。

Source

pub fn remove_node(&mut self, idx: usize)

Source

pub fn insert_before( &mut self, parent: usize, new_child: usize, ref_child: Option<usize>, )

parent.insertBefore(new_child, ref_child)。ref が None/不在なら末尾に追加。 new_child が DocumentFragment の場合は仕様どおりその子要素群を代わりに挿入する。 【2026-11-20】基準(ref_child)の位置は、挿入するノードを元の親から外した後に引く(同じ親の中で前から後ろへ動かすと 添字がずれていた)。ref_child が挿入するノード自身なら、その次の兄弟を基準にする(DOM 標準)。

Source

pub fn replace_child( &mut self, parent: usize, new_child: usize, old_child: usize, )

parent.replaceChild(new_child, old_child)。old を new で置換。new_child が DocumentFragment ならその子群で置き換える。

Source

pub fn clone_node(&mut self, idx: usize, deep: bool) -> usize

node.cloneNode(deep)。属性/テキストをコピーした新ノードを作る(親なし)。deep なら子も再帰。

Source

fn clone_node_inner(&mut self, idx: usize, deep: bool) -> usize

Source

fn subtree_contains(&self, root: usize, target: usize) -> bool

親の children から idx を外す。

Source

fn detach(&mut self, idx: usize)

Source

pub fn move_before( &mut self, parent: usize, new_child: usize, ref_child: Option<usize>, )

Source

pub fn insert_adjacent_node(&mut self, idx: usize, position: &str, node: usize)

単一ノードを基準ノード idx の相対位置へ挿入(insertAdjacent* 共通)。

Source

pub fn insert_adjacent_html(&mut self, idx: usize, position: &str, html: &str)

element.insertAdjacentHTML(position, html)。html をパースして相対位置へ挿入。

Source

pub fn attr_affects_layout(&self, idx: usize, name: &str) -> bool

属性 name の変更がスタイル計算やレイアウト(HTML 固有の表示属性を含む)に影響し得るか(TODO P4b)。

Source

pub fn set_inner_html(&mut self, idx: usize, html: &str)

element.innerHTML = html。フラグメントをパースして子を置換する。 appendChild/removeChild/insertBefore/replaceChild は全て notify_child_list 経由で MutationObserver に通知していたが、 innerHTML 代入だけがこの呼び出しを欠いており、最も頻繁に使われる DOM 書き換え手段にもかかわらず childList 変化が一切観察できなかった。

Source

pub fn set_outer_html(&mut self, idx: usize, html: &str)

element.outerHTML = html。自ノードを HTML パース結果のノード群で置き換える。

Source

pub fn import_node(&mut self, node: &Node) -> usize

dom::Node 部分木をブリッジへ取り込み、ルート idx を返す。

Source

pub fn normalize_foreign_attrs(&mut self, idx: usize)

SVG / MathML / XML 要素にある xlink href・xml lang・xmlns xlink 等を名前空間付き属性 ns_attrs へ正規化する。

Source

pub fn unmark_subtree_xml(&mut self, idx: usize)

XML/SVG パースで取り込まれた部分木をマークする(tagName で元のケースを保持するため)。 mark_subtree_xml の逆(XML 文書から HTML 文書へ取り込んだ(importNode)部分木に使う)。

Source

pub fn mark_subtree_xml(&mut self, idx: usize)

Source

pub fn to_dom_node(&self) -> Node

ブリッジツリー(node[0] をルート)を dom::Node へ変換する。 JS の変更(textContent/style/class/動的ノード)が反映された描画用ツリー。

Source

pub fn tree_order(&self) -> Vec<usize>

to_dom_node の木の pre-order 走査順に、ノードの添字を並べたもの。 動的に作った要素があると「走査順」と「nodes の添字」は一致しないので、 木の位置からノードへ戻すときはこの表を使う。

Source

fn tree_order_into(&self, idx: usize, out: &mut Vec<usize>)

Source

fn build_node(&self, idx: usize) -> Node

Source

pub fn get_text_content(&self, idx: usize) -> String

要素の textContent(現在値)を取得。

Source

fn descendant_text_nodes(&self, idx: usize) -> Vec<usize>

Source

fn descendant_text_into(&self, idx: usize, out: &mut Vec<usize>)

Source

pub fn set_style(&mut self, idx: usize, prop: &str, val: &str)

Source

pub fn get_style(&self, idx: usize, prop: &str) -> String

Source

pub fn get_style_priority(&self, idx: usize, prop: &str) -> String

element.style.getPropertyPriority(name)(丸ごと未対応だった。 2026-07-16 発見)。!important は生の値文字列末尾にそのまま保持 されている(set_style/css_prop_from_camel 参照)ため、 strip_style_priority で判定するだけで済む。

Source

pub fn get_css_text(&self, idx: usize) -> String

element.style.cssText の読み出し。以前は丸ごと未対応で、cssText を単なる 通常の CSS プロパティ名として扱う既存の汎用経路(get_style)に落ちてしまい、 常に空文字列を返していた(serialize_inline_style 自体は属性文字列の再構築で 既に使われていたが、JS からの読み出しには配線されていなかった)。

Source

pub fn set_css_text(&mut self, idx: usize, text: &str)

element.style.cssText = "..." の書き込み。単一プロパティとして扱われ常に 無視されていたのを、既存のスタイル属性パーサ(parse_inline_style)で丸ごと 置き換えるよう実装する。

Source

pub fn outline(&self, max: usize) -> Vec<String>

診断用: DOM の骨組み(tag#id.class [style])を字下げ付きで最大 max 行返す。 テキストノードは省く。実サイトの JS がどんな要素を組み立てたかを追うためのもの。

Source

pub fn get_outer_html(&self, idx: usize) -> String

element.outerHTML(読み出し専用。書き込み側は要素の親子関係の組み替えが 必要で改修規模が大きいため今回は見送り)が丸ごと未対応だった。自身のタグ・属性 (id/class/style を含む)・子孫を再帰的に HTML 文字列へ直列化する。

Source

pub fn get_inner_html(&self, idx: usize) -> String

element.innerHTML の読み出しが、実際にはマークアップ(子要素タグ)を含めず textContent と同じ「全テキストを連結しただけ」の値を返してしまっていたバグ。 <div>a<b>bold</b></div> の innerHTML が仕様どおりの "a<b>bold</b>" ではなく "abold" になっていた。自身のタグは含めず、子ノードだけを直列化する。

Source

fn serialize_node_html(&self, idx: usize, out: &mut String)

Source

pub fn class_add(&mut self, idx: usize, cls: &str)

Source

pub fn class_remove(&mut self, idx: usize, cls: &str)

Source

pub fn class_toggle(&mut self, idx: usize, cls: &str) -> bool

Source

pub fn class_contains(&self, idx: usize, cls: &str) -> bool

Source

fn collect_descendant_options(&self, idx: usize, out: &mut Vec<usize>)

<select>配下の<option>要素を全て集める(<optgroup>でグループ化 された<option>も含む再帰探索。丸ごと未対応だった。以前は直接の子 のみを見る実装だったため、``という非常によく使われる カテゴリ分けパターンで、``配下の`

Source

pub fn select_options(&self, idx: usize) -> Vec<usize>

<select> の option 子要素一覧(<optgroup>配下も含む)。select. options(丸ごと未対応だった。動的にドロップダウンを構築する定番 イディオムで使われる)向けに公開する。

Source

fn option_value(&self, opt_idx: usize) -> String

option 要素の実効値: value 属性があればそれ、無ければテキスト内容 (仕様どおり。collect_form_data の select フォールバックと同じ規則)。

Source

pub fn selected_option_indices(&self, idx: usize) -> Vec<usize>

select.selectedOptions(<select multiple> で選択中の option 一覧を得る 定番イディオム。FormData の multi-select 対応と同じく selected 属性を 真実源とする)。単一選択の <select> でも仕様どおり動作する (selected が無ければ既定選択の最初の option を1件返す)。

Source

pub fn select_effective_value(&self, idx: usize) -> String

select.value(丸ごと未対応だった。<select> 自身に value 属性は無く、 選択状態は子の <option selected> が持つため、汎用の属性直結 getter では 常に空文字列になっていた)。selected な option を優先し、無ければ HTML の既定選択どおり最初の option にフォールバックする。

Source

pub fn effective_form_value(&self, idx: usize) -> String

フォーム系コントロールの「現在の実効値」を文字列で解決する。 checkValidity()/.validationMessage/.validityが素朴に get_attr(idx,"value")だけを見ており、value属性を持たない <select>(選択状態は子<option selected>が持つ)や、初期値が value属性ではなくテキストノードで表現される<textarea>では 常に空文字列として(=未入力として)誤って検証されてしまうバグの 共通修正用。.valueゲッター(dom_props.rs)と同じフォールバック 規則をここに一本化する。

Source

pub fn set_select_value(&mut self, idx: usize, val: &str)

select.value = v(丸ごと未対応だった)。value が一致する最初の option へ 選択を移す(他の option の selected は解除。仕様どおり単一選択)。

Source

pub fn select_selected_index(&self, idx: usize) -> i32

select.selectedIndex(丸ごと未対応だった)。selected な option の位置、 無ければ option が1つ以上あれば 0(既定選択)、無ければ -1。

Source

pub fn set_select_selected_index(&mut self, idx: usize, n: i32)

select.selectedIndex = n。

Source

pub fn set_select_length(&mut self, idx: usize, n: usize)

select.length = n(HTML5。select.options.lengthと同じ値を返す ゲッター兼、nより末尾のoptionを切り捨てる/不足分を空の<option>で 埋めるセッター。丸ごと未対応だった)。仕様どおり、新しい長さが現在より 小さければ末尾から削除、大きければ空の<option>を追加する。

Source

pub fn option_index(&self, idx: usize) -> i32

option.index(HTML5。自身が属する<select>内での0始まりの位置。 select.selectedIndexの対になる、<option>側のIDL属性だが丸ごと 未対応だった)。<select>祖先が無い場合は仕様どおり0(要素が 「optionのリスト」に属さない場合の既定値。<datalist>配下は 対象外の簡略実装)。

Source

pub fn get_attr(&self, idx: usize, name: &str) -> Option<String>

Source

pub fn set_attr(&mut self, idx: usize, name: &str, val: &str)

Source

pub fn has_attr(&self, idx: usize, name: &str) -> bool

属性が存在するか(空値の boolean 属性も存在として true。id/class は専用フィールド)。

Source

pub fn remove_attr(&mut self, idx: usize, name: &str)

属性を削除(id/class フィールドも同期)。

Source

pub fn get_dataset(&self, idx: usize) -> BTreeMap<String, String>

W3C HTML5 §3.2.6.2 / DOMStringMap: data-* 属性から camelCase の dataset マップを抽出する。

Source

pub fn close_details_group_siblings(&mut self, idx: usize) -> Vec<usize>

<input type="radio"> の排他選択(同じ name を持つグループ内で1つだけが checked になる、というラジオボタンの最も基本的な仕様上の挙動)。idx を checked にする際、同じ name を持つ他の radio 全ての checked 属性を外す。 フォーム所有者(<form> 単位のスコープ)は区別せず、同じ name を持つ document 内の全 radio を対象にする簡略実装。 <details name="...">(HTML5。同じnameを持つ<details>同士は ラジオボタングループのように排他的に開閉する——1つを開くと同じ グループの他の<details>は自動的に閉じる——仕様が丸ごと未対応 だった。uncheck_radio_group_siblingsと同じ「name属性が一致する 兄弟(ドキュメント全体、DOM上の兄弟関係は問わない)を探して状態を 揃える」パターンをそのまま適用する。2026-07-18 発見・実装)。

Source

fn node_tree_root(&self, idx: usize) -> usize

Source

fn radio_form_owner(&self, idx: usize, root: usize) -> Option<usize>

Source

pub fn same_radio_group(&self, a: usize, b: usize) -> bool

Source

pub fn uncheck_radio_group_siblings(&mut self, idx: usize)

Source

pub fn assigned_slot_for(&self, idx: usize) -> Option<usize>

Source

pub fn slot_assigned_nodes( &self, slot_idx: usize, elem_only: bool, ) -> Vec<usize>

Source

pub fn node_matches(&self, idx: usize, selector: &str) -> bool

単一ノードがセレクタ(コンパウンド + 結合子、カンマ区切りは OR)にマッチするか。 matches()/closest()/querySelector(All) 共通の実装本体。以前は #id/.class/ tag/* の単純セレクタしか認識せず、div.active(コンパウンド)や [data-x] (属性セレクタ)、.a > .b(結合子)を渡すと文字列全体を tag 名として比較する 分岐に落ち、常に false になる静かな破壊バグだった(:not()/:nth-child()/ :is()/:where() 等の疑似クラスは引き続き非対応。改修規模を絞るための 意図的な割り切り)。

Source

pub fn node_matches_scoped( &self, idx: usize, selector: &str, scope_root: Option<usize>, ) -> bool

node_matches の :scope 対応版。scope_root に element. querySelectorAll/matches/closest 等の起点ノードを渡すと、セレクタ中の :scope 疑似クラス(Selectors Level 4。丸ごと未対応だった)がそのノードに のみ一致するようになる。scope_root が None(document.querySelectorAll 等、起点を持たない文脈)の場合は :scope は常に不一致として扱う簡略実装。

Source

pub fn node_matches_parsed( &self, idx: usize, groups: &[Vec<SelStep>], scope_root: Option<usize>, ) -> bool

解析済みのセレクタ(parse_selector_groups)に idx が一致するか。

Source

fn node_matches_parsed_with_anchor( &self, idx: usize, groups: &[Vec<SelStep>], scope_root: Option<usize>, has_anchor: Option<usize>, ) -> bool

Source

fn compound_matches( &self, idx: usize, c: &CompoundSel, scope_root: Option<usize>, ) -> bool

idx がコンパウンドセレクタ(タグ/#id/.class/[attr...])に一致するか。

Source

fn compound_matches_with_anchor( &self, idx: usize, c: &CompoundSel, scope_root: Option<usize>, has_anchor: Option<usize>, ) -> bool

Source

fn element_sibling_position(&self, idx: usize) -> (usize, usize)

idx の「要素兄弟のみを数えた」1始まりの位置と、要素兄弟の総数を返す (テキストノードは数えない。CSS の :nth-child() 等と同じ規則)。

Source

fn following_sibling_elements_and_descendants(&self, idx: usize) -> Vec<usize>

Source

fn element_type_sibling_position(&self, idx: usize) -> (usize, usize)

element_sibling_position と同じだが、同じタグ名の兄弟のみを数える (:first-of-type/:last-of-type/:nth-of-type() 用)。

Source

fn match_selector_chain( &self, idx: usize, steps: &[SelStep], step_i: usize, scope_root: Option<usize>, ) -> bool

idx は steps[step_i] に既に一致した状態で呼ばれる。steps[0..step_i] を 結合子に従って祖先/兄弟方向へ再帰的に検証する。

Source

fn match_selector_chain_with_anchor( &self, idx: usize, steps: &[SelStep], step_i: usize, scope_root: Option<usize>, has_anchor: Option<usize>, ) -> bool

Source

fn prev_element_sibling(&self, idx: usize) -> Option<usize>

idx の直前の要素兄弟(テキストノード・コメント等は飛ばす)。

Source

fn preceding_element_siblings(&self, idx: usize) -> Vec<usize>

idx より前にある全ての要素兄弟(テキストノード・コメント等は飛ばす、ドキュメント順)。

Source

pub fn is_ancestor_of(&self, anc: usize, idx: usize) -> bool

anc が idx の祖先か(idx 自身は含まない)。

Source

pub fn document_position(&self, this_idx: usize, other_idx: usize) -> u32

Node.compareDocumentPosition(other)(DOM標準)が丸ごと未対応だった。 this_idx(reference node)から見た other_idx の位置関係をビットマスクで返す (DOCUMENT_POSITION_* 定数は呼び出し側 builtins.rs で定義)。祖先/子孫関係は 既存の is_ancestor_of で判定し、それ以外(兄弟や別分岐)は両者の祖先鎖を根まで 辿って最も近い共通祖先(LCA)の子リスト内での順序を比較する。根が異なる (disconnected)場合、仕様上 PRECEDING/FOLLOWING の割当ては実装依存でよいため ノードindexの大小で決定的に決める。

Source

pub fn offset_parent(&self, idx: usize) -> Option<usize>

idx 自身を含め祖先方向へ、指定タグの最初の要素を返す(<form> 解決等)。 element.offsetParent(HTML5。丸ごと未対応だった)。祖先を遡り、算出 position が static 以外の最初の要素を返す。無ければ <body> (見つからなければ None = 仕様どおり null)。

Source

pub fn closest_tag(&self, idx: usize, tag: &str) -> Option<usize>

Source

pub fn associated_form(&self, idx: usize) -> Option<usize>

フォーム系コントロールが実際に属する<form>を解決する。HTML5仕様では form="formId"属性(<form>の子孫でなくても、そのidで明示的に関連付ける 「form owner」機構)が祖先探索より優先される。以前はclosest_tag(idx, "form")(祖先探索のみ)しか実装されておらず、<form id="f1">の外に置かれた <input form="f1">(フォーム外配置は<form>の視覚レイアウトを変えずに コントロールだけ離れた場所に置きたい場合の定番パターン)が element.formでnullになり、<form>.checkValidity()/送信データ収集からも 漏れる、という兄弟ギャップだった。

Source

pub fn form_associated_controls( &self, form_idx: usize, tags: &[&str], ) -> Vec<usize>

<form id="f1">に属するtagsに含まれるタグの全フォームコントロールを 収集する(form owner が当該フォームのもの。子孫でも form="他の id" で別のフォームに属するものは除く。 子孫でなくても form="f1" で関連付けられたものは含む)。 checkValidity()/FormData収集/form.elementsが使う (呼び出し側ごとに対象タグが異なる: checkValidity/FormDataは input/select/textareaのみ、form.elementsはそれにbuttonも含む)。

Source

pub fn first_by_tag(&self, tag: &str) -> Option<usize>

ドキュメント順で最初の指定タグ要素。

Source

pub fn element_children(&self, idx: usize) -> Vec<usize>

子のうち要素ノードの index 一覧(テキスト・コメント・PI・DOCTYPE 等は除外)。

Source

pub fn descendants_by_tag_name(&self, root: usize, tag: &str) -> Vec<usize>

root 以下(自身は含まない)の子孫のうち、tag が tags のいずれかに一致するものを 文書順で収集する。フォーム配下の入力欄列挙(バリデーション)に使用。 element.getElementsByTagName(tag) 用の子孫走査。tag が "*" なら全要素。

§なぜ文書全体の検索を使わないか

query_all は is_attached で文書に繋がっていないノードを除外する。 仕様では getElementsByTagName は文書への接続に関係なく自分の子孫を 返すので、切り離した要素(createElement した直後など)では結果が 空になってしまう。

jQuery 1.8.2 の機能検出はまさにこれをやる: 切り離した <div> に innerHTML を入れ、getElementsByTagName("a")[0] の style を触る。空が返ると undefined の style を読んで落ち、 jQuery 全体が初期化できなくなっていた。

なお is_attached は根(索引 0)まで遡る実装のため、空の DOM では 最初に作った要素自身が索引 0 になり偶然「接続済み」になる。 単体試験を空のランタイムで書くとこの不具合を再現できない (実際に 5 回取り逃がした)。試験は実ページの DOM で確かめること。

Source

pub fn descendants_by_tags(&self, root: usize, tags: &[&str]) -> Vec<usize>

Source

pub fn is_disabled(&self, idx: usize) -> bool

<fieldset disabled>の子孫コントロールは、自身にdisabled属性が無くても 暗黙に無効化される(HTML5仕様の「fieldset disabling」)。以前は要素自身の disabled属性の有無しか見ておらず、<fieldset disabled>配下の<input>は .disabledが常にfalse、制約バリデーションも無効化されずに常に対象内の ままになっていた。祖先をparentで遡り<fieldset disabled>が1つでも あれば無効とみなす(<fieldset>の最初の子<legend>直下のコントロールは 無効化対象外という仕様上の例外は、この処理系のフォーム系テストでは実用上 ほぼ現れないため今回は簡略化して見送る)。

Source

pub fn input_kind(&self, idx: usize) -> Kind

<input> の type 状態。

Source

pub fn input_value(&self, idx: usize) -> String

<input> の値(IDL の value)。モードに従い、value モードの種類は値のサニタイズを通す (内部の値は _live_value、無ければ value 属性)。属性(min/max/step)の変更や type の変更の後も、 取得の度にサニタイズし直すので、type を切り替えた直後の値も仕様どおりになる。

Source

pub fn set_input_value(&mut self, idx: usize, v: &str)

<input> に値を代入する(value モードはサニタイズして内部の値へ、default/default/on は value 属性へ)。 file は空文字列のときだけ受け付ける(本来は InvalidStateError。代入のフックは例外を返せない)。

Source

pub fn input_type_changed(&mut self, idx: usize, old: Option<&str>)

type 属性が変わったときの値の引き継ぎ(§4.10.5.4「When the type attribute changes state」)。 old は変更前の type 属性の値(無ければ None)。呼び出しは set_attr/remove_attr から(type を持つ input のみ)。

Source

pub fn barred_from_validation(&self, idx: usize) -> bool

制約検証の対象から外れている(barred)か、そもそも対象候補でない要素か。 対象候補: button(type が submit)・input(hidden・reset・button 以外)・select・textarea。 外れる条件: 無効(disabled・<fieldset disabled> の子孫)・readonly(適用される種類の input と textarea)・ 祖先に <datalist>。

Source

pub fn validity_flags(&self, idx: usize, _value: &str) -> ValidityFlags

ValidityState の各フラグ(§4.10.20.2)。無効・readonly などで対象外の要素でも、フラグ自体は計算する (validity.customError などは対象外でも読める。対象外のとき checkValidity() が true を返すのは呼び出し側)。 _value は互換のための引数(値は要素から取り直す)。

Source

fn is_checked_node(&self, idx: usize) -> bool

checkbox/radio の checked(_live_checked が優先、無ければ checked 属性)。

Source

pub fn validate_field(&self, idx: usize, _value: &str) -> Option<String>

制約検証のメッセージ(違反が無い・対象外なら None)。フラグから決める(最初に見つかった違反)。

Source

fn pattern_matches(pat: &str, val: &str) -> bool

<input pattern="...">(HTML Living Standard の制約検証。仕様上は値全体を ^(?:pattern)$ として完全一致させる)が、以前はメタ文字を含む複雑なパターンを 「誤検知で送信を妨げないため」全て無条件で通過させる簡易近似だった。この エンジンには既に本物の正規表現実装(js::regex::Regex)があるため、それを そのまま使えば近似ではなく正しく検証できる(\d/[...]/+/.* 等、 HTML pattern で使われる構文は通常の JS RegExp と同じ)。

Source

fn attr_names_default(&self, idx: usize) -> Vec<String>

既定の並び(id・class を先頭に、続いて名前順)の属性名。

Source

pub fn attr_names(&self, idx: usize) -> Vec<String>

属性名の一覧(挿入順。順序の記録が無いノードは id/class を先頭にした名前順 + ns_attrs)。

Source

pub fn attr_entries(&self, idx: usize) -> Vec<(Option<String>, String)>

属性 (ns, qname) の全一覧(挿入順)。

Source

fn attr_names_ordered_plain(&self, idx: usize) -> Vec<String>

Source

fn ensure_attr_ns_order(&mut self, idx: usize)

Source

pub fn attr_node_at(&mut self, elem: usize, pos: usize) -> Option<usize>

インデックス pos 番目の属性に対応する Attr ノード(同名異名前空間でも正確)。

Source

pub fn attr_order_replace( &mut self, idx: usize, before: Vec<String>, old: &str, new: &str, )

属性 old を new で置き換えた(位置は変えない)。before は置き換え前の属性名の並び。

Source

pub fn attr_ns_order_replace( &mut self, idx: usize, before: Vec<(Option<String>, String)>, old_ns: Option<&str>, old_q: &str, new_ns: Option<&str>, new_q: &str, )

名前空間付きを含めた属性置き換え時に元の挿入順を保持する。

Source

fn attr_order_push(&mut self, idx: usize, name: &str)

新しい属性 name を足す直前に呼ぶ。名前順の既定の並びと食い違うときだけ挿入順を記録する。

Source

pub fn add_listener(&mut self, node: usize, event: &str, func: Value)

Source

pub fn add_listener_opts( &mut self, node: usize, event: &str, func: Value, capture: bool, once: bool, ) -> u64

capture / once オプション付きでリスナを登録する。重複(同一 node+event+func+capture) は DOM 仕様どおり無視する。戻り値は発番した ID。

Source

pub fn add_listener_opts_signal( &mut self, node: usize, event: &str, func: Value, capture: bool, once: bool, signal: Option<Value>, ) -> u64

add_listener_opts の {signal} 対応版。signal が既に abort 済みなら 仕様どおり登録自体を行わない。

Source

pub fn add_listener_full( &mut self, node: usize, event: &str, func: Value, capture: bool, once: bool, passive: bool, signal: Option<Value>, ) -> u64

capture / once / passive / signal 全オプション対応のリスナ登録。

Source

pub fn remove_listener( &mut self, node: usize, event: &str, func: &Value, capture: bool, )

removeEventListener: 同一 (node, event, func, capture) のリスナを削除する。

Source

pub fn remove_listener_by_id(&mut self, id: u64)

ID 指定でリスナを削除する(once 発火後の自動削除に使う)。

Source

pub fn has_listener_by_id(&self, id: u64) -> bool

Source

pub fn has_listener(&self, event: &str) -> bool

指定イベント型のリスナがページ内に1つでも登録されているか(ホバー判定の省略用)。

Source

pub fn listeners_for(&self, node: usize, event: &str) -> Vec<Value>

指定ノードに登録された指定イベントのリスナ関数を返す(呼び出しは呼び元で)。 バブリングフェーズ用(capture=false のみ)。{signal} が abort 済みの リスナは除外する。

Source

pub fn listeners_phase( &self, node: usize, event: &str, want_capture: bool, ) -> Vec<(Value, bool, bool, u64, Option<Value>)>

指定ノード・イベントのリスナを (func, once, passive, id, signal) 付きで返す。 want_capture でキャプチャ/バブルのどちらのフェーズかを絞り込む。 {signal} が abort 済みのリスナは除外する。

Source

pub fn has_listener_on(&self, node: usize, event: &str) -> bool

指定ノードに当該イベントのリスナ(フェーズ問わず)が在るか。

Source

pub fn apply_overrides(&self, root: &mut Node)

再パースした DOM 木へ JS の変更を焼き戻す。木はビルド時と同一ドキュメント順前提。

Source

fn apply_node(&self, node: &mut Node, counter: &mut usize)

Source§

impl DomBridge

Source

pub fn subtree_elements(&self, root: usize) -> Vec<usize>

root を含む部分木の要素の添字(木順、シャドウ木を含む)。

Source

pub fn clean_unreachable_nodes<F>(&mut self, is_node_referenced: F) -> usize
where F: Fn(usize) -> bool,

文書ツリーに属しておらず、かつ JS からも参照されていない孤立ノード群を検出し、 そのノードに紐づく listeners, expandos, node_accessors, node_protos 等の強参照を一掃する。

【2026-11-06】YouTube 等の SPA では、画面更新や自動再生(次動画への遷移)で大量の要素が 切り離されるが、DomBridge が強参照を持ち続けるため cycle_gc で回収されず 生存オブジェクトが 70 万個を超えてヒープが尽きていた(TODO A7)。 このクリーンアップにより、死んだノード配下の JS オブジェクト・クロージャを循環 GC の対象へ引き渡す。

Source§

impl DomBridge

Source

pub fn new_html_collection(&mut self, kind: HtmlCollectionKind) -> usize

生きている HTMLCollection を登録して col_id を返す。

Source

pub fn html_collection_items(&self, col_id: usize) -> Vec<usize>

col_id の HTMLCollection に現在マッチする要素のノード index 一覧(文書順)。

Source

pub fn html_collection_named_item( &self, col_id: usize, name: &str, ) -> Option<usize>

HTMLCollection.namedItem(name)(DOM Standard §4.2.1)。空文字列は None。

Source

pub fn html_collection_supported_names(&self, col_id: usize) -> Vec<String>

HTMLCollection の supported property names(DOM Standard §4.2.1)。

Source

pub fn html_collection_entries(&self, col_id: usize) -> Vec<(String, String)>

HTMLCollection の Object.getOwnPropertyNames 用キー一覧(index + supported names + expandos)。

Source

pub fn attrs_map_entries(&self, elem_idx: usize) -> Vec<(String, String)>

NamedNodeMap (HOST_ATTRS) の Object.getOwnPropertyNames 用キー一覧(index + supported property names)。

Source

pub fn node_list_items(&self, id: usize) -> Vec<usize>

生きている NodeList (childNodes) の子ノード一覧。

Source

pub fn node_list_entries(&self, id: usize) -> Vec<(String, String)>

NodeList (HOST_NODELIST) の Object.getOwnPropertyNames 用キー一覧(0..len)。

Source

pub fn new_static_node_list(&mut self, items: Vec<usize>) -> usize

静的 NodeList を登録して id を返す。

Source

pub fn static_node_list_items(&self, id: usize) -> &[usize]

静的 NodeList の要素一覧。

Source

pub fn static_node_list_entries(&self, id: usize) -> Vec<(String, String)>

静的 NodeList の Object.getOwnPropertyNames 用キー一覧(0..len)。

Trait Implementations§

Source§

impl Default for DomBridge

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.