Bug 662324 - Add "Fill" and "Fit" position support for "Set As Desktop Background...". r=gavin

This commit is contained in:
Ian Moody 2012-02-01 11:37:55 +01:00
parent c70d70f634
commit b5be92d2d5
7 changed files with 64 additions and 1 deletions

View File

@ -68,6 +68,18 @@ var gSetBackground = {
if (this._screenWidth / this._screenHeight >= 1.6)
document.getElementById("monitor").setAttribute("aspectratio", "16:10");
#ifdef XP_WIN
// hide fill + fit options if <win7 since don't work
var version = Components.classes["@mozilla.org/system-info;1"]
.getService(Ci.nsIPropertyBag2)
.getProperty("version");
var isWindows7OrHigher = (parseFloat(version) >= 6.1);
if (!isWindows7OrHigher) {
document.getElementById("fillPosition").hidden = true;
document.getElementById("fitPosition").hidden = true;
}
#endif
// make sure that the correct dimensions will be used
setTimeout(function(self) {
self.init(window.arguments[0]);
@ -198,6 +210,39 @@ var gSetBackground = {
var x = (this._screenWidth - this._image.naturalWidth) / 2;
var y = (this._screenHeight - this._image.naturalHeight) / 2;
ctx.drawImage(this._image, x, y);
break;
case "FILL":
//Try maxing width first, overflow height
var widthRatio = this._screenWidth / this._image.naturalWidth;
var width = this._image.naturalWidth * widthRatio;
var height = this._image.naturalHeight * widthRatio;
if (height < this._screenHeight) {
//height less than screen, max height and overflow width
var heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
}
var x = (this._screenWidth - width) / 2;
var y = (this._screenHeight - height) / 2;
ctx.drawImage(this._image, x, y, width, height);
break;
case "FIT":
//Try maxing width first, top and bottom borders
var widthRatio = this._screenWidth / this._image.naturalWidth;
var width = this._image.naturalWidth * widthRatio;
var height = this._image.naturalHeight * widthRatio;
var x = 0;
var y = (this._screenHeight - height) / 2;
if (height > this._screenHeight) {
//height overflow, maximise height, side borders
var heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
x = (this._screenWidth - width) / 2;
y = 0;
}
ctx.drawImage(this._image, x, y, width, height);
break;
}
}
};

View File

@ -78,6 +78,8 @@
<menuitem label="&center.label;" value="CENTER"/>
<menuitem label="&tile.label;" value="TILE"/>
<menuitem label="&stretch.label;" value="STRETCH"/>
<menuitem label="&fill.label;" value="FILL" id="fillPosition"/>
<menuitem label="&fit.label;" value="FIT" id="fitPosition"/>
</menupopup>
</menulist>
<spacer flex="1"/>

View File

@ -81,6 +81,7 @@ interface nsIShellService : nsISupports
const long BACKGROUND_STRETCH = 2;
const long BACKGROUND_CENTER = 3;
const long BACKGROUND_FILL = 4;
const long BACKGROUND_FIT = 5;
/**
* Sets the desktop background image using either the HTML <IMG>

View File

@ -427,6 +427,10 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
options.Assign("wallpaper");
else if (aPosition == BACKGROUND_STRETCH)
options.Assign("stretched");
else if (aPosition == BACKGROUND_FILL)
options.Assign("zoom");
else if (aPosition == BACKGROUND_FIT)
options.Assign("scaled");
else
options.Assign("centered");

View File

@ -640,6 +640,14 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
style.AssignLiteral("2");
tile.AssignLiteral("0");
break;
case BACKGROUND_FILL:
style.AssignLiteral("10");
tile.AssignLiteral("0");
break;
case BACKGROUND_FIT:
style.AssignLiteral("6");
tile.AssignLiteral("0");
break;
}
rv = regKey->WriteStringValue(NS_LITERAL_STRING("TileWallpaper"), tile);

View File

@ -52,7 +52,8 @@ function onPageLoad() {
checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "centered");
checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom");
checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled");
// Restore GConf and wallpaper

View File

@ -2,6 +2,8 @@
<!ENTITY tile.label "Tile">
<!ENTITY center.label "Center">
<!ENTITY stretch.label "Stretch">
<!ENTITY fill.label "Fill">
<!ENTITY fit.label "Fit">
<!ENTITY preview.label "Preview">
<!ENTITY color.label "Color:">
<!ENTITY setDesktopBackground.title "Set Desktop Background">