Add hooks to get correct computed value for logical box properties.

This commit is contained in:
dbaron@dbaron.org 2007-07-22 12:56:13 -07:00
Родитель e324c875c5
Коммит a304a18648
4 изменённых файлов: 67 добавлений и 97 удалений

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

@ -51,6 +51,8 @@ const CSS_TYPE_SHORTHAND_AND_LONGHAND = 2;
// inherited: Whether the property is inherited by default (stated as
// yes or no in the property header in all CSS specs)
// type: see above
// get_computed: if present, the property's computed value shows up on
// another property, and this is a function used to get it
// initial_values: Values whose computed value should be the same as the
// computed value for the property's initial value.
// other_values: Values whose computed value should be different from the
@ -122,6 +124,7 @@ var gCSSProperties = {
domProp: "MozBorderEndColor",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
initial_values: [ "currentColor" ],
other_values: [ "green", "rgba(255,128,0,0.5)", "transparent" ],
invalid_values: [ "#0", "#00", "#0000", "#00000", "#0000000", "#00000000", "#000000000" ]
@ -130,6 +133,7 @@ var gCSSProperties = {
domProp: "MozBorderEndStyle",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* XXX hidden is sometimes the same as initial */
initial_values: [ "none" ],
other_values: [ "solid", "dashed", "dotted", "double", "outset", "inset", "groove", "ridge" ],
@ -139,6 +143,7 @@ var gCSSProperties = {
domProp: "MozBorderEndWidth",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
prerequisites: { "-moz-border-end-style": "solid" },
initial_values: [ "medium", "3px" ],
other_values: [ "thin", "thick", "1px", "2em" ],
@ -214,6 +219,7 @@ var gCSSProperties = {
domProp: "MozBorderStartColor",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
initial_values: [ "currentColor" ],
other_values: [ "green", "rgba(255,128,0,0.5)", "transparent" ],
invalid_values: [ "#0", "#00", "#0000", "#00000", "#0000000", "#00000000", "#000000000" ]
@ -222,6 +228,7 @@ var gCSSProperties = {
domProp: "MozBorderStartStyle",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* XXX hidden is sometimes the same as initial */
initial_values: [ "none" ],
other_values: [ "solid", "dashed", "dotted", "double", "outset", "inset", "groove", "ridge" ],
@ -231,6 +238,7 @@ var gCSSProperties = {
domProp: "MozBorderStartWidth",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
prerequisites: { "-moz-border-start-style": "solid" },
initial_values: [ "medium", "3px" ],
other_values: [ "thin", "thick", "1px", "2em" ],
@ -355,6 +363,7 @@ var gCSSProperties = {
domProp: "MozMarginEnd",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* no subproperties */
/* auto may or may not be initial */
initial_values: [ "0", "0px", "0%", "0em", "0ex" ],
@ -365,6 +374,7 @@ var gCSSProperties = {
domProp: "MozMarginStart",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* no subproperties */
/* auto may or may not be initial */
initial_values: [ "0", "0px", "0%", "0em", "0ex" ],
@ -416,6 +426,7 @@ var gCSSProperties = {
domProp: "MozPaddingEnd",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* no subproperties */
initial_values: [ "0", "0px", "0%", "0em", "0ex" ],
other_values: [ "1px", "3em" ],
@ -425,6 +436,7 @@ var gCSSProperties = {
domProp: "MozPaddingStart",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
get_computed: logical_box_prop_get_computed,
/* no subproperties */
initial_values: [ "0", "0px", "0%", "0em", "0ex" ],
other_values: [ "1px", "3em" ],
@ -1837,3 +1849,33 @@ var gCSSProperties = {
invalid_values: []
}
}
function logical_box_prop_get_computed(cs, property)
{
if (! /^-moz-/.test(property))
throw "Unexpected property";
property = property.substring(5);
if (cs.getPropertyValue("direction") == "ltr")
property = property.replace("-start", "-left").replace("-end", "-right");
else
property = property.replace("-start", "-right").replace("-end", "-left");
return cs.getPropertyValue(property);
}
// Get the computed value for a property. For shorthands, return the
// computed values of all the subproperties, delimited by " ; ".
function get_computed_value(cs, property)
{
var info = gCSSProperties[property];
if ("subproperties" in info) {
var results = [];
for (var idx in info.subproperties) {
var subprop = info.subproperties[idx];
results.push(get_computed_value(cs, subprop));
}
return results.join(" ; ");
}
if (info.get_computed)
return info.get_computed(cs, property);
return cs.getPropertyValue(property);
}

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

@ -23,18 +23,6 @@
/** Test for computation of CSS 'inherit' **/
var gNoComputedStyle = {
"-moz-border-end": true, // NB: shorthand
"-moz-border-end-color": true,
"-moz-border-end-style": true,
"-moz-border-end-width": true,
"-moz-border-start": true, // NB: shorthand
"-moz-border-start-color": true,
"-moz-border-start-style": true,
"-moz-border-start-width": true,
"-moz-margin-end": true,
"-moz-margin-start": true,
"-moz-padding-end": true,
"-moz-padding-start": true,
};
function xfail_diffcomputed(property) {
@ -67,21 +55,10 @@ var gChildRule3 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild.allother,
var gChildRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #nchild.allother, #fchild, #fchild.allother {}", gStyleSheet.cssRules.length)];
var gParentRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nparent, #fparent {}", gStyleSheet.cssRules.length)];
// Get the computed value for a property. For shorthands, return the
// computed values of all the subproperties, delimited by " ; ".
function get_computed_value(node, property)
function get_computed_value_node(node, property)
{
var info = gCSSProperties[property];
var cs = getComputedStyle(node, "");
if (!("subproperties" in info)) {
return cs.getPropertyValue(property);
}
var results = [];
for (var idx in info.subproperties) {
var subprop = info.subproperties[idx];
results.push(cs.getPropertyValue(subprop));
}
return results.join(" ; ");
return get_computed_value(cs, property);
}
function test_property(property)
@ -100,11 +77,11 @@ function test_property(property)
if (info.inherited) {
gParentRuleTop.style.setProperty(property, info.initial_values[0], "");
var initial_computed_n = get_computed_value(gNChild, property);
var initial_computed_f = get_computed_value(gFChild, property);
var initial_computed_n = get_computed_value_node(gNChild, property);
var initial_computed_f = get_computed_value_node(gFChild, property);
gChildRule1.style.setProperty(property, info.other_values[0], "");
var other_computed_n = get_computed_value(gNChild, property);
var other_computed_f = get_computed_value(gFChild, property);
var other_computed_n = get_computed_value_node(gNChild, property);
var other_computed_f = get_computed_value_node(gFChild, property);
(xfail_diffcomputed(property) ? todo_isnot : isnot)(
other_computed_n, initial_computed_n,
"should be testing with values that compute to different things " +
@ -116,8 +93,8 @@ function test_property(property)
gChildRule3.style.setProperty(property, "inherit", "");
gFChild.className="allother";
gNChild.className="allother";
var inherit_initial_computed_n = get_computed_value(gNChild, property);
var inherit_initial_computed_f = get_computed_value(gFChild, property);
var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
(xfail_inherit(property, true) ? todo_is : is)(
inherit_initial_computed_n, initial_computed_n,
"inherit should cause inheritance of initial value for '" +
@ -127,8 +104,8 @@ function test_property(property)
"inherit should cause inheritance of initial value for '" +
property + "'");
gParentRuleTop.style.setProperty(property, info.other_values[0], "");
var inherit_other_computed_n = get_computed_value(gNChild, property);
var inherit_other_computed_f = get_computed_value(gFChild, property);
var inherit_other_computed_n = get_computed_value_node(gNChild, property);
var inherit_other_computed_f = get_computed_value_node(gFChild, property);
var xfail_inherit_other = xfail_inherit(property, false) ||
property == "font-family"; /* bug 385699 */
(xfail_inherit_other ? todo_is : is)(
@ -146,10 +123,10 @@ function test_property(property)
gNChild.className="";
} else {
gParentRuleTop.style.setProperty(property, info.other_values[0], "");
var initial_computed_n = get_computed_value(gNChild, property);
var initial_computed_f = get_computed_value(gFChild, property);
var other_computed_n = get_computed_value(gNParent, property);
var other_computed_f = get_computed_value(gFParent, property);
var initial_computed_n = get_computed_value_node(gNChild, property);
var initial_computed_f = get_computed_value_node(gFChild, property);
var other_computed_n = get_computed_value_node(gNParent, property);
var other_computed_f = get_computed_value_node(gFParent, property);
(xfail_diffcomputed(property) ? todo_isnot : isnot)(
other_computed_n, initial_computed_n,
"should be testing with values that compute to different things " +
@ -159,8 +136,8 @@ function test_property(property)
"should be testing with values that compute to different things " +
"for '" + property + "'");
gChildRule2.style.setProperty(property, "inherit", "");
var inherit_other_computed_n = get_computed_value(gNChild, property);
var inherit_other_computed_f = get_computed_value(gFChild, property);
var inherit_other_computed_n = get_computed_value_node(gNChild, property);
var inherit_other_computed_f = get_computed_value_node(gFChild, property);
(xfail_inherit(property, false) ? todo_is : is)(
inherit_other_computed_n, other_computed_n,
"inherit should cause inheritance of other value for '" +
@ -171,8 +148,8 @@ function test_property(property)
property + "'");
gParentRuleTop.style.removeProperty(property);
gChildRule1.style.setProperty(property, info.other_values[0], "");
var inherit_initial_computed_n = get_computed_value(gNChild, property);
var inherit_initial_computed_f = get_computed_value(gFChild, property);
var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
(xfail_inherit(property, true) ? todo_is : is)(
inherit_initial_computed_n, initial_computed_n,
"inherit should cause inheritance of initial value for '" +

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

@ -36,18 +36,6 @@
/** Test for computation of CSS '-moz-initial' **/
var gNoComputedStyle = {
"-moz-border-end": true, // NB: shorthand
"-moz-border-end-color": true,
"-moz-border-end-style": true,
"-moz-border-end-width": true,
"-moz-border-start": true, // NB: shorthand
"-moz-border-start-color": true,
"-moz-border-start-style": true,
"-moz-border-start-width": true,
"-moz-margin-end": true,
"-moz-margin-start": true,
"-moz-padding-end": true,
"-moz-padding-start": true,
};
function xfail_diffcomputed(property) {
@ -164,22 +152,6 @@ function setup_initial_values(id, ivalprop, prereqprop) {
window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
}
// Get the computed value for a property. For shorthands, return the
// computed values of all the subproperties, delimited by " ; ".
function get_computed_value(cs, property)
{
var info = gCSSProperties[property];
if (!("subproperties" in info)) {
return cs.getPropertyValue(property);
}
var results = [];
for (var idx in info.subproperties) {
var subprop = info.subproperties[idx];
results.push(cs.getPropertyValue(subprop));
}
return results.join(" ; ");
}
function test_property(property)
{
var info = gCSSProperties[property];

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

@ -36,18 +36,6 @@
/** Test for computation of values in property database **/
var gNoComputedStyle = {
"-moz-border-end": true, // NB: shorthand
"-moz-border-end-color": true,
"-moz-border-end-style": true,
"-moz-border-end-width": true,
"-moz-border-start": true, // NB: shorthand
"-moz-border-start-color": true,
"-moz-border-start-style": true,
"-moz-border-start-width": true,
"-moz-margin-end": true,
"-moz-margin-start": true,
"-moz-padding-end": true,
"-moz-padding-start": true,
};
function xfail_diffcomputed(property) {
@ -72,6 +60,8 @@ var gBadComputed = {
"border-right": [ "thin" ],
"border-bottom": [ "thin" ],
"border-left": [ "thin" ],
"-moz-border-start": [ "thin" ],
"-moz-border-end": [ "thin" ],
"outline-width": [ "3px" ],
// 'normal' should compute to 0
@ -87,6 +77,11 @@ var gBadComputed = {
"-moz-outline-radius-bottomright": [ "0%" ],
"-moz-outline-radius-topleft": [ "0%" ],
"-moz-outline-radius-topright": [ "0%" ],
// These are probably bogus tests... (why not just when no frame?)
"-moz-margin-end": [ "0%" ],
"-moz-margin-start": [ "0%" ],
"-moz-padding-end": [ "0%" ],
"-moz-padding-start": [ "0%" ],
};
var gBadComputedNoFrame = {
@ -149,22 +144,6 @@ function setup_initial_values(id, ivalprop, prereqprop) {
window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)];
}
// Get the computed value for a property. For shorthands, return the
// computed values of all the subproperties, delimited by " ; ".
function get_computed_value(cs, property)
{
var info = gCSSProperties[property];
if (!("subproperties" in info)) {
return cs.getPropertyValue(property);
}
var results = [];
for (var idx in info.subproperties) {
var subprop = info.subproperties[idx];
results.push(cs.getPropertyValue(subprop));
}
return results.join(" ; ");
}
function test_value(property, val, is_initial)
{
var info = gCSSProperties[property];