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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // The fading length in pixels is passed by the caller. | 116 // The fading length in pixels is passed by the caller. |
117 var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' + | 117 var mask = 'linear-gradient(' + dir + ', rgba(0,0,0,1), rgba(0,0,0,1) ' + |
118 styles.textFadePos + 'px, rgba(0,0,0,0))'; | 118 styles.textFadePos + 'px, rgba(0,0,0,0))'; |
119 link.style.textOverflow = 'clip'; | 119 link.style.textOverflow = 'clip'; |
120 link.style.webkitMask = mask; | 120 link.style.webkitMask = mask; |
121 } | 121 } |
122 | 122 |
123 link.href = href; | 123 link.href = href; |
124 link.title = title; | 124 link.title = title; |
125 link.target = '_top'; | 125 link.target = '_top'; |
126 // Exclude links from the tab order. The tabIndex is added to the thumbnail | 126 // Include links in the tab order. The tabIndex is necessary for |
127 // parent container instead. | 127 // accessibility. |
128 link.tabIndex = '-1'; | 128 link.tabIndex = '0'; |
129 if (text) | 129 if (text) |
130 link.textContent = text; | 130 link.textContent = text; |
131 link.addEventListener('mouseover', function() { | 131 link.addEventListener('mouseover', function() { |
132 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 132 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
133 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); | 133 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); |
134 }); | 134 }); |
| 135 link.addEventListener('focus', function() { |
| 136 window.parent.postMessage('linkFocused', DOMAIN_ORIGIN); |
| 137 }); |
| 138 link.addEventListener('blur', function() { |
| 139 window.parent.postMessage('linkBlurred', DOMAIN_ORIGIN); |
| 140 }); |
135 | 141 |
136 // Webkit's security policy prevents some Most Visited thumbnails from | 142 // Webkit's security policy prevents some Most Visited thumbnails from |
137 // working (those with schemes different from http and https). Therefore, | 143 // working (those with schemes different from http and https). Therefore, |
138 // navigateContentWindow is being used in order to get all schemes working. | 144 // navigateContentWindow is being used in order to get all schemes working. |
139 link.addEventListener('click', function handleNavigation(e) { | 145 var navigateFunction = function handleNavigation(e) { |
140 var isServerSuggestion = 'url' in params; | 146 var isServerSuggestion = 'url' in params; |
141 | 147 |
142 // Ping are only populated for server-side suggestions, never for MV. | 148 // Ping are only populated for server-side suggestions, never for MV. |
143 if (isServerSuggestion && params.ping) { | 149 if (isServerSuggestion && params.ping) { |
144 generatePing(DOMAIN_ORIGIN + params.ping); | 150 generatePing(DOMAIN_ORIGIN + params.ping); |
145 } | 151 } |
146 | 152 |
147 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 153 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
148 if ('pos' in params && isFinite(params.pos)) { | 154 if ('pos' in params && isFinite(params.pos)) { |
149 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), | 155 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), |
150 provider || ''); | 156 provider || ''); |
151 } | 157 } |
152 | 158 |
153 if (!isServerSuggestion) { | 159 if (!isServerSuggestion) { |
154 e.preventDefault(); | 160 e.preventDefault(); |
155 ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e)); | 161 ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e)); |
156 } | 162 } |
157 // Else follow <a> normally, so transition type would be LINK. | 163 // Else follow <a> normally, so transition type would be LINK. |
| 164 }; |
| 165 |
| 166 link.addEventListener('click', navigateFunction); |
| 167 link.addEventListener('keydown', function(event) { |
| 168 if (event.keyCode == 46 /* DELETE */ || |
| 169 event.keyCode == 8 /* BACKSPACE */) { |
| 170 event.preventDefault(); |
| 171 window.parent.postMessage('tileBlacklisted,' + params.pos, DOMAIN_ORIGIN); |
| 172 } else if (event.keyCode == 13 /* ENTER */ || |
| 173 event.keyCode == 32 /* SPACE */) { |
| 174 navigateFunction(event); |
| 175 } |
158 }); | 176 }); |
159 | 177 |
160 return link; | 178 return link; |
161 } | 179 } |
162 | 180 |
163 | 181 |
164 /** | 182 /** |
165 * Returns the color to display string with, depending on whether title is | 183 * Returns the color to display string with, depending on whether title is |
166 * displayed, the current theme, and URL parameters. | 184 * displayed, the current theme, and URL parameters. |
167 * @param {Object.<string, string>} params URL parameters specifying style. | 185 * @param {Object.<string, string>} params URL parameters specifying style. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (navigator.sendBeacon) { | 296 if (navigator.sendBeacon) { |
279 navigator.sendBeacon(url); | 297 navigator.sendBeacon(url); |
280 } else { | 298 } else { |
281 // if sendBeacon is not enabled, we fallback for "a ping". | 299 // if sendBeacon is not enabled, we fallback for "a ping". |
282 var a = document.createElement('a'); | 300 var a = document.createElement('a'); |
283 a.href = '#'; | 301 a.href = '#'; |
284 a.ping = url; | 302 a.ping = url; |
285 a.click(); | 303 a.click(); |
286 } | 304 } |
287 } | 305 } |
OLD | NEW |