Bug 1884539 - Pass the used (rather than computed) font size to the parent when styling <select> options. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D204224
This commit is contained in:
Jonathan Kew 2024-03-12 11:23:37 +00:00
Родитель eecfd5f15b
Коммит 1e83fc2a29
7 изменённых файлов: 70 добавлений и 2 удалений

Просмотреть файл

@ -1,5 +1,5 @@
[DEFAULT]
prefs = ["gfx.font_loader.delay=0", "dom.select.showPicker.enabled=true"]
prefs = ["gfx.font_loader.delay=0", "dom.select.showPicker.enabled=true", "font.minimum-size.x-western=9"]
support-files = ["head.js"]
["browser_selectpopup.js"]
@ -18,6 +18,8 @@ skip-if = ["os == 'linux'"] # Bug 1329991 - test fails intermittently on Linux b
["browser_selectpopup_large.js"]
["browser_selectpopup_minFontSize.js"]
["browser_selectpopup_searchfocus.js"]
fail-if = ["a11y_checks"] # Bug 1854233 input may not be labeled

Просмотреть файл

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// NOTE that this test expects "font.minimum-size.x-western=9" to be set
// in the manifest.
const PAGE = `
<!doctype html>
<body lang="en-US">
<select>
<option style="font-size:24px">A</option>
<option style="font-size:6px">BCD</option>
</select>
`;
add_task(async function () {
const url = "data:text/html," + encodeURI(PAGE);
await BrowserTestUtils.withNewTab(
{
gBrowser,
url,
},
async function (browser) {
let popup = await openSelectPopup("click");
let menuitems = popup.querySelectorAll("menuitem");
is(
getComputedStyle(menuitems[0]).fontSize,
"24px",
"font-size should be honored"
);
is(
getComputedStyle(menuitems[1]).fontSize,
"9px",
"minimum font-size should be honored"
);
}
);
});

Просмотреть файл

@ -21,6 +21,9 @@ interface CSSStyleDeclaration {
[Throws, ChromeOnly]
sequence<UTF8String> getCSSImageURLs(UTF8String property);
[ChromeOnly]
readonly attribute float usedFontSize;
UTF8String getPropertyValue(UTF8String property);
UTF8String getPropertyPriority(UTF8String property);
[CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]

Просмотреть файл

@ -733,6 +733,16 @@ static void CollectImageURLsForProperty(nsCSSPropertyID aProp,
}
}
float nsComputedDOMStyle::UsedFontSize() {
UpdateCurrentStyleSources(eCSSProperty_font_size);
if (!mComputedStyle) {
return -1.0;
}
return mComputedStyle->StyleFont()->mFont.size.ToCSSPixels();
}
void nsComputedDOMStyle::GetCSSImageURLs(const nsACString& aPropertyName,
nsTArray<nsCString>& aImageURLs,
mozilla::ErrorResult& aRv) {

Просмотреть файл

@ -120,6 +120,8 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration,
mExposeVisitedStyle = aExpose;
}
float UsedFontSize() final;
void GetCSSImageURLs(const nsACString& aPropertyName,
nsTArray<nsCString>& aImageURLs,
mozilla::ErrorResult& aRv) final;

Просмотреть файл

@ -86,6 +86,11 @@ class nsICSSDeclaration : public nsISupports, public nsWrapperCache {
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
}
// [Chrome only]
// Used font-size (taking account of the min-font-size prefs), if available;
// returns -1.0 on failure to retrieve a value.
virtual float UsedFontSize() { return -1.0; }
// WebIDL interface for CSSStyleDeclaration
virtual void SetCssText(const nsACString& aString,
nsIPrincipal* aSubjectPrincipal,

Просмотреть файл

@ -277,7 +277,7 @@ SelectContentHelper.prototype = {
InspectorUtils.removeContentState(this.element, kStateHover);
break;
case "Forms:MouseUp":
case "Forms:MouseUp": {
let win = this.element.ownerGlobal;
if (message.data.onAnchor) {
this.dispatchMouseEvent(win, this.element, "mouseup");
@ -287,6 +287,7 @@ SelectContentHelper.prototype = {
this.dispatchMouseEvent(win, this.element, "click");
}
break;
}
case "Forms:SearchFocused":
this._closeAfterBlur = false;
@ -346,6 +347,13 @@ function getComputedStyles(element) {
function supportedStyles(cs, supportedProps) {
let styles = {};
for (let property of supportedProps) {
if (property == "font-size") {
let usedSize = cs.usedFontSize;
if (usedSize >= 0.0) {
styles[property] = usedSize + "px";
continue;
}
}
styles[property] = cs.getPropertyValue(property);
}
return styles;