Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_selection.js

Issue 14799005: Fix legacy UI in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 /** 83 /**
84 * Computes the total size of selected files. 84 * Computes the total size of selected files.
85 * 85 *
86 * @param {function} callback Completion callback. Not called when cancelled, 86 * @param {function} callback Completion callback. Not called when cancelled,
87 * or a new call has been invoked in the meantime. 87 * or a new call has been invoked in the meantime.
88 */ 88 */
89 FileSelection.prototype.computeBytes = function(callback) { 89 FileSelection.prototype.computeBytes = function(callback) {
90 if (this.entries.length == 0) { 90 if (this.entries.length == 0) {
91 this.bytesKnown = true; 91 this.bytesKnown = true;
92 this.showBytes = false;
92 this.bytes = 0; 93 this.bytes = 0;
93 return; 94 return;
94 } 95 }
95 96
96 var computeBytesSequence = ++this.computeBytesSequence_; 97 var computeBytesSequence = ++this.computeBytesSequence_;
97 var pendingMetadataCount = 0; 98 var pendingMetadataCount = 0;
98 99
99 var maybeDone = function() { 100 var maybeDone = function() {
100 if (pendingMetadataCount == 0) { 101 if (pendingMetadataCount == 0) {
101 this.bytesKnown = true; 102 this.bytesKnown = true;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 209 }
209 } 210 }
210 211
211 this.updateOkButton(); 212 this.updateOkButton();
212 213
213 if (this.selectionUpdateTimer_) { 214 if (this.selectionUpdateTimer_) {
214 clearTimeout(this.selectionUpdateTimer_); 215 clearTimeout(this.selectionUpdateTimer_);
215 this.selectionUpdateTimer_ = null; 216 this.selectionUpdateTimer_ = null;
216 } 217 }
217 218
218 if (!indexes.length) { 219 if (!util.platform.newUI() && !indexes.length) {
219 this.updatePreviewPanelVisibility_(); 220 this.updatePreviewPanelVisibility_();
220 this.updatePreviewPanelText_(); 221 this.updatePreviewPanelText_();
221 this.fileManager_.updateContextMenuActionItems(null, false); 222 this.fileManager_.updateContextMenuActionItems(null, false);
222 return; 223 return;
223 } 224 }
224 225
225 this.hideCalculating_(); 226 this.hideCalculating_();
226 227
227 // The rest of the selection properties are computed via (sometimes lengthy) 228 // The rest of the selection properties are computed via (sometimes lengthy)
228 // asynchronous calls. We initiate these calls after a timeout. If the 229 // asynchronous calls. We initiate these calls after a timeout. If the
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 310
310 /** 311 /**
311 * Animates preview panel show/hide transitions. 312 * Animates preview panel show/hide transitions.
312 * 313 *
313 * @private 314 * @private
314 */ 315 */
315 FileSelectionHandler.prototype.updatePreviewPanelVisibility_ = function() { 316 FileSelectionHandler.prototype.updatePreviewPanelVisibility_ = function() {
316 var panel = this.previewPanel_; 317 var panel = this.previewPanel_;
317 var state = panel.getAttribute('visibility'); 318 var state = panel.getAttribute('visibility');
318 var mustBeVisible = (this.selection.totalCount > 0); 319 var mustBeVisible = (this.selection.totalCount > 0);
320 if (util.platform.newUI()) {
321 mustBeVisible = (this.selection.totalCount > 0 ||
322 !PathUtil.isRootPath(this.fileManager_.getCurrentDirectory()));
323 }
319 var self = this; 324 var self = this;
320 var fm = this.fileManager_; 325 var fm = this.fileManager_;
321 326
322 var stopHidingAndShow = function() { 327 var stopHidingAndShow = function() {
323 clearTimeout(self.hidingTimeout_); 328 clearTimeout(self.hidingTimeout_);
324 self.hidingTimeout_ = 0; 329 self.hidingTimeout_ = 0;
325 setVisibility('visible'); 330 setVisibility('visible');
326 }; 331 };
327 332
328 var startHiding = function() { 333 var startHiding = function() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return this.previewPanel_.getAttribute('visibility') != 'hidden'; 374 return this.previewPanel_.getAttribute('visibility') != 'hidden';
370 }; 375 };
371 376
372 /** 377 /**
373 * Update the selection summary in preview panel. 378 * Update the selection summary in preview panel.
374 * 379 *
375 * @private 380 * @private
376 */ 381 */
377 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() { 382 FileSelectionHandler.prototype.updatePreviewPanelText_ = function() {
378 var selection = this.selection; 383 var selection = this.selection;
379 if (selection.totalCount == 0) { 384 if (!util.platform.newUI()) {
380 // We dont want to change the string during preview panel animating away. 385 if (selection.totalCount == 0) {
381 return; 386 // We dont want to change the string during preview panel animating
387 return;
388 }
389 } else {
390 if (selection.totalCount <= 1) {
391 // Hides the preview text if zero or one file is selected. We shows a
392 // breadcrumb list instead on the preview panel.
393 this.hideCalculating_();
394 this.previewText_.textContent = '';
395 return;
396 }
382 } 397 }
383 398
384 var text = ''; 399 var text = '';
385 if (selection.totalCount == 1) { 400 if (selection.totalCount == 1) {
386 text = selection.entries[0].name; 401 text = selection.entries[0].name;
387 } else if (selection.directoryCount == 0) { 402 } else if (selection.directoryCount == 0) {
388 text = strf('MANY_FILES_SELECTED', selection.fileCount); 403 text = strf('MANY_FILES_SELECTED', selection.fileCount);
389 } else if (selection.fileCount == 0) { 404 } else if (selection.fileCount == 0) {
390 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount); 405 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount);
391 } else { 406 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if (this.fileManager_.dialogType == DialogType.FULL_PAGE && 485 if (this.fileManager_.dialogType == DialogType.FULL_PAGE &&
471 selection.directoryCount == 0 && selection.fileCount > 0) { 486 selection.directoryCount == 0 && selection.fileCount > 0) {
472 selection.createTasks(onTasks); 487 selection.createTasks(onTasks);
473 } else { 488 } else {
474 this.taskItems_.hidden = true; 489 this.taskItems_.hidden = true;
475 } 490 }
476 491
477 // Update the UI. 492 // Update the UI.
478 var wasVisible = this.isPreviewPanelVisibile_(); 493 var wasVisible = this.isPreviewPanelVisibile_();
479 this.updatePreviewPanelVisibility_(); 494 this.updatePreviewPanelVisibility_();
480 this.updateSearchBreadcrumbs_(); 495
496 if (util.platform.newUI() && selection.totalCount == 0) {
497 var path = this.fileManager_.getCurrentDirectory();
498 // Hides the breadcrumbs list on the root path.
499 if (PathUtil.isRootPath(path))
500 this.updatePreviewPanelBreadcrumbs_(null);
501 else
502 this.updatePreviewPanelBreadcrumbs_(path);
503 var entry = this.fileManager_.getCurrentDirectoryEntry();
504 this.showPreviewThumbnails_([entry]);
505 this.updatePreviewPanelText_();
506 return;
507 }
508
481 this.fileManager_.updateContextMenuActionItems(null, false); 509 this.fileManager_.updateContextMenuActionItems(null, false);
482 if (!wasVisible && this.selection.totalCount == 1) { 510 if (!wasVisible && this.selection.totalCount == 1) {
483 var list = this.fileManager_.getCurrentList(); 511 var list = this.fileManager_.getCurrentList();
484 list.scrollIndexIntoView(list.selectionModel.selectedIndex); 512 list.scrollIndexIntoView(list.selectionModel.selectedIndex);
485 } 513 }
486 514
487 // Sync the commands availability. 515 // Sync the commands availability.
488 var commands = this.fileManager_.dialogDom_.querySelectorAll('command'); 516 var commands = this.fileManager_.dialogDom_.querySelectorAll('command');
489 for (var i = 0; i < commands.length; i++) 517 for (var i = 0; i < commands.length; i++)
490 commands[i].canExecuteChange(); 518 commands[i].canExecuteChange();
491 519
492 // Update the summary information. 520 if (!util.platform.newUI()) {
493 var onBytes = function() { 521 this.updateSearchBreadcrumbs_();
494 if (this.selection != selection) return; 522 // Update the summary information.
523 var onBytes = function() {
524 if (this.selection != selection) return;
525 this.updatePreviewPanelText_();
526 }.bind(this);
527 selection.computeBytes(onBytes);
495 this.updatePreviewPanelText_(); 528 this.updatePreviewPanelText_();
496 }.bind(this); 529 } else {
497 selection.computeBytes(onBytes); 530 if (selection.totalCount == 1) {
498 this.updatePreviewPanelText_(); 531 // Shows the breadcrumb list.
532 var firstEntry = selection.entries[0];
533 this.updatePreviewPanelBreadcrumbs_(firstEntry.fullPath);
534 this.updatePreviewPanelText_();
535 } else {
536 this.updatePreviewPanelBreadcrumbs_(null);
537
538 // Update the summary information.
539 var onBytes = function() {
540 if (this.selection != selection) return;
541 this.updatePreviewPanelText_();
542 }.bind(this);
543 selection.computeBytes(onBytes);
544 this.updatePreviewPanelText_();
545 }
546 }
499 547
500 // Inform tests it's OK to click buttons now. 548 // Inform tests it's OK to click buttons now.
501 chrome.test.sendMessage('selection-change-complete'); 549 chrome.test.sendMessage('selection-change-complete');
502 550
503 // Show thumbnails. 551 // Show thumbnails.
504 this.showPreviewThumbnails_(selection); 552 this.showPreviewThumbnails_(selection.entries);
505 }; 553 };
506 554
507 /** 555 /**
508 * Renders preview thumbnails in preview panel. 556 * Renders preview thumbnails in preview panel.
509 * 557 *
510 * @param {FileSelection} selection The selection object. 558 * @param {Array.<FileEntry>} entries The entries of selected object.
511 * @private 559 * @private
512 */ 560 */
513 FileSelectionHandler.prototype.showPreviewThumbnails_ = function(selection) { 561 FileSelectionHandler.prototype.showPreviewThumbnails_ = function(entries) {
562 var selection = this.selection;
514 var thumbnails = []; 563 var thumbnails = [];
515 var thumbnailCount = 0; 564 var thumbnailCount = 0;
516 var thumbnailLoaded = -1; 565 var thumbnailLoaded = -1;
517 var forcedShowTimeout = null; 566 var forcedShowTimeout = null;
518 var thumbnailsHaveZoom = false; 567 var thumbnailsHaveZoom = false;
519 var self = this; 568 var self = this;
520 569
521 var showThumbnails = function() { 570 var showThumbnails = function() {
522 // have-zoom class may be updated twice: then timeout exceeds and then 571 // have-zoom class may be updated twice: then timeout exceeds and then
523 // then all images loaded. 572 // then all images loaded.
(...skipping 23 matching lines...) Expand all
547 if (thumbnailLoaded == thumbnailCount) 596 if (thumbnailLoaded == thumbnailCount)
548 showThumbnails(); 597 showThumbnails();
549 }; 598 };
550 599
551 var thumbnailClickHandler = function() { 600 var thumbnailClickHandler = function() {
552 if (selection.tasks) 601 if (selection.tasks)
553 selection.tasks.executeDefault(); 602 selection.tasks.executeDefault();
554 }; 603 };
555 604
556 var doc = this.fileManager_.document_; 605 var doc = this.fileManager_.document_;
557 for (var i = 0; i < selection.entries.length; i++) { 606 for (var i = 0; i < entries.length; i++) {
558 var entry = selection.entries[i]; 607 var entry = entries[i];
559 608
560 if (thumbnailCount < FileSelectionHandler.MAX_PREVIEW_THUMBNAIL_COUNT) { 609 if (thumbnailCount < FileSelectionHandler.MAX_PREVIEW_THUMBNAIL_COUNT) {
561 var box = doc.createElement('div'); 610 var box = doc.createElement('div');
562 box.className = 'thumbnail'; 611 box.className = 'thumbnail';
563 if (thumbnailCount == 0) { 612 if (thumbnailCount == 0) {
564 var zoomed = doc.createElement('div'); 613 var zoomed = doc.createElement('div');
565 zoomed.hidden = true; 614 zoomed.hidden = true;
566 thumbnails.push(zoomed); 615 thumbnails.push(zoomed);
567 var onFirstThumbnailLoaded = function(img, transform) { 616 var onFirstThumbnailLoaded = function(img, transform) {
568 if (img && self.decorateThumbnailZoom_(zoomed, img, transform)) { 617 if (img && self.decorateThumbnailZoom_(zoomed, img, transform)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 FileGrid.decorateThumbnailBox(thumbnail, 653 FileGrid.decorateThumbnailBox(thumbnail,
605 entry, 654 entry,
606 this.fileManager_.metadataCache_, 655 this.fileManager_.metadataCache_,
607 ThumbnailLoader.FillMode.FILL, 656 ThumbnailLoader.FillMode.FILL,
608 ThumbnailLoader.OptimizationMode.NEVER_DISCARD, 657 ThumbnailLoader.OptimizationMode.NEVER_DISCARD,
609 callback); 658 callback);
610 return thumbnail; 659 return thumbnail;
611 }; 660 };
612 661
613 /** 662 /**
614 * Updates the search breadcrumbs. 663 * Updates the breadcrumbs in the preview panel.
664 *
665 * @param {?string} path Path to be shown in the breadcrumbs list
666 * @private
667 */
668 FileSelectionHandler.prototype.updatePreviewPanelBreadcrumbs_ = function(path) {
669 if (!path)
670 this.searchBreadcrumbs_.hide();
671 else
672 this.searchBreadcrumbs_.show(PathUtil.getRootPath(path), path);
673 };
674
675 /**
676 * Updates the search breadcrumbs. This method should not be used in the new ui.
615 * 677 *
616 * @private 678 * @private
617 */ 679 */
618 FileSelectionHandler.prototype.updateSearchBreadcrumbs_ = function() { 680 FileSelectionHandler.prototype.updateSearchBreadcrumbs_ = function() {
619 var selectedIndexes = 681 var selectedIndexes =
620 this.fileManager_.getCurrentList().selectionModel.selectedIndexes; 682 this.fileManager_.getCurrentList().selectionModel.selectedIndexes;
621 if (selectedIndexes.length !== 1 || 683 if (selectedIndexes.length !== 1 ||
622 !this.fileManager_.directoryModel_.isSearching()) { 684 !this.fileManager_.directoryModel_.isSearching()) {
623 this.searchBreadcrumbs_.hide(); 685 this.searchBreadcrumbs_.hide();
624 return; 686 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 style.left = (boxWidth - imageWidth) / 2 + 'px'; 758 style.left = (boxWidth - imageWidth) / 2 + 'px';
697 style.top = (boxHeight - imageHeight) / 2 + 'px'; 759 style.top = (boxHeight - imageHeight) / 2 + 'px';
698 style.position = 'relative'; 760 style.position = 'relative';
699 761
700 util.applyTransform(largeImage, transform); 762 util.applyTransform(largeImage, transform);
701 763
702 largeImageBox.appendChild(largeImage); 764 largeImageBox.appendChild(largeImage);
703 largeImageBox.style.zIndex = 1000; 765 largeImageBox.style.zIndex = 1000;
704 return true; 766 return true;
705 }; 767 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698