Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: chrome/browser/resources/local_ntp/local_ntp.js

Issue 14261017: Local NTP: Render two rows of Most Visited tiles. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/local_ntp/local_ntp.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/local_ntp/local_ntp.js
diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js
index 8610518c190a9de19e7a1d190da4795d251c590b..1b38e26537d9e35fe270c95ffb451ff9df3d6b06 100644
--- a/chrome/browser/resources/local_ntp/local_ntp.js
+++ b/chrome/browser/resources/local_ntp/local_ntp.js
@@ -36,6 +36,7 @@ var CLASSES = {
HIDE_NOTIFICATION: 'mv-notice-hide',
HIDE_TILE: 'mv-tile-hide', // hides tiles on small browser width
PAGE: 'mv-page', // page tiles
+ ROW: 'mv-row', // tile row
SELECTED: 'selected', // a selected suggestion (if any)
THUMBNAIL: 'mv-thumb',
TILE: 'mv-tile',
@@ -121,13 +122,6 @@ var tiles = [];
var lastBlacklistedTile = null;
/**
- * The index of the last blacklisted tile, if any. Used to determine where to
- * re-insert a tile on undo.
- * @type {number}
- */
-var lastBlacklistedIndex = -1;
-
-/**
* True if a page has been blacklisted and we're waiting on the
* onmostvisitedchange callback. See onMostVisitedChange() for how this
* is used.
@@ -136,18 +130,11 @@ var lastBlacklistedIndex = -1;
var isBlacklisting = false;
/**
- * True if a blacklist has been undone and we're waiting on the
- * onmostvisitedchange callback. See onMostVisitedChange() for how this
- * is used.
- * @type {boolean}
- */
-var isUndoing = false;
-
-/**
- * Current number of tiles shown based on the window width, including filler.
+ * Current number of tiles columns shown based on the window width, including
+ * those that just contain filler.
* @type {number}
*/
-var numTilesShown = 0;
+var numColumnsShown = 0;
/**
* The browser embeddedSearch.newTabPage object.
@@ -175,13 +162,19 @@ var TILE_WIDTH = 160;
* @type {number}
* @const
*/
-var MOST_VISITED_HEIGHT = 156;
+var MOST_VISITED_HEIGHT = 296;
+
+/** @type {number} @const */
+var MAX_NUM_TILES_TO_SHOW = 8;
/** @type {number} @const */
-var MAX_NUM_TILES_TO_SHOW = 4;
+var MIN_NUM_COLUMNS = 2;
/** @type {number} @const */
-var MIN_NUM_TILES_TO_SHOW = 2;
+var MAX_NUM_COLUMNS = 4;
+
+/** @type {number} @const */
+var NUM_ROWS = 2;
/**
* Minimum total padding to give to the left and right of the most visited
@@ -262,35 +255,13 @@ function onMostVisitedChange() {
var pages = ntpApiHandle.mostVisited;
if (isBlacklisting) {
- // If this was called as a result of a blacklist, add a new replacement
- // (possibly filler) tile at the end and trigger the blacklist animation.
- var replacementTile = createTile(pages[MAX_NUM_TILES_TO_SHOW - 1]);
-
- tiles.push(replacementTile);
- tilesContainer.appendChild(replacementTile.elem);
-
+ // Trigger the blacklist animation and re-render the tiles when it
+ // completes.
var lastBlacklistedTileElement = lastBlacklistedTile.elem;
lastBlacklistedTileElement.addEventListener(
'webkitTransitionEnd', blacklistAnimationDone);
lastBlacklistedTileElement.classList.add(CLASSES.BLACKLIST);
- // In order to animate the replacement tile sliding into place, it must
- // be made visible.
- updateTileVisibility(numTilesShown + 1);
-
- } else if (isUndoing) {
Dan Beam 2013/04/25 00:09:49 ^ so what happened to this?
jeremycho 2013/04/25 00:15:04 We're getting rid of the undo animation - the new
- // If this was called as a result of an undo, re-insert the last blacklisted
- // tile in its old location and trigger the undo animation.
- tiles.splice(
- lastBlacklistedIndex, 0, lastBlacklistedTile);
- var lastBlacklistedTileElement = lastBlacklistedTile.elem;
- tilesContainer.insertBefore(
- lastBlacklistedTileElement,
- tilesContainer.childNodes[lastBlacklistedIndex]);
- lastBlacklistedTileElement.addEventListener(
- 'webkitTransitionEnd', undoAnimationDone);
- // Force the removal to happen synchronously.
- lastBlacklistedTileElement.scrollTop;
- lastBlacklistedTileElement.classList.remove(CLASSES.BLACKLIST);
+
} else {
// Otherwise render the tiles using the new data without animation.
tiles = [];
@@ -302,12 +273,17 @@ function onMostVisitedChange() {
}
/**
- * Renders the current set of tiles without animation.
+ * Renders the current set of tiles.
*/
function renderTiles() {
- removeChildren(tilesContainer);
- for (var i = 0, length = tiles.length; i < length; ++i) {
- tilesContainer.appendChild(tiles[i].elem);
+ var rows = tilesContainer.children;
+ for (var i = 0; i < rows.length; ++i) {
+ removeChildren(rows[i]);
+ }
+
+ for (var i = 0, length = tiles.length;
+ i < Math.min(length, numColumnsShown * NUM_ROWS); ++i) {
+ rows[Math.floor(i / numColumnsShown)].appendChild(tiles[i].elem);
}
}
@@ -388,19 +364,16 @@ function createTile(page) {
* is blacklisted.
* @param {number} rid The RID of the page being blacklisted.
* @return {function(Event)} A function which handles the blacklisting of the
- * page by displaying the notification, updating state variables, and
- * notifying Chrome.
+ * page by updating state variables and notifying Chrome.
*/
function generateBlacklistFunction(rid) {
return function(e) {
// Prevent navigation when the page is being blacklisted.
e.stopPropagation();
- showNotification();
isBlacklisting = true;
tilesContainer.classList.add(CLASSES.HIDE_BLACKLIST_BUTTON);
lastBlacklistedTile = getTileByRid(rid);
- lastBlacklistedIndex = tiles.indexOf(lastBlacklistedTile);
ntpApiHandle.deleteMostVisitedItem(rid);
};
}
@@ -423,16 +396,19 @@ function hideNotification() {
}
/**
- * Handles the end of the blacklist animation by removing the blacklisted tile.
+ * Handles the end of the blacklist animation by showing the notification and
+ * re-rendering the tiles
*/
function blacklistAnimationDone() {
- tiles.splice(lastBlacklistedIndex, 1);
- removeNode(lastBlacklistedTile.elem);
- updateTileVisibility(numTilesShown);
+ showNotification();
isBlacklisting = false;
tilesContainer.classList.remove(CLASSES.HIDE_BLACKLIST_BUTTON);
lastBlacklistedTile.elem.removeEventListener(
'webkitTransitionEnd', blacklistAnimationDone);
+ // Need to call explicitly to re-render the tiles, since the initial
+ // onmostvisitedchange issued by the blacklist function only triggered
+ // the animation.
+ onMostVisitedChange();
}
/**
@@ -443,24 +419,11 @@ function onUndo() {
hideNotification();
var lastBlacklistedRID = lastBlacklistedTile.rid;
if (typeof lastBlacklistedRID != 'undefined') {
Dan Beam 2013/04/25 00:09:49 nit: no curlies
jeremycho 2013/04/25 00:15:04 Done.
- isUndoing = true;
ntpApiHandle.undoMostVisitedDeletion(lastBlacklistedRID);
}
}
/**
- * Handles the end of the undo animation by removing the extraneous end tile.
- */
-function undoAnimationDone() {
- isUndoing = false;
- tiles.splice(tiles.length - 1, 1);
- removeNode(tilesContainer.lastElementChild);
- updateTileVisibility(numTilesShown);
- lastBlacklistedTile.elem.removeEventListener(
- 'webkitTransitionEnd', undoAnimationDone);
-}
-
-/**
* Handles a click on the restore all notification link by hiding the
* notification and informing Chrome.
*/
@@ -471,7 +434,7 @@ function onRestoreAll() {
/**
* Handles a resize by vertically centering the most visited section
- * and triggering the tile show/hide animation if necessary.
+ * and re-rendering the tiles if the number of columns has changed.
*/
function onResize() {
// The Google page uses a fixed layout instead.
@@ -481,23 +444,13 @@ function onResize() {
Math.max(0, (clientHeight - MOST_VISITED_HEIGHT) / 2) + 'px';
}
var clientWidth = document.documentElement.clientWidth;
- var numTilesToShow = Math.floor(
+ var numColumnsToShow = Math.floor(
(clientWidth - MIN_TOTAL_HORIZONTAL_PADDING) / TILE_WIDTH);
- numTilesToShow = Math.max(MIN_NUM_TILES_TO_SHOW, numTilesToShow);
- if (numTilesToShow != numTilesShown) {
- updateTileVisibility(numTilesToShow);
- numTilesShown = numTilesToShow;
- }
-}
-
-/**
- * Triggers an animation to show the first numTilesToShow tiles and hide the
- * remaining.
- * @param {number} numTilesToShow The number of tiles to show.
- */
-function updateTileVisibility(numTilesToShow) {
- for (var i = 0, length = tiles.length; i < length; ++i) {
- tiles[i].elem.classList.toggle(CLASSES.HIDE_TILE, i >= numTilesToShow);
+ numColumnsToShow = Math.max(MIN_NUM_COLUMNS,
+ Math.min(MAX_NUM_COLUMNS, numColumnsToShow));
+ if (numColumnsToShow != numColumnsShown) {
+ numColumnsShown = numColumnsToShow;
+ renderTiles();
}
}
@@ -981,6 +934,12 @@ function init() {
attribution = $(IDS.ATTRIBUTION);
ntpContents = $(IDS.NTP_CONTENTS);
+ for (var i = 0; i < NUM_ROWS; i++) {
+ var row = document.createElement('div');
+ row.classList.add(CLASSES.ROW);
+ tilesContainer.appendChild(row);
+ }
+
if (isGooglePage) {
document.body.classList.add(CLASSES.GOOGLE_PAGE);
var logo = document.createElement('div');
@@ -1038,11 +997,6 @@ function init() {
$(IDS.SUGGESTIONS_CONTAINER).dir = searchboxApiHandle.rtl ? 'rtl' : 'ltr';
- if (!document.webkitHidden)
- window.addEventListener('resize', addDelayedTransitions);
- else
- document.addEventListener('webkitvisibilitychange', addDelayedTransitions);
-
if (fakebox) {
// Listener for updating the fakebox focus.
document.body.onclick = function(event) {
@@ -1060,22 +1014,6 @@ function init() {
}
}
-/**
- * Applies webkit transitions to NTP elements which need to be delayed until
- * after the page is made visible and any initial resize has occurred. This is
- * to prevent animations from triggering when the NTP is shown.
- */
-function addDelayedTransitions() {
- if (fakebox) {
- fakebox.style.webkitTransition =
- '-webkit-transform 100ms linear, width 200ms ease';
- }
-
- tilesContainer.style.webkitTransition = 'width 200ms';
- window.removeEventListener('resize', addDelayedTransitions);
- document.removeEventListener('webkitvisibilitychange', addDelayedTransitions);
-}
-
document.addEventListener('DOMContentLoaded', init);
window.addEventListener('message', handleMessage, false);
})();
« no previous file with comments | « chrome/browser/resources/local_ntp/local_ntp.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698