nsh-core 0.7.2

Platform-independent core: shadow tree, styles, layout and mount instructions.
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
//! Lists in their parent's viewport (`viewport="parent"`,
//! [`crate::ListViewport::Parent`]): no scroll view of their own, laid out
//! at their full length, virtualized against the scroll view around them.
//!
//! The mode is fixed when the list's native view is made (a change in the
//! batch that makes it still counts). The list then mounts as a plain view
//! that clips its cells, and its Taffy node gets a child of its own, the
//! spacer, as long as its content: the list's padding, border and size
//! limits work as in a browser, and the scroll view around it covers it in
//! its content size.
//!
//! The view it is virtualized against ([`Outer`]) is the nearest scroll
//! view (a `Scroll` or a list of its own) around it on its axis, stopping
//! at root views (screens, modals, overlays, header items, accessories),
//! which are its viewport when there is none. It is found again when views
//! are inserted or moved in a tree with such lists, and the scroll view
//! keeps its lists ([`super::ScrollState`]'s `dependents`), which its
//! scrolls mark for an update. Each update reads where the list starts in
//! the view's content (frames summed up to it, plus the list's border and
//! padding) and feeds [`super::list::ListState`] the view's offset less it.
//!
//! Scrolls the lists ask of their view (anchoring, `scrollToIndex`,
//! `scrollToEnd`) are summed per view and sent once at the end of the
//! commit, counted with the view's other scrolls: platforms report how
//! many they applied, and the view replays the rest over a stale report
//! (as lists do theirs, `ListState::reported`).
//!
//! Lists of their own pay nothing for any of this: every step is reached
//! only through a list in parent mode, and a plain scroll view checks an
//! empty list of dependents.

use super::{
    Core, Key, Kind, NO_KEY, ScrollState, dirty,
    list::{Outer, PendingScroll, StickyRange, ignored, replay},
};
use crate::{
    ListViewport,
    geometry::Points,
    mount::{MountItem, ScrollBehavior, StickyCell, ViewKind},
    ops::{Command, EventKind},
    text::TextEngine,
};

/// The scrolls a scroll view's parent-viewport lists asked of it in the
/// current commit, sent at its end.
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub(super) struct Asked {
    /// A scroll to this offset (main axis), animated or not.
    to: Option<(f32, bool)>,
    /// Then by this much.
    by: f32,
}

/// What a parent-viewport list is virtualized against in this update.
#[derive(Debug, Clone, Copy)]
pub(super) struct OuterInput {
    /// The view.
    pub(super) view: Key,
    /// Where the list's content starts in the view's content.
    pub(super) start: f32,
    /// The view's offset, its pending scrolls included.
    pub(super) offset: f32,
    /// Its viewport's size.
    pub(super) viewport: f32,
    /// The furthest it scrolls.
    pub(super) max: f32,
    /// None of the scrolls issued to it is pending.
    pub(super) settled: bool,
    /// Where the cells start in the list: its border and padding, along
    /// the main and the cross axis.
    pub(super) inset: (f32, f32),
    /// The cross size of the list's content box.
    pub(super) cross: f32,
}

/// The layout style of a list's spacer: `len` along its main axis.
fn spacer_style(horizontal: bool, len: f32) -> taffy::Style {
    let len = taffy::Dimension::length(len.max(0.0));
    taffy::Style {
        size: if horizontal {
            taffy::Size {
                width: len,
                height: taffy::Dimension::auto(),
            }
        } else {
            taffy::Size {
                width: taffy::Dimension::auto(),
                height: len,
            }
        },
        flex_shrink: 0.0,
        ..Default::default()
    }
}

/// The main-axis offset of a plain scroll view: the reported one with the
/// scrolls not applied yet and the ones asked this commit.
fn scroll_offset(scroll: &ScrollState) -> f32 {
    let reported = if scroll.horizontal {
        scroll.offset.0
    } else {
        scroll.offset.1
    };
    let mut at = replay(reported, &scroll.pending);
    if let Some(asked) = &scroll.asked {
        if let Some((to, _)) = asked.to {
            at = to;
        }
        at += asked.by;
    }
    at
}

impl<M: TextEngine> Core<M> {
    /// `viewport` of list `key`: switches its mode while its native view
    /// is not sent yet; later, warns once and keeps it.
    pub(super) fn set_list_viewport(&mut self, key: Key, mode: ListViewport) {
        let node = &self.nodes[key as usize];
        let Some(list) = node.list.as_ref() else {
            return;
        };
        let parent = mode == ListViewport::Parent;
        if list.parent == parent {
            return;
        }
        let id = node.id;
        let (created, layout) = (node.created, node.layout);
        // A list that was a component's view before it took its kind has
        // its first `Create` among the items until they go.
        self.drop_retagged();
        let create = created.then(|| {
            self.mount
                .iter()
                .position(|m| matches!(m, MountItem::Create { id: c, .. } if *c == id))
        });
        if create == Some(None) {
            // Made in an earlier batch.
            let list = self.nodes[key as usize].list.as_mut().expect("list");
            if list.warned & ignored::VIEWPORT == 0 {
                list.warned |= ignored::VIEWPORT;
                log::warn!(
                    target: "js",
                    "List {id}: `viewport` is fixed when the list is made; the change is ignored (render a new list)"
                );
            }
            return;
        }
        let layout = layout.expect("list layout");
        let list = self.nodes[key as usize].list.as_mut().expect("list");
        list.set_parent(parent);
        if parent {
            let len = list.content_len();
            let spacer = self.layout.new_leaf(spacer_style(list.horizontal, len));
            self.layout.add_child(layout, spacer);
            list.spacer = Some((spacer, len));
            self.parent_lists.push(key);
            self.outer_moved = true;
        } else {
            if let Some((spacer, _)) = list.spacer.take() {
                self.layout.remove(spacer);
            }
            self.parent_lists.retain(|&k| k != key);
            self.forget_outer(key);
        }
        self.layout.mark_dirty(layout);
        self.needs_layout = true;
        if let Some(Some(at)) = create {
            let kind = if parent {
                ViewKind::View
            } else {
                ViewKind::Scroll
            };
            self.mount[at] = MountItem::Create { id, kind };
            // Parent mode clips its cells; a scroll view gets its config.
            let refreshing = self.nodes[key as usize]
                .scroll
                .as_ref()
                .is_some_and(|s| s.refreshing);
            let flags = match (parent, refreshing) {
                // Its children are read in screen order (`ViewProps::screen_order`).
                (true, _) => dirty::VIEW | dirty::VIEW_PROPS,
                (false, false) => dirty::VIEW | dirty::SCROLL,
                (false, true) => dirty::VIEW | dirty::SCROLL | dirty::REFRESHING,
            };
            self.mark(key, flags);
        }
        if parent {
            self.warn_ignored(key);
        }
    }

    /// Gives list `key`'s spacer its content length (and its axis, with
    /// `axis`); a change lays the page out again in this commit.
    pub(super) fn sync_spacer(&mut self, key: Key, axis: bool) {
        let Some(list) = self.nodes[key as usize].list.as_mut() else {
            return;
        };
        let Some((spacer, len)) = list.spacer else {
            return;
        };
        let new = list.content_len();
        if new == len && !axis {
            return;
        }
        list.spacer = Some((spacer, new));
        self.layout
            .set_style(spacer, spacer_style(list.horizontal, new));
        self.needs_layout = true;
        self.extent_changed = true;
    }

    /// Finds the view each parent-viewport list is virtualized against
    /// (after views moved), keeps the scroll views' lists of them, and
    /// orders the lists outer ones first.
    pub(super) fn resolve_outer(&mut self) {
        self.outer_moved = false;
        for i in 0..self.parent_lists.len() {
            let key = self.parent_lists[i];
            let found = self.find_outer(key);
            let list = self.nodes[key as usize].list.as_mut().expect("list");
            let old = std::mem::replace(&mut list.outer, found);
            if old.map(|o| o.view) == found.map(|o| o.view) {
                continue;
            }
            list.dirty = true;
            // Its sticky cells go to the new view with ranges in its offsets.
            let had_sticky = !std::mem::take(&mut list.sent_sticky).is_empty();
            if let Some(old) = old
                && let Some(scroll) = self
                    .nodes
                    .get_mut(old.view as usize)
                    .and_then(|n| n.scroll.as_mut())
            {
                scroll.dependents.retain(|&k| k != key);
                if had_sticky {
                    self.sticky_views.push(old.view);
                }
            }
            if let Some(found) = found
                && found.scrolls
                && let Some(scroll) = self.nodes[found.view as usize].scroll.as_mut()
            {
                scroll.dependents.push(key);
            }
        }
        let nodes = &self.nodes;
        self.parent_lists.sort_by_key(|&k| {
            nodes[k as usize]
                .list
                .as_ref()
                .and_then(|l| l.outer)
                .map_or(0, |o| o.depth)
        });
    }

