apace-dom 0.3.0

Apace DOM implementation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
//! CSS vertical writing modes (`writing-mode` feature).
//!
//! Takia is a horizontal-tb engine: `width`/x is the inline axis and `height`/+y the block axis.
//! Apace runs each box's layout algorithm in the axes of the box's own writing mode and translates at
//! the boundary (see [`stylo_takia::writing_mode`] for the axis mapping):
//!
//! - Style getters: a box's own algorithm reads its style in its own writing mode
//!   (`get_core_container_style`); the algorithm laying it out reads it in *that* algorithm's writing mode
//!   (`get_*_child_style`, `get_oof_item_style`, [`BaseDocument::child_layout_style`]).
//!   [`LayoutPassState::layout_wm`] tracks the writing mode of the running algorithm.
//! - Orthogonal flows ([`compute_child_layout_in_own_wm`]): when a box's writing mode differs from its
//!   parent's, the `LayoutInput` is transposed into the box's axes, its auto inline size is
//!   resolved to fit-content (css-writing-modes-3 §7.3.1), and the `LayoutOutput` is transposed
//!   back. Percentage padding on such a box resolves against the containing block's inline size
//!   ([`LayoutPassState::orthogonal_percent_basis`]).
//! - Geometry: `unrounded_layout` is written by the placing algorithm in *its* writing mode.
//!   [`physicalise_and_round_layout`] converts every layout to physical coordinates (mirroring
//!   the block axis for `*-rl` modes) and rounds it, replacing `takia::round_layout`.
//!
//! [`compute_child_layout_in_own_wm`]: LayoutPassState::compute_child_layout_in_own_wm
//! [`physicalise_and_round_layout`]: LayoutPassState::physicalise_and_round_layout

use super::{BlockContext, LayoutPassState, resolve_calc_value};
use crate::document::BaseDocument;
use crate::dom_node_id;
use crate::node::Node;
use stylo_takia::WritingMode;
use stylo_takia::WritingModeExt;
use takia::{
    AvailableSpace, AxisStaticEdge, AxisStaticPosition, CoreStyle, Layout, LayoutInput,
    LayoutOutput, NodeId, Point, ResolveOrZero, RoundTree, RunMode, Size, TraversePartialTree,
};

impl BaseDocument {
    /// The writing mode in which the root element's layout algorithm runs: the HTML special case of
    /// css-writing-modes-3 §8 uses the `writing-mode` of its `<body>` child instead of its own.
    pub(crate) fn root_layout_wm(&self, root_id: crate::NodeId) -> WritingMode {
        let root = &self.nodes[root_id];
        let wm = root.writing_mode();
        if root.has_containment() {
            return wm;
        }
        root.children
            .iter()
            .map(|&child| &self.nodes[child])
            .find(|child| {
                child
                    .data
                    .downcast_element()
                    .is_some_and(|el| *el.name.local == *"body")
            })
            .filter(|body| !body.has_containment())
            .map(|body| body.writing_mode())
            .unwrap_or(wm)
    }
}

