Skip to content

Truly independent web browser

LibWeb: Honor line-height on selects without native appearance

sideshowbarkerd3193396835f
diff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
index 0a493482bc0..c763f2d5cd3 100644
--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
@@ -78,6 +78,7 @@ NonnullRefPtr<ComputedStyleWorkingSet> ComputedStyleWorkingSet::create_for_anima
auto working_set = create_over_record(StyleRecordRef { record });
if (overlay) {
working_set->m_had_animated_post_compute_adjustment_property = ComputedValuesFFI::rust_animated_overlay_contains(overlay, to_underlying(PropertyID::Display))
+ || ComputedValuesFFI::rust_animated_overlay_contains(overlay, to_underlying(PropertyID::Appearance))
|| ComputedValuesFFI::rust_animated_overlay_contains(overlay, to_underlying(PropertyID::Position))
|| ComputedValuesFFI::rust_animated_overlay_contains(overlay, to_underlying(PropertyID::Float))
|| ComputedValuesFFI::rust_animated_overlay_contains(overlay, to_underlying(PropertyID::LineHeight))
@@ -225,6 +226,7 @@ void ComputedStyleWorkingSet::finish_animated_overlay_rust_mutation(Badge<StyleC
bool ComputedStyleWorkingSet::requires_animated_post_compute_adjustments() const
{
return m_had_animated_post_compute_adjustment_property
+ || has_animated_property(PropertyID::Appearance)
|| has_animated_property(PropertyID::Display)
|| has_animated_property(PropertyID::Position)
|| has_animated_property(PropertyID::Float)
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rs
index bfcf3b54f6f..a1501afb066 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs
@@ -3048,7 +3048,7 @@ impl StyleGroupMasks {
const fn compute() -> Self {
use crate::css::property_metadata::property_id::{
- CONTENT_VISIBILITY, DIRECTION, POSITION_ANCHOR, WRITING_MODE,
+ APPEARANCE, CONTENT_VISIBILITY, DIRECTION, POSITION_ANCHOR, WRITING_MODE,
};
use crate::css::property_metadata::{
FIRST_INHERITED_PROPERTY_ID, FIRST_LONGHAND_PROPERTY_ID, LAST_INHERITED_PROPERTY_ID,
@@ -3105,6 +3105,8 @@ impl StyleGroupMasks {
}
masks[index(DIRECTION)] |= logical_mapping_mask;
masks[index(WRITING_MODE)] |= logical_mapping_mask;
+ // Appearance controls the line-height adjustment of select elements.
+ masks[index(APPEARANCE)] |= 1 << crate::css::table_group_builder::group_index::FONT;
// NB: The box group holds the used containment flags implied by hidden content visibility.
masks[index(CONTENT_VISIBILITY)] |= 1 << crate::css::table_group_builder::group_index::BOX;
// NB: The surround group holds whether the element names a default anchor, which layout reads beside the
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
index 431a8981033..ed944806ab2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
@@ -350,6 +350,7 @@ fn push_longhands(property: u16, keeps: &impl Fn(u16) -> bool, properties: &mut
fn post_compute_adjusts(property: u16, facts: u32) -> bool {
use element_adjustment_fact::{CHECK_INPUT_LINE_HEIGHT, FORCE_LINE_HEIGHT_NORMAL};
match property {
+ prop::APPEARANCE => facts & FORCE_LINE_HEIGHT_NORMAL != 0,
prop::LINE_HEIGHT => facts & (FORCE_LINE_HEIGHT_NORMAL | CHECK_INPUT_LINE_HEIGHT) != 0,
_ => POST_COMPUTE_ADJUSTED_LONGHANDS.contains(&property),
}
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 3f1579cfce0..10fec25f51a 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -4371,6 +4371,7 @@ fn adjust_computed_box(
)
.0;
box_type_input.position = inputs.position;
+ box_type_input.force_line_height_normal &= keyword_of(prop::APPEARANCE) != keyword::NONE;
box_type_input.webkit_box_layout_transformation_applies =
keyword_of(prop::_WEBKIT_BOX_ORIENT) == keyword::VERTICAL && keyword_of(prop::CONTINUE) != keyword::AUTO;
let adjustments = compute_element_style_adjustments(&box_type_input, inputs.text_align);
@@ -5037,9 +5038,10 @@ pub(crate) fn compute_font_values<'a>(
}
/// The inputs every drive evaluates, selected or not.
-pub(crate) const REQUIRED_DRIVER_INPUTS: [u16; 10] = {
+pub(crate) const REQUIRED_DRIVER_INPUTS: [u16; 11] = {
use crate::css::property_metadata::property_id as prop;
[
+ prop::APPEARANCE,
prop::COLOR_SCHEME,
prop::DIRECTION,
prop::DISPLAY,
@@ -5057,7 +5059,8 @@ pub(crate) fn is_required_driver_input(property_id: u16) -> bool {
use crate::css::property_metadata::property_id as prop;
matches!(
property_id,
- prop::COLOR_SCHEME
+ prop::APPEARANCE
+ | prop::COLOR_SCHEME
| prop::DIRECTION
| prop::DISPLAY
| prop::FLOAT
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
index 8c4fc319a20..3a2322553eb 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute/adjustments.rs
@@ -623,6 +623,7 @@ pub(super) fn finalize_animated_box_type(
box_type.position = effective_keyword(longhands, view, prop::POSITION);
box_type.float_value = effective_keyword(longhands, view, prop::FLOAT);
box_type.writing_mode = longhands.effective_writing_mode(view);
+ box_type.force_line_height_normal &= effective_keyword(longhands, view, prop::APPEARANCE) != keyword::NONE;
box_type.webkit_box_layout_transformation_applies = webkit_box_layout_transformation_applies(longhands, view);
// An axis the overlay does not animate is adjusted from its keyword before the base adjusted it against the other
// axis, which the overlay may animate out of that adjustment.
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size-ref.html
new file mode 100644
index 00000000000..3e437494c0a
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size-ref.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Reference: Combobox block-size test</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 monospace; padding:0; margin:0;
+}
+
+select { -webkit-appearance: none; }
+
+.big { font-size: 48pt; min-height: 40pt; }
+.lh { line-height: 48pt; min-height: 40pt; }
+
+.mask { position:fixed; left:20px; right:0; top:0; bottom:0; background: black; }
+ </style>
+</head>
+<body>
+
+<!-- mask off differences on the right side -->
+<div class="mask"></div>
+
+<select><optgroup label="label"><option>option</option></select><br>
+<select class="big"><optgroup label="label"><option>option</option></select><br>
+<select class="lh"><optgroup label="label"><option>option</option></select><br>
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height-ref.html
new file mode 100644
index 00000000000..26e5f332821
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height-ref.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Reference: Combobox ignores CSS 'line-height'</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">
+ <style type="text/css">
+html,body {
+ color:black; background-color:white; font:16px/1 monospace;
+}
+
+ </style>
+</head>
+<body>
+
+<select><option>aaaaaaaaaa<option>bbbbbbbbbb</select>
+
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size.html b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size.html
new file mode 100644
index 00000000000..14bff8b6915
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Test: Combobox block-size test</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">
+ <link rel="match" href="../../../../../../expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-block-size-ref.html">
+ <link rel="help" href="https://html.spec.whatwg.org/multipage/rendering.html#the-select-element-2">
+ <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1499578">
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 monospace; padding:0; margin:0;
+}
+
+select { -webkit-appearance: none; }
+
+optgroup { font-size: 32pt; }
+option { font-size: 24pt; }
+.big { font-size: 48pt; }
+.lh { line-height: 48pt; }
+
+.mask { position:fixed; left:20px; right:0; top:0; bottom:0; background: black; }
+ </style>
+</head>
+<body>
+
+<!-- mask off differences on the right side -->
+<div class="mask"></div>
+
+<select><optgroup label="label"><option>option</option></select><br>
+<select class="big"><optgroup label="label"><option>option</option></select><br>
+<select class="lh"><optgroup label="label"><option>option</option></select><br>
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height.html b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height.html
new file mode 100644
index 00000000000..d9b625bd237
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Test: Combobox ignores CSS 'line-height'</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">
+ <link rel="match" href="../../../../../../expected/wpt-import/html/rendering/replaced-elements/the-select-element/select-1-line-height-ref.html">
+ <link rel="help" href="https://html.spec.whatwg.org/multipage/rendering.html#the-select-element-2">
+ <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1501908">
+ <style type="text/css">
+html,body {
+ color:black; background-color:white; font:16px/1 monospace;
+}
+
+select { line-height:100px; }
+
+ </style>
+</head>
+<body>
+
+<select><option>aaaaaaaaaa<option>bbbbbbbbbb</select>
+
+<script>
+document.body.offsetHeight;
+var cv = window.getComputedStyle(document.querySelector('select')).lineHeight;
+if (cv != "normal" && parseInt(cv) > 50) {
+ document.body.appendChild(document.createTextNode(
+ "FAIL: got computed line-height '" + cv + "', " +
+ "expected 'normal' or a length <= 50px"));
+}</script>
+
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/expected/css/select-appearance-none-line-height.txt b/Tests/LibWeb/Text/expected/css/select-appearance-none-line-height.txt
new file mode 100644
index 00000000000..8f78f5cb73e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/select-appearance-none-line-height.txt
@@ -0,0 +1,16 @@
+input: 26px, height 68
+native: normal
+inherited: 26px, height 68
+explicit: 32px, height 74
+unitless: 32px, height 74
+restored native: normal
+inherited: 26px, height 68
+inherited: 36px, height 78
+inherited: 40px, height 82
+native important: normal
+inherited: 40px, height 82
+inherited: 50px, height 92
+inherited: 36px, height 78
+inherited: 36px, height 78
+animated native: normal
+inherited: 36px, height 78
diff --git a/Tests/LibWeb/Text/input/css/select-appearance-none-line-height.html b/Tests/LibWeb/Text/input/css/select-appearance-none-line-height.html
new file mode 100644
index 00000000000..d6cb7c35bc3
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/select-appearance-none-line-height.html
@@ -0,0 +1,65 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ #controls { font: 16px/26px serif; }
+ .control {
+ display: block;
+ box-sizing: border-box;
+ width: 300px;
+ padding: 20px;
+ border: 1px solid;
+ font: inherit;
+ }
+ .plain { appearance: none; }
+</style>
+<div id="controls">
+ <input class="control" id="input" value="input">
+ <select class="control" id="native"><option>select</option></select>
+ <select class="control plain" id="inherited"><option>select</option></select>
+ <select class="control plain" id="explicit" style="line-height: 32px"><option>select</option></select>
+ <select class="control plain" id="unitless" style="line-height: 2"><option>select</option></select>
+</div>
+<script>
+ test(() => {
+ function report(id) {
+ const element = document.getElementById(id);
+ println(`${id}: ${getComputedStyle(element).lineHeight}, height ${element.getBoundingClientRect().height}`);
+ }
+ report("input");
+ println(`native: ${getComputedStyle(document.getElementById("native")).lineHeight}`);
+ report("inherited");
+ report("explicit");
+ report("unitless");
+
+ const select = document.getElementById("inherited");
+ select.style.appearance = "auto";
+ println(`restored native: ${getComputedStyle(select).lineHeight}`);
+ select.style.appearance = "none";
+ report("inherited");
+ document.getElementById("controls").style.lineHeight = "36px";
+ report("inherited");
+ select.style.setProperty("line-height", "40px", "important");
+ report("inherited");
+ select.style.appearance = "auto";
+ println(`native important: ${getComputedStyle(select).lineHeight}`);
+ select.style.appearance = "none";
+ report("inherited");
+ select.style.removeProperty("line-height");
+
+ const animation = select.animate({ lineHeight: ["40px", "60px"] }, 1000);
+ animation.pause();
+ animation.currentTime = 500;
+ report("inherited");
+ animation.cancel();
+ report("inherited");
+
+ const appearance = select.animate({ appearance: ["none", "auto"] }, 1000);
+ appearance.pause();
+ appearance.currentTime = 250;
+ report("inherited");
+ appearance.currentTime = 750;
+ println(`animated native: ${getComputedStyle(select).lineHeight}`);
+ appearance.cancel();
+ report("inherited");
+ });
+</script>