    /// The nearest scroll view around list `key` on its axis, else the root
    /// view it is in; `None` out of the tree.
    fn find_outer(&self, key: Key) -> Option<Outer> {
        let horizontal = self.nodes[key as usize].list.as_ref()?.horizontal;
        let mut depth = 0;
        let mut k = self.nodes[key as usize].parent;
        while k != NO_KEY {
            depth += 1;
            let n = &self.nodes[k as usize];
            if k == self.root || n.kind.is_root() {
                return Some(Outer {
                    view: k,
                    scrolls: false,
                    depth,
                });
            }
            let scrolls = match n.kind {
                Kind::Scroll => n
                    .scroll
                    .as_ref()
                    .is_some_and(|s| s.horizontal == horizontal),
                Kind::List => n
                    .list
                    .as_ref()
                    .is_some_and(|l| !l.parent && l.horizontal == horizontal),
                _ => false,
            };
            if scrolls {
                return Some(Outer {
                    view: k,
                    scrolls: true,
                    depth,
                });
            }
            k = n.parent;
        }
        None
    }

    /// Whether moving `key` can move a list in its parent's viewport: it is
    /// one, or a view with children (a text block holds no lists).
    pub(super) fn may_hold_page_list(&self, key: Key) -> bool {
        let node = &self.nodes[key as usize];
        node.list.as_ref().is_some_and(|l| l.parent)
            || (node.kind != Kind::Text && !node.children.is_empty())
    }

    /// List `key` leaves the view it was virtualized against.
    pub(super) fn forget_outer(&mut self, key: Key) {
        let Some(list) = self.nodes[key as usize].list.as_mut() else {
            return;
        };
        let had_sticky = !std::mem::take(&mut list.sent_sticky).is_empty();
        if let Some(outer) = list.outer.take()
            && let Some(scroll) = self
                .nodes
                .get_mut(outer.view as usize)
                .and_then(|n| n.scroll.as_mut())
        {
            scroll.dependents.retain(|&k| k != key);
            if had_sticky {
                self.sticky_views.push(outer.view);
            }
        }
    }

    /// The sticky cells of list `key`, in the viewport of `view`, changed
    /// from `old`: the cells that became sticky go on top of the list's
    /// other cells (the platforms keep the cells of a scroll view's own
    /// list on top), and the view's sticky cells are sent again.
    pub(super) fn page_sticky_changed(&mut self, key: Key, view: Key, old: &[StickyRange]) {
        let list = self.nodes[key as usize].list.as_ref().expect("list");
        let id = self.nodes[key as usize].id;
        let new: Vec<u32> = list
            .sent_sticky
            .iter()
            .map(|r| r.cell)
            .filter(|c| !old.iter().any(|o| o.cell == *c))
            .collect();
        for cell in new {
            self.mount.push(MountItem::Insert {
                parent: id,
                child: cell,
                before: None,
            });
        }
        self.sticky_views.push(view);
    }

    /// Where a cell inserted into list `key` in its parent's viewport goes:
    /// below its sticky cells.
    pub(super) fn below_sticky(&self, key: Key, child: Key) -> Option<crate::NodeId> {
        let list = self.nodes[key as usize].list.as_ref()?;
        let child = self.nodes[child as usize].id;
        list.sent_sticky.iter().map(|r| r.cell).find(|&c| {
            c != child
                && self.key(c).is_ok_and(|k| {
                    self.nodes[k as usize].parent == key && self.nodes[k as usize].created
                })
        })
    }

