LibWeb: Resolve effective overflow-x and overflow-y according to spec
Implements following rule from CSS Overflow Module Level 3: "The visible/clip values of overflow compute to auto/hidden (respectively) if one of overflow-x or overflow-y is neither visible nor clip."
This commit is contained in:
parent
b6292a2d7d
commit
623ad94582
Notes:
sideshowbarker
2024-07-17 11:06:06 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/623ad94582 Pull-request: https://github.com/SerenityOS/serenity/pull/23066 Reviewed-by: https://github.com/awesomekling
6 changed files with 74 additions and 0 deletions
19
Tests/LibWeb/Ref/overflow-hidden-7.html
Normal file
19
Tests/LibWeb/Ref/overflow-hidden-7.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<link rel="match" href="reference/overflow-hidden-7-ref.html" />
|
||||
<style>
|
||||
.box {
|
||||
overflow-y: hidden;
|
||||
overflow-x: visible;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.inner {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
background-color: darkblue;
|
||||
}
|
||||
</style>
|
||||
<div class="box">
|
||||
<div class="inner"></div>
|
||||
</div>
|
9
Tests/LibWeb/Ref/reference/overflow-hidden-7-ref.html
Normal file
9
Tests/LibWeb/Ref/reference/overflow-hidden-7-ref.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<style>
|
||||
.box {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background-color: darkblue;
|
||||
}
|
||||
</style>
|
||||
<div class="box"></div>
|
|
@ -0,0 +1,2 @@
|
|||
overflow-x: auto
|
||||
overflow-y: hidden
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<style>
|
||||
.box {
|
||||
overflow-y: hidden;
|
||||
overflow-x: visible;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background-color: darkblue;
|
||||
}
|
||||
</style>
|
||||
<body><div class="box"></div></body>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const box = window.getComputedStyle(document.querySelector(".box"));
|
||||
println(`overflow-x: ${box.getPropertyValue("overflow-x")}`);
|
||||
println(`overflow-y: ${box.getPropertyValue("overflow-y")}`);
|
||||
});
|
||||
</script>
|
|
@ -1959,6 +1959,27 @@ void StyleComputer::absolutize_values(StyleProperties& style) const
|
|||
style.set_line_height({}, line_height);
|
||||
}
|
||||
|
||||
void StyleComputer::resolve_effective_overflow_values(StyleProperties& style) const
|
||||
{
|
||||
// https://www.w3.org/TR/css-overflow-3/#overflow-control
|
||||
// The visible/clip values of overflow compute to auto/hidden (respectively) if one of overflow-x or
|
||||
// overflow-y is neither visible nor clip.
|
||||
auto overflow_x = value_id_to_overflow(style.property(PropertyID::OverflowX)->to_identifier());
|
||||
auto overflow_y = value_id_to_overflow(style.property(PropertyID::OverflowY)->to_identifier());
|
||||
auto overflow_x_is_visible_or_clip = overflow_x == Overflow::Visible || overflow_x == Overflow::Clip;
|
||||
auto overflow_y_is_visible_or_clip = overflow_y == Overflow::Visible || overflow_y == Overflow::Clip;
|
||||
if (!overflow_x_is_visible_or_clip || !overflow_y_is_visible_or_clip) {
|
||||
if (overflow_x == CSS::Overflow::Visible)
|
||||
style.set_property(CSS::PropertyID::OverflowX, IdentifierStyleValue::create(CSS::ValueID::Auto), nullptr);
|
||||
if (overflow_x == CSS::Overflow::Clip)
|
||||
style.set_property(CSS::PropertyID::OverflowX, IdentifierStyleValue::create(CSS::ValueID::Hidden), nullptr);
|
||||
if (overflow_y == CSS::Overflow::Visible)
|
||||
style.set_property(CSS::PropertyID::OverflowY, IdentifierStyleValue::create(CSS::ValueID::Auto), nullptr);
|
||||
if (overflow_y == CSS::Overflow::Clip)
|
||||
style.set_property(CSS::PropertyID::OverflowY, IdentifierStyleValue::create(CSS::ValueID::Hidden), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
enum class BoxTypeTransformation {
|
||||
None,
|
||||
Blockify,
|
||||
|
@ -2139,6 +2160,9 @@ ErrorOr<RefPtr<StyleProperties>> StyleComputer::compute_style_impl(DOM::Element&
|
|||
// 6. Run automatic box type transformations
|
||||
transform_box_type_if_needed(style, element, pseudo_element);
|
||||
|
||||
// 7. Resolve effective overflow values
|
||||
resolve_effective_overflow_values(style);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ private:
|
|||
void compute_math_depth(StyleProperties&, DOM::Element const*, Optional<CSS::Selector::PseudoElement::Type>) const;
|
||||
void compute_defaulted_values(StyleProperties&, DOM::Element const*, Optional<CSS::Selector::PseudoElement::Type>) const;
|
||||
void absolutize_values(StyleProperties&) const;
|
||||
void resolve_effective_overflow_values(StyleProperties&) const;
|
||||
void transform_box_type_if_needed(StyleProperties&, DOM::Element const&, Optional<CSS::Selector::PseudoElement::Type>) const;
|
||||
|
||||
void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional<CSS::Selector::PseudoElement::Type>) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue