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; | |
30 | 29 |
31 // Synchronously compute what we can. | 30 // Synchronously compute what we can. |
32 for (var i = 0; i < this.indexes.length; i++) { | 31 for (var i = 0; i < this.indexes.length; i++) { |
33 var entry = fileManager.getFileList().item(this.indexes[i]); | 32 var entry = fileManager.getFileList().item(this.indexes[i]); |
34 if (!entry) | 33 if (!entry) |
35 continue; | 34 continue; |
36 | 35 |
37 this.entries.push(entry); | 36 this.entries.push(entry); |
38 this.urls.push(entry.toURL()); | 37 this.urls.push(entry.toURL()); |
39 | 38 |
40 if (this.iconType == null) { | 39 if (this.iconType == null) { |
41 this.iconType = FileType.getIcon(entry); | 40 this.iconType = FileType.getIcon(entry); |
42 } else if (this.iconType != 'unknown') { | 41 } else if (this.iconType != 'unknown') { |
43 var iconType = FileType.getIcon(entry); | 42 var iconType = FileType.getIcon(entry); |
44 if (this.iconType != iconType) | 43 if (this.iconType != iconType) |
45 this.iconType = 'unknown'; | 44 this.iconType = 'unknown'; |
46 } | 45 } |
47 | 46 |
48 if (entry.isFile) { | 47 if (entry.isFile) { |
49 this.fileCount += 1; | 48 this.fileCount += 1; |
50 } else { | 49 } else { |
51 this.directoryCount += 1; | 50 this.directoryCount += 1; |
52 } | 51 } |
53 this.totalCount++; | 52 this.totalCount++; |
54 } | 53 } |
55 | 54 |
56 this.tasks = new FileTasks(this.fileManager_); | 55 this.tasks = new FileTasks(this.fileManager_); |
57 | |
58 Object.seal(this); | |
59 } | 56 } |
60 | 57 |
61 /** | 58 /** |
62 * Computes data required to get file tasks and requests the tasks. | 59 * Computes data required to get file tasks and requests the tasks. |
63 * | 60 * |
64 * @param {function} callback The callback. | 61 * @param {function} callback The callback. |
65 */ | 62 */ |
66 FileSelection.prototype.createTasks = function(callback) { | 63 FileSelection.prototype.createTasks = function(callback) { |
67 if (!this.fileManager_.isOnDrive()) { | 64 if (!this.fileManager_.isOnDrive()) { |
68 this.tasks.init(this.urls); | 65 this.tasks.init(this.urls); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 * | 149 * |
153 * @param {FileManager} fileManager File manager instance. | 150 * @param {FileManager} fileManager File manager instance. |
154 * @extends {cr.EventTarget} | 151 * @extends {cr.EventTarget} |
155 * @constructor | 152 * @constructor |
156 */ | 153 */ |
157 function FileSelectionHandler(fileManager) { | 154 function FileSelectionHandler(fileManager) { |
158 this.fileManager_ = fileManager; | 155 this.fileManager_ = fileManager; |
159 // TODO(dgozman): create a shared object with most of UI elements. | 156 // TODO(dgozman): create a shared object with most of UI elements. |
160 this.okButton_ = fileManager.okButton_; | 157 this.okButton_ = fileManager.okButton_; |
161 this.filenameInput_ = fileManager.filenameInput_; | 158 this.filenameInput_ = fileManager.filenameInput_; |
162 this.previewPanel_ = fileManager.previewPanel_; | 159 |
163 this.previewPanelElement_ = | 160 this.previewPanel_ = fileManager.dialogDom_.querySelector('.preview-panel'); |
164 fileManager.dialogDom_.querySelector('.preview-panel'); | 161 this.previewThumbnails_ = this.previewPanel_. |
165 this.previewThumbnails_ = this.previewPanelElement_. | |
166 querySelector('.preview-thumbnails'); | 162 querySelector('.preview-thumbnails'); |
167 this.previewSummary_ = | 163 this.previewSummary_ = this.previewPanel_.querySelector('.preview-summary'); |
168 this.previewPanelElement_.querySelector('.preview-summary'); | |
169 this.previewText_ = this.previewSummary_.querySelector('.preview-text'); | 164 this.previewText_ = this.previewSummary_.querySelector('.preview-text'); |
170 this.calculatingSize_ = this.previewSummary_. | 165 this.calculatingSize_ = this.previewSummary_. |
171 querySelector('.calculating-size'); | 166 querySelector('.calculating-size'); |
172 this.calculatingSize_.textContent = str('CALCULATING_SIZE'); | 167 this.calculatingSize_.textContent = str('CALCULATING_SIZE'); |
173 | 168 |
174 this.searchBreadcrumbs_ = fileManager.searchBreadcrumbs_; | 169 this.searchBreadcrumbs_ = fileManager.searchBreadcrumbs_; |
175 this.taskItems_ = fileManager.taskItems_; | 170 this.taskItems_ = fileManager.taskItems_; |
176 | 171 |
177 this.animationTimeout_ = null; | 172 this.animationTimeout_ = null; |
178 } | 173 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 * @return {boolean} True if all files in the current selection are | 303 * @return {boolean} True if all files in the current selection are |
309 * available. | 304 * available. |
310 */ | 305 */ |
311 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { | 306 FileSelectionHandler.prototype.isFileSelectionAvailable = function() { |
312 return !this.fileManager_.isOnDrive() || | 307 return !this.fileManager_.isOnDrive() || |
313 !this.fileManager_.isDriveOffline() || | 308 !this.fileManager_.isDriveOffline() || |
314 this.selection.allDriveFilesPresent; | 309 this.selection.allDriveFilesPresent; |
315 }; | 310 }; |
316 | 311 |
317 /** | 312 /** |
| 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 /** |
318 * Update the selection summary in preview panel. | 389 * Update the selection summary in preview panel. |
319 * | 390 * |
320 * @private | 391 * @private |
321 */ | 392 */ |
322 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { | 393 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { |
323 var selection = this.selection; | 394 var selection = this.selection; |
324 if (selection.totalCount <= 1) { | 395 if (selection.totalCount <= 1) { |
325 // Hides the preview text if zero or one file is selected. We shows a | 396 // Hides the preview text if zero or one file is selected. We shows a |
326 // breadcrumb list instead on the preview panel. | 397 // breadcrumb list instead on the preview panel. |
327 this.hideCalculating_(); | 398 this.hideCalculating_(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 if (this.selection != selection) | 486 if (this.selection != selection) |
416 return; | 487 return; |
417 selection.tasks.display(this.taskItems_); | 488 selection.tasks.display(this.taskItems_); |
418 selection.tasks.updateMenuItem(); | 489 selection.tasks.updateMenuItem(); |
419 }.bind(this)); | 490 }.bind(this)); |
420 } else { | 491 } else { |
421 this.taskItems_.hidden = true; | 492 this.taskItems_.hidden = true; |
422 } | 493 } |
423 | 494 |
424 // Update preview panels. | 495 // Update preview panels. |
425 var wasVisible = this.previewPanel_.visible; | 496 var wasVisible = this.isPreviewPanelVisibile_(); |
426 var thumbnailEntries; | 497 var thumbnailEntries; |
427 if (selection.totalCount == 0) { | 498 if (selection.totalCount == 0) { |
428 thumbnailEntries = [ | 499 thumbnailEntries = [ |
429 this.fileManager_.getCurrentDirectoryEntry() | 500 this.fileManager_.getCurrentDirectoryEntry() |
430 ]; | 501 ]; |
431 } else { | 502 } else { |
432 thumbnailEntries = selection.entries; | 503 thumbnailEntries = selection.entries; |
433 if (selection.totalCount != 1) { | 504 if (selection.totalCount != 1) { |
434 selection.computeBytes(function() { | 505 selection.computeBytes(function() { |
435 if (this.selection != selection) | 506 if (this.selection != selection) |
436 return; | 507 return; |
437 this.updatePreviewPanelText_(); | 508 this.updatePreviewPanelText_(); |
438 }.bind(this)); | 509 }.bind(this)); |
439 } | 510 } |
440 } | 511 } |
441 this.previewPanel_.entries = selection.entries; | 512 this.updatePreviewPanelVisibility_(); |
442 this.updatePreviewPanelText_(); | 513 this.updatePreviewPanelText_(); |
443 this.showPreviewThumbnails_(thumbnailEntries); | 514 this.showPreviewThumbnails_(thumbnailEntries); |
444 | 515 |
445 // Update breadcrums. | 516 // Update breadcrums. |
446 var updateTarget = null; | 517 var updateTarget = null; |
447 var path = this.fileManager_.getCurrentDirectory(); | 518 var path = this.fileManager_.getCurrentDirectory(); |
448 if (selection.totalCount == 1) { | 519 if (selection.totalCount == 1) { |
449 // Shows the breadcrumb list when a file is selected. | 520 // Shows the breadcrumb list when a file is selected. |
450 updateTarget = selection.entries[0].fullPath; | 521 updateTarget = selection.entries[0].fullPath; |
451 } else if (selection.totalCount == 0 && | 522 } else if (selection.totalCount == 0 && |
452 this.previewPanel_.visible) { | 523 this.isPreviewPanelVisibile_()) { |
453 // Shows the breadcrumb list when no file is selected and the preview | 524 // Shows the breadcrumb list when no file is selected and the preview |
454 // panel is visible. | 525 // panel is visible. |
455 updateTarget = path; | 526 updateTarget = path; |
456 } | 527 } |
457 this.updatePreviewPanelBreadcrumbs_(updateTarget); | 528 this.updatePreviewPanelBreadcrumbs_(updateTarget); |
458 | 529 |
459 // Scroll to item | 530 // Scroll to item |
460 if (!wasVisible && this.selection.totalCount == 1) { | 531 if (!wasVisible && this.selection.totalCount == 1) { |
461 var list = this.fileManager_.getCurrentList(); | 532 var list = this.fileManager_.getCurrentList(); |
462 list.scrollIndexIntoView(list.selectionModel.selectedIndex); | 533 list.scrollIndexIntoView(list.selectionModel.selectedIndex); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 style.left = (boxWidth - imageWidth) / 2 + 'px'; | 752 style.left = (boxWidth - imageWidth) / 2 + 'px'; |
682 style.top = (boxHeight - imageHeight) / 2 + 'px'; | 753 style.top = (boxHeight - imageHeight) / 2 + 'px'; |
683 style.position = 'relative'; | 754 style.position = 'relative'; |
684 | 755 |
685 util.applyTransform(largeImage, transform); | 756 util.applyTransform(largeImage, transform); |
686 | 757 |
687 largeImageBox.appendChild(largeImage); | 758 largeImageBox.appendChild(largeImage); |
688 largeImageBox.style.zIndex = 1000; | 759 largeImageBox.style.zIndex = 1000; |
689 return true; | 760 return true; |
690 }; | 761 }; |
OLD | NEW |