impl LayoutPassState<'_> {
    /// The writing mode in which `node_id`'s layout algorithm runs (the root's is resolved once per
    /// pass by [`BaseDocument::root_layout_wm`]).
    #[inline]
    pub(crate) fn layout_wm_of(&self, node_id: crate::NodeId) -> WritingMode {
        if Some(node_id) == self.root_id {
            self.root_wm
        } else {
            self.nodes[node_id].writing_mode()
        }
    }

    /// Lay out `node_id`, translating between the parent's writing mode and the node's own at an
    /// orthogonal-flow boundary.
    pub(crate) fn compute_child_layout_in_own_wm(
        &mut self,
        node_id: NodeId,
        inputs: LayoutInput,
        block_ctx: Option<&mut BlockContext<'_>>,
    ) -> LayoutOutput {
        let node_wm = self.layout_wm_of(dom_node_id(node_id));
        let parent_wm = core::mem::replace(&mut self.layout_wm, node_wm);
        // Set by `dispatch_child_layout` when the node turns out to be a column flex container.
        let parent_align_axis_is_inline =
            core::mem::replace(&mut self.current_align_axis_is_inline, false);

        let mut output = if node_wm.is_vertical() == parent_wm.is_vertical() {
            let mut output = self.compute_child_layout_in_current_wm(node_id, inputs, block_ctx);
            if node_wm.is_vertical() && node_wm.is_vertical_lr() != parent_wm.is_vertical_lr() {
                // Parallel writing modes with opposite block directions (`vertical-lr` in `vertical-rl`
                // or vice versa) share Takia's axes but run the block axis the other way.
                let extent = output.size.height;
                for candidate in output.oof_candidates.as_mut_slice() {
                    candidate.static_position.y =
                        mirror_static_position(candidate.static_position.y, extent);
                }
            }
            output
        } else {
            self.compute_orthogonal_child_layout(node_id, inputs, parent_wm)
        };

        let node_block_reversed = node_wm.block_left_is_end();
        let parent_block_reversed = parent_wm.block_left_is_end();
        let mirror_x = node_block_reversed && !parent_wm.is_vertical();
        let mirror_y = (node_block_reversed && parent_wm.is_vertical()) ^ parent_block_reversed;
        if mirror_x || mirror_y {
            let style = self.nodes[dom_node_id(node_id)].layout_style_in(parent_wm);
            let border = style
                .border()
                .resolve_or_zero(inputs.parent_size.width, resolve_calc_value);
            let client_size = output.size - border.sum_axes();
            let overflow = style.overflow();
            let is_scroll_container =
                overflow.x.is_scroll_container() || overflow.y.is_scroll_container();
            output.scrollable_overflow_rect = mirror_overflow(
                output.scrollable_overflow_rect,
                client_size,
                Point {
                    x: mirror_x,
                    y: mirror_y,
                },
                is_scroll_container,
            );
        }

        self.layout_wm = parent_wm;
        self.current_align_axis_is_inline = parent_align_axis_is_inline;
        output
    }

    fn compute_orthogonal_child_layout(
        &mut self,
        node_id: NodeId,
        inputs: LayoutInput,
        parent_wm: WritingMode,
    ) -> LayoutOutput {
        let percent_basis = self.orthogonal_percent_basis.replace((
            dom_node_id(node_id),
            inputs.parent_size.width.unwrap_or(0.0),
        ));

        let mut inputs = inputs.transpose();

        // A block container stretches its in-flow children's inline size and passes it as a known
        // dimension. For an orthogonal child that is its block size, which is content-sized.
        // (An out-of-flow box's known dimensions come from its insets and are kept.)
        let node = &self.nodes[dom_node_id(node_id)];
        let placed_by_block_container = !self.is_out_of_flow(node_id)
            && node
                .layout_parent
                .get()
                .map(|parent| self.nodes[parent].takia_display() == takia::Display::Block)
                .unwrap_or(true);
        if placed_by_block_container
            && takia::CoreStyle::size(&node.layout_style())
                .height
                .is_auto()
        {
            inputs.known_dimensions.height = None;
            inputs.known_dimensions_are_definite.height = false;
        }

        let is_intrinsic_inline_measurement = inputs.axis == takia::RequestedAxis::Horizontal
            && matches!(
                inputs.available_space.width,
                AvailableSpace::MinContent | AvailableSpace::MaxContent
            );

        if inputs.run_mode != RunMode::PerformHiddenLayout
            && inputs.known_dimensions.width.is_none()
            && !is_intrinsic_inline_measurement
        {
            let inline_size_is_auto =
                takia::CoreStyle::size(&self.nodes[dom_node_id(node_id)].layout_style())
                    .width
                    .is_auto();
            if inline_size_is_auto {
                // css-writing-modes-3 §7.3.1: an auto inline size in an orthogonal flow is
                // fit-content against the available space in that axis: the containing block's
                // block size if definite, else the initial containing block (nearest fixed-size
                // scroll container not implemented).
                let available = match (inputs.available_space.width, inputs.parent_size.width) {
                    (AvailableSpace::Definite(size), _) => size,
                    (_, Some(size)) => size,
                    _ => {
                        let viewport = self.stylist.device().au_viewport_size();
                        if parent_wm.is_vertical() {
                            viewport.width.to_f32_px()
                        } else {
                            viewport.height.to_f32_px()
                        }
                    }
                };
                let measure = |doc: &mut Self, available_space: AvailableSpace| {
                    let measure_inputs = LayoutInput {
                        run_mode: RunMode::ComputeSize,
                        axis: takia::RequestedAxis::Horizontal,
                        known_dimensions: Size {
                            width: None,
                            height: inputs.known_dimensions.height,
                        },
                        available_space: Size {
                            width: available_space,
                            height: inputs.available_space.height,
                        },
                        ..inputs
                    };
                    doc.compute_child_layout_in_current_wm(node_id, measure_inputs, None)
                        .size
                        .width
                };
                let max_content = measure(self, AvailableSpace::MaxContent);
                let min_content = measure(self, AvailableSpace::MinContent);
                inputs.known_dimensions.width = Some(available.min(max_content).max(min_content));
                inputs.known_dimensions_are_definite.width = true;
            }
        }

        let mut output = self.compute_child_layout_in_current_wm(node_id, inputs, None);
        self.orthogonal_percent_basis = percent_basis;
        transpose_static_positions(&mut output, self.layout_wm, parent_wm);
        output.transpose()
    }

    /// Convert every `unrounded_layout` (written in the writing mode of the box that placed it) to
    /// physical coordinates and round it into `final_layout`. Mirrors `takia::round_layout`,
    /// which it replaces: rounding is applied to cumulative physical positions so that adjacent
    /// boxes never gain gaps or overlaps.
    pub(crate) fn physicalise_and_round_layout(&mut self, root: NodeId) {
        let viewport = self.stylist.device().au_viewport_size();
        let viewport = Size {
            width: viewport.width.to_f32_px(),
            height: viewport.height.to_f32_px(),
        };
        let root_wm = self.layout_wm_of(dom_node_id(root));
        self.physicalise_and_round_inner(root, root_wm, viewport, Point::ZERO, Point::ZERO);
    }

    fn physicalise_and_round_inner(
        &mut self,
        node_id: NodeId,
        placer_wm: WritingMode,
        placer_size: Size<f32>,
        parent_pos: Point<f32>,
        rounded_parent_pos: Point<f32>,
    ) {
        let node = &self.doc.nodes[dom_node_id(node_id)];
        // Hidden subtrees can retain their box roster while Stylo deliberately
        // leaves descendants unstyled. They have no box to physicalise.
        if node.primary_styles().is_none() {
            return;
        }
        let overflow = node.layout_style().overflow();
        let is_scroll_container =
            overflow.x.is_scroll_container() || overflow.y.is_scroll_container();
        let unrounded = physical_layout(
            self.get_unrounded_layout(node_id),
            placer_wm,
            placer_size,
            is_scroll_container,
        );

        let pos = Point {
            x: parent_pos.x + unrounded.location.x,
            y: parent_pos.y + unrounded.location.y,
        };
        let size = unrounded.size;
        // As in `takia::round_layout`: the box's outer edges are rounded in absolute coordinates and
        // every inner edge is rounded relative to them, so adjacent boxes never overlap or gap.
        let rounded_pos = Point {
            x: pos.x.round(),
            y: pos.y.round(),
        };
        let rounded_end = Point {
            x: (pos.x + size.width).round(),
            y: (pos.y + size.height).round(),
        };
        let from_left = |v: f32| (pos.x + v).round() - rounded_pos.x;
        let from_top = |v: f32| (pos.y + v).round() - rounded_pos.y;
        let from_right = |v: f32| rounded_end.x - (pos.x + size.width - v).round();
        let from_bottom = |v: f32| rounded_end.y - (pos.y + size.height - v).round();

        let mut layout = unrounded;
        layout.location = Point {
            x: rounded_pos.x - rounded_parent_pos.x,
            y: rounded_pos.y - rounded_parent_pos.y,
        };
        layout.size = Size {
            width: rounded_end.x - rounded_pos.x,
            height: rounded_end.y - rounded_pos.y,
        };
        layout.scrollbar_size = unrounded.scrollbar_size.map(f32::round);
        layout.border = takia::Rect {
            left: from_left(unrounded.border.left),
            right: from_right(unrounded.border.right),
            top: from_top(unrounded.border.top),
            bottom: from_bottom(unrounded.border.bottom),
        };
        layout.padding = takia::Rect {
            left: from_left(unrounded.padding.left),
            right: from_right(unrounded.padding.right),
            top: from_top(unrounded.padding.top),
            bottom: from_bottom(unrounded.padding.bottom),
        };
        let overflow = unrounded.scrollable_overflow_rect.rect();
        layout.scrollable_overflow_rect = takia::ScrollableOverflow::new(
            takia::Rect {
                left: from_left(overflow.left),
                right: from_left(overflow.right),
                top: from_top(overflow.top),
                bottom: from_top(overflow.bottom),
            },
            unrounded.scrollable_overflow_rect.is_reversed(),
        );

        // `unrounded_layout` is left in the placer's writing mode: Takia's cache may skip re-placing
        // this node on a later layout, and only `final_layout` is read downstream.
        self.set_final_layout(node_id, &layout);

        let wm = self.layout_wm_of(dom_node_id(node_id));
        self.node_from_id_mut(node_id)
            .layout_data_mut()
            .writing_mode = wm;
        for index in 0..self.child_count(node_id) {
            let child = self.get_child_id(node_id, index);
            if !self.is_out_of_flow(child) {
                self.physicalise_and_round_inner(child, wm, size, pos, rounded_pos);
            }
        }
        for index in 0..self.hoisted_child_count(node_id) {
            let child = self.get_hoisted_child_id(node_id, index);
            self.physicalise_and_round_inner(child, wm, size, pos, rounded_pos);
        }
    }
}

