Skip to main content

LayoutBox

Struct LayoutBox 

Source
pub struct LayoutBox<'a> {
    pub dimensions: Dimensions,
    pub box_type: BoxType<'a>,
    pub children: Vec<LayoutBox<'a>>,
}

Fields§

§dimensions: Dimensions§box_type: BoxType<'a>§children: Vec<LayoutBox<'a>>

Implementations§

Source§

impl<'a> LayoutBox<'a>

Source

fn translate_y(&mut self, dy: i32)

自身と全子孫の絶対 y 座標を dy だけ平行移動する(table セルの vertical-align 実装用)。 各ボックスの content.y は既に絶対ピクセル座標として確定しているため、 この再帰1回で子孫すべての位置がまとめてずれる。

Source

fn translate(&mut self, dx: i32, dy: i32)

自身と全子孫の絶対座標を (dx, dy) だけ平行移動する。

多段組で「通常フローで積み終えた子を列の位置へ移す」ために使う。 translate_y の 2 軸版で、考え方は同じ(content 座標が絶対値なので 再帰 1 回で子孫がまとめてずれる)。

Source

fn layout_captions_at( &mut self, indices: &[usize], base_x: i32, y: i32, width: i32, ) -> i32

indices で指定した caption 群を y から順に縦積みでレイアウトし、消費した合計高さを返す。 caption-side:top(既定)/bottom どちらの配置にも使う共通ヘルパー。

Source

fn layout(&mut self, containing_block: Dimensions)

Source

fn establish_abs_cb(&self) -> Option<(i32, i32, i32, i32)>

この要素が positioned(relative/absolute/fixed)なら、子孫 absolute の包含ブロック (ABS_CB)を self の content box に切替え、切替前の値を返す。戻り値は restore_abs_cb に渡して復元する。非 positioned なら None。 content.width / content.height が確定済みであることを前提とする(bottom/right 解決のため)。

Source

fn restore_abs_cb(saved: Option<(i32, i32, i32, i32)>)

establish_abs_cb の戻り値を使って ABS_CB を元に戻す。

Source

fn child_is_out_of_flow(child: &LayoutBox<'_>) -> bool

子のうち out-of-flow(absolute / fixed)なものを判定するヘルパ。

Source

fn apply_positioned_offsets(&mut self)

position 後処理。全フォーマッティングコンテキスト(block/flex/grid/table)で共有。

  • relative: フロー確定位置から top/left(または bottom/right の符号反転)でオフセット。
  • absolute: 最近傍 positioned 祖先(ABS_CB、昇り解決済み)基準で top/left/right/bottom 配置。
  • fixed: ビューポート原点基準で配置。
  • transform: translate を最後に視覚シフトとして適用(兄弟は再フローしない=仕様通り)。

self.dimensions.content.{width,height} が確定済みであることを前提とする。

Source

fn layout_grid(&mut self, containing_block: Dimensions)

テーブルレイアウト (RFC 風の簡易固定/自動テーブル)。

  • 列数 = 最大セル数の行
  • 列幅 = 各列セルの intrinsic 幅の最大値。総和が利用幅を超えたら比例縮小、 下回ったら余りを均等配分して幅いっぱいに広げる
  • 各行は縦に積み、行内のセルは列幅で横並び、行高さ = セル最大高さに揃える
Source

fn layout_table(&mut self, containing_block: Dimensions)

Source

fn layout_flex(&mut self, containing_block: Dimensions)

Source

fn layout_flex_wrapped( &mut self, is_row: bool, is_reverse: bool, wrap_reverse: bool, justify_content: &str, align_items: &str, align_content: &str, gap_main: i32, gap_cross: i32, height_val: Option<String>, )

flex-wrap: wrap / wrap-reverse のレイアウト。 子を主軸に沿って並べ、コンテナ主軸長を超えたら次の行へ折り返す。 各行ごとに justify-content(主軸)と align-items / align-self(交差軸)を適用する。

Source

fn layout_block(&mut self, containing_block: Dimensions)

Source

fn intrinsic_inline_size_ext(&self, avail_hint: i32, pure: bool) -> (i32, i32)

avail_hint: 包含ブロックのコンテンツ幅。テキスト折り返し計測に使う。 (以前は固定 800px フォールバックだったため、実コンテナ幅と食い違い layout の行数 < flatten の行数 となって後続要素と重なるバグがあった) 内容ベースの寸法を返す。avail_hint は折り返しに使える幅。

pure が真なら現在の箱の幅を見ない。内在幅 (min-content / max-content)の算出専用の入口で、 block_intrinsic_widths だけが真を渡す。

内在幅は「今どう組まれているか」に依存してはいけない値だが、 この関数は内在幅以外の用途(表の列幅・インライン配置など)でも 呼ばれており、そちらは現在の幅を前提にしている。 【2026-09-05】一度この区別をせずに順序だけ入れ替えたところ、 ヒーローの見出しが 2 行に折り返す退行を招いて戻した。 入口を分けることで、内在幅の算出だけを正す。

Source

fn intrinsic_inline_size(&self, avail_hint: i32) -> (i32, i32)

従来どおりの入口(現在の箱の幅を見る)。

Source

fn layout_inline(&mut self, containing_block: Dimensions, _block_like: bool)

Source

fn finalize_inline_line_vertical_align( &mut self, start: usize, end: usize, line_h: i32, max_w: i32, )

インラインの1行ぶん([start, end) の子要素)に vertical-align を適用する。 簡略化: top/baseline/sub/super/text-top はいずれも無調整(top相当)、 middle は行の中央、bottom/text-bottom は行の下端に揃える。table セルの vertical-align(内容のみシフト)とは異なり、ここでは子要素自身(背景/境界線含む)を まるごとシフトする(インラインボックス自体の行内配置を変えるのが目的のため)。

Source

fn resolve_sizing_value(&self, value: Option<String>, base: i32) -> Option<i32>

min-width/max-width 等のサイジング値を解決する。px/% は base 基準、 min-content/max-content/fit-content は内容計測で解決。auto/未指定は None。

Source

fn block_intrinsic_widths(&self) -> (i32, i32)

ブロック要素の内容ベース幅を返す: (min_content, max_content)。 max_content = 折返しなしの最大行幅、min_content = 最大限折返したときの最小幅。 直下の子(inline/text/block)を計測して集約する。

Source

fn inline_content_intrinsic_size(&self, available_width: i32) -> (i32, i32)

Source

fn is_inline_line_break(&self) -> bool

Source

fn apply_box_model_styles_with_base(&mut self, containing_width: i32)

Source

fn apply_box_model_styles(&mut self)

Auto Trait Implementations§

§

impl<'a> !Send for LayoutBox<'a>

§

impl<'a> !Sync for LayoutBox<'a>

§

impl<'a> Freeze for LayoutBox<'a>

§

impl<'a> RefUnwindSafe for LayoutBox<'a>

§

impl<'a> Unpin for LayoutBox<'a>

§

impl<'a> UnsafeUnpin for LayoutBox<'a>

§

impl<'a> UnwindSafe for LayoutBox<'a>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.