OLD | NEW |
---|---|
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 minimum height required to show the Bottom Panel. If the height is | |
jeremycho_google
2012/08/24 00:54:42
nit:The second sentence seems redundant. And I th
pedrosimonetti2
2012/08/24 01:16:41
Done.
| |
21 * smaller than this value, the Bottom Panel will be hidden. | |
22 * @type {Number} | |
23 * @const | |
24 */ | |
25 var HEIGHT_FOR_BOTTOM_PANEL = 170; | |
26 | |
27 /** | |
28 * The Bottom Panel width required to show 5 cols of Tiles. | |
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 Bottom Panel width will be the available | |
37 * width minus the Bottom Panel's side margin. If the available width is | |
38 * smaller than this value, then the Bottom Panel's width will be an | |
39 * interpolation between the default width, and the minimum width defined | |
40 * by 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 | |
jeremycho_google
2012/08/24 00:54:42
To me, this first sentence is misleading, since th
pedrosimonetti2
2012/08/24 01:16:41
I think it's better now.
| |
48 * this value, then the Bottom Panel width 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 var width = colCount * requiredWidth - this.config_.cellMarginStart; | 548 var width = colCount * requiredWidth - this.config_.cellMarginStart; |
495 return width; | 549 return width; |
496 }, | 550 }, |
497 | 551 |
498 /** | 552 /** |
499 * Gets the bottom panel width. | 553 * Gets the bottom panel width. |
500 * @private | 554 * @private |
501 */ | 555 */ |
502 getBottomPanelWidth_: function() { | 556 getBottomPanelWidth_: function() { |
503 var windowWidth = cr.doc.documentElement.clientWidth; | 557 var windowWidth = cr.doc.documentElement.clientWidth; |
558 var margin = this.config_.bottomPanelHorizontalMargin; | |
504 var width; | 559 var width; |
505 // TODO(pedrosimonetti): Add constants? | 560 if (windowWidth >= MAX_BOTTOM_PANEL_WIDTH) |
506 if (windowWidth >= 948) | 561 width = MAX_BOTTOM_PANEL_WIDTH - 2 * margin; |
507 width = 748; | 562 else if (windowWidth >= NORMAL_BOTTOM_PANEL_WIDTH) |
508 else if (windowWidth >= 500) | 563 width = windowWidth - 2 * margin; |
509 width = windowWidth - 2 * this.config_.bottomPanelHorizontalMargin; | 564 else if (windowWidth >= MIN_BOTTOM_PANEL_WIDTH) { |
510 else if (windowWidth >= 300) | 565 // Interpolation between the previous and next states. |
511 // TODO(pedrosimonetti): Check specification. | 566 width = Math.floor((windowWidth - MIN_BOTTOM_PANEL_WIDTH) / |
512 width = Math.floor(((windowWidth - 300) / 200) * 100 + 200); | 567 (NORMAL_BOTTOM_PANEL_WIDTH - MIN_BOTTOM_PANEL_WIDTH) * |
513 else | 568 (NORMAL_BOTTOM_PANEL_WIDTH - |
514 width = 200; | 569 2 * margin - MIN_BOTTOM_PANEL_CONTENT_WIDTH) + |
570 MIN_BOTTOM_PANEL_CONTENT_WIDTH); | |
571 } else | |
572 width = MIN_BOTTOM_PANEL_CONTENT_WIDTH; | |
515 | 573 |
516 return width; | 574 return width; |
517 }, | 575 }, |
518 | 576 |
519 /** | 577 /** |
520 * Gets the number of available columns. | 578 * Gets the number of available columns. |
521 * @private | 579 * @private |
522 */ | 580 */ |
523 getAvailableColCount_: function() { | 581 getAvailableColCount_: function() { |
524 return this.getColCountForWidth_(this.getBottomPanelWidth_()); | 582 return this.getColCountForWidth_(this.getBottomPanelWidth_()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 | 685 |
628 var bottomPanelWidth = this.getBottomPanelWidth_(); | 686 var bottomPanelWidth = this.getBottomPanelWidth_(); |
629 var colCount = this.getColCountForWidth_(bottomPanelWidth); | 687 var colCount = this.getColCountForWidth_(bottomPanelWidth); |
630 var lastColCount = this.colCount_; | 688 var lastColCount = this.colCount_; |
631 var animatingColCount = this.animatingColCount_; | 689 var animatingColCount = this.animatingColCount_; |
632 | 690 |
633 var windowHeight = cr.doc.documentElement.clientHeight; | 691 var windowHeight = cr.doc.documentElement.clientHeight; |
634 | 692 |
635 this.tileGridContent_.classList.add('animate-tile'); | 693 this.tileGridContent_.classList.add('animate-tile'); |
636 | 694 |
637 // TODO(pedrosimonetti): Better handling of height state. | 695 this.showBottomPanel_(windowHeight >= HEIGHT_FOR_BOTTOM_PANEL); |
638 // TODO(pedrosimonetti): Add constants? | 696 |
639 var numOfVisibleRows = windowHeight > 500 ? 2 : 1; | 697 var numOfVisibleRows = windowHeight > HEIGHT_FOR_TWO_ROWS ? 2 : 1; |
640 if (numOfVisibleRows != this.numOfVisibleRows_) { | 698 if (numOfVisibleRows != this.numOfVisibleRows_) { |
641 this.numOfVisibleRows_ = numOfVisibleRows; | 699 this.numOfVisibleRows_ = numOfVisibleRows; |
642 this.paginate_(null, true); | 700 this.paginate_(null, true); |
643 $('page-list').style.height = | 701 $('page-list').style.height = |
644 (this.config_.rowHeight * numOfVisibleRows) + 'px'; | 702 (this.config_.rowHeight * numOfVisibleRows) + 'px'; |
645 } | 703 } |
646 | 704 |
647 // changeVisibleCols | 705 // changeVisibleCols |
648 if (colCount != animatingColCount) { | 706 if (colCount != animatingColCount) { |
649 var newWidth = this.getWidthForColCount_(colCount); | 707 var newWidth = this.getWidthForColCount_(colCount); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 | 746 |
689 this.content_.style.width = bottomPanelWidth + 'px'; | 747 this.content_.style.width = bottomPanelWidth + 'px'; |
690 | 748 |
691 this.animatingColCount_ = colCount; | 749 this.animatingColCount_ = colCount; |
692 }, | 750 }, |
693 | 751 |
694 // animation helpers | 752 // animation helpers |
695 // ------------------------------------------------------------------------- | 753 // ------------------------------------------------------------------------- |
696 | 754 |
697 /** | 755 /** |
756 * Animates the display the Bottom Panel. | |
757 * @param {boolean} show Whether or not to show the Bottom Panel. | |
758 */ | |
759 showBottomPanel_: function(show) { | |
760 $('card-slider-frame').classList[show ? 'remove' : 'add']( | |
761 'hide-card-slider'); | |
762 }, | |
763 | |
764 /** | |
698 * Animates the display of a row. TODO(pedrosimonetti): Make it local? | 765 * Animates the display of a row. TODO(pedrosimonetti): Make it local? |
699 * @param {HTMLElement} row The row element. | 766 * @param {HTMLElement} row The row element. |
700 * @param {boolean} show Whether or not to show the row. | 767 * @param {boolean} show Whether or not to show the row. |
701 */ | 768 */ |
702 showTileRow_: function(row, show) { | 769 showTileRow_: function(row, show) { |
703 row.classList[show ? 'remove' : 'add']('hide-row'); | 770 row.classList[show ? 'remove' : 'add']('hide-row'); |
704 }, | 771 }, |
705 | 772 |
706 /** | 773 /** |
707 * Animates the display of columns. TODO(pedrosimonetti): Make it local? | 774 * Animates the display of columns. TODO(pedrosimonetti): Make it local? |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 } | 865 } |
799 | 866 |
800 return { | 867 return { |
801 // TODO(pedrosimonetti): Drag. Delete after porting the rest of the code. | 868 // TODO(pedrosimonetti): Drag. Delete after porting the rest of the code. |
802 getCurrentlyDraggingTile2: deprecate, | 869 getCurrentlyDraggingTile2: deprecate, |
803 setCurrentDropEffect2: deprecate, | 870 setCurrentDropEffect2: deprecate, |
804 Tile2: Tile, | 871 Tile2: Tile, |
805 TilePage2: TilePage | 872 TilePage2: TilePage |
806 }; | 873 }; |
807 }); | 874 }); |
OLD | NEW |