| 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 /** | 5 /** |
| 6 * @fileoverview PageListView implementation. | 6 * @fileoverview PageListView implementation. |
| 7 * PageListView manages page list, dot list, switcher buttons and handles apps | 7 * PageListView manages page list, dot list, switcher buttons and handles apps |
| 8 * pages callbacks from backend. | 8 * pages callbacks from backend. |
| 9 * | 9 * |
| 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. | 10 * Note that you need to have AppLauncherHandler in your WebUI to use this code. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 */ | 79 */ |
| 80 tilePages: undefined, | 80 tilePages: undefined, |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * A list of all 'apps-page' elements. | 83 * A list of all 'apps-page' elements. |
| 84 * @type {!NodeList|undefined} | 84 * @type {!NodeList|undefined} |
| 85 */ | 85 */ |
| 86 appsPages: undefined, | 86 appsPages: undefined, |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * The Suggestions page. | |
| 90 * @type {!Element|undefined} | |
| 91 */ | |
| 92 suggestionsPage: undefined, | |
| 93 | |
| 94 /** | |
| 95 * The Most Visited page. | 89 * The Most Visited page. |
| 96 * @type {!Element|undefined} | 90 * @type {!Element|undefined} |
| 97 */ | 91 */ |
| 98 mostVisitedPage: undefined, | 92 mostVisitedPage: undefined, |
| 99 | 93 |
| 100 /** | 94 /** |
| 101 * The 'dots-list' element. | 95 * The 'dots-list' element. |
| 102 * @type {!Element|undefined} | 96 * @type {!Element|undefined} |
| 103 */ | 97 */ |
| 104 dotList: undefined, | 98 dotList: undefined, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 260 } |
| 267 | 261 |
| 268 // Remember special MostVisitedPage. | 262 // Remember special MostVisitedPage. |
| 269 if (typeof ntp.MostVisitedPage != 'undefined' && | 263 if (typeof ntp.MostVisitedPage != 'undefined' && |
| 270 page instanceof ntp.MostVisitedPage) { | 264 page instanceof ntp.MostVisitedPage) { |
| 271 assert(this.tilePages.length == 1, | 265 assert(this.tilePages.length == 1, |
| 272 'MostVisitedPage should be added as first tile page'); | 266 'MostVisitedPage should be added as first tile page'); |
| 273 this.mostVisitedPage = page; | 267 this.mostVisitedPage = page; |
| 274 } | 268 } |
| 275 | 269 |
| 276 if (typeof ntp.SuggestionsPage != 'undefined' && | |
| 277 page instanceof ntp.SuggestionsPage) { | |
| 278 this.suggestionsPage = page; | |
| 279 } | |
| 280 | |
| 281 // If we're appending an AppsPage and it's a temporary page, animate it. | 270 // If we're appending an AppsPage and it's a temporary page, animate it. |
| 282 var animate = page instanceof ntp.AppsPage && | 271 var animate = page instanceof ntp.AppsPage && |
| 283 page.classList.contains('temporary'); | 272 page.classList.contains('temporary'); |
| 284 // Make a deep copy of the dot template to add a new one. | 273 // Make a deep copy of the dot template to add a new one. |
| 285 var newDot = new ntp.NavDot(page, title, titleIsEditable, animate); | 274 var newDot = new ntp.NavDot(page, title, titleIsEditable, animate); |
| 286 page.navigationDot = newDot; | 275 page.navigationDot = newDot; |
| 287 this.dotList.insertBefore(newDot, | 276 this.dotList.insertBefore(newDot, |
| 288 opt_refNode ? opt_refNode.navigationDot : null); | 277 opt_refNode ? opt_refNode.navigationDot : null); |
| 289 // Set a tab index on the first dot. | 278 // Set a tab index on the first dot. |
| 290 if (this.dotList.dots.length == 1) | 279 if (this.dotList.dots.length == 1) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 518 |
| 530 /** | 519 /** |
| 531 * Invoked whenever the pages in apps-page-list have changed so that | 520 * Invoked whenever the pages in apps-page-list have changed so that |
| 532 * the Slider knows about the new elements. | 521 * the Slider knows about the new elements. |
| 533 */ | 522 */ |
| 534 updateSliderCards: function() { | 523 updateSliderCards: function() { |
| 535 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, | 524 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, |
| 536 this.tilePages.length - 1)); | 525 this.tilePages.length - 1)); |
| 537 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), | 526 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), |
| 538 pageNo); | 527 pageNo); |
| 539 // The shownPage property was potentially saved from a previous webui that | |
| 540 // didn't have the same set of pages as the current one. So we cascade | |
| 541 // from suggestions, to most visited and then to apps because we can have | |
| 542 // an page with apps only (e.g., chrome://apps) or one with only the most | |
| 543 // visited, but not one with only suggestions. And we alwayd default to | |
| 544 // most visited first when previously shown page is not availabel anymore. | |
| 545 // If most visited isn't there either, we go to apps. | |
| 546 if (this.shownPage == loadTimeData.getInteger('suggestions_page_id')) { | |
| 547 if (this.suggestionsPage) | |
| 548 this.cardSlider.selectCardByValue(this.suggestionsPage); | |
| 549 else | |
| 550 this.shownPage = loadTimeData.getInteger('most_visited_page_id'); | |
| 551 } | |
| 552 if (this.shownPage == loadTimeData.getInteger('most_visited_page_id')) { | 528 if (this.shownPage == loadTimeData.getInteger('most_visited_page_id')) { |
| 553 if (this.mostVisitedPage) | 529 if (this.mostVisitedPage) |
| 554 this.cardSlider.selectCardByValue(this.mostVisitedPage); | 530 this.cardSlider.selectCardByValue(this.mostVisitedPage); |
| 555 else | 531 else |
| 556 this.shownPage = loadTimeData.getInteger('apps_page_id'); | 532 this.shownPage = loadTimeData.getInteger('apps_page_id'); |
| 557 } | 533 } |
| 558 if (this.shownPage == loadTimeData.getInteger('apps_page_id') && | 534 if (this.shownPage == loadTimeData.getInteger('apps_page_id') && |
| 559 loadTimeData.getBoolean('showApps')) { | 535 loadTimeData.getBoolean('showApps')) { |
| 560 this.cardSlider.selectCardByValue( | 536 this.cardSlider.selectCardByValue( |
| 561 this.appsPages[Math.min(this.shownPageIndex, | 537 this.appsPages[Math.min(this.shownPageIndex, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 661 |
| 686 // Don't change shownPage until startup is done (and page changes actually | 662 // Don't change shownPage until startup is done (and page changes actually |
| 687 // reflect user actions). | 663 // reflect user actions). |
| 688 if (!this.isStartingUp_()) { | 664 if (!this.isStartingUp_()) { |
| 689 if (page.classList.contains('apps-page')) { | 665 if (page.classList.contains('apps-page')) { |
| 690 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), | 666 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), |
| 691 this.getAppsPageIndex(page)); | 667 this.getAppsPageIndex(page)); |
| 692 } else if (page.classList.contains('most-visited-page')) { | 668 } else if (page.classList.contains('most-visited-page')) { |
| 693 this.setShownPage_( | 669 this.setShownPage_( |
| 694 loadTimeData.getInteger('most_visited_page_id'), 0); | 670 loadTimeData.getInteger('most_visited_page_id'), 0); |
| 695 } else if (page.classList.contains('suggestions-page')) { | |
| 696 this.setShownPage_(loadTimeData.getInteger('suggestions_page_id'), 0); | |
| 697 } else { | 671 } else { |
| 698 console.error('unknown page selected'); | 672 console.error('unknown page selected'); |
| 699 } | 673 } |
| 700 } | 674 } |
| 701 | 675 |
| 702 // Update the active dot | 676 // Update the active dot |
| 703 var curDot = this.dotList.getElementsByClassName('selected')[0]; | 677 var curDot = this.dotList.getElementsByClassName('selected')[0]; |
| 704 if (curDot) | 678 if (curDot) |
| 705 curDot.classList.remove('selected'); | 679 curDot.classList.remove('selected'); |
| 706 page.navigationDot.classList.add('selected'); | 680 page.navigationDot.classList.add('selected'); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 if (page.navigationDot) | 811 if (page.navigationDot) |
| 838 page.navigationDot.remove(opt_animate); | 812 page.navigationDot.remove(opt_animate); |
| 839 this.cardSlider.removeCard(page); | 813 this.cardSlider.removeCard(page); |
| 840 }, | 814 }, |
| 841 }; | 815 }; |
| 842 | 816 |
| 843 return { | 817 return { |
| 844 PageListView: PageListView | 818 PageListView: PageListView |
| 845 }; | 819 }; |
| 846 }); | 820 }); |
| OLD | NEW |