Skip to content

Commit 8cecdfb

Browse files
sjlangleyStuart Langley
authored andcommitted
Show the USB icon for external media roots in Computers.
Bug: 884020 Change-Id: I056a5a830c8ca5821d6ca3338372ee27702c0ff9 Reviewed-on: https://chromium-review.googlesource.com/c/1355308 Commit-Queue: Stuart Langley <slangley@chromium.org> Reviewed-by: Luciano Pacheco <lucmult@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#613421}(cherry picked from commit adefd8b) Reviewed-on: https://chromium-review.googlesource.com/c/1362487 Reviewed-by: Stuart Langley <slangley@chromium.org> Cr-Commit-Position: refs/branch-heads/3626@{#64} Cr-Branched-From: d897fb1-refs/heads/master@{#612437}
1 parent efcef9a commit 8cecdfb

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

chrome/common/extensions/api/file_manager_private.idl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ enum EntryPropertyName {
184184
canDelete,
185185
canRename,
186186
canAddChildren,
187-
canShare
187+
canShare,
188+
isMachineRoot,
189+
isExternalMedia,
190+
isArbitrarySyncFolder
188191
};
189192

190193
// Entry property visibility for setEntryTag();

ui/file_manager/base/js/volume_manager_types.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ VolumeManagerCommon.RootType = {
113113

114114
// Root directory of a Computer.
115115
COMPUTER: 'computer',
116+
117+
// Root directory of an external media folder under computers grand root.
118+
EXTERNAL_MEDIA: 'external_media',
116119
};
117120
Object.freeze(VolumeManagerCommon.RootType);
118121