/// Map the static positions of `output`'s out-of-flow candidates (relative to the border box of a
/// node laid out in `child_wm`) into `parent_wm`, ahead of [`LayoutOutput::transpose`],
/// which leaves them untouched. The block axis of `vertical-rl` runs against Takia's
/// coordinate, so that coordinate is mirrored within the node's size.
fn transpose_static_positions(
    output: &mut LayoutOutput,
    child_wm: WritingMode,
    parent_wm: WritingMode,
) {
    if output.oof_candidates.is_empty() {
        return;
    }
    let vertical_wm = if child_wm.is_vertical() {
        child_wm
    } else {
        parent_wm
    };
    let mirror_block = !vertical_wm.is_vertical_lr();
    let size = output.size;
    for candidate in output.oof_candidates.as_mut_slice() {
        let Point { mut x, mut y } = candidate.static_position;
        if mirror_block {
            if child_wm.is_vertical() {
                y = mirror_static_position(y, size.height);
            } else {
                x = mirror_static_position(x, size.width);
            }
        }
        candidate.static_position = Point { x: y, y: x };
    }
}

fn mirror_static_position(position: AxisStaticPosition, extent: f32) -> AxisStaticPosition {
    let flip = |edge: AxisStaticEdge| match edge {
        AxisStaticEdge::Start => AxisStaticEdge::End,
        AxisStaticEdge::End => AxisStaticEdge::Start,
        AxisStaticEdge::Center => AxisStaticEdge::Center,
    };
    AxisStaticPosition {
        area: takia::Line {
            start: extent - position.area.end,
            end: extent - position.area.start,
        },
        align: takia::AxisStaticAlign {
            keyword: flip(position.align.keyword),
            fallback: flip(position.align.fallback),
            ..position.align
        },
    }
}

