Bug 1562257 part 5. Fix style mapping of border attribues to more closely match the spec. r=mccr8

Per spec, "border" is parsed as a non-negative integer, only mapped if nonzero
(though this is not observably different from mapping even if 0, except if user
or UA stylesheets style the border), and supported on img, object,
<input type="image">, but NOT embed, iframe, or marquee.

This matches the Chrome and Safari behavior, as far as I can tell.  The
substantive change here is that we are removing mapping for the <embed border>
case.

Differential Revision: https://phabricator.services.mozilla.com/D36376

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-06-28 23:55:38 +00:00
Родитель 1725cec1ac
Коммит 827dd3e9ce
4 изменённых файлов: 58 добавлений и 4 удалений

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

@ -187,8 +187,9 @@ bool HTMLEmbedElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
if (aAttribute == nsGkAtoms::align) {
return ParseAlignValue(aValue, aResult);
}
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
return true;
if (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height ||
aAttribute == nsGkAtoms::hspace || aAttribute == nsGkAtoms::vspace) {
return aResult.ParseHTMLDimension(aValue);
}
}
@ -198,7 +199,6 @@ bool HTMLEmbedElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
static void MapAttributesIntoRuleBase(const nsMappedAttributes* aAttributes,
MappedDeclarations& aDecls) {
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aDecls);
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aDecls);
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aDecls);
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aDecls);

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

@ -1043,7 +1043,7 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,
return aResult.ParseHTMLDimension(aString);
}
if (aAttribute == nsGkAtoms::border) {
return aResult.ParseIntWithBounds(aString, 0);
return aResult.ParseNonNegativeIntValue(aString);
}
return false;
}

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

@ -6,6 +6,11 @@
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<div id="container" style="display: none">
<img id="defaultImg">
<object id="defaultObject"></object>
<input type="image" id="defaultInput"></input>
</div>
<script>
/*
* This test tests
@ -77,8 +82,34 @@ const tests = [
[ createBody, "marginheight", "marginBottom", document.body ],
[ createBody, "topmargin", "marginTop", document.body ],
[ createBody, "bottommargin", "marginBottom", document.body ],
[ newElem("img"), "border", "borderTopWidth", defaultImg ],
[ newElem("img"), "border", "borderRightWidth", defaultImg ],
[ newElem("img"), "border", "borderBottomWidth", defaultImg ],
[ newElem("img"), "border", "borderLeftWidth", defaultImg ],
[ newElem("object"), "border", "borderTopWidth", defaultObject ],
[ newElem("object"), "border", "borderRightWidth", defaultObject ],
[ newElem("object"), "border", "borderBottomWidth", defaultObject ],
[ newElem("object"), "border", "borderLeftWidth", defaultObject ],
[ newImageInput, "border", "borderTopWidth", defaultInput ],
[ newImageInput, "border", "borderRightWidth", defaultInput ],
[ newImageInput, "border", "borderBottomWidth", defaultInput ],
[ newImageInput, "border", "borderLeftWidth", defaultInput ],
];
function newElem(name) {
return () => {
var elem = document.createElement(name);
document.getElementById("container").appendChild(elem);
return [ elem, elem, () => elem.remove() ];
}
}
function newImageInput() {
var elem = document.createElement("input");
elem.type = "image";
document.getElementById("container").appendChild(elem);
return [ elem, elem, () => elem.remove() ];
}
function createIframe() {
let ifr = document.createElement("iframe");

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

@ -44,6 +44,29 @@ const tests = [
[ newElem("table"), "hspace", "marginRight" ],
[ newElem("table"), "vspace", "marginTop" ],
[ newElem("table"), "vspace", "marginBottom" ],
[ newElem("embed"), "border", "borderTopWidth" ],
[ newElem("embed"), "border", "borderRightWidth" ],
[ newElem("embed"), "border", "borderBottomWidth" ],
[ newElem("embed"), "border", "borderLeftWidth" ],
[ newElem("iframe"), "border", "borderTopWidth" ],
[ newElem("iframe"), "border", "borderRightWidth" ],
[ newElem("iframe"), "border", "borderBottomWidth" ],
[ newElem("iframe"), "border", "borderLeftWidth" ],
[ newElem("marquee"), "border", "borderTopWidth" ],
[ newElem("marquee"), "border", "borderRightWidth" ],
[ newElem("marquee"), "border", "borderBottomWidth" ],
[ newElem("marquee"), "border", "borderLeftWidth" ],
// Non-image input
[ newElem("input"), "border", "borderTopWidth" ],
[ newElem("input"), "border", "borderRightWidth" ],
[ newElem("input"), "border", "borderBottomWidth" ],
[ newElem("input"), "border", "borderLeftWidth" ],
[ newElem("input"), "width", "width" ],
[ newElem("input"), "height", "height" ],
[ newElem("input"), "hspace", "marginLeft" ],
[ newElem("input"), "hspace", "marginRight" ],
[ newElem("input"), "vspace", "marginTop" ],
[ newElem("input"), "vspace", "marginBottom" ],
];
function style(element) {