Bug 1501908 - Force line-height:normal for themed comboboxes for compat with other UAs. r=emilio, a=RyanVM
authorMats Palmgren <mats@mozilla.com>
Sat, 27 Oct 2018 15:41:00 -0400
changeset 500938 fcb8fd2dd657df97912e2d754ed613372456c32e
parent 500937 f82eaa1ff6a520b47242a776fbcf431b39900ed3
child 500939 59be666e2781b30954d40ecf5a11543af40b5f95
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, RyanVM
bugs1501908
milestone64.0
Bug 1501908 - Force line-height:normal for themed comboboxes for compat with other UAs. r=emilio, a=RyanVM
servo/components/style/style_adjuster.rs
testing/web-platform/tests/html/rendering/replaced-elements/the-select-element/select-1-line-height-ref.html
testing/web-platform/tests/html/rendering/replaced-elements/the-select-element/select-1-line-height.html
--- a/servo/components/style/style_adjuster.rs
+++ b/servo/components/style/style_adjuster.rs
@@ -4,18 +4,20 @@
 
 //! A struct to encapsulate all the style fixups and flags propagations
 //! a computed style needs in order for it to adhere to the CSS spec.
 
 use app_units::Au;
 use dom::TElement;
 use properties::{self, ComputedValues, StyleBuilder};
 use properties::computed_value_flags::ComputedValueFlags;
+use properties::longhands::_moz_appearance::computed_value::T as Appearance;
 use properties::longhands::display::computed_value::T as Display;
 use properties::longhands::float::computed_value::T as Float;
+use properties::longhands::line_height::computed_value::T as LineHeight;
 use properties::longhands::overflow_x::computed_value::T as Overflow;
 use properties::longhands::position::computed_value::T as Position;
 
 /// A struct that implements all the adjustment methods.
 ///
 /// NOTE(emilio): If new adjustments are introduced that depend on reset
 /// properties of the parent, you may need tweaking the
 /// `ChildCascadeRequirement` code in `matching.rs`.
@@ -689,16 +691,33 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
             return;
         }
 
         self.style
             .mutate_position()
             .set_computed_justify_items(parent_justify_items.computed);
     }
 
+    ///
+    /// If '-webkit-appearance' is 'menulist' on a <select> element then
+    /// the computed value of 'line-height' is 'normal'.
+    ///
+    /// https://github.com/w3c/csswg-drafts/issues/3257
+    fn adjust_for_line_height<E>(&mut self, element: Option<E>)
+    where
+        E: TElement,
+    {
+        if self.style.get_box().clone__moz_appearance() == Appearance::Menulist &&
+            self.style.get_inherited_text().clone_line_height() != LineHeight::normal() &&
+            element.map_or(false, |e| e.is_html_element() &&
+                           e.local_name().as_ptr() == local_name!("select").as_ptr()) {
+            self.style.mutate_inherited_text().set_line_height(LineHeight::normal());
+        }
+    }
+
     /// Adjusts the style to account for various fixups that don't fit naturally
     /// into the cascade.
     ///
     /// When comparing to Gecko, this is similar to the work done by
     /// `ComputedStyle::ApplyStyleFixups`, plus some parts of
     /// `nsStyleSet::GetContext`.
     pub fn adjust<E>(&mut self, layout_parent_style: &ComputedValues, element: Option<E>)
     where
@@ -750,11 +769,12 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
         #[cfg(feature = "gecko")]
         {
             self.adjust_for_ruby(layout_parent_style, element);
         }
         #[cfg(feature = "servo")]
         {
             self.adjust_for_text_decorations_in_effect();
         }
+        self.adjust_for_line_height(element);
         self.set_bits();
     }
 }
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/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:mats@mozilla.com">
+  <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>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/rendering/replaced-elements/the-select-element/select-1-line-height.html
@@ -0,0 +1,35 @@
+<!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:mats@mozilla.com">
+  <link rel="match" href="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 a length <= 50px"));
+}</script>
+
+</body>
+</html>