OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * The current selection object. | 8 * The current selection object. |
9 * | 9 * |
10 * @param {FileManager} fileManager FileManager instance. | 10 * @param {FileManager} fileManager FileManager instance. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 this.updateOkButton(); | 224 this.updateOkButton(); |
225 | 225 |
226 if (this.selectionUpdateTimer_) { | 226 if (this.selectionUpdateTimer_) { |
227 clearTimeout(this.selectionUpdateTimer_); | 227 clearTimeout(this.selectionUpdateTimer_); |
228 this.selectionUpdateTimer_ = null; | 228 this.selectionUpdateTimer_ = null; |
229 } | 229 } |
230 | 230 |
231 this.hideCalculating_(); | |
232 | |
233 // The rest of the selection properties are computed via (sometimes lengthy) | 231 // The rest of the selection properties are computed via (sometimes lengthy) |
234 // asynchronous calls. We initiate these calls after a timeout. If the | 232 // asynchronous calls. We initiate these calls after a timeout. If the |
235 // selection is changing quickly we only do this once when it slows down. | 233 // selection is changing quickly we only do this once when it slows down. |
236 | 234 |
237 var updateDelay = 200; | 235 var updateDelay = 200; |
238 var now = Date.now(); | 236 var now = Date.now(); |
239 if (now > (this.lastFileSelectionTime_ || 0) + updateDelay) { | 237 if (now > (this.lastFileSelectionTime_ || 0) + updateDelay) { |
240 // The previous selection change happened a while ago. Update the UI soon. | 238 // The previous selection change happened a while ago. Update the UI soon. |
241 updateDelay = 0; | 239 updateDelay = 0; |
242 } | 240 } |
243 this.lastFileSelectionTime_ = now; | 241 this.lastFileSelectionTime_ = now; |
244 | 242 |
245 this.selectionUpdateTimer_ = setTimeout(function() { | 243 this.selectionUpdateTimer_ = setTimeout(function() { |
246 this.selectionUpdateTimer_ = null; | 244 this.selectionUpdateTimer_ = null; |
247 if (this.selection == selection) | 245 if (this.selection == selection) |
248 this.updateFileSelectionAsync(selection); | 246 this.updateFileSelectionAsync(selection); |
249 }.bind(this), updateDelay); | 247 }.bind(this), updateDelay); |
250 }; | 248 }; |
251 | 249 |
252 /** | 250 /** |
253 * Clears the primary UI selection elements. | |
254 */ | |
255 FileSelectionHandler.prototype.clearUI = function() { | |
256 this.previewThumbnails_.textContent = ''; | |
257 this.previewText_.textContent = ''; | |
258 this.hideCalculating_(); | |
259 this.taskItems_.hidden = true; | |
260 this.okButton_.disabled = true; | |
261 }; | |
262 | |
263 /** | |
264 * Updates the Ok button enabled state. | 251 * Updates the Ok button enabled state. |
265 * | 252 * |
266 * @return {boolean} Whether button is enabled. | 253 * @return {boolean} Whether button is enabled. |
267 */ | 254 */ |
268 FileSelectionHandler.prototype.updateOkButton = function() { | 255 FileSelectionHandler.prototype.updateOkButton = function() { |
269 var selectable; | 256 var selectable; |
270 var dialogType = this.fileManager_.dialogType; | 257 var dialogType = this.fileManager_.dialogType; |
271 | 258 |
272 if (dialogType == DialogType.SELECT_FOLDER || | 259 if (dialogType == DialogType.SELECT_FOLDER || |
273 dialogType == DialogType.SELECT_UPLOAD_FOLDER) { | 260 dialogType == DialogType.SELECT_UPLOAD_FOLDER) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 * @return {boolean} True if all files in the current selection are | 295 * @return {boolean} True if all files in the current selection are |
309 * available. | 296 * available. |
310 */ | 297 */ |
311 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { | 298 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { |
312 return !this.fileManager_.isOnDrive() || | 299 return !this.fileManager_.isOnDrive() || |
313 !this.fileManager_.isDriveOffline() || | 300 !this.fileManager_.isDriveOffline() || |
314 this.selection.allDriveFilesPresent; | 301 this.selection.allDriveFilesPresent; |
315 }; | 302 }; |
316 | 303 |
317 /** | 304 /** |
318 * Update the selection summary in preview panel. | |
319 * | |
320 * @private | |
321 */ | |
322 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { | |
323 var selection = this.selection; | |
324 if (selection.totalCount <= 1) { | |
325 // Hides the preview text if zero or one file is selected. We shows a | |
326 // breadcrumb list instead on the preview panel. | |
327 this.hideCalculating_(); | |
328 this.previewText_.textContent = ''; | |
329 return; | |
330 } | |
331 | |
332 var text = ''; | |
333 if (selection.totalCount == 1) { | |
334 text = selection.entries[0].name; | |
335 } else if (selection.directoryCount == 0) { | |
336 text = strf('MANY_FILES_SELECTED', selection.fileCount); | |
337 } else if (selection.fileCount == 0) { | |
338 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount); | |
339 } else { | |
340 text = strf('MANY_ENTRIES_SELECTED', selection.totalCount); | |
341 } | |
342 | |
343 if (selection.bytesKnown) { | |
344 this.hideCalculating_(); | |
345 if (selection.showBytes) { | |
346 var bytes = util.bytesToString(selection.bytes); | |
347 text += ', ' + bytes; | |
348 } | |
349 } else { | |
350 this.showCalculating_(); | |
351 } | |
352 | |
353 this.previewText_.textContent = text; | |
354 }; | |
355 | |
356 /** | |
357 * Displays the 'calculating size' label. | |
358 * | |
359 * @private | |
360 */ | |
361 FileSelectionHandler.prototype.showCalculating_ = function() { | |
362 if (this.animationTimeout_) { | |
363 clearTimeout(this.animationTimeout_); | |
364 this.animationTimeout_ = null; | |
365 } | |
366 | |
367 var dotCount = 0; | |
368 | |
369 var advance = function() { | |
370 this.animationTimeout_ = setTimeout(advance, 1000); | |
371 | |
372 var s = this.calculatingSize_.textContent; | |
373 s = s.replace(/(\.)+$/, ''); | |
374 for (var i = 0; i < dotCount; i++) { | |
375 s += '.'; | |
376 } | |
377 this.calculatingSize_.textContent = s; | |
378 | |
379 dotCount = (dotCount + 1) % 3; | |
380 }.bind(this); | |
381 | |
382 var start = function() { | |
383 this.calculatingSize_.hidden = false; | |
384 advance(); | |
385 }.bind(this); | |
386 | |
387 this.animationTimeout_ = setTimeout(start, 500); | |
388 }; | |
389 | |
390 /** | |
391 * Hides the 'calculating size' label. | |
392 * | |
393 * @private | |
394 */ | |
395 FileSelectionHandler.prototype.hideCalculating_ = function() { | |
396 if (this.animationTimeout_) { | |
397 clearTimeout(this.animationTimeout_); | |
398 this.animationTimeout_ = null; | |
399 } | |
400 this.calculatingSize_.hidden = true; | |
401 }; | |
402 | |
403 /** | |
404 * Calculates async selection stats and updates secondary UI elements. | 305 * Calculates async selection stats and updates secondary UI elements. |
405 * | 306 * |
406 * @param {FileSelection} selection The selection object. | 307 * @param {FileSelection} selection The selection object. |
407 */ | 308 */ |
408 FileSelectionHandler.prototype.updateFileSelectionAsync = function(selection) { | 309 FileSelectionHandler.prototype.updateFileSelectionAsync = function(selection) { |
409 if (this.selection != selection) return; | 310 if (this.selection != selection) return; |
410 | 311 |
411 // Update the file tasks. | 312 // Update the file tasks. |
412 if (this.fileManager_.dialogType == DialogType.FULL_PAGE && | 313 if (this.fileManager_.dialogType == DialogType.FULL_PAGE && |
413 selection.directoryCount == 0 && selection.fileCount > 0) { | 314 selection.directoryCount == 0 && selection.fileCount > 0) { |
414 selection.createTasks(function() { | 315 selection.createTasks(function() { |
415 if (this.selection != selection) | 316 if (this.selection != selection) |
416 return; | 317 return; |
417 selection.tasks.display(this.taskItems_); | 318 selection.tasks.display(this.taskItems_); |
418 selection.tasks.updateMenuItem(); | 319 selection.tasks.updateMenuItem(); |
419 }.bind(this)); | 320 }.bind(this)); |
420 } else { | 321 } else { |
421 this.taskItems_.hidden = true; | 322 this.taskItems_.hidden = true; |
422 } | 323 } |
423 | 324 |
424 // Update preview panels. | 325 // Update preview panels. |
425 var wasVisible = this.previewPanel_.visible; | 326 var wasVisible = this.previewPanel_.visible; |
426 var thumbnailEntries; | 327 var thumbnailEntries; |
427 if (selection.totalCount == 0) { | 328 if (selection.totalCount == 0) { |
428 thumbnailEntries = [ | 329 thumbnailEntries = [ |
429 this.fileManager_.getCurrentDirectoryEntry() | 330 this.fileManager_.getCurrentDirectoryEntry() |
430 ]; | 331 ]; |
431 } else { | 332 } else { |
432 thumbnailEntries = selection.entries; | 333 thumbnailEntries = selection.entries; |
433 if (selection.totalCount != 1) { | |
434 selection.computeBytes(function() { | |
435 if (this.selection != selection) | |
436 return; | |
437 this.updatePreviewPanelText_(); | |
438 }.bind(this)); | |
439 } | |
440 } | 334 } |
441 this.previewPanel_.entries = selection.entries; | 335 this.previewPanel_.setSelection(selection); |
442 this.updatePreviewPanelText_(); | |
443 this.showPreviewThumbnails_(thumbnailEntries); | 336 this.showPreviewThumbnails_(thumbnailEntries); |
444 | 337 |
445 // Update breadcrums. | 338 // Update breadcrums. |
446 var updateTarget = null; | 339 var updateTarget = null; |
447 var path = this.fileManager_.getCurrentDirectory(); | 340 var path = this.fileManager_.getCurrentDirectory(); |
448 if (selection.totalCount == 1) { | 341 if (selection.totalCount == 1) { |
449 // Shows the breadcrumb list when a file is selected. | 342 // Shows the breadcrumb list when a file is selected. |
450 updateTarget = selection.entries[0].fullPath; | 343 updateTarget = selection.entries[0].fullPath; |
451 } else if (selection.totalCount == 0 && | 344 } else if (selection.totalCount == 0 && |
452 this.previewPanel_.visible) { | 345 this.previewPanel_.visible) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 style.left = (boxWidth - imageWidth) / 2 + 'px'; | 574 style.left = (boxWidth - imageWidth) / 2 + 'px'; |
682 style.top = (boxHeight - imageHeight) / 2 + 'px'; | 575 style.top = (boxHeight - imageHeight) / 2 + 'px'; |
683 style.position = 'relative'; | 576 style.position = 'relative'; |
684 | 577 |
685 util.applyTransform(largeImage, transform); | 578 util.applyTransform(largeImage, transform); |
686 | 579 |
687 largeImageBox.appendChild(largeImage); | 580 largeImageBox.appendChild(largeImage); |
688 largeImageBox.style.zIndex = 1000; | 581 largeImageBox.style.zIndex = 1000; |
689 return true; | 582 return true; |
690 }; | 583 }; |
OLD | NEW |