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

Side by Side Diff: chrome/browser/resources/new_new_tab.js

Issue 3371010: NTP Apps bug fixes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Arv's comments Created 10 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
« no previous file with comments | « no previous file | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more 5 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more
6 // than this many items in the miniview. 6 // than this many items in the miniview.
7 var MAX_MINIVIEW_ITEMS = 15; 7 var MAX_MINIVIEW_ITEMS = 15;
8 8
9 // Extra spacing at the top of the layout. 9 // Extra spacing at the top of the layout.
10 var LAYOUT_SPACING_TOP = 25; 10 var LAYOUT_SPACING_TOP = 25;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 var gradientHeightPx = Math.min(10, Math.floor(visibleHeightPx / 2)); 263 var gradientHeightPx = Math.min(10, Math.floor(visibleHeightPx / 2));
264 var gradientDestination = 'rgba(0,0,0,' + (gradientHeightPx / 10) + ')'; 264 var gradientDestination = 'rgba(0,0,0,' + (gradientHeightPx / 10) + ')';
265 265
266 var bottomSpacing = 15; 266 var bottomSpacing = 15;
267 var first = parseFloat(maxiview.style.top) / window.innerHeight; 267 var first = parseFloat(maxiview.style.top) / window.innerHeight;
268 var second = first + gradientHeightPx / window.innerHeight; 268 var second = first + gradientHeightPx / window.innerHeight;
269 var fourth = first + (visibleHeightPx - bottomSpacing) / window.innerHeight; 269 var fourth = first + (visibleHeightPx - bottomSpacing) / window.innerHeight;
270 var third = fourth - gradientHeightPx / window.innerHeight; 270 var third = fourth - gradientHeightPx / window.innerHeight;
271 271
272 var gradientArguments = [ 272 var gradientArguments = [
273 "linear", 273 'linear',
274 "0 0", 274 '0 0',
275 "0 100%", 275 '0 100%',
276 "from(transparent)", 276 'from(transparent)',
277 getColorStopString(first, "transparent"), 277 getColorStopString(first, 'transparent'),
278 getColorStopString(second, gradientDestination), 278 getColorStopString(second, gradientDestination),
279 getColorStopString(third, gradientDestination), 279 getColorStopString(third, gradientDestination),
280 getColorStopString(fourth, "transparent"), 280 getColorStopString(fourth, 'transparent'),
281 "to(transparent)" 281 'to(transparent)'
282 ]; 282 ];
283 283
284 var gradient = '-webkit-gradient(' + gradientArguments.join(', ') + ')'; 284 var gradient = '-webkit-gradient(' + gradientArguments.join(', ') + ')';
285 maxiview.style.WebkitMaskImage = gradient; 285 maxiview.style.WebkitMaskImage = gradient;
286 } 286 }
287 287
288 function getColorStopString(height, color) { 288 function getColorStopString(height, color) {
289 return "color-stop(" + height + ", " + color + ")"; 289 return 'color-stop(' + height + ', ' + color + ')';
290 } 290 }
291 291
292 window.addEventListener('resize', handleWindowResize); 292 window.addEventListener('resize', handleWindowResize);
293 293
294 var sectionToElementMap; 294 var sectionToElementMap;
295 function getSectionElement(section) { 295 function getSectionElement(section) {
296 if (!sectionToElementMap) { 296 if (!sectionToElementMap) {
297 sectionToElementMap = {}; 297 sectionToElementMap = {};
298 for (var key in Section) { 298 for (var key in Section) {
299 sectionToElementMap[Section[key]] = 299 sectionToElementMap[Section[key]] =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 maxiview.classList.add('hiding'); 350 maxiview.classList.add('hiding');
351 351
352 var miniview = el.getElementsByClassName('miniview')[0]; 352 var miniview = el.getElementsByClassName('miniview')[0];
353 if (miniview) 353 if (miniview)
354 updateMiniviewClipping(miniview); 354 updateMiniviewClipping(miniview);
355 } 355 }
356 } 356 }
357 } 357 }
358 358
359 window.addEventListener('webkitTransitionEnd', function(e) { 359 window.addEventListener('webkitTransitionEnd', function(e) {
360 if (e.target.classList.contains('hiding')) 360 if (e.target.classList.contains('hiding')) {
361 e.target.classList.add('hidden'); 361 e.target.classList.add('hidden');
362 e.target.classList.remove('hiding');
363 }
362 364
363 document.documentElement.setAttribute("enable-section-animations", "false"); 365 document.documentElement.setAttribute('enable-section-animations', 'false');
364 }); 366 });
365 367
366 /** 368 /**
367 * Callback when the shown sections changes in another NTP. 369 * Callback when the shown sections changes in another NTP.
368 * @param {number} newShownSections Bitmask of the shown sections. 370 * @param {number} newShownSections Bitmask of the shown sections.
369 */ 371 */
370 function setShownSections(newShownSections) { 372 function setShownSections(newShownSections) {
371 for (var key in Section) { 373 for (var key in Section) {
372 if (newShownSections & Section[key]) 374 if (newShownSections & Section[key])
373 showSection(Section[key]); 375 showSection(Section[key]);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 $('main').addEventListener('click', function(e) { 652 $('main').addEventListener('click', function(e) {
651 var p = e.target; 653 var p = e.target;
652 while (p && p.tagName != 'H2') { 654 while (p && p.tagName != 'H2') {
653 // In case the user clicks on a button we do not want to expand/collapse a 655 // In case the user clicks on a button we do not want to expand/collapse a
654 // section. 656 // section.
655 if (p.tagName == 'BUTTON') 657 if (p.tagName == 'BUTTON')
656 return; 658 return;
657 p = p.parentNode; 659 p = p.parentNode;
658 } 660 }
659 661
660 if (!p) { 662 if (!p)
661 return; 663 return;
662 }
663 664
664 p = p.parentNode; 665 p = p.parentNode;
665 if (!getSectionMaxiview(p)) { 666 if (!getSectionMaxiview(p))
666 return; 667 return;
668
669 toggleSectionVisibilityAndAnimate(p.getAttribute('section'));
670 });
671
672 function toggleSectionVisibilityAndAnimate(section) {
673 if (!section)
674 return;
675
676 // We set it back in webkitTransitionEnd.
677 document.documentElement.setAttribute('enable-section-animations', 'true');
678 if (shownSections & Section[section]) {
679 hideSection(Section[section]);
680 } else {
681 for (var p in Section) {
682 if (p == section)
683 showSection(Section[p]);
684 else
685 hideSection(Section[p]);
686 }
667 } 687 }
668 688 layoutSections();
669 var section = p.getAttribute('section'); 689 saveShownSections();
670 if (section) { 690 }
671 // We set it back in webkitTransitionEnd.
672 document.documentElement.setAttribute("enable-section-animations", "true");
673 if (shownSections & Section[section]) {
674 hideSection(Section[section]);
675 } else {
676 for (var p in Section) {
677 if (p == section)
678 showSection(Section[p]);
679 else
680 hideSection(Section[p]);
681 }
682 }
683 layoutSections();
684 saveShownSections();
685 }
686 });
687 691
688 function handleIfEnterKey(f) { 692 function handleIfEnterKey(f) {
689 return function(e) { 693 return function(e) {
690 if (e.keyIdentifier == 'Enter') { 694 if (e.keyIdentifier == 'Enter')
691 f(e); 695 f(e);
692 }
693 }; 696 };
694 } 697 }
695 698
696 function maybeReopenTab(e) { 699 function maybeReopenTab(e) {
697 var el = findAncestor(e.target, function(el) { 700 var el = findAncestor(e.target, function(el) {
698 return el.sessionId !== undefined; 701 return el.sessionId !== undefined;
699 }); 702 });
700 if (el) { 703 if (el) {
701 chrome.send('reopenTab', [String(el.sessionId)]); 704 chrome.send('reopenTab', [String(el.sessionId)]);
702 e.preventDefault(); 705 e.preventDefault();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 window.setTimeout(function() { 938 window.setTimeout(function() {
936 mostVisited.ensureSmallGridCorrect(); 939 mostVisited.ensureSmallGridCorrect();
937 document.body.classList.remove('loading'); 940 document.body.classList.remove('loading');
938 }, 1); 941 }, 1);
939 942
940 // Only show the first run notification if first run. 943 // Only show the first run notification if first run.
941 if (firstRun) { 944 if (firstRun) {
942 showFirstRunNotification(); 945 showFirstRunNotification();
943 } 946 }
944 } 947 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698