fn mirror_overflow(
    overflow: takia::ScrollableOverflow,
    client_size: Size<f32>,
    axes: Point<bool>,
    is_scroll_container: bool,
) -> takia::ScrollableOverflow {
    let mut rect = overflow.rect();
    let mut reversed = overflow.is_reversed();
    if axes.x {
        let left = client_size.width - rect.right;
        rect.right = (client_size.width - rect.left).max(0.0);
        rect.left = left.min(0.0);
        reversed.x = is_scroll_container && !reversed.x;
    }
    if axes.y {
        let top = client_size.height - rect.bottom;
        rect.bottom = (client_size.height - rect.top).max(0.0);
        rect.top = top.min(0.0);
        reversed.y = is_scroll_container && !reversed.y;
    }
    takia::ScrollableOverflow::new(rect, reversed)
}

/// `logical`, written by a placing algorithm running in `placer_wm` within a box of physical size
/// `placer_size`, in physical coordinates.
fn physical_layout(
    logical: Layout,
    placer_wm: WritingMode,
    placer_size: Size<f32>,
    is_scroll_container: bool,
) -> Layout {
    if !placer_wm.is_vertical() {
        return logical;
    }
    let mut overflow = logical.scrollable_overflow_rect.transpose();
    if !placer_wm.is_vertical_lr() {
        let client_width = logical.size.height
            - logical.border.top
            - logical.border.bottom
            - logical.scrollbar_size.height;
        overflow = mirror_overflow(
            overflow,
            Size {
                width: client_width,
                height: 0.0,
            },
            Point { x: true, y: false },
            is_scroll_container,
        );
    }
    Layout {
        location: Point {
            x: if placer_wm.is_vertical_lr() {
                logical.location.y
            } else {
                placer_size.width - logical.location.y - logical.size.height
            },
            y: logical.location.x,
        },
        size: logical.size.transpose(),
        scrollbar_size: logical.scrollbar_size.transpose(),
        scrollable_overflow_rect: overflow,
        border: placer_wm.physical_rect(logical.border),
        padding: placer_wm.physical_rect(logical.padding),
        margin: placer_wm.physical_rect(logical.margin),
        ..logical
    }
}

