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

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

Issue 17257004: [Android] Fix NTP bookmark image unit for low resolution device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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 | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // File Description: 5 // File Description:
6 // Contains all the necessary functions for rendering the NTP on mobile 6 // Contains all the necessary functions for rendering the NTP on mobile
7 // devices. 7 // devices.
8 8
9 /** 9 /**
10 * The event type used to determine when a touch starts. 10 * The event type used to determine when a touch starts.
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 var iconUrl = item.icon || 'chrome://touch-icon/largest/' + item.url; 700 var iconUrl = item.icon || 'chrome://touch-icon/largest/' + item.url;
701 var faviconIcon = createDiv('favicon-icon'); 701 var faviconIcon = createDiv('favicon-icon');
702 faviconIcon.style.backgroundImage = 'url(' + iconUrl + ')'; 702 faviconIcon.style.backgroundImage = 'url(' + iconUrl + ')';
703 trackImageLoad(iconUrl); 703 trackImageLoad(iconUrl);
704 704
705 var image = new Image(); 705 var image = new Image();
706 image.src = iconUrl; 706 image.src = iconUrl;
707 image.onload = function() { 707 image.onload = function() {
708 var w = image.width; 708 var w = image.width;
709 var h = image.height; 709 var h = image.height;
710 var wDip = w / window.devicePixelRatio; 710 if (Math.floor(w) <= 16 || Math.floor(h) <= 16) {
711 var hDip = h / window.devicePixelRatio;
712 if (Math.floor(wDip) <= 16 || Math.floor(hDip) <= 16) {
713 // it's a standard favicon (or at least it's small). 711 // it's a standard favicon (or at least it's small).
714 faviconBox.classList.add('document'); 712 faviconBox.classList.add('document');
715 713
716 faviconBox.appendChild( 714 faviconBox.appendChild(
717 createDiv('color-strip colorstrip-' + faviconIndex)); 715 createDiv('color-strip colorstrip-' + faviconIndex));
718 faviconBox.appendChild(createDiv('bookmark-border')); 716 faviconBox.appendChild(createDiv('bookmark-border'));
719 var foldDiv = createDiv('fold'); 717 var foldDiv = createDiv('fold');
720 foldDiv.id = 'fold_' + faviconIndex; 718 foldDiv.id = 'fold_' + faviconIndex;
721 foldDiv.style['background'] = 719 foldDiv.style['background'] =
722 '-webkit-canvas(fold_' + faviconIndex + ')'; 720 '-webkit-canvas(fold_' + faviconIndex + ')';
(...skipping 10 matching lines...) Expand all
733 // the dominant color for all scale factors is the same. 731 // the dominant color for all scale factors is the same.
734 chrome.send('getFaviconDominantColor', 732 chrome.send('getFaviconDominantColor',
735 [('chrome://favicon/size/16@1x/' + item.url), '' + faviconIndex]); 733 [('chrome://favicon/size/16@1x/' + item.url), '' + faviconIndex]);
736 faviconIndex++; 734 faviconIndex++;
737 } else if ((w == 57 && h == 57) || (w == 114 && h == 114)) { 735 } else if ((w == 57 && h == 57) || (w == 114 && h == 114)) {
738 // it's a touch icon for 1x or 2x. 736 // it's a touch icon for 1x or 2x.
739 faviconIcon.classList.add('touch-icon'); 737 faviconIcon.classList.add('touch-icon');
740 } else { 738 } else {
741 // It's an html5 icon (or at least it's larger). 739 // It's an html5 icon (or at least it's larger).
742 // Rescale it to be no bigger than 64x64 dip. 740 // Rescale it to be no bigger than 64x64 dip.
743 var maxDip = 64; // DIP 741 var max = 64;
744 if (wDip > maxDip || hDip > maxDip) { 742 if (w > max || h > max) {
745 var scale = (wDip > hDip) ? (maxDip / wDip) : (maxDip / hDip); 743 var scale = (w > h) ? (max / w) : (max / h);
746 wDip *= scale; 744 w *= scale;
747 hDip *= scale; 745 h *= scale;
748 } 746 }
749 faviconIcon.style.backgroundSize = wDip + 'px ' + hDip + 'px'; 747 faviconIcon.style.backgroundSize = w + 'px ' + h + 'px';
750 } 748 }
751 }; 749 };
752 faviconBox.appendChild(faviconIcon); 750 faviconBox.appendChild(faviconIcon);
753 } 751 }
754 holder.appendChild(faviconBox); 752 holder.appendChild(faviconBox);
755 753
756 var title = createDiv('title'); 754 var title = createDiv('title');
757 title.textContent = item.title; 755 title.textContent = item.title;
758 holder.appendChild(title); 756 holder.appendChild(title);
759 757
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 var labelLeft = (thumbWidth - labelWidth) / 2; 2205 var labelLeft = (thumbWidth - labelWidth) / 2;
2208 var itemHeight = thumbHeight + labelHeight; 2206 var itemHeight = thumbHeight + labelHeight;
2209 2207
2210 // default vertical margin between items 2208 // default vertical margin between items
2211 var itemMarginTop = 0; 2209 var itemMarginTop = 0;
2212 var itemMarginBottom = 0; 2210 var itemMarginBottom = 0;
2213 var itemMarginLeft = 20; 2211 var itemMarginLeft = 20;
2214 var itemMarginRight = 20; 2212 var itemMarginRight = 20;
2215 2213
2216 var listHeight = 0; 2214 var listHeight = 0;
2217 // set it to the unscaled size so centerGrid works correctly
2218 modifyCssRule('body[device="phone"] .thumbnail-cell',
2219 'width', thumbWidth + 'px');
2220 2215
2221 var screenHeight = 2216 var screenHeight =
2222 document.documentElement.offsetHeight - 2217 document.documentElement.offsetHeight -
2223 getButtonBarPadding(); 2218 getButtonBarPadding();
2224 2219
2225 if (isPortrait()) { 2220 if (isPortrait()) {
2226 mostVisitedList.setAttribute(GRID_COLUMNS, '2'); 2221 mostVisitedList.setAttribute(GRID_COLUMNS, '2');
2227 listHeight = screenHeight * .85; 2222 listHeight = screenHeight;
2228 listHeight = listHeight >= 420 ? 420 : listHeight; 2223 listHeight = listHeight >= 400 ? 400 : listHeight;
2229 // Size for 3 rows (4 gutters) 2224 // Size for 3 rows (4 gutters)
2230 itemMarginTop = (listHeight - (itemHeight * 3)) / 4; 2225 itemMarginTop = (listHeight - (itemHeight * 3)) / 4;
2231 } else { 2226 } else {
2232 mostVisitedList.setAttribute(GRID_COLUMNS, '3'); 2227 mostVisitedList.setAttribute(GRID_COLUMNS, '3');
2233 listHeight = screenHeight; 2228 listHeight = screenHeight;
2234 2229
2235 // If the screen height is less than targetHeight, scale the size of the 2230 // If the screen height is less than targetHeight, scale the size of the
2236 // thumbnails such that the margin between the thumbnails remains 2231 // thumbnails such that the margin between the thumbnails remains
2237 // constant. 2232 // constant.
2238 var targetHeight = 220; 2233 var targetHeight = 220;
2239 if (screenHeight < targetHeight) { 2234 if (screenHeight < targetHeight) {
2240 var targetRemainder = targetHeight - 2 * (thumbHeight + labelHeight); 2235 var targetRemainder = targetHeight - 2 * (thumbHeight + labelHeight);
2241 var scale = (screenHeight - 2 * labelHeight - 2236 var scale = (screenHeight - 2 * labelHeight -
2242 targetRemainder) / (2 * thumbHeight); 2237 targetRemainder) / (2 * thumbHeight);
2243 // update values based on scale 2238 // update values based on scale
2244 thumbWidth *= scale; 2239 thumbWidth = Math.round(thumbWidth * scale);
2245 thumbHeight *= scale; 2240 thumbHeight = Math.round(thumbHeight * scale);
2246 labelWidth = thumbWidth + 20; 2241 labelWidth = thumbWidth + 20;
2247 itemHeight = thumbHeight + labelHeight; 2242 itemHeight = thumbHeight + labelHeight;
2248 } 2243 }
2249 2244
2250 // scale the vertical margin such that the items fit perfectly on the 2245 // scale the vertical margin such that the items fit perfectly on the
2251 // screen 2246 // screen
2252 var remainder = screenHeight - (2 * itemHeight); 2247 var remainder = screenHeight - (2 * itemHeight);
2253 var margin = (remainder / 2); 2248 var margin = (remainder / 2);
2254 margin = margin > 24 ? 24 : margin; 2249 margin = margin > 24 ? 24 : margin;
2255 itemMarginTop = Math.round(margin / 2); 2250 itemMarginTop = Math.round(margin / 2);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 // NTP Entry point. 2682 // NTP Entry point.
2688 ///////////////////////////////////////////////////////////////////////////// 2683 /////////////////////////////////////////////////////////////////////////////
2689 2684
2690 /* 2685 /*
2691 * Handles initializing the UI when the page has finished loading. 2686 * Handles initializing the UI when the page has finished loading.
2692 */ 2687 */
2693 window.addEventListener('DOMContentLoaded', function(evt) { 2688 window.addEventListener('DOMContentLoaded', function(evt) {
2694 ntp.init(); 2689 ntp.init();
2695 $('content-area').style.display = 'block'; 2690 $('content-area').style.display = 'block';
2696 }); 2691 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698