    /// The native scroll view's own and nested lists' ranges, plus CSS
    /// sticky views. Remount replays the same data without restacking.
    pub(super) fn sticky_ranges(&self, view: Key) -> Vec<StickyRange> {
        let node = &self.nodes[view as usize];
        // A parent-viewport list mounts as a plain view. Its scroll view
        // receives these ranges through `dependents` below.
        if node.list.as_ref().is_some_and(|list| list.parent) {
            return Vec::new();
        }
        let Some(scroll) = node.scroll.as_ref() else {
            return Vec::new();
        };
        let mut all: Vec<StickyRange> = node
            .list
            .as_ref()
            .map(|l| l.sent_sticky.clone())
            .unwrap_or_default();
        for &d in &scroll.dependents {
            if let Some(list) = self.nodes[d as usize].list.as_ref() {
                all.extend_from_slice(&list.sent_sticky);
            }
        }
        // And its `position: sticky` views'.
        all.extend_from_slice(&scroll.view_sticky);
        // By cell, its built-in bar last: the platforms raise the cells in
        // this order, and the bar draws over the viewport, rows included.
        let bar = scroll.bar.as_ref().map(|b| b.0);
        all.sort_by_key(|r| (Some(r.cell) == bar, r.cell));
        all
    }

    /// Sends each view in `sticky_views` its sticky cells: its lists' in
    /// its viewport, its own when it is a list, and its sticky views'
    /// ([`super::sticky`]).
    pub(super) fn send_page_sticky(&mut self) {
        let mut views = std::mem::take(&mut self.sticky_views);
        views.sort_unstable();
        views.dedup();
        for view in views {
            let Some(node) = self.nodes.get(view as usize).filter(|node| node.created) else {
                continue;
            };
            let Some(scroll) = node.scroll.as_ref() else {
                continue;
            };
            let all = self.sticky_ranges(view);
            if all == scroll.page_sticky {
                continue;
            }
            let id = node.id;
            let cells = all
                .iter()
                .map(|r| StickyCell {
                    cell: r.cell,
                    start: Points(r.start),
                    end: Points(r.end),
                    offset: r.offset,
                })
                .collect();
            self.nodes[view as usize]
                .scroll
                .as_mut()
                .expect("scroll")
                .page_sticky = all;
            self.mount.push(MountItem::StickyCells { id, cells });
        }
    }

    /// Node `key`, a view parent-viewport lists were virtualized against,
    /// is released with these lists: they find theirs again.
    pub(super) fn outer_released(&mut self, dependents: &[Key]) {
        for &d in dependents {
            if let Some(list) = self.nodes.get_mut(d as usize).and_then(|n| n.list.as_mut()) {
                list.outer = None;
                list.dirty = true;
            }
        }
        self.outer_moved = true;
    }

    /// Where list `key` is in the view it is virtualized against, and
    /// where that view is; `None` while the list or a view between them is
    /// not laid out.
    pub(super) fn outer_input(&self, key: Key) -> Option<OuterInput> {
        let node = &self.nodes[key as usize];
        let list = node.list.as_ref()?;
        let outer = list.outer?;
        let horizontal = list.horizontal;
        let l = self.rounded_layout(node.layout?);
        let (inset, cross) = if horizontal {
            (
                (l.border.left + l.padding.left, l.border.top + l.padding.top),
                l.size.height - l.border.top - l.border.bottom - l.padding.top - l.padding.bottom,
            )
        } else {
            (
                (l.border.top + l.padding.top, l.border.left + l.padding.left),
                l.size.width - l.border.left - l.border.right - l.padding.left - l.padding.right,
            )
        };
        let main = |x: Points, y: Points| if horizontal { x.0 } else { y.0 };
        let mut start = inset.0;
        let mut k = key;
        while k != outer.view {
            let n = &self.nodes[k as usize];
            let at = main(n.frame.origin.x, n.frame.origin.y);
            if at.is_nan() || n.parent == NO_KEY {
                return None;
            }
            start += at;
            k = n.parent;
        }
        let view = &self.nodes[outer.view as usize];
        let (offset, viewport, max, settled) = if !outer.scrolls {
            let size = if outer.view == self.root {
                self.viewport
            } else {
                let l = self.rounded_layout(view.layout?);
                crate::geometry::size_pt(l.size.width, l.size.height)
            };
            (0.0, main(size.width, size.height), 0.0, true)
        } else {
            let scroll = view.scroll.as_ref()?;
            match view.list.as_ref() {
                Some(own) => (
                    own.offset,
                    own.viewport,
                    (own.content_len() - own.viewport).max(0.0),
                    own.settled() && scroll.asked.is_none(),
                ),
                None => {
                    let viewport = main(view.frame.size.width, view.frame.size.height);
                    if viewport.is_nan() {
                        return None;
                    }
                    let content = scroll.content.map_or(viewport, |c| main(c.width, c.height));
                    (
                        scroll_offset(scroll),
                        viewport,
                        (content - viewport).max(0.0),
                        scroll.pending.is_empty() && scroll.asked.is_none(),
                    )
                }
            }
        };
        Some(OuterInput {
            view: outer.view,
            start,
            offset,
            viewport,
            max,
            settled,
            inset,
            cross: cross.max(0.0),
        })
    }

