| OLD | NEW |
| 1 | 1 |
| 2 // Helpers | 2 // Helpers |
| 3 | 3 |
| 4 function $(id) { | 4 function $(id) { |
| 5 return document.getElementById(id); | 5 return document.getElementById(id); |
| 6 } | 6 } |
| 7 | 7 |
| 8 // TODO(arv): Remove these when classList is available in HTML5. | 8 // TODO(arv): Remove these when classList is available in HTML5. |
| 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 | 9 // https://bugs.webkit.org/show_bug.cgi?id=20709 |
| 10 function hasClass(el, name) { | 10 function hasClass(el, name) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // differently. | 77 // differently. |
| 78 var maxItems = 8; | 78 var maxItems = 8; |
| 79 data.length = Math.min(maxItems, data.length); | 79 data.length = Math.min(maxItems, data.length); |
| 80 var len = data.length; | 80 var len = data.length; |
| 81 for (var i = len; i < maxItems; i++) { | 81 for (var i = len; i < maxItems; i++) { |
| 82 data[i] = {filler: true}; | 82 data[i] = {filler: true}; |
| 83 } | 83 } |
| 84 | 84 |
| 85 mostVisitedData = data; | 85 mostVisitedData = data; |
| 86 renderMostVisited(data); | 86 renderMostVisited(data); |
| 87 layoutMostVisited(); | |
| 88 | 87 |
| 89 gotMostVisited = true; | 88 gotMostVisited = true; |
| 90 onDataLoaded(); | 89 onDataLoaded(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 function downloadsList(data) { | 92 function downloadsList(data) { |
| 94 logEvent('received downloads'); | 93 logEvent('received downloads'); |
| 95 data.length = Math.min(data.length, 5); | 94 data.length = Math.min(data.length, 5); |
| 96 processData('#download-items', data); | 95 processData('#download-items', data); |
| 97 } | 96 } |
| 98 | 97 |
| 99 function recentlyClosedTabs(data) { | 98 function recentlyClosedTabs(data) { |
| 100 logEvent('received recently closed tabs'); | 99 logEvent('received recently closed tabs'); |
| 101 data.length = Math.min(data.length, 5); | 100 data.length = Math.min(data.length, 5); |
| 102 processData('#tab-items', data); | 101 processData('#tab-items', data); |
| 103 } | 102 } |
| 104 | 103 |
| 105 function onShownSections(mask) { | 104 function onShownSections(mask) { |
| 106 logEvent('received shown sections'); | 105 logEvent('received shown sections'); |
| 107 if (mask != shownSections) { | 106 if (mask != shownSections) { |
| 107 |
| 108 // Only invalidate most visited if needed. |
| 109 if (mask & Section.THUMB != shownSections & Section.THUMB || |
| 110 mask & Section.LIST != shownSections & Section.LIST) { |
| 111 mostVisited.invalidate(); |
| 112 } |
| 113 |
| 108 shownSections = mask; | 114 shownSections = mask; |
| 109 // No need to relayout these unless changed. | |
| 110 mostVisited.updateDisplayMode(); | 115 mostVisited.updateDisplayMode(); |
| 111 layoutMostVisited(); | |
| 112 layoutLowerSections(); | 116 layoutLowerSections(); |
| 113 updateOptionMenu(); | 117 updateOptionMenu(); |
| 114 } | 118 } |
| 115 | 119 |
| 116 gotShownSections = true; | 120 gotShownSections = true; |
| 117 onDataLoaded(); | 121 onDataLoaded(); |
| 118 } | 122 } |
| 119 | 123 |
| 120 function saveShownSections() { | 124 function saveShownSections() { |
| 121 chrome.send('setShownSections', [String(shownSections)]); | 125 chrome.send('setShownSections', [String(shownSections)]); |
| 122 } | 126 } |
| 123 | 127 |
| 124 function tips(data) { | 128 function tips(data) { |
| 125 logEvent('received tips data'); | 129 logEvent('received tips data'); |
| 126 data.length = Math.min(data.length, 5); | 130 data.length = Math.min(data.length, 5); |
| 127 processData('#tip-items', data); | 131 processData('#tip-items', data); |
| 128 } | 132 } |
| 129 | 133 |
| 130 function layoutMostVisited() { | |
| 131 var d0 = Date.now(); | |
| 132 var mostVisitedElement = $('most-visited'); | |
| 133 var thumbnails = mostVisitedElement.querySelectorAll('.thumbnail-container'); | |
| 134 | |
| 135 if (thumbnails.length < 8) { | |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 var small = useSmallGrid(); | |
| 140 | |
| 141 var cols = 4; | |
| 142 var rows = 2; | |
| 143 var marginWidth = 10; | |
| 144 var marginHeight = 7; | |
| 145 var borderWidth = 4; | |
| 146 var thumbWidth = small ? 150 : 212; | |
| 147 var thumbHeight = small ? 93 : 132; | |
| 148 var w = thumbWidth + 2 * borderWidth + 2 * marginWidth; | |
| 149 var h = thumbHeight + 40 + 2 * marginHeight; | |
| 150 var sumWidth = cols * w - 2 * marginWidth; | |
| 151 var sumHeight = rows * h; | |
| 152 var opacity = 1; | |
| 153 | |
| 154 if (shownSections & Section.LIST) { | |
| 155 w = (sumWidth + 2 * marginWidth) / 2; | |
| 156 h = 45; | |
| 157 rows = 4; | |
| 158 cols = 2; | |
| 159 sumHeight = rows * h; | |
| 160 addClass(mostVisitedElement, 'list'); | |
| 161 } else if (shownSections & Section.THUMB) { | |
| 162 removeClass(mostVisitedElement, 'list'); | |
| 163 } else { | |
| 164 sumHeight = 0; | |
| 165 opacity = 0; | |
| 166 } | |
| 167 | |
| 168 mostVisitedElement.style.height = sumHeight + 'px'; | |
| 169 mostVisitedElement.style.opacity = opacity; | |
| 170 // We set overflow to hidden so that the most visited element does not | |
| 171 // "leak" when we hide and show it. | |
| 172 mostVisitedElement.style.overflow = 'hidden'; | |
| 173 | |
| 174 var rtl = document.documentElement.dir == 'rtl'; | |
| 175 | |
| 176 if (shownSections & Section.THUMB || shownSections & Section.LIST) { | |
| 177 for (var i = 0; i < thumbnails.length; i++) { | |
| 178 var t = thumbnails[i]; | |
| 179 | |
| 180 var row, col; | |
| 181 if (shownSections & Section.THUMB) { | |
| 182 row = Math.floor(i / cols); | |
| 183 col = i % cols; | |
| 184 } else { | |
| 185 col = Math.floor(i / rows); | |
| 186 row = i % rows; | |
| 187 } | |
| 188 | |
| 189 if (shownSections & Section.THUMB) { | |
| 190 t.style.left = (rtl ? | |
| 191 sumWidth - col * w - thumbWidth - 2 * borderWidth : | |
| 192 col * w) + 'px'; | |
| 193 } else { | |
| 194 t.style.left = (rtl ? | |
| 195 sumWidth - col * w - w + 2 * marginWidth : | |
| 196 col * w) + 'px'; | |
| 197 } | |
| 198 t.style.top = row * h + 'px'; | |
| 199 | |
| 200 if (shownSections & Section.LIST) { | |
| 201 t.style.width = w - 2 * marginWidth + 'px'; | |
| 202 } else { | |
| 203 t.style.width = ''; | |
| 204 } | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 afterTransition(function() { | |
| 209 // Only set overflow to visible if the element is shown. | |
| 210 if (opacity) { | |
| 211 mostVisitedElement.style.overflow = ''; | |
| 212 } | |
| 213 }); | |
| 214 | |
| 215 logEvent('layoutMostVisited: ' + (Date.now() - d0)); | |
| 216 } | |
| 217 | |
| 218 // This global variable is used to skip parts of the DOM tree for the global | 134 // This global variable is used to skip parts of the DOM tree for the global |
| 219 // jst processing done by the i18n. | 135 // jst processing done by the i18n. |
| 220 var processing = false; | 136 var processing = false; |
| 221 | 137 |
| 222 function processData(selector, data) { | 138 function processData(selector, data) { |
| 223 var output = document.querySelector(selector); | 139 var output = document.querySelector(selector); |
| 224 | 140 |
| 225 // Wait until ready | 141 // Wait until ready |
| 226 if (typeof JsEvalContext !== 'function' || !output) { | 142 if (typeof JsEvalContext !== 'function' || !output) { |
| 227 logEvent('JsEvalContext is not yet available, ' + selector); | 143 logEvent('JsEvalContext is not yet available, ' + selector); |
| 228 document.addEventListener('DOMContentLoaded', function() { | 144 document.addEventListener('DOMContentLoaded', function() { |
| 229 processData(selector, data); | 145 processData(selector, data); |
| 230 }); | 146 }); |
| 231 } else { | 147 } else { |
| 232 var d0 = Date.now(); | 148 var d0 = Date.now(); |
| 233 var input = new JsEvalContext(data); | 149 var input = new JsEvalContext(data); |
| 234 processing = true; | 150 processing = true; |
| 235 jstProcess(input, output); | 151 jstProcess(input, output); |
| 236 processing = false; | 152 processing = false; |
| 237 logEvent('processData: ' + selector + ', ' + (Date.now() - d0)); | 153 logEvent('processData: ' + selector + ', ' + (Date.now() - d0)); |
| 238 } | 154 } |
| 239 } | 155 } |
| 240 | 156 |
| 241 var thumbnailTemplate; | |
| 242 | |
| 243 function getThumbnailClassName(data) { | 157 function getThumbnailClassName(data) { |
| 244 return 'thumbnail-container' + | 158 return 'thumbnail-container' + |
| 245 (data.pinned ? ' pinned' : '') + | 159 (data.pinned ? ' pinned' : '') + |
| 246 (data.filler ? ' filler' : ''); | 160 (data.filler ? ' filler' : ''); |
| 247 } | 161 } |
| 248 | 162 |
| 249 function renderMostVisited(data) { | 163 function renderMostVisited(data) { |
| 250 var parent = $('most-visited'); | 164 var parent = $('most-visited'); |
| 251 if (!thumbnailTemplate) { | |
| 252 thumbnailTemplate = $('thumbnail-template'); | |
| 253 thumbnailTemplate.parentNode.removeChild(thumbnailTemplate); | |
| 254 } | |
| 255 | |
| 256 var children = parent.children; | 165 var children = parent.children; |
| 257 for (var i = 0; i < data.length; i++) { | 166 for (var i = 0; i < data.length; i++) { |
| 258 var d = data[i]; | 167 var d = data[i]; |
| 259 var reuse = !!children[i]; | 168 var t = children[i]; |
| 260 var t = children[i] || thumbnailTemplate.cloneNode(true); | 169 |
| 261 t.style.display = ''; | 170 // If we have a filler continue |
| 262 t.className = getThumbnailClassName(d); | 171 var oldClassName = t.className; |
| 172 var newClassName = getThumbnailClassName(d); |
| 173 if (oldClassName != newClassName) { |
| 174 t.className = newClassName; |
| 175 } |
| 176 |
| 177 // No need to continue if this is a filler. |
| 178 if (newClassName == 'thumbnail-container filler') { |
| 179 continue; |
| 180 } |
| 181 |
| 263 t.title = d.title; | 182 t.title = d.title; |
| 264 t.href = d.url; | 183 t.href = d.url; |
| 265 t.querySelector('.pin').title = localStrings.getString(d.pinned ? | 184 t.querySelector('.pin').title = localStrings.getString(d.pinned ? |
| 266 'unpinthumbnailtooltip' : 'pinthumbnailtooltip'); | 185 'unpinthumbnailtooltip' : 'pinthumbnailtooltip'); |
| 267 t.querySelector('.remove').title = | 186 t.querySelector('.remove').title = |
| 268 localStrings.getString('removethumbnailtooltip'); | 187 localStrings.getString('removethumbnailtooltip'); |
| 269 | 188 |
| 270 // There was some concern that a malformed malicious URL could cause an XSS | 189 // There was some concern that a malformed malicious URL could cause an XSS |
| 271 // attack but setting style.backgroundImage = 'url(javascript:...)' does | 190 // attack but setting style.backgroundImage = 'url(javascript:...)' does |
| 272 // not execute the JavaScript in WebKit. | 191 // not execute the JavaScript in WebKit. |
| 273 t.querySelector('.thumbnail-wrapper').style.backgroundImage = | 192 t.querySelector('.thumbnail-wrapper').style.backgroundImage = |
| 274 'url(chrome://thumb/' + d.url + ')'; | 193 'url(chrome://thumb/' + d.url + ')'; |
| 275 var titleDiv = t.querySelector('.title > div'); | 194 var titleDiv = t.querySelector('.title > div'); |
| 276 titleDiv.textContent = d.title; | 195 titleDiv.textContent = d.title; |
| 277 titleDiv.style.backgroundImage = 'url(chrome://favicon/' + d.url + ')'; | 196 titleDiv.style.backgroundImage = 'url(chrome://favicon/' + d.url + ')'; |
| 278 titleDiv.dir = d.direction; | 197 titleDiv.dir = d.direction; |
| 279 if (!reuse) { | |
| 280 parent.appendChild(t); | |
| 281 } | |
| 282 } | 198 } |
| 283 } | 199 } |
| 284 | 200 |
| 285 /** | 201 /** |
| 286 * Calls chrome.send with a callback and restores the original afterwards. | 202 * Calls chrome.send with a callback and restores the original afterwards. |
| 287 */ | 203 */ |
| 288 function chromeSend(name, params, callbackName, callback) { | 204 function chromeSend(name, params, callbackName, callback) { |
| 289 var old = global[callbackName]; | 205 var old = global[callbackName]; |
| 290 global[callbackName] = function() { | 206 global[callbackName] = function() { |
| 291 // restore | 207 // restore |
| (...skipping 12 matching lines...) Expand all Loading... |
| 304 function handleWindowResize(e, opt_noUpdate) { | 220 function handleWindowResize(e, opt_noUpdate) { |
| 305 var body = document.body; | 221 var body = document.body; |
| 306 if (!body || body.clientWidth < 10) { | 222 if (!body || body.clientWidth < 10) { |
| 307 // We're probably a background tab, so don't do anything. | 223 // We're probably a background tab, so don't do anything. |
| 308 return; | 224 return; |
| 309 } | 225 } |
| 310 | 226 |
| 311 var hasSmallClass = hasClass(body, 'small'); | 227 var hasSmallClass = hasClass(body, 'small'); |
| 312 if (hasSmallClass && !useSmallGrid()) { | 228 if (hasSmallClass && !useSmallGrid()) { |
| 313 removeClass(body, 'small'); | 229 removeClass(body, 'small'); |
| 230 mostVisited.invalidate(); |
| 314 if (!opt_noUpdate) { | 231 if (!opt_noUpdate) { |
| 315 layoutMostVisited(); | 232 mostVisited.layout(); |
| 316 layoutLowerSections(); | 233 layoutLowerSections(); |
| 317 } | 234 } |
| 318 } else if (!hasSmallClass && useSmallGrid()) { | 235 } else if (!hasSmallClass && useSmallGrid()) { |
| 319 addClass(body, 'small'); | 236 addClass(body, 'small'); |
| 237 mostVisited.invalidate(); |
| 320 if (!opt_noUpdate) { | 238 if (!opt_noUpdate) { |
| 321 layoutMostVisited(); | 239 mostVisited.layout(); |
| 322 layoutLowerSections(); | 240 layoutLowerSections(); |
| 323 } | 241 } |
| 324 } | 242 } |
| 325 } | 243 } |
| 326 | 244 |
| 327 /** | 245 /** |
| 328 * Bitmask for the different UI sections. | 246 * Bitmask for the different UI sections. |
| 329 * This matches the Section enum in ../dom_ui/shown_sections_handler.h | 247 * This matches the Section enum in ../dom_ui/shown_sections_handler.h |
| 330 * @enum {number} | 248 * @enum {number} |
| 331 */ | 249 */ |
| 332 var Section = { | 250 var Section = { |
| 333 THUMB: 1, | 251 THUMB: 1, |
| 334 LIST: 2, | 252 LIST: 2, |
| 335 RECENT: 4, | 253 RECENT: 4, |
| 336 TIPS: 8 | 254 TIPS: 8 |
| 337 }; | 255 }; |
| 338 | 256 |
| 339 var shownSections = Section.THUMB | Section.RECENT | Section.TIPS; | 257 var shownSections = Section.THUMB | Section.RECENT | Section.TIPS; |
| 340 | 258 |
| 341 function showSection(section) { | 259 function showSection(section) { |
| 342 if (!(section & shownSections)) { | 260 if (!(section & shownSections)) { |
| 261 shownSections |= section; |
| 262 |
| 343 // THUMBS and LIST are mutually exclusive. | 263 // THUMBS and LIST are mutually exclusive. |
| 344 if (section == Section.THUMB) { | 264 if (section == Section.THUMB) { |
| 345 hideSection(Section.LIST); | 265 // hide LIST |
| 266 shownSections &= ~Section.LIST; |
| 267 mostVisited.invalidate(); |
| 346 } else if (section == Section.LIST) { | 268 } else if (section == Section.LIST) { |
| 347 hideSection(Section.THUMB); | 269 // hide THUMB |
| 270 shownSections &= ~Section.THUMB; |
| 271 mostVisited.invalidate(); |
| 272 } else { |
| 273 notifyLowerSectionForChange(section, false); |
| 274 layoutLowerSections(); |
| 348 } | 275 } |
| 349 | 276 |
| 350 shownSections |= section; | 277 updateOptionMenu(); |
| 351 notifyLowerSectionForChange(section, false); | |
| 352 | |
| 353 mostVisited.updateDisplayMode(); | 278 mostVisited.updateDisplayMode(); |
| 354 layoutMostVisited(); | 279 mostVisited.layout(); |
| 355 updateOptionMenu(); | |
| 356 layoutLowerSections(); | |
| 357 } | 280 } |
| 358 } | 281 } |
| 359 | 282 |
| 360 function hideSection(section) { | 283 function hideSection(section) { |
| 361 if (section & shownSections) { | 284 if (section & shownSections) { |
| 362 shownSections &= ~section; | 285 shownSections &= ~section; |
| 363 notifyLowerSectionForChange(section, true); | |
| 364 | 286 |
| 287 if (section & Section.THUMB || section & Section.LIST) { |
| 288 mostVisited.invalidate(); |
| 289 } |
| 290 |
| 291 if (section & Section.RECENT|| section & Section.TIPS) { |
| 292 notifyLowerSectionForChange(section, true); |
| 293 layoutLowerSections(); |
| 294 } |
| 295 |
| 296 updateOptionMenu(); |
| 365 mostVisited.updateDisplayMode(); | 297 mostVisited.updateDisplayMode(); |
| 366 layoutMostVisited(); | 298 mostVisited.layout(); |
| 367 updateOptionMenu(); | |
| 368 layoutLowerSections(); | |
| 369 } | 299 } |
| 370 } | 300 } |
| 371 | 301 |
| 372 function notifyLowerSectionForChange(section, large) { | 302 function notifyLowerSectionForChange(section, large) { |
| 373 // Notify recent and tips if they need to display more data. | 303 // Notify recent and tips if they need to display more data. |
| 374 if (section == Section.RECENT || section == Section.TIPS) { | 304 if (section == Section.RECENT || section == Section.TIPS) { |
| 375 // we are hiding one of them so if the other one is visible it is now | 305 // we are hiding one of them so if the other one is visible it is now |
| 376 // {@code large}. | 306 // {@code large}. |
| 377 if (shownSections & Section.RECENT) { | 307 if (shownSections & Section.RECENT) { |
| 378 recentChangedSize(large); | 308 recentChangedSize(large); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 423 |
| 494 removeFromBlackList: function(url) { | 424 removeFromBlackList: function(url) { |
| 495 chrome.send('removeURLsFromMostVisitedBlacklist', [url]); | 425 chrome.send('removeURLsFromMostVisitedBlacklist', [url]); |
| 496 }, | 426 }, |
| 497 | 427 |
| 498 clearAllBlacklisted: function() { | 428 clearAllBlacklisted: function() { |
| 499 chrome.send('clearMostVisitedURLsBlacklist', []); | 429 chrome.send('clearMostVisitedURLsBlacklist', []); |
| 500 }, | 430 }, |
| 501 | 431 |
| 502 updateDisplayMode: function() { | 432 updateDisplayMode: function() { |
| 433 if (!this.dirty_) { |
| 434 return; |
| 435 } |
| 436 |
| 503 var thumbCheckbox = $('thumb-checkbox'); | 437 var thumbCheckbox = $('thumb-checkbox'); |
| 504 var listCheckbox = $('list-checkbox'); | 438 var listCheckbox = $('list-checkbox'); |
| 505 var mostVisitedElement = $('most-visited'); | 439 var mostVisitedElement = $('most-visited'); |
| 506 | 440 |
| 507 if (shownSections & Section.THUMB) { | 441 if (shownSections & Section.THUMB) { |
| 508 thumbCheckbox.checked = true; | 442 thumbCheckbox.checked = true; |
| 509 listCheckbox.checked = false; | 443 listCheckbox.checked = false; |
| 510 removeClass(mostVisitedElement, 'list'); | 444 removeClass(mostVisitedElement, 'list'); |
| 511 } else if (shownSections & Section.LIST) { | 445 } else if (shownSections & Section.LIST) { |
| 512 thumbCheckbox.checked = false; | 446 thumbCheckbox.checked = false; |
| 513 listCheckbox.checked = true; | 447 listCheckbox.checked = true; |
| 514 addClass(mostVisitedElement, 'list'); | 448 addClass(mostVisitedElement, 'list'); |
| 515 } else { | 449 } else { |
| 516 thumbCheckbox.checked = false; | 450 thumbCheckbox.checked = false; |
| 517 listCheckbox.checked = false; | 451 listCheckbox.checked = false; |
| 518 } | 452 } |
| 519 | 453 |
| 520 thumbCheckbox.title = localStrings.getString( | 454 thumbCheckbox.title = localStrings.getString( |
| 521 shownSections & Section.THUMB ? 'hidethumbnails' : 'showthumbnails'); | 455 shownSections & Section.THUMB ? 'hidethumbnails' : 'showthumbnails'); |
| 522 listCheckbox.title = localStrings.getString( | 456 listCheckbox.title = localStrings.getString( |
| 523 shownSections & Section.LIST ? 'hidelist' : 'showlist'); | 457 shownSections & Section.LIST ? 'hidelist' : 'showlist'); |
| 458 }, |
| 459 |
| 460 dirty_: false, |
| 461 |
| 462 invalidate: function() { |
| 463 this.dirty_ = true; |
| 464 }, |
| 465 |
| 466 layout: function() { |
| 467 if (!this.dirty_) { |
| 468 return; |
| 469 } |
| 470 var d0 = Date.now(); |
| 471 var mostVisitedElement = $('most-visited'); |
| 472 var thumbnails = mostVisitedElement.children; |
| 473 |
| 474 var small = useSmallGrid(); |
| 475 |
| 476 var cols = 4; |
| 477 var rows = 2; |
| 478 var marginWidth = 10; |
| 479 var marginHeight = 7; |
| 480 var borderWidth = 4; |
| 481 var thumbWidth = small ? 150 : 212; |
| 482 var thumbHeight = small ? 93 : 132; |
| 483 var w = thumbWidth + 2 * borderWidth + 2 * marginWidth; |
| 484 var h = thumbHeight + 40 + 2 * marginHeight; |
| 485 var sumWidth = cols * w - 2 * marginWidth; |
| 486 var sumHeight = rows * h; |
| 487 var opacity = 1; |
| 488 |
| 489 if (shownSections & Section.LIST) { |
| 490 w = (sumWidth + 2 * marginWidth) / 2; |
| 491 h = 45; |
| 492 rows = 4; |
| 493 cols = 2; |
| 494 sumHeight = rows * h; |
| 495 addClass(mostVisitedElement, 'list'); |
| 496 } else if (shownSections & Section.THUMB) { |
| 497 removeClass(mostVisitedElement, 'list'); |
| 498 } else { |
| 499 sumHeight = 0; |
| 500 opacity = 0; |
| 501 } |
| 502 |
| 503 mostVisitedElement.style.height = sumHeight + 'px'; |
| 504 mostVisitedElement.style.opacity = opacity; |
| 505 // We set overflow to hidden so that the most visited element does not |
| 506 // "leak" when we hide and show it. |
| 507 if (!opacity) { |
| 508 mostVisitedElement.style.overflow = 'hidden'; |
| 509 } |
| 510 |
| 511 var rtl = document.documentElement.dir == 'rtl'; |
| 512 |
| 513 if (shownSections & Section.THUMB || shownSections & Section.LIST) { |
| 514 for (var i = 0; i < thumbnails.length; i++) { |
| 515 var t = thumbnails[i]; |
| 516 |
| 517 var row, col; |
| 518 if (shownSections & Section.THUMB) { |
| 519 row = Math.floor(i / cols); |
| 520 col = i % cols; |
| 521 } else { |
| 522 col = Math.floor(i / rows); |
| 523 row = i % rows; |
| 524 } |
| 525 |
| 526 if (shownSections & Section.THUMB) { |
| 527 t.style.left = (rtl ? |
| 528 sumWidth - col * w - thumbWidth - 2 * borderWidth : |
| 529 col * w) + 'px'; |
| 530 } else { |
| 531 t.style.left = (rtl ? |
| 532 sumWidth - col * w - w + 2 * marginWidth : |
| 533 col * w) + 'px'; |
| 534 } |
| 535 t.style.top = row * h + 'px'; |
| 536 |
| 537 if (shownSections & Section.LIST) { |
| 538 t.style.width = w - 2 * marginWidth + 'px'; |
| 539 } else { |
| 540 t.style.width = ''; |
| 541 } |
| 542 } |
| 543 } |
| 544 |
| 545 afterTransition(function() { |
| 546 // Only set overflow to visible if the element is shown. |
| 547 if (opacity) { |
| 548 mostVisitedElement.style.overflow = ''; |
| 549 } |
| 550 }); |
| 551 |
| 552 this.dirty_ = false; |
| 553 |
| 554 logEvent('mostVisited.layout: ' + (Date.now() - d0)); |
| 524 } | 555 } |
| 525 }; | 556 }; |
| 526 | 557 |
| 527 function recentChangedSize(large) { | 558 function recentChangedSize(large) { |
| 528 // TODO(arv): Implement | 559 // TODO(arv): Implement |
| 529 } | 560 } |
| 530 | 561 |
| 531 function tipsChangedSize(large) { | 562 function tipsChangedSize(large) { |
| 532 // TODO(arv): Implement | 563 // TODO(arv): Implement |
| 533 } | 564 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 return localStrings.getString('closedwindowsingle'); | 616 return localStrings.getString('closedwindowsingle'); |
| 586 return localStrings.formatString('closedwindowmultiple', numTabs); | 617 return localStrings.formatString('closedwindowmultiple', numTabs); |
| 587 } | 618 } |
| 588 | 619 |
| 589 /** | 620 /** |
| 590 * We need both most visited and the shown sections to be considered loaded. | 621 * We need both most visited and the shown sections to be considered loaded. |
| 591 * @return {boolean} | 622 * @return {boolean} |
| 592 */ | 623 */ |
| 593 function onDataLoaded() { | 624 function onDataLoaded() { |
| 594 if (gotMostVisited && gotShownSections) { | 625 if (gotMostVisited && gotShownSections) { |
| 626 mostVisited.layout(); |
| 595 loading = false; | 627 loading = false; |
| 596 // Remove class name in a timeout so that changes done in this JS thread are | 628 // Remove class name in a timeout so that changes done in this JS thread are |
| 597 // not animated. | 629 // not animated. |
| 598 window.setTimeout(function() { | 630 window.setTimeout(function() { |
| 599 removeClass(document.body, 'loading'); | 631 removeClass(document.body, 'loading'); |
| 600 }, 10); | 632 }, 10); |
| 601 } | 633 } |
| 602 } | 634 } |
| 603 | 635 |
| 604 // Theme related | 636 // Theme related |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 executeItem: function(item) { | 879 executeItem: function(item) { |
| 848 var section = Section[item.getAttribute('section')]; | 880 var section = Section[item.getAttribute('section')]; |
| 849 var show = item.getAttribute('show') == 'true'; | 881 var show = item.getAttribute('show') == 'true'; |
| 850 if (show) { | 882 if (show) { |
| 851 showSection(section); | 883 showSection(section); |
| 852 } else { | 884 } else { |
| 853 hideSection(section); | 885 hideSection(section); |
| 854 } | 886 } |
| 855 | 887 |
| 856 this.hideMenu(); | 888 this.hideMenu(); |
| 857 | |
| 858 layoutLowerSections(); | |
| 859 mostVisited.updateDisplayMode(); | |
| 860 layoutMostVisited(); | |
| 861 | |
| 862 saveShownSections(); | 889 saveShownSections(); |
| 863 } | 890 } |
| 864 }; | 891 }; |
| 865 | 892 |
| 866 new OptionMenu($('option-button'), $('option-menu')); | 893 new OptionMenu($('option-button'), $('option-menu')); |
| 867 | 894 |
| 868 $('most-visited').addEventListener('click', function(e) { | 895 $('most-visited').addEventListener('click', function(e) { |
| 869 var target = e.target; | 896 var target = e.target; |
| 870 if (hasClass(target, 'pin')) { | 897 if (hasClass(target, 'pin')) { |
| 871 mostVisited.togglePinned(mostVisited.getItem(target)); | 898 mostVisited.togglePinned(mostVisited.getItem(target)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 menuEl.style.top = rect.top + bodyRect.top + rect.height + 'px'; | 975 menuEl.style.top = rect.top + bodyRect.top + rect.height + 'px'; |
| 949 | 976 |
| 950 } | 977 } |
| 951 | 978 |
| 952 $('thumb-checkbox').addEventListener('change', function(e) { | 979 $('thumb-checkbox').addEventListener('change', function(e) { |
| 953 if (e.target.checked) { | 980 if (e.target.checked) { |
| 954 showSection(Section.THUMB); | 981 showSection(Section.THUMB); |
| 955 } else { | 982 } else { |
| 956 hideSection(Section.THUMB); | 983 hideSection(Section.THUMB); |
| 957 } | 984 } |
| 958 mostVisited.updateDisplayMode(); | |
| 959 layoutMostVisited(); | |
| 960 saveShownSections(); | 985 saveShownSections(); |
| 961 }); | 986 }); |
| 962 | 987 |
| 963 $('list-checkbox').addEventListener('change', function(e) { | 988 $('list-checkbox').addEventListener('change', function(e) { |
| 964 var newValue = shownSections; | |
| 965 if (e.target.checked) { | 989 if (e.target.checked) { |
| 966 showSection(Section.LIST); | 990 showSection(Section.LIST); |
| 967 } else { | 991 } else { |
| 968 hideSection(Section.LIST); | 992 hideSection(Section.LIST); |
| 969 } | 993 } |
| 970 mostVisited.updateDisplayMode(); | |
| 971 layoutMostVisited(); | |
| 972 saveShownSections(); | 994 saveShownSections(); |
| 973 }); | 995 }); |
| 974 | 996 |
| 975 window.addEventListener('load', bind(logEvent, global, 'onload fired')); | 997 window.addEventListener('load', bind(logEvent, global, 'onload fired')); |
| 976 window.addEventListener('load', onDataLoaded); | 998 window.addEventListener('load', onDataLoaded); |
| 977 window.addEventListener('resize', handleWindowResize); | 999 window.addEventListener('resize', handleWindowResize); |
| 978 document.addEventListener('DOMContentLoaded', bind(logEvent, global, | 1000 document.addEventListener('DOMContentLoaded', bind(logEvent, global, |
| 979 'domcontentloaded fired')); | 1001 'domcontentloaded fired')); |
| 980 | 1002 |
| 981 // DnD | 1003 // DnD |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 } | 1042 } |
| 1021 | 1043 |
| 1022 this.currentOverItem = null; | 1044 this.currentOverItem = null; |
| 1023 }, | 1045 }, |
| 1024 | 1046 |
| 1025 handleDrop: function(e) { | 1047 handleDrop: function(e) { |
| 1026 var dropTarget = mostVisited.getItem(e.target); | 1048 var dropTarget = mostVisited.getItem(e.target); |
| 1027 if (this.canDropOnElement(dropTarget)) { | 1049 if (this.canDropOnElement(dropTarget)) { |
| 1028 dropTarget.style.zIndex = 1; | 1050 dropTarget.style.zIndex = 1; |
| 1029 mostVisited.swapPosition(this.dragItem, dropTarget); | 1051 mostVisited.swapPosition(this.dragItem, dropTarget); |
| 1030 layoutMostVisited(); | 1052 mostVisited.invalidate(); |
| 1053 mostVisited.layout(); |
| 1031 e.preventDefault(); | 1054 e.preventDefault(); |
| 1032 if (this.dragEndTimer) { | 1055 if (this.dragEndTimer) { |
| 1033 window.clearTimeout(this.dragEndTimer); | 1056 window.clearTimeout(this.dragEndTimer); |
| 1034 this.dragEndTimer = null; | 1057 this.dragEndTimer = null; |
| 1035 } | 1058 } |
| 1036 afterTransition(function() { | 1059 afterTransition(function() { |
| 1037 dropTarget.style.zIndex = ''; | 1060 dropTarget.style.zIndex = ''; |
| 1038 }); | 1061 }); |
| 1039 } | 1062 } |
| 1040 }, | 1063 }, |
| 1041 | 1064 |
| 1042 handleDragEnd: function(e) { | 1065 handleDragEnd: function(e) { |
| 1043 // WebKit fires dragend before drop. | 1066 // WebKit fires dragend before drop. |
| 1044 var dragItem = this.dragItem; | 1067 var dragItem = this.dragItem; |
| 1045 if (dragItem) { | 1068 if (dragItem) { |
| 1046 dragItem.style.pointerEvents = ''; | 1069 dragItem.style.pointerEvents = ''; |
| 1047 removeClass(dragItem, 'dragging'); | 1070 removeClass(dragItem, 'dragging'); |
| 1048 | 1071 |
| 1049 afterTransition(function() { | 1072 afterTransition(function() { |
| 1050 // Delay resetting zIndex to let the animation finish. | 1073 // Delay resetting zIndex to let the animation finish. |
| 1051 dragItem.style.zIndex = ''; | 1074 dragItem.style.zIndex = ''; |
| 1052 // Same for overflow. | 1075 // Same for overflow. |
| 1053 dragItem.parentNode.style.overflow = ''; | 1076 dragItem.parentNode.style.overflow = ''; |
| 1054 }); | 1077 }); |
| 1055 var self = this; | 1078 var self = this; |
| 1056 this.dragEndTimer = window.setTimeout(function() { | 1079 this.dragEndTimer = window.setTimeout(function() { |
| 1057 // These things needto happen after the drop event. | 1080 // These things needto happen after the drop event. |
| 1058 layoutMostVisited(); | 1081 mostVisited.invalidate(); |
| 1082 mostVisited.layout(); |
| 1059 self.dragItem = null; | 1083 self.dragItem = null; |
| 1060 }, 10); | 1084 }, 10); |
| 1061 | 1085 |
| 1062 } | 1086 } |
| 1063 }, | 1087 }, |
| 1064 | 1088 |
| 1065 handleDrag: function(e) { | 1089 handleDrag: function(e) { |
| 1066 var item = mostVisited.getItem(e.target); | 1090 var item = mostVisited.getItem(e.target); |
| 1067 var rect = document.querySelector('#most-visited').getBoundingClientRect(); | 1091 var rect = document.querySelector('#most-visited').getBoundingClientRect(); |
| 1068 item.style.pointerEvents = 'none'; | 1092 item.style.pointerEvents = 'none'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1094 el.addEventListener('dragover', bind(this.handleDragOver, this)); | 1118 el.addEventListener('dragover', bind(this.handleDragOver, this)); |
| 1095 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); | 1119 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); |
| 1096 el.addEventListener('drop', bind(this.handleDrop, this)); | 1120 el.addEventListener('drop', bind(this.handleDrop, this)); |
| 1097 el.addEventListener('dragend', bind(this.handleDragEnd, this)); | 1121 el.addEventListener('dragend', bind(this.handleDragEnd, this)); |
| 1098 el.addEventListener('drag', bind(this.handleDrag, this)); | 1122 el.addEventListener('drag', bind(this.handleDrag, this)); |
| 1099 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); | 1123 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); |
| 1100 } | 1124 } |
| 1101 }; | 1125 }; |
| 1102 | 1126 |
| 1103 dnd.init(); | 1127 dnd.init(); |
| OLD | NEW |