Commit 1826022c authored by huangs's avatar huangs Committed by Commit bot

[New Tab Page] Reset default parameters for NTP title.html, adding param for multiline.

http://crrev.com/1047223004 added experimental icon NTP support and
changed default "white-space: nowrap" to "white-space: pre-wrap", then
make current Material Design select the old one. This is broke 3rd-party
NTPs that don't have the same setting. This CL changes the defaults back,
and adds a new "ntl" to signal intent of having multiline titles. Also
updated single-iframe NTP to match.

BUG=474164

Review URL: https://codereview.chromium.org/1061163003

Cr-Commit-Position: refs/heads/master@{#324097}
parent a8179af3
...@@ -637,6 +637,8 @@ function getMostVisitedTitleIframeUrl(rid, position) { ...@@ -637,6 +637,8 @@ function getMostVisitedTitleIframeUrl(rid, position) {
params.push('ta=' + encodeURIComponent(NTP_DESIGN.titleTextAlign)); params.push('ta=' + encodeURIComponent(NTP_DESIGN.titleTextAlign));
if (NTP_DESIGN.titleTextFade) if (NTP_DESIGN.titleTextFade)
params.push('tf=' + encodeURIComponent(NTP_DESIGN.titleTextFade)); params.push('tf=' + encodeURIComponent(NTP_DESIGN.titleTextFade));
if (NTP_DESIGN.numTitleLines > 1)
params.push('ntl=' + NTP_DESIGN.numTitleLines);
return url + '?' + params.join('&'); return url + '?' + params.join('&');
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* fontFamily: Font family to use for title and thumbnail iframes. * fontFamily: Font family to use for title and thumbnail iframes.
* fontSize: Font size to use for the iframes, in px. * fontSize: Font size to use for the iframes, in px.
* mainClass: Class applied to #ntp-contents to control CSS. * mainClass: Class applied to #ntp-contents to control CSS.
* numTitleLines: Number of lines to display in titles.
* showFavicon: Whether to show favicon. * showFavicon: Whether to show favicon.
* thumbnailTextColor: The 4-component color that thumbnail iframe may use to * thumbnailTextColor: The 4-component color that thumbnail iframe may use to
* display text message in place of missing thumbnail. * display text message in place of missing thumbnail.
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
* fontFamily: string, * fontFamily: string,
* fontSize: number, * fontSize: number,
* mainClass: string, * mainClass: string,
* numTitleLines: number,
* showFavicon: boolean, * showFavicon: boolean,
* thumbnailTextColor: string, * thumbnailTextColor: string,
* thumbnailFallback: string|null|undefined, * thumbnailFallback: string|null|undefined,
...@@ -57,6 +59,7 @@ var NTP_DESIGN = { ...@@ -57,6 +59,7 @@ var NTP_DESIGN = {
fontFamily: 'arial, sans-serif', fontFamily: 'arial, sans-serif',
fontSize: 12, fontSize: 12,
mainClass: 'thumb-ntp', mainClass: 'thumb-ntp',
numTitleLines: 1,
showFavicon: true, showFavicon: true,
thumbnailTextColor: [50, 50, 50, 255], thumbnailTextColor: [50, 50, 50, 255],
thumbnailFallback: THUMBNAIL_FALLBACK.DOT, thumbnailFallback: THUMBNAIL_FALLBACK.DOT,
...@@ -75,6 +78,7 @@ var NTP_DESIGN = { ...@@ -75,6 +78,7 @@ var NTP_DESIGN = {
function modifyNtpDesignForIcons() { function modifyNtpDesignForIcons() {
NTP_DESIGN.fakeboxWingSize = 132; NTP_DESIGN.fakeboxWingSize = 132;
NTP_DESIGN.mainClass = 'icon-ntp'; NTP_DESIGN.mainClass = 'icon-ntp';
NTP_DESIGN.numTitleLines = 2;
NTP_DESIGN.showFavicon = false; NTP_DESIGN.showFavicon = false;
NTP_DESIGN.thumbnailFallback = null; NTP_DESIGN.thumbnailFallback = null;
NTP_DESIGN.tileWidth = 48 + 2 * 18; NTP_DESIGN.tileWidth = 48 + 2 * 18;
......
...@@ -772,6 +772,8 @@ function init() { ...@@ -772,6 +772,8 @@ function init() {
args.push('rtl=1'); args.push('rtl=1');
if (window.configData.useIcons) if (window.configData.useIcons)
args.push('icons=1'); args.push('icons=1');
if (NTP_DESIGN.numTitleLines > 1)
args.push('ntl=' + NTP_DESIGN.numTitleLines);
args.push('removeTooltip=' + args.push('removeTooltip=' +
encodeURIComponent(configData.translatedStrings.removeThumbnailTooltip)); encodeURIComponent(configData.translatedStrings.removeThumbnailTooltip));
......
...@@ -142,6 +142,11 @@ a:visited { ...@@ -142,6 +142,11 @@ a:visited {
text-overflow: clip; text-overflow: clip;
} }
.mv-title.multiline {
white-space: pre-wrap;
word-wrap: break-word;
}
.thumb-ntp .mv-title { .thumb-ntp .mv-title {
-webkit-mask-image: -webkit-mask-image:
linear-gradient(to right, #000, #000, 100px, transparent); linear-gradient(to right, #000, #000, 100px, transparent);
...@@ -180,7 +185,6 @@ html[dir=rtl] .thumb-ntp .mv-title[style*='direction: rtl'] { ...@@ -180,7 +185,6 @@ html[dir=rtl] .thumb-ntp .mv-title[style*='direction: rtl'] {
right: auto; right: auto;
text-align: center; text-align: center;
top: 76px; top: 76px;
white-space: pre-wrap;
width: 100%; width: 100%;
z-index: 5; z-index: 5;
} }
......
...@@ -47,18 +47,25 @@ var LOG_TYPE = { ...@@ -47,18 +47,25 @@ var LOG_TYPE = {
/** /**
* Whether to use icons instead of thumbnails. * Total number of tiles to show at any time. If the host page doesn't send
* enough tiles, we fill them blank.
* @const {number} * @const {number}
*/ */
var NUMBER_OF_TILES = 8;
/**
* Whether to use icons instead of thumbnails.
* @type {boolean}
*/
var USE_ICONS = false; var USE_ICONS = false;
/** /**
* Total number of tiles to show at any time. If the host page doesn't send * Number of lines to display in titles.
* enough tiles, we fill them blank. * @type {number}
* @const {number}
*/ */
var NUMBER_OF_TILES = 8; var NUM_TITLE_LINES = 1;
/** /**
...@@ -345,6 +352,9 @@ var renderTile = function(data) { ...@@ -345,6 +352,9 @@ var renderTile = function(data) {
var title = tile.querySelector('.mv-title'); var title = tile.querySelector('.mv-title');
title.innerText = data.title; title.innerText = data.title;
title.style.direction = data.direction || 'ltr'; title.style.direction = data.direction || 'ltr';
if (NUM_TITLE_LINES > 1) {
title.classList.add('multiline');
}
var hasIcon = USE_ICONS && data.largeIconUrl; var hasIcon = USE_ICONS && data.largeIconUrl;
var hasThumb = !USE_ICONS && data.thumbnailUrl; var hasThumb = !USE_ICONS && data.thumbnailUrl;
...@@ -427,6 +437,12 @@ var init = function() { ...@@ -427,6 +437,12 @@ var init = function() {
// Apply class for icon NTP, if specified. // Apply class for icon NTP, if specified.
USE_ICONS = queryArgs['icons'] == '1'; USE_ICONS = queryArgs['icons'] == '1';
if ('ntl' in queryArgs) {
var ntl = parseInt(queryArgs['ntl'], 10);
if (isFinite(ntl))
NUM_TITLE_LINES = ntl;
}
// Duplicating NTP_DESIGN.mainClass. // Duplicating NTP_DESIGN.mainClass.
document.querySelector('#most-visited').classList.add( document.querySelector('#most-visited').classList.add(
USE_ICONS ? 'icon-ntp' : 'thumb-ntp'); USE_ICONS ? 'icon-ntp' : 'thumb-ntp');
......
...@@ -15,8 +15,14 @@ a { ...@@ -15,8 +15,14 @@ a {
line-height: 117%; line-height: 117%;
overflow: hidden; overflow: hidden;
text-align: center; /* Can be overridden in JS. */ text-align: center; /* Can be overridden in JS. */
text-overflow: clip; /* Can be overridden in JS. */ text-overflow: ellipsis; /* Can be overridden in JS. */
white-space: pre-wrap; /* Can be overridden in JS. */ white-space: nowrap; /* Can be overridden in JS. */
}
a.multiline {
text-overflow: clip;
white-space: pre-wrap;
word-wrap: break-word;
} }
a:focus { a:focus {
......
...@@ -118,10 +118,11 @@ function createMostVisitedLink(params, href, title, text, direction, provider) { ...@@ -118,10 +118,11 @@ function createMostVisitedLink(params, href, title, text, direction, provider) {
// The fading length in pixels is passed by the caller. // The fading length in pixels is passed by the caller.
var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' + var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' +
styles.textFadePos + 'px, rgba(0,0,0,0))'; styles.textFadePos + 'px, rgba(0,0,0,0))';
link.style.lineHeight = 'auto';
link.style.textOverflow = 'clip'; link.style.textOverflow = 'clip';
link.style.webkitMask = mask; link.style.webkitMask = mask;
link.style.whiteSpace = 'nowrap'; }
if (styles.numTitleLines && styles.numTitleLines > 1) {
link.classList.add('multiline');
} }
link.href = href; link.href = href;
...@@ -130,8 +131,12 @@ function createMostVisitedLink(params, href, title, text, direction, provider) { ...@@ -130,8 +131,12 @@ function createMostVisitedLink(params, href, title, text, direction, provider) {
// Include links in the tab order. The tabIndex is necessary for // Include links in the tab order. The tabIndex is necessary for
// accessibility. // accessibility.
link.tabIndex = '0'; link.tabIndex = '0';
if (text) if (text) {
link.textContent = text; // Wrap text with span so ellipsis will appear at the end of multiline.
var spanWrap = document.createElement('span');
spanWrap.textContent = text;
link.appendChild(spanWrap);
}
link.addEventListener('mouseover', function() { link.addEventListener('mouseover', function() {
var ntpApiHandle = chrome.embeddedSearch.newTabPage; var ntpApiHandle = chrome.embeddedSearch.newTabPage;
ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER);
...@@ -224,7 +229,8 @@ function getTextColor(params, isTitle) { ...@@ -224,7 +229,8 @@ function getTextColor(params, isTitle) {
* - f: font-family. * - f: font-family.
* - fs: font-size as a number in pixels. * - fs: font-size as a number in pixels.
* - ta: text-align property, as a string. * - ta: text-align property, as a string.
* - tf: specifying a text fade starting position, in pixels. * - tf: text fade starting position, in pixels.
* - ntl: number of lines in the title.
* @param {Object<string, string>} params URL parameters specifying style. * @param {Object<string, string>} params URL parameters specifying style.
* @param {boolean} isTitle if the style is for the Most Visited Title. * @param {boolean} isTitle if the style is for the Most Visited Title.
* @return {Object} Styles suitable for CSS interpolation. * @return {Object} Styles suitable for CSS interpolation.
...@@ -246,6 +252,11 @@ function getMostVisitedStyles(params, isTitle) { ...@@ -246,6 +252,11 @@ function getMostVisitedStyles(params, isTitle) {
if (isFinite(tf)) if (isFinite(tf))
styles.textFadePos = tf; styles.textFadePos = tf;
} }
if ('ntl' in params) {
var ntl = parseInt(params.ntl, 10);
if (isFinite(ntl))
styles.numTitleLines = ntl;
}
return styles; return styles;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment