merge m-c to fx-team

This commit is contained in:
Tim Taubert 2012-08-19 21:07:15 -07:00
commit 5506df3555
17 changed files with 279 additions and 118 deletions

View File

@ -1128,6 +1128,12 @@ pref("browser.newtab.preload", false);
// Toggles the content of 'about:newtab'. Shows the grid when enabled.
pref("browser.newtabpage.enabled", true);
// number of rows of newtab grid
pref("browser.newtabpage.rows", 3);
// number of columns of newtab grid
pref("browser.newtabpage.columns", 3);
// Enable the DOM fullscreen API.
pref("full-screen-api.enabled", true);

View File

@ -22,17 +22,8 @@ let gGrid = {
/**
* All cells contained in the grid.
*/
get cells() {
let cells = [];
let children = this.node.querySelectorAll(".newtab-cell");
for (let i = 0; i < children.length; i++)
cells.push(new Cell(this, children[i]));
// Replace the getter with our cached value.
Object.defineProperty(this, "cells", {value: cells, enumerable: true});
return cells;
},
_cells: null,
get cells() this._cells,
/**
* All sites contained in the grid's cells. Sites may be empty.
@ -46,7 +37,7 @@ let gGrid = {
init: function Grid_init() {
this._node = document.getElementById("newtab-grid");
this._createSiteFragment();
this._draw();
this._render();
},
/**
@ -74,8 +65,8 @@ let gGrid = {
node.removeChild(child);
}, this);
// Draw the grid again.
this._draw();
// Render the grid again.
this._render();
},
/**
@ -92,6 +83,32 @@ let gGrid = {
this.node.removeAttribute("locked");
},
/**
* Creates the newtab grid.
*/
_renderGrid: function Grid_renderGrid() {
let row = document.createElementNS(HTML_NAMESPACE, "div");
let cell = document.createElementNS(HTML_NAMESPACE, "div");
row.classList.add("newtab-row");
cell.classList.add("newtab-cell");
// Clear the grid
this._node.innerHTML = "";
// Creates the structure of one row
for (let i = 0; i < gGridPrefs.gridColumns; i++) {
row.appendChild(cell.cloneNode(true));
}
// Creates the grid
for (let j = 0; j < gGridPrefs.gridRows; j++) {
this._node.appendChild(row.cloneNode(true));
}
// (Re-)initialize all cells.
let cellElements = this.node.querySelectorAll(".newtab-cell");
this._cells = [new Cell(this, cell) for (cell of cellElements)];
},
/**
* Creates the DOM fragment that is re-used when creating sites.
*/
@ -116,11 +133,10 @@ let gGrid = {
},
/**
* Draws the grid, creates all sites and puts them into their cells.
* Renders the sites, creates all sites and puts them into their cells.
*/
_draw: function Grid_draw() {
_renderSites: function Grid_renderSites() {
let cells = this.cells;
// Put sites into the cells.
let links = gLinks.getLinks();
let length = Math.min(links.length, cells.length);
@ -129,5 +145,24 @@ let gGrid = {
if (links[i])
this.createSite(links[i], cells[i]);
}
},
/**
* Renders the grid.
*/
_render: function Grid_render() {
if (this._shouldRenderGrid()) {
this._renderGrid();
}
this._renderSites();
},
_shouldRenderGrid : function Grid_shouldRenderGrid() {
let rowsLength = this._node.querySelectorAll(".newtab-row").length;
let cellsLength = this._node.querySelectorAll(".newtab-cell").length;
return (rowsLength != gGridPrefs.gridRows ||
cellsLength != (gGridPrefs.gridRows * gGridPrefs.gridColumns));
}
};

View File

@ -20,7 +20,8 @@ let {
allPages: gAllPages,
linkChecker: gLinkChecker,
pinnedLinks: gPinnedLinks,
blockedLinks: gBlockedLinks
blockedLinks: gBlockedLinks,
gridPrefs: gGridPrefs
} = NewTabUtils;
XPCOMUtils.defineLazyGetter(this, "gStringBundle", function() {

View File

@ -26,21 +26,6 @@
<div class="newtab-side-margin"/>
<div id="newtab-grid">
<div class="newtab-row">
<div class="newtab-cell"/>
<div class="newtab-cell"/>
<div class="newtab-cell"/>
</div>
<div class="newtab-row">
<div class="newtab-cell"/>
<div class="newtab-cell"/>
<div class="newtab-cell"/>
</div>
<div class="newtab-row">
<div class="newtab-cell"/>
<div class="newtab-cell"/>
<div class="newtab-cell"/>
</div>
</div>
<div class="newtab-side-margin"/>

View File

@ -28,6 +28,7 @@ _BROWSER_FILES = \
browser_newtab_bug725996.js \
browser_newtab_bug734043.js \
browser_newtab_bug735987.js \
browser_newtab_bug752841.js \
browser_newtab_bug765628.js \
head.js \
$(NULL)

View File

@ -0,0 +1,53 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const PREF_NEWTAB_ROWS = "browser.newtabpage.rows";
const PREF_NEWTAB_COLUMNS = "browser.newtabpage.columns";
function runTests() {
let testValues = [
{row: 0, column: 0},
{row: -1, column: -1},
{row: -1, column: 0},
{row: 0, column: -1},
{row: 2, column: 4},
{row: 2, column: 5},
];
// Expected length of grid
let expectedValues = [1, 1, 1, 1, 8, 10];
// Values before setting new pref values (9 is the default value -> 3 x 3)
let previousValues = [9, 1, 1, 1, 1, 8];
let existingTab, existingTabGridLength, newTab, newTabGridLength;
yield addNewTabPageTab();
existingTab = gBrowser.selectedTab;
for (let i = 0; i < expectedValues.length; i++) {
gBrowser.selectedTab = existingTab;
existingTabGridLength = getGrid().cells.length;
is(existingTabGridLength, previousValues[i],
"Grid length of existing page before update is correctly.");
Services.prefs.setIntPref(PREF_NEWTAB_ROWS, testValues[i].row);
Services.prefs.setIntPref(PREF_NEWTAB_COLUMNS, testValues[i].column);
existingTabGridLength = getGrid().cells.length;
is(existingTabGridLength, expectedValues[i],
"Existing page grid is updated correctly.");
yield addNewTabPageTab();
newTab = gBrowser.selectedTab;
newTabGridLength = getGrid().cells.length;
is(newTabGridLength, expectedValues[i],
"New page grid is updated correctly.");
gBrowser.removeTab(newTab);
}
gBrowser.removeTab(existingTab);
Services.prefs.clearUserPref(PREF_NEWTAB_ROWS);
Services.prefs.clearUserPref(PREF_NEWTAB_COLUMNS);
}

View File

@ -909,8 +909,22 @@ function JSPropertyProvider(aScope, aInputValue)
return null;
}
let matches = null;
let matchProp = "";
let lastDot = completionPart.lastIndexOf(".");
if (lastDot > 0 &&
(completionPart[0] == "'" || completionPart[0] == '"') &&
completionPart[lastDot - 1] == completionPart[0]) {
// We are completing a string literal.
obj = obj.String.prototype;
matchProp = completionPart.slice(lastDot + 1);
}
else {
// We are completing a variable / a property lookup.
let properties = completionPart.split(".");
let matchProp;
if (properties.length > 1) {
matchProp = properties.pop().trimLeft();
for (let i = 0; i < properties.length; i++) {
@ -952,6 +966,7 @@ function JSPropertyProvider(aScope, aInputValue)
if (WCU.isIteratorOrGenerator(obj)) {
return null;
}
}
let matches = Object.keys(getMatchedProps(obj, {matchProp:matchProp}));

View File

@ -105,6 +105,13 @@ function testCompletion(hud) {
is(jsterm.completeNode.value, " ice", "non-object completion");
// Test string literal autocompletion.
input.value = "'Asimov'.sl";
jsterm.complete(jsterm.COMPLETE_HINT_ONLY, testNext);
yield;
is(jsterm.completeNode.value, " ice", "string literal completion");
testDriver = jsterm = input = null;
executeSoon(finishTest);
yield;

View File

@ -24,6 +24,12 @@ XPCOMUtils.defineLazyGetter(this, "gPrincipal", function () {
// The preference that tells whether this feature is enabled.
const PREF_NEWTAB_ENABLED = "browser.newtabpage.enabled";
// The preference that tells the number of rows of the newtab grid.
const PREF_NEWTAB_ROWS = "browser.newtabpage.rows";
// The preference that tells the number of columns of the newtab grid.
const PREF_NEWTAB_COLUMNS = "browser.newtabpage.columns";
// The maximum number of results we want to retrieve from history.
const HISTORY_RESULTS_LIMIT = 100;
@ -183,6 +189,60 @@ let AllPages = {
Ci.nsISupportsWeakReference])
};
/**
* Singleton that keeps Grid preferences
*/
let GridPrefs = {
/**
* Cached value that tells the number of rows of newtab grid.
*/
_gridRows: null,
get gridRows() {
if (!this._gridRows) {
this._gridRows = Math.max(1, Services.prefs.getIntPref(PREF_NEWTAB_ROWS));
}
return this._gridRows;
},
/**
* Cached value that tells the number of columns of newtab grid.
*/
_gridColumns: null,
get gridColumns() {
if (!this._gridColumns) {
this._gridColumns = Math.max(1, Services.prefs.getIntPref(PREF_NEWTAB_COLUMNS));
}
return this._gridColumns;
},
/**
* Initializes object. Adds a preference observer
*/
init: function GridPrefs_init() {
Services.prefs.addObserver(PREF_NEWTAB_ROWS, this, false);
Services.prefs.addObserver(PREF_NEWTAB_COLUMNS, this, false);
},
/**
* Implements the nsIObserver interface to get notified when the preference
* value changes.
*/
observe: function GridPrefs_observe(aSubject, aTopic, aData) {
if (aData == PREF_NEWTAB_ROWS) {
this._gridRows = null;
} else {
this._gridColumns = null;
}
AllPages.update();
}
};
GridPrefs.init();
/**
* Singleton that keeps track of all pinned links and their positions in the
* grid.
@ -606,5 +666,6 @@ let NewTabUtils = {
allPages: AllPages,
linkChecker: LinkChecker,
pinnedLinks: PinnedLinks,
blockedLinks: BlockedLinks
blockedLinks: BlockedLinks,
gridPrefs: GridPrefs
};

View File

@ -13,7 +13,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=292789
<p id="display"></p>
<div id="content" style="display: none">
<script src="chrome://global/content/strres.js"></script>
<script src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js"></script>
<script type="application/javascript;version=1.8" src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js"></script>
<script id="resjs" type="application/javascript;version=1.8"></script>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
@ -36,13 +37,13 @@ function testScriptSrc(aCallback) {
/** make sure the last one didn't pass because someone
** moved the resource
**/
var resjs = document.createElement("script");
var resjs = document.getElementById("resjs");
resjs.onload = scriptOnload;
#ifdef MOZ_CHROME_FILE_FORMAT_JAR
resjs.src = "jar:resource://gre/chrome/toolkit.jar!/content/mozapps/xpinstall/xpinstallConfirm.js";
#else
resjs.src = "resource://gre/chrome/toolkit/content/mozapps/xpinstall/xpinstallConfirm.js";
#endif
resjs.onload = scriptOnload;
document.getElementById("content").appendChild(resjs);
function scriptOnload() {

View File

@ -1023,11 +1023,11 @@ var AddonRepository = {
break;
case "authors":
let authorNodes = node.getElementsByTagName("author");
Array.forEach(authorNodes, function(aAuthorNode) {
let name = self._getDescendantTextContent(aAuthorNode, "name");
let link = self._getDescendantTextContent(aAuthorNode, "link");
for (let authorNode of authorNodes) {
let name = self._getDescendantTextContent(authorNode, "name");
let link = self._getDescendantTextContent(authorNode, "link");
if (name == null || link == null)
return;
continue;
let author = new AddonManagerPrivate.AddonAuthor(name, link);
if (addon.creator == null)
@ -1038,27 +1038,27 @@ var AddonRepository = {
addon.developers.push(author);
}
});
}
break;
case "previews":
let previewNodes = node.getElementsByTagName("preview");
Array.forEach(previewNodes, function(aPreviewNode) {
let full = self._getUniqueDescendant(aPreviewNode, "full");
for (let previewNode of previewNodes) {
let full = self._getUniqueDescendant(previewNode, "full");
if (full == null)
return;
continue;
let fullURL = self._getTextContent(full);
let fullWidth = full.getAttribute("width");
let fullHeight = full.getAttribute("height");
let thumbnailURL, thumbnailWidth, thumbnailHeight;
let thumbnail = self._getUniqueDescendant(aPreviewNode, "thumbnail");
let thumbnail = self._getUniqueDescendant(previewNode, "thumbnail");
if (thumbnail) {
thumbnailURL = self._getTextContent(thumbnail);
thumbnailWidth = thumbnail.getAttribute("width");
thumbnailHeight = thumbnail.getAttribute("height");
}
let caption = self._getDescendantTextContent(aPreviewNode, "caption");
let caption = self._getDescendantTextContent(previewNode, "caption");
let screenshot = new AddonManagerPrivate.AddonScreenshot(fullURL, fullWidth, fullHeight,
thumbnailURL, thumbnailWidth,
thumbnailHeight, caption);
@ -1066,11 +1066,11 @@ var AddonRepository = {
if (addon.screenshots == null)
addon.screenshots = [];
if (aPreviewNode.getAttribute("primary") == 1)
if (previewNode.getAttribute("primary") == 1)
addon.screenshots.unshift(screenshot);
else
addon.screenshots.push(screenshot);
});
}
break;
case "learnmore":
addon.homepageURL = addon.homepageURL || this._getTextContent(node);

View File

@ -2150,9 +2150,6 @@ var XPIProvider = {
.QueryInterface(Ci.nsIDirectoryEnumerator);
let entry;
while (entry = entries.nextFile) {
// Should never happen really
if (!(entry instanceof Ci.nsIFile))
continue;
let id = entry.leafName;

View File

@ -2422,8 +2422,7 @@ var gListView = {
return;
let prop = aIsInstall ? "mInstall" : "mAddon";
for (let i = 0; i < this._listBox.itemCount; i++) {
let item = this._listBox.childNodes[i];
for (let item of this._listBox.childNodes) {
if (item[prop] == aObj)
return;
}
@ -2436,8 +2435,7 @@ var gListView = {
removeItem: function gListView_removeItem(aObj, aIsInstall) {
let prop = aIsInstall ? "mInstall" : "mAddon";
for (let i = 0; i < this._listBox.itemCount; i++) {
let item = this._listBox.childNodes[i];
for (let item of this._listBox.childNodes) {
if (item[prop] == aObj) {
this._listBox.removeChild(item);
this.showEmptyNotice(this._listBox.itemCount == 0);
@ -2653,12 +2651,13 @@ var gDetailView = {
!gViewController.commands.cmd_showItemPreferences.isEnabled(aAddon);
var gridRows = document.querySelectorAll("#detail-grid rows row");
for (var i = 0, first = true; i < gridRows.length; ++i) {
if (first && window.getComputedStyle(gridRows[i], null).getPropertyValue("display") != "none") {
gridRows[i].setAttribute("first-row", true);
let first = true;
for (let gridRow of gridRows) {
if (first && window.getComputedStyle(gridRow, null).getPropertyValue("display") != "none") {
gridRow.setAttribute("first-row", true);
first = false;
} else {
gridRows[i].removeAttribute("first-row");
gridRow.removeAttribute("first-row");
}
}

View File

@ -30,25 +30,25 @@ XPInstallConfirm.init = function ()
var itemList = document.getElementById("itemList");
var numItemsToInstall = args.installs.length;
for (var i = 0; i < numItemsToInstall; ++i) {
for (let install of args.installs) {
var installItem = document.createElement("installitem");
itemList.appendChild(installItem);
installItem.name = args.installs[i].addon.name;
installItem.url = args.installs[i].sourceURI.spec;
var icon = args.installs[i].iconURL;
installItem.name = install.addon.name;
installItem.url = install.sourceURI.spec;
var icon = install.iconURL;
if (icon)
installItem.icon = icon;
var type = args.installs[i].type;
var type = install.type;
if (type)
installItem.type = type;
if (args.installs[i].certName) {
installItem.cert = bundle.getFormattedString("signed", [args.installs[i].certName]);
if (install.certName) {
installItem.cert = bundle.getFormattedString("signed", [install.certName]);
}
else {
installItem.cert = bundle.getString("unverified");
}
installItem.signed = args.installs[i].certName ? "true" : "false";
installItem.signed = install.certName ? "true" : "false";
}
var introString = bundle.getString("itemWarnIntroSingle");

View File

@ -17,7 +17,7 @@
ondialogaccept="return XPInstallConfirm.onOK();"
ondialogcancel="return XPInstallConfirm.onCancel();">
<script src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js"/>
<script src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js" type="application/javascript"/>
<stringbundle id="xpinstallConfirmStrings"
src="chrome://mozapps/locale/xpinstall/xpinstallConfirm.properties"/>

View File

@ -163,8 +163,8 @@ function wait_for_page(aWindow, aPageId, aCallback) {
function get_list_names(aList) {
var items = [];
for (let i = 0; i < aList.childNodes.length; i++)
items.push(aList.childNodes[i].label);
for (let listItem of aList.childNodes)
items.push(listItem.label);
items.sort();
return items;
}
@ -219,16 +219,16 @@ add_test(function() {
"Next button should be enabled");
// Uncheck all
for (let i = 0; i < list.childNodes.length; i++)
EventUtils.synthesizeMouse(list.childNodes[i], 2, 2, { }, aWindow);
for (let listItem of list.childNodes)
EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow);
ok(doc.documentElement.getButton("next").disabled,
"Next button should not be enabled");
// Check the ones we want to install
for (let i = 0; i < list.childNodes.length; i++) {
if (list.childNodes[i].label != "Addon7 2.0")
EventUtils.synthesizeMouse(list.childNodes[i], 2, 2, { }, aWindow);
for (let listItem of list.childNodes) {
if (listItem.label != "Addon7 2.0")
EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow);
}
var button = doc.documentElement.getButton("next");
@ -313,9 +313,9 @@ add_test(function() {
is(items[2], "Addon9 2.0", "Should have seen update for addon9");
// Unheck the ones we don't want to install
for (let i = 0; i < list.childNodes.length; i++) {
if (list.childNodes[i].label != "Addon7 2.0")
EventUtils.synthesizeMouse(list.childNodes[i], 2, 2, { }, aWindow);
for (let listItem of list.childNodes) {
if (listItem.label != "Addon7 2.0")
EventUtils.synthesizeMouse(listItem, 2, 2, { }, aWindow);
}
var button = doc.documentElement.getButton("next");

View File

@ -1170,9 +1170,9 @@ if ("nsIWindowsRegKey" in AM_Ci) {
},
readStringValue: function(aName) {
for (let i = 0; i < this.values.length; i++) {
if (this.values[i].name == aName)
return this.values[i].value;
for (let value of this.values) {
if (value.name == aName)
return value.value;
}
}
};