impl BaseDocument {
    /// `node_id`'s document-relative position and unrounded layout in physical coordinates, for
    /// CSSOM geometry. `unrounded_layout` itself is left in the placing algorithm's writing mode (see
    /// [`LayoutPassState::physicalise_and_round_layout`]), so the containing-block chain is
    /// physicalised root-down in a single descent, each box in its placer's writing mode and size.
    pub(crate) fn physical_unrounded_geometry(
        &self,
        node_id: crate::NodeId,
    ) -> (crate::util::Point<f32>, Layout) {
        // Without a vertical box on the containing-block chain there is nothing to physicalise.
        let mut pos = crate::util::Point { x: 0.0, y: 0.0 };
        let mut has_vertical = false;
        let mut current = Some(node_id);
        while let Some(id) = current {
            let node = &self.nodes[id];
            pos.x += node.unrounded_layout().location.x - node.scroll_offset().x as f32;
            pos.y += node.unrounded_layout().location.y - node.scroll_offset().y as f32;
            if node.flags.is_top_layer() {
                pos.x += self.viewport_scroll().x as f32;
                pos.y += self.viewport_scroll().y as f32;
            }
            has_vertical |= node.layout_data().writing_mode.is_vertical();
            current = node.containing_block();
        }
        if !has_vertical {
            return (pos, *self.nodes[node_id].unrounded_layout());
        }

        let root_id = self.try_root_element().map(|root| root.id);
        let node = &self.nodes[node_id];
        let (mut pos, placer_wm, placer_size) = self.placer_geometry(node, node_id, root_id);
        let overflow = node.layout_style().overflow();
        let layout = physical_layout(
            *node.unrounded_layout(),
            placer_wm,
            placer_size,
            overflow.x.is_scroll_container() || overflow.y.is_scroll_container(),
        );
        pos.x += layout.location.x - node.scroll_offset().x as f32;
        pos.y += layout.location.y - node.scroll_offset().y as f32;
        (pos, layout)
    }

