function run() { var subdoc = document.getElementById("subdoc").contentDocument; var subwin = document.getElementById("subdoc").contentWindow; varstyle = subdoc.createElement("style"); style.setAttribute("type", "text/css");
subdoc.getElementsByTagName("head")[0].appendChild(style); var sheet = style.sheet; var iframe_style = document.getElementById("subdoc").style;
// Create a style rule and an element now based on the given media
// query "q", and return the computed style that should be passed to
// query_applies to see if that query currently applies. var n = 0;
function make_query(q) { var i = ++n;
sheet.insertRule("@media " + q + " { #e" + i + " { text-decoration: underline; } }", sheet.cssRules.length); var e = subdoc.createElement("div");
e.id = "e" + i;
subdoc.body.appendChild(e); var cs = subdoc.defaultView.getComputedStyle(e);
cs._originalQueryText = q;
return cs;
}
function query_applies(cs) {
return cs.getPropertyValue("text-decoration-line") == "underline";
}
function should_apply(cs) {
ok(query_applies(cs), cs._originalQueryText + " should apply");
}
function should_not_apply(cs) {
ok(!query_applies(cs), cs._originalQueryText + " should not apply");
}
var content_div = document.getElementById("content");
content_div.style.font = "initial"; var em_size =
getComputedStyle(content_div, "").fontSize.match(/^(\d+)px$/)[1];
let width_val = 317; // pick two not-too-round numbers
let height_val = 228;
iframe_style.width = width_val + "px";
iframe_style.height = height_val + "px"; var wh_queries = [
make_query("all and (min-width: " +
(Math.ceil(width_val/em_size) + 1) + "em)"),
make_query("all and (min-width: " +
(Math.floor(width_val/em_size) - 1) + "em)"),
make_query("all and (max-width: " +
(Math.ceil(width_val/em_size) + 1) + "em)"),
make_query("all and (max-width: " +
(Math.floor(width_val/em_size) - 1) + "em)"),
make_query("all and (min-width: " +
(Math.ceil(width_val/(em_size*2)) + 1) + "em)"),
make_query("all and (min-width: " +
(Math.floor(width_val/(em_size*2)) - 1) + "em)"),
make_query("all and (max-width: " +
(Math.ceil(width_val/(em_size*2)) + 1) + "em)"),
make_query("all and (max-width: " +
(Math.floor(width_val/(em_size*2)) - 1) + "em)")
];
is(wh_queries[0].fontSize, em_size + "px", "text zoom is 1.0");
should_not_apply(wh_queries[0]);
should_apply(wh_queries[1]);
should_apply(wh_queries[2]);
should_not_apply(wh_queries[3]);
SpecialPowers.setTextZoom(subwin, 2.0);
isnot(wh_queries[0].fontSize, em_size + "px", "text zoom is not 1.0");
should_not_apply(wh_queries[4]);
should_apply(wh_queries[5]);
should_apply(wh_queries[6]);
should_not_apply(wh_queries[7]);
SpecialPowers.setTextZoom(subwin, 1.0);
is(wh_queries[0].fontSize, em_size + "px", "text zoom is 1.0");
is(subwin.innerHeight, 228, "full zoom is 1.0");
should_not_apply(wh_queries[0]);
should_apply(wh_queries[1]);
should_apply(wh_queries[2]);
should_not_apply(wh_queries[3]);
SpecialPowers.setFullZoom(subwin, 2.0);
isnot(subwin.innerHeight, 228, "full zoom is not 1.0");
should_not_apply(wh_queries[4]);
should_apply(wh_queries[5]);
should_apply(wh_queries[6]);
should_not_apply(wh_queries[7]);
SpecialPowers.setFullZoom(subwin, 1.0);
is(subwin.innerHeight, 228, "full zoom is 1.0");
// Now test that certain things *don't* happen, i.e., that we're
// making the optimizations we expect.
subdoc.body.textContent = "";
subdoc.body.appendChild(subdoc.createElement("div"));
for (var ruleIdx = sheet.cssRules.length; ruleIdx-- != 0; ) {
sheet.deleteRule(ruleIdx);
}
var utils = SpecialPowers.getDOMWindowUtils(subwin); var restyleGeneration, framesConstructed, framesReflowed;
function reset_change_counters()
{
restyleGeneration = utils.restyleGeneration;
framesConstructed = utils.framesConstructed;
framesReflowed = utils.framesReflowed;
}
function flush_and_assert_change_counters(desc, expected) {
subdoc.body.offsetHeight;
if (!("restyle" in expected) ||
!("construct" in expected) ||
!("reflow" in expected)) {
ok(false, "parameter missing expectation");
return;
}
var didRestyle = utils.restyleGeneration != restyleGeneration; var constructs = utils.framesConstructed - framesConstructed; var reflows = utils.framesReflowed - framesReflowed;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.