    /// A parent-viewport list asks its view to scroll to `to` (animated or
    /// not), then by `by`: summed with the other asks of the commit and
    /// sent at its end. The view's lists follow at once.
    pub(super) fn ask_outer(&mut self, view: Key, to: Option<(f32, bool)>, by: f32) {
        let node = &mut self.nodes[view as usize];
        let Some(scroll) = node.scroll.as_mut() else {
            // A root view: nothing scrolls.
            return;
        };
        let asked = match &mut scroll.asked {
            Some(asked) => asked,
            None => {
                self.outer_asked.push(view);
                scroll.asked.insert(Asked::default())
            }
        };
        if let Some(to) = to {
            *asked = Asked {
                to: Some(to),
                by: 0.0,
            };
        }
        asked.by += by;
        if let Some(own) = node.list.as_mut() {
            // A list of its own moves its window as for its own commands.
            if let Some((to, animated)) = to
                && !animated
            {
                own.jump(to);
            }
            own.offset += by;
            own.dirty = true;
        }
        self.dependents_dirty(view);
    }

    /// The lists virtualized against scroll view `view` update in the
    /// next round.
    pub(super) fn dependents_dirty(&mut self, view: Key) {
        let count = self.nodes[view as usize]
            .scroll
            .as_ref()
            .map_or(0, |s| s.dependents.len());
        for i in 0..count {
            let d = self.nodes[view as usize]
                .scroll
                .as_ref()
                .expect("scroll")
                .dependents[i];
            if let Some(list) = self.nodes[d as usize].list.as_mut() {
                list.dirty = true;
            }
        }
    }

    /// Sends the scrolls the lists asked of their views in this commit:
    /// growing content comes first (it is queued already), a scroll back
    /// goes before the view's content shrinks.
    pub(super) fn send_outer_scrolls(&mut self) {
        let batch = self.batches;
        for view in std::mem::take(&mut self.outer_asked) {
            let Some(node) = self.nodes.get_mut(view as usize) else {
                continue;
            };
            let id = node.id;
            let Some(scroll) = node.scroll.as_mut() else {
                continue;
            };
            let Some(asked) = scroll.asked.take() else {
                continue;
            };
            let horizontal = scroll.horizontal;
            let content_item = scroll.content_item.filter(|&(b, _)| b == batch);
            let along = |v: f32| {
                if horizontal {
                    (Points(v), Points::ZERO)
                } else {
                    (Points::ZERO, Points(v))
                }
            };
            if let Some((to, animated)) = asked.to {
                match node.list.as_mut() {
                    Some(own) => own.issue_scroll_to(to),
                    None => issue(scroll, PendingScroll::To(to)),
                }
                let (x, y) = along(to);
                self.mount.push(MountItem::Command {
                    id,
                    command: Command::ScrollTo { x, y, animated },
                });
            }
            if asked.by != 0.0 {
                let node = &mut self.nodes[view as usize];
                match node.list.as_mut() {
                    Some(own) => own.issue_scroll_by(asked.by),
                    None => issue(
                        node.scroll.as_mut().expect("scroll"),
                        PendingScroll::By(asked.by),
                    ),
                }
                let (dx, dy) = along(asked.by);
                let item = MountItem::ScrollBy { id, dx, dy };
                let before =
                    (asked.by < 0.0)
                        .then_some(content_item)
                        .flatten()
                        .and_then(|(_, i)| {
                            let at = self.mount.get(i..)?.iter().position(
                                |m| matches!(m, MountItem::ScrollContent { id: c, .. } if *c == id),
                            )?;
                            Some(i + at)
                        });
                match before {
                    Some(at) => self.mount.insert(at, item),
                    None => self.mount.push(item),
                }
            }
        }
    }