@@ -146,6 +149,7 @@ VolumeManagerCommon.RootTypesForUMA = [
146149
VolumeManagerCommon.RootType.MY_FILES,
147150
VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT,
148151
VolumeManagerCommon.RootType.COMPUTER,
152+
VolumeManagerCommon.RootType.EXTERNAL_MEDIA,
149153
];
150154
console.assert(
151155
Object.keys(VolumeManagerCommon.RootType).length ===
@@ -282,6 +286,7 @@ VolumeManagerCommon.getVolumeTypeFromRootType = function(rootType) {
282286
case VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT:
283287
case VolumeManagerCommon.RootType.COMPUTER:
284288
case VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT:
289+
case VolumeManagerCommon.RootType.EXTERNAL_MEDIA:
285290
return VolumeManagerCommon.VolumeType.DRIVE;
286291
case VolumeManagerCommon.RootType.MTP:
287292
return VolumeManagerCommon.VolumeType.MTP;

ui/file_manager/file_manager/foreground/css/file_types.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ tree .tree-item[selected] > .tree-row >
362362
}
363363

364364
.external-media-root[file-type-icon='folder'],
365+
[volume-type-icon='external_media'],
365366
[volume-type-icon='removable'] {
366367
background-image: -webkit-image-set(
367368
url(../images/volumes/usb.png) 1x,
@@ -370,6 +371,7 @@ tree .tree-item[selected] > .tree-row >
370371

371372
tree .tree-item[selected] > .tree-row >
372373
.external-media-root[file-type-icon='folder'],
374+
.tree-row[selected] [volume-type-icon='external_media'],
373375
.tree-row[selected] [volume-type-icon='removable'] {
374376
background-image: -webkit-image-set(
375377
url(../images/volumes/usb_active.png) 1x,

ui/file_manager/file_manager/foreground/js/constants.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,22 @@ constants.FILE_SELECTION_METADATA_PREFETCH_PROPERTY_NAMES = [
4747
* @const {!Array<string>}
4848
*/
4949
constants.LIST_CONTAINER_METADATA_PREFETCH_PROPERTY_NAMES = [
50-
'availableOffline', 'contentMimeType', 'customIconUrl', 'hosted',
51-
'modificationTime', 'modificationByMeTime', 'shared', 'size', 'canCopy',
52-
'canDelete', 'canRename', 'canAddChildren', 'canShare'
50+
'availableOffline',
51+
'contentMimeType',
52+
'customIconUrl',
53+
'hosted',
54+
'modificationTime',
55+
'modificationByMeTime',
56+
'shared',
57+
'size',
58+
'canCopy',
59+
'canDelete',
60+
'canRename',
61+
'canAddChildren',
62+
'canShare',
63+
'isMachineRoot',
64+
'isExternalMedia',
65+
'isArbitrarySyncFolder',
5366
];
5467

5568
/**
@@ -62,4 +75,4 @@ constants.FILES_QUICK_VIEW_HTML = 'foreground/elements/files_quick_view.html';
6275
* Path for drive_welcome.css file. Allow override for testing.
6376
* @type {string}
6477
*/
65-
constants.DRIVE_WELCOME_CSS = 'foreground/css/drive_welcome.css';
78+
constants.DRIVE_WELCOME_CSS = 'foreground/css/drive_welcome.css';

ui/file_manager/file_manager/foreground/js/ui/directory_tree.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,22 @@ DirectoryItem.prototype = {
237237
locationInfo.rootType === VolumeManagerCommon.RootType.DRIVE;
238238
},
239239

240+
/**
241+
* Returns true if this item is inside any part of Computers.
242+
* @type {!boolean}
243+
*/
244+
get insideComputers() {
245+
if (!this.entry)
246+
return false;
247+
248+
const locationInfo =
249+
this.parentTree_.volumeManager.getLocationInfo(this.entry);
250+
return locationInfo &&
251+
(locationInfo.rootType ===
252+
VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT ||
253+
locationInfo.rootType === VolumeManagerCommon.RootType.COMPUTER);
254+
},
255+
240256
/**
241257
* Returns true if this item is inside any part of Drive, including Team
242258
* Drive.
@@ -269,8 +285,8 @@ DirectoryItem.prototype = {
269285
* support it.
270286
* @type {!boolean}
271287
*/
272-
get supportsSharedFeature() {
273-
return this.insideMyDrive;
288+
get supportDriveSpecificIcons() {
289+
return this.insideMyDrive || this.insideComputers;
274290
},
275291
};
276292

@@ -280,7 +296,11 @@ DirectoryItem.prototype = {
280296
* @param {Event} event Metadata update event.
281297
*/
282298
DirectoryItem.prototype.onMetadataUpdated_ = function(event) {
283-
if (!(event.names.has('shared') && this.supportsSharedFeature))
299+
if (!this.supportDriveSpecificIcons)
300+
return;
301+
302+
const updateableProperties = ['shared', 'isMachineRoot', 'isExternalMedia'];
303+
if (!updateableProperties.some((prop) => event.names.has(prop)))
284304
return;
285305

286306
let index = 0;
@@ -289,7 +309,7 @@ DirectoryItem.prototype.onMetadataUpdated_ = function(event) {
289309
const childElement = this.items[index];
290310

291311
if (event.entriesMap.has(childEntry.toURL()))
292-
childElement.updateSharedStatusIcon();
312+
childElement.updateDriveSpecificIcons();
293313

294314
index++;
295315
}
@@ -328,7 +348,7 @@ DirectoryItem.prototype.updateSubElementsFromList = function(recursive) {
328348
this.add(item);
329349
index++;
330350
} else if (util.isSameEntry(currentEntry, currentElement.entry)) {
331-
currentElement.updateSharedStatusIcon();
351+
currentElement.updateDriveSpecificIcons();
332352
if (recursive && this.expanded) {
333353
if (this.delayExpansion) {
334354
// Only update deeper on expanded children.
@@ -430,7 +450,7 @@ DirectoryItem.prototype.clearHasChildren = function() {
430450
* @private
431451
*/
432452
DirectoryItem.prototype.onExpand_ = function(e) {
433-
if (this.supportsSharedFeature && !this.onMetadataUpdateBound_) {
453+
if (this.supportDriveSpecificIcons && !this.onMetadataUpdateBound_) {
434454
this.onMetadataUpdateBound_ = this.onMetadataUpdated_.bind(this);
435455
this.parentTree_.metadataModel_.addEventListener(
436456
'update', this.onMetadataUpdateBound_);
@@ -581,7 +601,7 @@ DirectoryItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
581601
/**
582602
* Update the icon based on whether the folder is shared on Drive.
583603
*/
584-
DirectoryItem.prototype.updateSharedStatusIcon = function() {};
604+
DirectoryItem.prototype.updateDriveSpecificIcons = function() {};
585605

586606
/**
587607
* Select the item corresponding to the given {@code entry}.
@@ -665,7 +685,7 @@ function SubDirectoryItem(label, dirEntry, parentDirItem, tree) {
665685
if (iconOverride)
666686
icon.setAttribute('volume-type-icon', iconOverride);
667687
icon.setAttribute('file-type-icon', iconOverride || 'folder');
668-
item.updateSharedStatusIcon();
688+
item.updateDriveSpecificIcons();
669689
}
670690

671691
// Sets up context menu of the item.
@@ -699,11 +719,17 @@ SubDirectoryItem.prototype = {
699719
* Update the icon based on whether the folder is shared on Drive.
700720
* @override
701721
*/
702-
SubDirectoryItem.prototype.updateSharedStatusIcon = function() {
722+
SubDirectoryItem.prototype.updateDriveSpecificIcons = function() {
703723
const icon = this.querySelector('.icon');
704-
const metadata =
705-
this.parentTree_.metadataModel.getCache([this.dirEntry_], ['shared']);
724+
const metadata = this.parentTree_.metadataModel.getCache(
725+
[this.dirEntry_], ['shared', 'isMachineRoot', 'isExternalMedia']);
706726
icon.classList.toggle('shared', !!(metadata[0] && metadata[0].shared));
727+
if (metadata[0] && metadata[0].isMachineRoot)
728+
icon.setAttribute(
729+
'volume-type-icon', VolumeManagerCommon.RootType.COMPUTER);
730+
if (metadata[0] && metadata[0].isExternalMedia)
731+
icon.setAttribute(
732+
'volume-type-icon', VolumeManagerCommon.RootType.EXTERNAL_MEDIA);
707733
};
708734

709735
/**
@@ -1605,7 +1631,7 @@ FakeItem.prototype.updateSubDirectories = function(
16051631
/**
16061632
* FakeItem doesn't really have shared status/icon so we define here as no-op.
16071633
*/
1608-
FakeItem.prototype.updateSharedStatusIcon = function() {};
1634+
FakeItem.prototype.updateDriveSpecificIcons = function() {};
16091635

16101636
////////////////////////////////////////////////////////////////////////////////
16111637
// DirectoryTree

0 commit comments

Comments
 (0)