| 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. |
| 11 * @param {Array.<number>} indexes Selected indexes. | 11 * @param {Array.<number>} indexes Selected indexes. |
| 12 * @constructor | 12 * @constructor |
| 13 */ | 13 */ |
| 14 function FileSelection(fileManager, indexes) { | 14 function FileSelection(fileManager, indexes) { |
| 15 this.fileManager_ = fileManager; | 15 this.fileManager_ = fileManager; |
| 16 this.computeBytesSequence_ = 0; | 16 this.computeBytesSequence_ = 0; |
| 17 this.indexes = indexes; | 17 this.indexes = indexes; |
| 18 this.entries = []; | 18 this.entries = []; |
| 19 this.urls = []; | 19 this.urls = []; |
| 20 this.totalCount = 0; | 20 this.totalCount = 0; |
| 21 this.fileCount = 0; | 21 this.fileCount = 0; |
| 22 this.directoryCount = 0; | 22 this.directoryCount = 0; |
| 23 this.bytes = 0; | 23 this.bytes = 0; |
| 24 this.showBytes = false; | 24 this.showBytes = false; |
| 25 this.allDriveFilesPresent = false, | 25 this.allDriveFilesPresent = false, |
| 26 this.iconType = null; | 26 this.iconType = null; |
| 27 this.bytesKnown = false; | 27 this.bytesKnown = false; |
| 28 this.mustBeHidden_ = false; | 28 this.mustBeHidden_ = false; |
| 29 this.mimeTypes = null; |
| 29 | 30 |
| 30 // Synchronously compute what we can. | 31 // Synchronously compute what we can. |
| 31 for (var i = 0; i < this.indexes.length; i++) { | 32 for (var i = 0; i < this.indexes.length; i++) { |
| 32 var entry = fileManager.getFileList().item(this.indexes[i]); | 33 var entry = fileManager.getFileList().item(this.indexes[i]); |
| 33 if (!entry) | 34 if (!entry) |
| 34 continue; | 35 continue; |
| 35 | 36 |
| 36 this.entries.push(entry); | 37 this.entries.push(entry); |
| 37 this.urls.push(entry.toURL()); | 38 this.urls.push(entry.toURL()); |
| 38 | 39 |
| 39 if (this.iconType == null) { | 40 if (this.iconType == null) { |
| 40 this.iconType = FileType.getIcon(entry); | 41 this.iconType = FileType.getIcon(entry); |
| 41 } else if (this.iconType != 'unknown') { | 42 } else if (this.iconType != 'unknown') { |
| 42 var iconType = FileType.getIcon(entry); | 43 var iconType = FileType.getIcon(entry); |
| 43 if (this.iconType != iconType) | 44 if (this.iconType != iconType) |
| 44 this.iconType = 'unknown'; | 45 this.iconType = 'unknown'; |
| 45 } | 46 } |
| 46 | 47 |
| 47 if (entry.isFile) { | 48 if (entry.isFile) { |
| 48 this.fileCount += 1; | 49 this.fileCount += 1; |
| 49 } else { | 50 } else { |
| 50 this.directoryCount += 1; | 51 this.directoryCount += 1; |
| 51 } | 52 } |
| 52 this.totalCount++; | 53 this.totalCount++; |
| 53 } | 54 } |
| 54 | 55 |
| 55 this.tasks = new FileTasks(this.fileManager_); | 56 this.tasks = new FileTasks(this.fileManager_); |
| 57 |
| 58 Object.seal(this); |
| 56 } | 59 } |
| 57 | 60 |
| 58 /** | 61 /** |
| 59 * Computes data required to get file tasks and requests the tasks. | 62 * Computes data required to get file tasks and requests the tasks. |
| 60 * | 63 * |
| 61 * @param {function} callback The callback. | 64 * @param {function} callback The callback. |
| 62 */ | 65 */ |
| 63 FileSelection.prototype.createTasks = function(callback) { | 66 FileSelection.prototype.createTasks = function(callback) { |
| 64 if (!this.fileManager_.isOnDrive()) { | 67 if (!this.fileManager_.isOnDrive()) { |
| 65 this.tasks.init(this.urls); | 68 this.tasks.init(this.urls); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 * | 152 * |
| 150 * @param {FileManager} fileManager File manager instance. | 153 * @param {FileManager} fileManager File manager instance. |
| 151 * @extends {cr.EventTarget} | 154 * @extends {cr.EventTarget} |
| 152 * @constructor | 155 * @constructor |
| 153 */ | 156 */ |
| 154 function FileSelectionHandler(fileManager) { | 157 function FileSelectionHandler(fileManager) { |
| 155 this.fileManager_ = fileManager; | 158 this.fileManager_ = fileManager; |
| 156 // TODO(dgozman): create a shared object with most of UI elements. | 159 // TODO(dgozman): create a shared object with most of UI elements. |
| 157 this.okButton_ = fileManager.okButton_; | 160 this.okButton_ = fileManager.okButton_; |
| 158 this.filenameInput_ = fileManager.filenameInput_; | 161 this.filenameInput_ = fileManager.filenameInput_; |
| 159 | 162 this.previewPanel_ = fileManager.previewPanel_; |
| 160 this.previewPanel_ = fileManager.dialogDom_.querySelector('.preview-panel'); | 163 this.previewPanelElement_ = |
| 161 this.previewThumbnails_ = this.previewPanel_. | 164 fileManager.dialogDom_.querySelector('.preview-panel'); |
| 165 this.previewThumbnails_ = this.previewPanelElement_. |
| 162 querySelector('.preview-thumbnails'); | 166 querySelector('.preview-thumbnails'); |
| 163 this.previewSummary_ = this.previewPanel_.querySelector('.preview-summary'); | 167 this.previewSummary_ = |
| 168 this.previewPanelElement_.querySelector('.preview-summary'); |
| 164 this.previewText_ = this.previewSummary_.querySelector('.preview-text'); | 169 this.previewText_ = this.previewSummary_.querySelector('.preview-text'); |
| 165 this.calculatingSize_ = this.previewSummary_. | 170 this.calculatingSize_ = this.previewSummary_. |
| 166 querySelector('.calculating-size'); | 171 querySelector('.calculating-size'); |
| 167 this.calculatingSize_.textContent = str('CALCULATING_SIZE'); | 172 this.calculatingSize_.textContent = str('CALCULATING_SIZE'); |
| 168 | 173 |
| 169 this.searchBreadcrumbs_ = fileManager.searchBreadcrumbs_; | 174 this.searchBreadcrumbs_ = fileManager.searchBreadcrumbs_; |
| 170 this.taskItems_ = fileManager.taskItems_; | 175 this.taskItems_ = fileManager.taskItems_; |
| 171 | 176 |
| 172 this.animationTimeout_ = null; | 177 this.animationTimeout_ = null; |
| 173 } | 178 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 * @return {boolean} True if all files in the current selection are | 308 * @return {boolean} True if all files in the current selection are |
| 304 * available. | 309 * available. |
| 305 */ | 310 */ |
| 306 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { | 311 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { |
| 307 return !this.fileManager_.isOnDrive() || | 312 return !this.fileManager_.isOnDrive() || |
| 308 !this.fileManager_.isDriveOffline() || | 313 !this.fileManager_.isDriveOffline() || |
| 309 this.selection.allDriveFilesPresent; | 314 this.selection.allDriveFilesPresent; |
| 310 }; | 315 }; |
| 311 | 316 |
| 312 /** | 317 /** |
| 313 * Sets the flag to force the preview panel hidden. | |
| 314 * @param {boolean} hidden True to force hidden. | |
| 315 */ | |
| 316 FileSelectionHandler.prototype.setPreviewPanelMustBeHidden = function(hidden) { | |
| 317 this.previewPanelMustBeHidden_ = hidden; | |
| 318 this.updatePreviewPanelVisibility_(); | |
| 319 }; | |
| 320 | |
| 321 /** | |
| 322 * Animates preview panel show/hide transitions. | |
| 323 * | |
| 324 * @private | |
| 325 */ | |
| 326 FileSelectionHandler.prototype.updatePreviewPanelVisibility_ = function() { | |
| 327 var panel = this.previewPanel_; | |
| 328 var state = panel.getAttribute('visibility'); | |
| 329 var mustBeVisible = | |
| 330 // If one or more files are selected, show the file info. | |
| 331 (this.selection.totalCount > 0 || | |
| 332 // If the directory is not root dir, show the directory info. | |
| 333 !PathUtil.isRootPath(this.fileManager_.getCurrentDirectory()) || | |
| 334 // On Open File dialog, the preview panel is always shown. | |
| 335 this.fileManager_.dialogType == DialogType.SELECT_OPEN_FILE || | |
| 336 this.fileManager_.dialogType == DialogType.SELECT_OPEN_MULTI_FILE); | |
| 337 | |
| 338 var stopHidingAndShow = function() { | |
| 339 clearTimeout(this.hidingTimeout_); | |
| 340 this.hidingTimeout_ = 0; | |
| 341 setVisibility('visible'); | |
| 342 }.bind(this); | |
| 343 | |
| 344 var startHiding = function() { | |
| 345 setVisibility('hiding'); | |
| 346 this.hidingTimeout_ = setTimeout(function() { | |
| 347 this.hidingTimeout_ = 0; | |
| 348 setVisibility('hidden'); | |
| 349 cr.dispatchSimpleEvent(this, 'hide-preview-panel'); | |
| 350 }.bind(this), 250); | |
| 351 }.bind(this); | |
| 352 | |
| 353 var show = function() { | |
| 354 setVisibility('visible'); | |
| 355 this.previewThumbnails_.textContent = ''; | |
| 356 cr.dispatchSimpleEvent(this, 'show-preview-panel'); | |
| 357 }.bind(this); | |
| 358 | |
| 359 var setVisibility = function(visibility) { | |
| 360 panel.setAttribute('visibility', visibility); | |
| 361 }; | |
| 362 | |
| 363 switch (state) { | |
| 364 case 'visible': | |
| 365 if (!mustBeVisible || this.previewPanelMustBeHidden_) | |
| 366 startHiding(); | |
| 367 break; | |
| 368 | |
| 369 case 'hiding': | |
| 370 if (mustBeVisible && !this.previewPanelMustBeHidden_) | |
| 371 stopHidingAndShow(); | |
| 372 break; | |
| 373 | |
| 374 case 'hidden': | |
| 375 if (mustBeVisible && !this.previewPanelMustBeHidden_) | |
| 376 show(); | |
| 377 } | |
| 378 }; | |
| 379 | |
| 380 /** | |
| 381 * @return {boolean} True if space reserverd for the preview panel. | |
| 382 * @private | |
| 383 */ | |
| 384 FileSelectionHandler.prototype.isPreviewPanelVisibile_ = function() { | |
| 385 return this.previewPanel_.getAttribute('visibility') == 'visible'; | |
| 386 }; | |
| 387 | |
| 388 /** | |
| 389 * Update the selection summary in preview panel. | 318 * Update the selection summary in preview panel. |
| 390 * | 319 * |
| 391 * @private | 320 * @private |
| 392 */ | 321 */ |
| 393 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { | 322 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { |
| 394 var selection = this.selection; | 323 var selection = this.selection; |
| 395 if (selection.totalCount <= 1) { | 324 if (selection.totalCount <= 1) { |
| 396 // Hides the preview text if zero or one file is selected. We shows a | 325 // Hides the preview text if zero or one file is selected. We shows a |
| 397 // breadcrumb list instead on the preview panel. | 326 // breadcrumb list instead on the preview panel. |
| 398 this.hideCalculating_(); | 327 this.hideCalculating_(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 if (this.selection != selection) | 415 if (this.selection != selection) |
| 487 return; | 416 return; |
| 488 selection.tasks.display(this.taskItems_); | 417 selection.tasks.display(this.taskItems_); |
| 489 selection.tasks.updateMenuItem(); | 418 selection.tasks.updateMenuItem(); |
| 490 }.bind(this)); | 419 }.bind(this)); |
| 491 } else { | 420 } else { |
| 492 this.taskItems_.hidden = true; | 421 this.taskItems_.hidden = true; |
| 493 } | 422 } |
| 494 | 423 |
| 495 // Update preview panels. | 424 // Update preview panels. |
| 496 var wasVisible = this.isPreviewPanelVisibile_(); | 425 var wasVisible = this.previewPanel_.visible; |
| 497 var thumbnailEntries; | 426 var thumbnailEntries; |
| 498 if (selection.totalCount == 0) { | 427 if (selection.totalCount == 0) { |
| 499 thumbnailEntries = [ | 428 thumbnailEntries = [ |
| 500 this.fileManager_.getCurrentDirectoryEntry() | 429 this.fileManager_.getCurrentDirectoryEntry() |
| 501 ]; | 430 ]; |
| 502 } else { | 431 } else { |
| 503 thumbnailEntries = selection.entries; | 432 thumbnailEntries = selection.entries; |
| 504 if (selection.totalCount != 1) { | 433 if (selection.totalCount != 1) { |
| 505 selection.computeBytes(function() { | 434 selection.computeBytes(function() { |
| 506 if (this.selection != selection) | 435 if (this.selection != selection) |
| 507 return; | 436 return; |
| 508 this.updatePreviewPanelText_(); | 437 this.updatePreviewPanelText_(); |
| 509 }.bind(this)); | 438 }.bind(this)); |
| 510 } | 439 } |
| 511 } | 440 } |
| 512 this.updatePreviewPanelVisibility_(); | 441 this.previewPanel_.entries = selection.entries; |
| 513 this.updatePreviewPanelText_(); | 442 this.updatePreviewPanelText_(); |
| 514 this.showPreviewThumbnails_(thumbnailEntries); | 443 this.showPreviewThumbnails_(thumbnailEntries); |
| 515 | 444 |
| 516 // Update breadcrums. | 445 // Update breadcrums. |
| 517 var updateTarget = null; | 446 var updateTarget = null; |
| 518 var path = this.fileManager_.getCurrentDirectory(); | 447 var path = this.fileManager_.getCurrentDirectory(); |
| 519 if (selection.totalCount == 1) { | 448 if (selection.totalCount == 1) { |
| 520 // Shows the breadcrumb list when a file is selected. | 449 // Shows the breadcrumb list when a file is selected. |
| 521 updateTarget = selection.entries[0].fullPath; | 450 updateTarget = selection.entries[0].fullPath; |
| 522 } else if (selection.totalCount == 0 && | 451 } else if (selection.totalCount == 0 && |
| 523 this.isPreviewPanelVisibile_()) { | 452 this.previewPanel_.visible) { |
| 524 // Shows the breadcrumb list when no file is selected and the preview | 453 // Shows the breadcrumb list when no file is selected and the preview |
| 525 // panel is visible. | 454 // panel is visible. |
| 526 updateTarget = path; | 455 updateTarget = path; |
| 527 } | 456 } |
| 528 this.updatePreviewPanelBreadcrumbs_(updateTarget); | 457 this.updatePreviewPanelBreadcrumbs_(updateTarget); |
| 529 | 458 |
| 530 // Scroll to item | 459 // Scroll to item |
| 531 if (!wasVisible && this.selection.totalCount == 1) { | 460 if (!wasVisible && this.selection.totalCount == 1) { |
| 532 var list = this.fileManager_.getCurrentList(); | 461 var list = this.fileManager_.getCurrentList(); |
| 533 list.scrollIndexIntoView(list.selectionModel.selectedIndex); | 462 list.scrollIndexIntoView(list.selectionModel.selectedIndex); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 style.left = (boxWidth - imageWidth) / 2 + 'px'; | 681 style.left = (boxWidth - imageWidth) / 2 + 'px'; |
| 753 style.top = (boxHeight - imageHeight) / 2 + 'px'; | 682 style.top = (boxHeight - imageHeight) / 2 + 'px'; |
| 754 style.position = 'relative'; | 683 style.position = 'relative'; |
| 755 | 684 |
| 756 util.applyTransform(largeImage, transform); | 685 util.applyTransform(largeImage, transform); |
| 757 | 686 |
| 758 largeImageBox.appendChild(largeImage); | 687 largeImageBox.appendChild(largeImage); |
| 759 largeImageBox.style.zIndex = 1000; | 688 largeImageBox.style.zIndex = 1000; |
| 760 return true; | 689 return true; |
| 761 }; | 690 }; |
| OLD | NEW |