    /// Document-relative position, writing mode and physical size of the box that places `node`.
    fn placer_geometry(
        &self,
        node: &Node,
        node_id: crate::NodeId,
        root_id: Option<crate::NodeId>,
    ) -> (crate::util::Point<f32>, WritingMode, Size<f32>) {
        let Some(placer_id) = node.containing_block().filter(|_| Some(node_id) != root_id) else {
            let viewport = self.stylist.device().au_viewport_size();
            let viewport = Size {
                width: viewport.width.to_f32_px(),
                height: viewport.height.to_f32_px(),
            };
            let wm = if node.flags.is_top_layer() {
                node.writing_mode()
            } else {
                root_id.map_or(WritingMode::empty(), |root| {
                    self.nodes[root].layout_data().writing_mode
                })
            };
            let pos = if node.flags.is_top_layer() {
                crate::util::Point {
                    x: self.viewport_scroll().x as f32,
                    y: self.viewport_scroll().y as f32,
                }
            } else {
                crate::util::Point { x: 0.0, y: 0.0 }
            };
            return (pos, wm, viewport);
        };

        let placer = &self.nodes[placer_id];
        let (mut pos, grand_wm, grand_size) = self.placer_geometry(placer, placer_id, root_id);
        let logical = placer.unrounded_layout();
        let (location, size) = if grand_wm.is_vertical() {
            let overflow = placer.layout_style().overflow();
            let physical = physical_layout(
                *logical,
                grand_wm,
                grand_size,
                overflow.x.is_scroll_container() || overflow.y.is_scroll_container(),
            );
            (physical.location, physical.size)
        } else {
            (logical.location, logical.size)
        };
        pos.x += location.x - placer.scroll_offset().x as f32;
        pos.y += location.y - placer.scroll_offset().y as f32;
        (pos, placer.layout_data().writing_mode, size)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn mirrored_overflow_preserves_both_sides_and_scroll_container_flags() {
        for is_scroll_container in [false, true] {
            let original = takia::ScrollableOverflow::new(
                takia::Rect {
                    left: -96.0,
                    right: 204.0,
                    top: -20.0,
                    bottom: 150.0,
                },
                Point { x: false, y: false },
            );
            let size = Size {
                width: 100.0,
                height: 80.0,
            };
            let axes = Point { x: true, y: true };
            let mirrored = mirror_overflow(original, size, axes, is_scroll_container);
            assert_eq!(
                mirrored.rect(),
                takia::Rect {
                    left: -104.0,
                    right: 196.0,
                    top: -70.0,
                    bottom: 100.0
                }
            );
            assert_eq!(
                mirrored.is_reversed(),
                Point {
                    x: is_scroll_container,
                    y: is_scroll_container
                }
            );
            assert_eq!(
                mirror_overflow(mirrored, size, axes, is_scroll_container),
                original
            );
        }
    }

    #[test]
    fn empty_overflow_remains_without_scrollable_extent_when_mirrored() {
        let size = Size {
            width: 100.0,
            height: 80.0,
        };
        let overflow = mirror_overflow(
            takia::ScrollableOverflow::ZERO,
            size,
            Point { x: true, y: true },
            true,
        );
        let layout = Layout {
            size,
            scrollable_overflow_rect: overflow,
            ..Layout::new()
        };
        assert_eq!((layout.scroll_width(), layout.scroll_height()), (0.0, 0.0));
    }
}