// SPDX-FileCopyrightText: MailCraft contributors // SPDX-License-Identifier: MIT OR Apache-2.0 //! The body of a message being read: parsed and laid out once, painted every frame. //! //! A frame costs what is in view: the layout of the last few messages read is kept (with the //! message it was made from, where it is shown, the width, the theme and the display scale), and //! painting walks it and paints the pieces inside the clip rectangle. Laying out is spread over //! frames ([`FRAME_BUDGET`]), so opening a very long message does not stall the window. //! //! The look of a message depends on the pane it is read in when its style sheet has `@media`: the //! blocks are made for the width the body is laid out at and the theme ([`Env`]), kept with the //! message by what its own `@media` lists say of them ([`Look`]), and made again only when the //! pane changes in a way one of them notices, never per frame; the last few looks seen stay at //! hand, so a pane dragged back and forth across a break costs nothing the second time. //! //! A message can be on screen in more than one place (the reading pane, a window of its own), //! each as wide as it likes: every [`Place`] has its own layout, and they share the parsed body. use std::collections::HashSet; use std::sync::{Arc, Mutex}; use egui::{Color32, Rect, Sense, Stroke, Ui, pos2, vec2}; use mailcraft_html::{Block, BlockKind, Env, Marker}; use mailcraft_model::Message; use super::Place; use super::colors::Paper; use super::images::{self, Picture, Pictures, Remote}; use super::layout::{Glue, ItemKind, Laid, PIECE_CHARS, PlaceholderItem, TextItem, TextLink, cut}; use super::remote::Access; use super::select::{self, Action}; use crate::MailApp; use crate::theme::{Tokens, paint_clipped, regular}; /// About how many characters of text are laid out in one frame. pub const FRAME_BUDGET: usize = 60_000; /// How many messages' layouts are kept for the reading pane. const KEPT: usize = 4; /// How many layouts are kept for windows: one each, and a few that outlive theirs for a moment. const KEPT_IN_WINDOWS: usize = 16; /// How many layouts are kept for chat bubbles in the contact/project timeline (#1907). const KEPT_IN_CHAT: usize = 64; /// How many other looks of a message's blocks are kept besides the one in use. const KEPT_CLASSES: usize = 3; /// The width a message is laid out at is a multiple of this many points. const WIDTH_STEP: f32 = 4.0; /// A message's body as display blocks. #[derive(Debug, Default)] pub struct Doc { pub blocks: Vec, /// Pictures that are not part of the message: they are placeholders unless the owner asks /// for them (and then only those in `remote`). pub remote_pictures: usize, /// The addresses of the pictures on the web that may be asked for: each once, in reading /// order, as the message wrote them, [`super::remote::MAX_PER_MESSAGE`] at most. pub remote: Vec>, /// How many more such addresses the message has than may be asked for. pub remote_left_out: usize, /// Per block: `Some` when it goes on in the paragraph of the block before, which was cut for /// its length, with what was dropped at the cut. Empty when nothing was cut. pub cuts: Arc<[Option]>, /// The message's media lists (`@media` and `