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

Side by Side Diff: chrome/browser/resources/ntp_search/tile_page.js

Issue 10867021: NTP5: Improving the Tile Page resize logic (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing Evan's comments Created 8 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('ntp', function() { 5 cr.define('ntp', function() {
6 'use strict'; 6 'use strict';
7 7
8 //---------------------------------------------------------------------------- 8 //----------------------------------------------------------------------------
9 // Constants
10 //----------------------------------------------------------------------------
11
12 /**
13 * The height required to show 2 rows of Tiles in the Bottom Panel.
14 * @type {number}
15 * @const
16 */
17 var HEIGHT_FOR_TWO_ROWS = 275;
18
19 /**
20 * The height required to show the Bottom Panel.
21 * @type {number}
22 * @const
23 */
24 var HEIGHT_FOR_BOTTOM_PANEL = 170;
25
26 /**
27 * The Bottom Panel width required to show 5 cols of Tiles, which is used
28 * in the width computation.
29 * @type {number}
30 * @const
31 */
32 var MAX_BOTTOM_PANEL_WIDTH = 948;
33
34 /**
35 * The normal Bottom Panel width. If the window width is greater than or
36 * equal to this value, then the width of the Bottom Panel's content will be
37 * the available width minus side margin. If the available width is smaller
38 * than this value, then the width of the Bottom Panel's content will be an
39 * interpolation between the normal width, and the minimum width defined by
40 * the constant MIN_BOTTOM_PANEL_CONTENT_WIDTH.
41 * @type {number}
42 * @const
43 */
44 var NORMAL_BOTTOM_PANEL_WIDTH = 500;
45
46 /**
47 * The minimum Bottom Panel width. If the available width is smaller than
48 * this value, then the width of the Bottom Panel's content will be fixed to
49 * MIN_BOTTOM_PANEL_CONTENT_WIDTH.
50 * @type {number}
51 * @const
52 */
53 var MIN_BOTTOM_PANEL_WIDTH = 300;
54
55 /**
56 * The minimum width of the Bottom Panel's content.
57 * @type {number}
58 * @const
59 */
60 var MIN_BOTTOM_PANEL_CONTENT_WIDTH = 200;
61
62 //----------------------------------------------------------------------------
9 // Tile 63 // Tile
10 //---------------------------------------------------------------------------- 64 //----------------------------------------------------------------------------
11 65
12 /** 66 /**
13 * A virtual Tile class. Each TilePage subclass should have its own Tile 67 * A virtual Tile class. Each TilePage subclass should have its own Tile
14 * subclass implemented too (e.g. MostVisitedPage contains MostVisited 68 * subclass implemented too (e.g. MostVisitedPage contains MostVisited
15 * tiles, and MostVisited is a Tile subclass). 69 * tiles, and MostVisited is a Tile subclass).
16 * @constructor 70 * @constructor
17 * @param {Object} config TilePage configuration object. 71 * @param {Object} config TilePage configuration object.
18 */ 72 */
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 var width = colCount * requiredWidth - this.config_.cellMarginStart; 525 var width = colCount * requiredWidth - this.config_.cellMarginStart;
472 return width; 526 return width;
473 }, 527 },
474 528
475 /** 529 /**
476 * Gets the bottom panel width. 530 * Gets the bottom panel width.
477 * @private 531 * @private
478 */ 532 */
479 getBottomPanelWidth_: function() { 533 getBottomPanelWidth_: function() {
480 var windowWidth = cr.doc.documentElement.clientWidth; 534 var windowWidth = cr.doc.documentElement.clientWidth;
535 var margin = 2 * this.config_.bottomPanelHorizontalMargin;
481 var width; 536 var width;
482 // TODO(pedrosimonetti): Add constants? 537 if (windowWidth >= MAX_BOTTOM_PANEL_WIDTH) {
483 if (windowWidth >= 948) 538 width = MAX_BOTTOM_PANEL_WIDTH - margin;
484 width = 748; 539 } else if (windowWidth >= NORMAL_BOTTOM_PANEL_WIDTH) {
485 else if (windowWidth >= 500) 540 width = windowWidth - margin;
486 width = windowWidth - 2 * this.config_.bottomPanelHorizontalMargin; 541 } else if (windowWidth >= MIN_BOTTOM_PANEL_WIDTH) {
487 else if (windowWidth >= 300) 542 // Interpolation between the previous and next states.
488 // TODO(pedrosimonetti): Check specification. 543 var minMargin = MIN_BOTTOM_PANEL_WIDTH - MIN_BOTTOM_PANEL_CONTENT_WIDTH;
489 width = Math.floor(((windowWidth - 300) / 200) * 100 + 200); 544 var factor = (windowWidth - MIN_BOTTOM_PANEL_WIDTH) /
490 else 545 (NORMAL_BOTTOM_PANEL_WIDTH - MIN_BOTTOM_PANEL_WIDTH);
491 width = 200; 546 var interpolatedMargin = minMargin + factor * (margin - minMargin);
547 width = windowWidth - interpolatedMargin;
548 } else {
549 width = MIN_BOTTOM_PANEL_CONTENT_WIDTH;
550 }
492 551
493 return width; 552 return width;
494 }, 553 },
495 554
496 /** 555 /**
497 * Gets the number of available columns. 556 * Gets the number of available columns.
498 * @private 557 * @private
499 */ 558 */
500 getAvailableColCount_: function() { 559 getAvailableColCount_: function() {
501 return this.getColCountForWidth_(this.getBottomPanelWidth_()); 560 return this.getColCountForWidth_(this.getBottomPanelWidth_());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 var lastColCount = this.colCount_; 664 var lastColCount = this.colCount_;
606 var animatingColCount = this.animatingColCount_; 665 var animatingColCount = this.animatingColCount_;
607 666
608 var windowHeight = cr.doc.documentElement.clientHeight; 667 var windowHeight = cr.doc.documentElement.clientHeight;
609 668
610 // We should not animate the very first layout, that is, when both 669 // We should not animate the very first layout, that is, when both
611 // numOfVisibleRows_ and animatingColCount_ are undefined. 670 // numOfVisibleRows_ and animatingColCount_ are undefined.
612 var shouldAnimate = this.numOfVisibleRows_ !== undefined || 671 var shouldAnimate = this.numOfVisibleRows_ !== undefined ||
613 this.animatingColCount_ !== undefined; 672 this.animatingColCount_ !== undefined;
614 673
674 this.showBottomPanel_(windowHeight >= HEIGHT_FOR_BOTTOM_PANEL);
675
615 // TODO(pedrosimonetti): Add constants? 676 // TODO(pedrosimonetti): Add constants?
616 // If the number of visible rows has changed, then we need to resize the 677 // If the number of visible rows has changed, then we need to resize the
617 // grid and animate the affected rows. We also need to keep track of 678 // grid and animate the affected rows. We also need to keep track of
618 // whether the number of visible rows has changed because we might have 679 // whether the number of visible rows has changed because we might have
619 // to render the grid when the number of columns hasn't changed. 680 // to render the grid when the number of columns hasn't changed.
620 var numberOfRowsHasChanged = false; 681 var numberOfRowsHasChanged = false;
621 var numOfVisibleRows = windowHeight > 500 ? 2 : 1; 682 var numOfVisibleRows = windowHeight > HEIGHT_FOR_TWO_ROWS ? 2 : 1;
622 if (numOfVisibleRows != this.numOfVisibleRows_) { 683 if (numOfVisibleRows != this.numOfVisibleRows_) {
623 this.numOfVisibleRows_ = numOfVisibleRows; 684 this.numOfVisibleRows_ = numOfVisibleRows;
624 numberOfRowsHasChanged = true; 685 numberOfRowsHasChanged = true;
625 686
626 var pageList = $('page-list'); 687 var pageList = $('page-list');
627 if (shouldAnimate) 688 if (shouldAnimate)
628 pageList.classList.add('animate-page-height'); 689 pageList.classList.add('animate-page-height');
629 690
630 // By forcing the pagination, all affected rows will be animated. 691 // By forcing the pagination, all affected rows will be animated.
631 this.paginate_(null, true); 692 this.paginate_(null, true);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 759
699 this.content_.style.width = bottomPanelWidth + 'px'; 760 this.content_.style.width = bottomPanelWidth + 'px';
700 761
701 this.animatingColCount_ = colCount; 762 this.animatingColCount_ = colCount;
702 }, 763 },
703 764
704 // animation helpers 765 // animation helpers
705 // ------------------------------------------------------------------------- 766 // -------------------------------------------------------------------------
706 767
707 /** 768 /**
769 * Animates the display the Bottom Panel.
770 * @param {boolean} show Whether or not to show the Bottom Panel.
771 */
772 showBottomPanel_: function(show) {
773 $('card-slider-frame').classList[show ? 'remove' : 'add'](
774 'hide-card-slider');
775 },
776
777 /**
708 * Animates the display of a row. TODO(pedrosimonetti): Make it local? 778 * Animates the display of a row. TODO(pedrosimonetti): Make it local?
709 * @param {HTMLElement} row The row element. 779 * @param {HTMLElement} row The row element.
710 * @param {boolean} show Whether or not to show the row. 780 * @param {boolean} show Whether or not to show the row.
711 */ 781 */
712 showTileRow_: function(row, show) { 782 showTileRow_: function(row, show) {
713 row.classList[show ? 'remove' : 'add']('hide-row'); 783 row.classList[show ? 'remove' : 'add']('hide-row');
714 }, 784 },
715 785
716 /** 786 /**
717 * Animates the display of columns. TODO(pedrosimonetti): Make it local? 787 * Animates the display of columns. TODO(pedrosimonetti): Make it local?
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 902 }
833 903
834 return { 904 return {
835 // TODO(pedrosimonetti): Drag. Delete after porting the rest of the code. 905 // TODO(pedrosimonetti): Drag. Delete after porting the rest of the code.
836 getCurrentlyDraggingTile2: deprecate, 906 getCurrentlyDraggingTile2: deprecate,
837 setCurrentDropEffect2: deprecate, 907 setCurrentDropEffect2: deprecate,
838 Tile2: Tile, 908 Tile2: Tile,
839 TilePage2: TilePage 909 TilePage2: TilePage
840 }; 910 };
841 }); 911 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698