/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ // Helper file for shared image functionality // // Note that this is use by tests elsewhere in the source tree. When in doubt, // check mxr before removing or changing functionality.
// Helper function to clear both the content and chrome image caches function clearAllImageCaches() { var tools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService(
SpecialPowers.Ci.imgITools
); var imageCache = tools.getImgCacheForDocument(window.document);
imageCache.clearCache(true); // true=chrome
imageCache.clearCache(false); // false=content
}
// Helper function to clear the image cache of content images function clearImageCache() { var tools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService(
SpecialPowers.Ci.imgITools
); var imageCache = tools.getImgCacheForDocument(window.document);
imageCache.clearCache(false); // true=chrome, false=content
}
// Helper function to determine if the frame is decoded for a given image id function isFrameDecoded(id) { return !!(
getImageStatus(id) & SpecialPowers.Ci.imgIRequest.STATUS_FRAME_COMPLETE
);
}
// Helper function to determine if the image is loaded for a given image id function isImageLoaded(id) { return !!(
getImageStatus(id) & SpecialPowers.Ci.imgIRequest.STATUS_LOAD_COMPLETE
);
}
// Helper function to get the status flags of an image function getImageStatus(id) { // Get the image var img = SpecialPowers.wrap(document.getElementById(id));
// Get the request var request = img.getRequest(
SpecialPowers.Ci.nsIImageLoadingContent.CURRENT_REQUEST
);
// Return the status return request.imageStatus;
}
// Forces a synchronous decode of an image by drawing it to a canvas. Only // really meaningful if the image is fully loaded first function forceDecode(id) { // Get the image var img = document.getElementById(id);
// Make a new canvas var canvas = document.createElement("canvas");
// Draw the image to the canvas. This forces a synchronous decode var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
}
// Functions to facilitate getting/setting various image-related prefs // // If you change a pref in a mochitest, Don't forget to reset it to its // original value! // // Null indicates no pref set
function getImagePref(pref) { var prefService = SpecialPowers.Services.prefs; var branch = prefService.getBranch(pref.branch); if (branch.prefHasUserValue(pref.name)) { switch (pref.type) { case"bool": return branch.getBoolPref(pref.name); case"int": return branch.getIntPref(pref.name); default: thrownew Error("Unknown pref type");
}
} else { returnnull;
}
}
// JS implementation of imgIScriptedNotificationObserver with stubs for all of its methods. function ImageDecoderObserverStub() { this.sizeAvailable = function sizeAvailable() {}; this.frameComplete = function frameComplete() {}; this.decodeComplete = function decodeComplete() {}; this.loadComplete = function loadComplete() {}; this.frameUpdate = function frameUpdate() {}; this.discard = function discard() {}; this.isAnimated = function isAnimated() {}; this.hasTransparency = function hasTransparency() {};
}
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.