    /// A plain scroll view `key` was sent a scroll of the core's (each one
    /// counts: platforms report how many they applied); its lists replay
    /// it over reports that predate it.
    pub(super) fn scroll_issued(&mut self, key: Key, scroll: PendingScroll) {
        let Some(state) = self.nodes[key as usize].scroll.as_mut() else {
            return;
        };
        issue(state, scroll);
        if !state.dependents.is_empty() {
            self.dependents_dirty(key);
        }
    }

    /// Warns once of each prop list `key` ignores in its parent's
    /// viewport: they are the scroll view's around it, or need a scroll
    /// view of the list's own.
    pub(super) fn warn_ignored(&mut self, key: Key) {
        let node = &self.nodes[key as usize];
        let Some(list) = node.list.as_ref().filter(|l| l.parent) else {
            return;
        };
        let mut bits = list.ignored;
        if [
            EventKind::Scroll,
            EventKind::ScrollEnd,
            EventKind::ScrollDragStart,
            EventKind::ScrollDragEnd,
            EventKind::MomentumStart,
            EventKind::MomentumEnd,
        ]
        .into_iter()
        .any(|e| node.events.contains(e))
        {
            bits |= ignored::ON_SCROLL;
        }
        if node.events.contains(EventKind::Refresh) {
            bits |= ignored::REFRESH;
        }
        if let Some(scroll) = node.scroll.as_ref() {
            if scroll.scroll_value.is_some() {
                bits |= ignored::SCROLL_VALUE;
            }
            if scroll.refreshing
                || scroll.pull_value.is_some()
                || scroll.behavior.refresh_indicator.is_some()
            {
                bits |= ignored::REFRESH;
            }
            // The app's refresh indicator counts as refresh above.
            let behavior = ScrollBehavior {
                refresh_indicator: None,
                ..scroll.behavior.clone()
            };
            if behavior != ScrollBehavior::default()
                || scroll.keyboard_dismiss != crate::ops::KeyboardDismissMode::None
            {
                bits |= ignored::BEHAVIOR;
            }
            if scroll.scrollbar != crate::ScrollbarSetting::Shown {
                bits |= ignored::SCROLLBAR;
            }
        }
        let new = bits & !list.warned;
        if new == 0 {
            return;
        }
        let id = node.id;
        self.nodes[key as usize].list.as_mut().expect("list").warned |= new;
        for (bit, what, why) in IGNORED {
            if new & bit != 0 {
                log::warn!(target: "js", "List {id} (viewport=\"parent\") ignores {what}: {why}");
            }
        }
    }
}

/// Counts a scroll sent to a plain scroll view, kept for its lists'
/// replay while it has any.
fn issue(scroll: &mut ScrollState, pending: PendingScroll) {
    scroll.issued = scroll.issued.wrapping_add(1);
    if let Some((n, (x, y))) = scroll.target.as_mut() {
        *n = scroll.issued;
        if let PendingScroll::By(by) = pending {
            if scroll.horizontal {
                *x += by;
            } else {
                *y += by;
            }
        }
    }
    if !scroll.dependents.is_empty() {
        scroll.pending.push((scroll.issued, pending));
    }
}

const AROUND: &str = "the scroll view around the list scrolls it";
const OWN: &str = "it needs a scroll view of its own (viewport=\"own\")";

/// What each [`ignored`] bit stands for, and why.
const IGNORED: [(u16, &str, &str); 8] = [
    (ignored::INVERTED, "`inverted`", OWN),
    (ignored::FOLLOW_END, "`maintainVisibleContentPosition`", OWN),
    (ignored::ALIGNMENT, "`alignment`", OWN),
    (
        ignored::ON_SCROLL,
        "`onScroll` and the other scroll events",
        AROUND,
    ),
    (ignored::SCROLL_VALUE, "`scrollValue`", AROUND),
    (
        ignored::REFRESH,
        "`refreshing`, `onRefresh`, `pullValue` and `refreshIndicator`",
        AROUND,
    ),
    (
        ignored::BEHAVIOR,
        "paging, snapping, `contentInset`, `scrollbarInset`, `contentOffset`, `bounces`, `scrollsToTop`, `smoothWheel`, `wheelLineHeight`, `scrollable` and `keyboardDismissMode`",
        AROUND,
    ),
    (ignored::SCROLLBAR, "`scrollbar`", AROUND),
];