mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Retain size definiteness when transferred through aspect ratio
If a box has definite width and a preferred aspect ratio, we can determine its height without performing layout. Hence, its height should also be considered definite. And the other way around for width from height as well.
This commit is contained in:
parent
ca53eefe11
commit
1cfd8b3ac0
Notes:
sideshowbarker
2024-07-16 21:39:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1cfd8b3ac0 Pull-request: https://github.com/SerenityOS/serenity/pull/23742
1 changed files with 17 additions and 0 deletions
|
@ -482,6 +482,23 @@ void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* co
|
|||
m_has_definite_width = is_definite_size(computed_values.width(), m_content_width, true);
|
||||
m_has_definite_height = is_definite_size(computed_values.height(), m_content_height, false);
|
||||
|
||||
// For boxes with a preferred aspect ratio and one definite size, we can infer the other size
|
||||
// and consider it definite since this did not require performing layout.
|
||||
if (is<Box>(node)) {
|
||||
auto const& box = static_cast<Box const&>(node);
|
||||
if (auto aspect_ratio = box.preferred_aspect_ratio(); aspect_ratio.has_value()) {
|
||||
if (m_has_definite_width && m_has_definite_height) {
|
||||
// Both width and height are definite.
|
||||
} else if (m_has_definite_width) {
|
||||
m_content_height = m_content_width / *aspect_ratio;
|
||||
m_has_definite_height = true;
|
||||
} else if (m_has_definite_height) {
|
||||
m_content_width = m_content_height * *aspect_ratio;
|
||||
m_has_definite_width = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_has_definite_width) {
|
||||
if (has_definite_min_width)
|
||||
m_content_width = max(min_width, m_content_width);
|
||||
|
|
Loading…
Reference in a new issue