OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 6 /** |
7 * @fileoverview Utilities for rendering most visited thumbnails and titles. | 7 * @fileoverview Utilities for rendering most visited thumbnails and titles. |
8 */ | 8 */ |
9 | 9 |
10 <include src="instant_iframe_validation.js"> | 10 <include src="instant_iframe_validation.js"> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 link.style.fontSize = styles.fontSize + 'px'; | 111 link.style.fontSize = styles.fontSize + 'px'; |
112 if (styles.fontFamily) | 112 if (styles.fontFamily) |
113 link.style.fontFamily = styles.fontFamily; | 113 link.style.fontFamily = styles.fontFamily; |
114 if (styles.textAlign) | 114 if (styles.textAlign) |
115 link.style.textAlign = styles.textAlign; | 115 link.style.textAlign = styles.textAlign; |
116 if (styles.textFadePos) { | 116 if (styles.textFadePos) { |
117 var dir = /^rtl$/i.test(direction) ? 'to left' : 'to right'; | 117 var dir = /^rtl$/i.test(direction) ? 'to left' : 'to right'; |
118 // The fading length in pixels is passed by the caller. | 118 // The fading length in pixels is passed by the caller. |
119 var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' + | 119 var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' + |
120 styles.textFadePos + 'px, rgba(0,0,0,0))'; | 120 styles.textFadePos + 'px, rgba(0,0,0,0))'; |
121 link.style.lineHeight = 'auto'; | |
122 link.style.textOverflow = 'clip'; | 121 link.style.textOverflow = 'clip'; |
123 link.style.webkitMask = mask; | 122 link.style.webkitMask = mask; |
124 link.style.whiteSpace = 'nowrap'; | 123 } |
| 124 if (styles.numTitleLines && styles.numTitleLines > 1) { |
| 125 link.classList.add('multiline'); |
125 } | 126 } |
126 | 127 |
127 link.href = href; | 128 link.href = href; |
128 link.title = title; | 129 link.title = title; |
129 link.target = '_top'; | 130 link.target = '_top'; |
130 // Include links in the tab order. The tabIndex is necessary for | 131 // Include links in the tab order. The tabIndex is necessary for |
131 // accessibility. | 132 // accessibility. |
132 link.tabIndex = '0'; | 133 link.tabIndex = '0'; |
133 if (text) | 134 if (text) { |
134 link.textContent = text; | 135 // Wrap text with span so ellipsis will appear at the end of multiline. |
| 136 var spanWrap = document.createElement('span'); |
| 137 spanWrap.textContent = text; |
| 138 link.appendChild(spanWrap); |
| 139 } |
135 link.addEventListener('mouseover', function() { | 140 link.addEventListener('mouseover', function() { |
136 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 141 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
137 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); | 142 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); |
138 }); | 143 }); |
139 link.addEventListener('focus', function() { | 144 link.addEventListener('focus', function() { |
140 window.parent.postMessage('linkFocused', DOMAIN_ORIGIN); | 145 window.parent.postMessage('linkFocused', DOMAIN_ORIGIN); |
141 }); | 146 }); |
142 link.addEventListener('blur', function() { | 147 link.addEventListener('blur', function() { |
143 window.parent.postMessage('linkBlurred', DOMAIN_ORIGIN); | 148 window.parent.postMessage('linkBlurred', DOMAIN_ORIGIN); |
144 }); | 149 }); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 return c; | 222 return c; |
218 } | 223 } |
219 | 224 |
220 | 225 |
221 /** | 226 /** |
222 * Decodes most visited styles from URL parameters. | 227 * Decodes most visited styles from URL parameters. |
223 * - c: A hexadecimal number interpreted as a hex color code. | 228 * - c: A hexadecimal number interpreted as a hex color code. |
224 * - f: font-family. | 229 * - f: font-family. |
225 * - fs: font-size as a number in pixels. | 230 * - fs: font-size as a number in pixels. |
226 * - ta: text-align property, as a string. | 231 * - ta: text-align property, as a string. |
227 * - tf: specifying a text fade starting position, in pixels. | 232 * - tf: text fade starting position, in pixels. |
| 233 * - ntl: number of lines in the title. |
228 * @param {Object<string, string>} params URL parameters specifying style. | 234 * @param {Object<string, string>} params URL parameters specifying style. |
229 * @param {boolean} isTitle if the style is for the Most Visited Title. | 235 * @param {boolean} isTitle if the style is for the Most Visited Title. |
230 * @return {Object} Styles suitable for CSS interpolation. | 236 * @return {Object} Styles suitable for CSS interpolation. |
231 */ | 237 */ |
232 function getMostVisitedStyles(params, isTitle) { | 238 function getMostVisitedStyles(params, isTitle) { |
233 var styles = { | 239 var styles = { |
234 color: getTextColor(params, isTitle), // Handles 'c' in params. | 240 color: getTextColor(params, isTitle), // Handles 'c' in params. |
235 fontFamily: '', | 241 fontFamily: '', |
236 fontSize: 11 | 242 fontSize: 11 |
237 }; | 243 }; |
238 if ('f' in params && /^[-0-9a-zA-Z ,]+$/.test(params.f)) | 244 if ('f' in params && /^[-0-9a-zA-Z ,]+$/.test(params.f)) |
239 styles.fontFamily = params.f; | 245 styles.fontFamily = params.f; |
240 if ('fs' in params && isFinite(parseInt(params.fs, 10))) | 246 if ('fs' in params && isFinite(parseInt(params.fs, 10))) |
241 styles.fontSize = parseInt(params.fs, 10); | 247 styles.fontSize = parseInt(params.fs, 10); |
242 if ('ta' in params && /^[-0-9a-zA-Z ,]+$/.test(params.ta)) | 248 if ('ta' in params && /^[-0-9a-zA-Z ,]+$/.test(params.ta)) |
243 styles.textAlign = params.ta; | 249 styles.textAlign = params.ta; |
244 if ('tf' in params) { | 250 if ('tf' in params) { |
245 var tf = parseInt(params.tf, 10); | 251 var tf = parseInt(params.tf, 10); |
246 if (isFinite(tf)) | 252 if (isFinite(tf)) |
247 styles.textFadePos = tf; | 253 styles.textFadePos = tf; |
248 } | 254 } |
| 255 if ('ntl' in params) { |
| 256 var ntl = parseInt(params.ntl, 10); |
| 257 if (isFinite(ntl)) |
| 258 styles.numTitleLines = ntl; |
| 259 } |
249 return styles; | 260 return styles; |
250 } | 261 } |
251 | 262 |
252 | 263 |
253 /** | 264 /** |
254 * @param {string} location A location containing URL parameters. | 265 * @param {string} location A location containing URL parameters. |
255 * @param {function(Object, Object)} fill A function called with styles and | 266 * @param {function(Object, Object)} fill A function called with styles and |
256 * data to fill. | 267 * data to fill. |
257 */ | 268 */ |
258 function fillMostVisited(location, fill) { | 269 function fillMostVisited(location, fill) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 if (navigator.sendBeacon) { | 317 if (navigator.sendBeacon) { |
307 navigator.sendBeacon(url); | 318 navigator.sendBeacon(url); |
308 } else { | 319 } else { |
309 // if sendBeacon is not enabled, we fallback for "a ping". | 320 // if sendBeacon is not enabled, we fallback for "a ping". |
310 var a = document.createElement('a'); | 321 var a = document.createElement('a'); |
311 a.href = '#'; | 322 a.href = '#'; |
312 a.ping = url; | 323 a.ping = url; |
313 a.click(); | 324 a.click(); |
314 } | 325 } |
315 } | 326 } |
OLD | NEW |