Commit 8a6458be authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[directory tree] Make ShortcutItem derive from TreeItem

TreeItem handles the item content creation, label, tree parent_ etc so
remove local ShortcutItem code related to that.

Bug: 992819
Change-Id: I137853c9f85db7c78516cbe708cc79186f449412
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868351
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707267}
parent 1486c652
...@@ -854,8 +854,6 @@ class SubDirectoryItem extends DirectoryItem { ...@@ -854,8 +854,6 @@ class SubDirectoryItem extends DirectoryItem {
/** /**
* The DirectoryEntry corresponding to this DirectoryItem. * The DirectoryEntry corresponding to this DirectoryItem.
* @type {DirectoryEntry}
* @override
*/ */
get entry() { get entry() {
return this.dirEntry_; return this.dirEntry_;
...@@ -863,7 +861,6 @@ class SubDirectoryItem extends DirectoryItem { ...@@ -863,7 +861,6 @@ class SubDirectoryItem extends DirectoryItem {
/** /**
* Sets the DirectoryEntry corresponding to this DirectoryItem. * Sets the DirectoryEntry corresponding to this DirectoryItem.
* @param {DirectoryEntry} value The directory entry.
*/ */
set entry(value) { set entry(value) {
this.dirEntry_ = value; this.dirEntry_ = value;
...@@ -1522,26 +1519,23 @@ class DriveVolumeItem extends VolumeItem { ...@@ -1522,26 +1519,23 @@ class DriveVolumeItem extends VolumeItem {
* A TreeItem which represents a shortcut for Drive folder. * A TreeItem which represents a shortcut for Drive folder.
* Shortcut items are displayed as top-level children of DirectoryTree. * Shortcut items are displayed as top-level children of DirectoryTree.
*/ */
class ShortcutItem extends cr.ui.TreeItem { class ShortcutItem extends TreeItem {
/** /**
* @param {!NavigationModelShortcutItem} modelItem NavigationModelItem of this * @param {!NavigationModelShortcutItem} modelItem NavigationModelItem of this
* volume. * volume.
* @param {!DirectoryTree} tree Current tree, which contains this item. * @param {!DirectoryTree} tree Current tree, which contains this item.
*/ */
constructor(modelItem, tree) { constructor(modelItem, tree) {
super(); super(modelItem.entry.name, tree);
// Get the original label id defined by TreeItem, before overwriting
// prototype.
const labelId = this.labelElement.id;
this.__proto__ = ShortcutItem.prototype; this.__proto__ = ShortcutItem.prototype;
this.parentTree_ = tree; if (window.IN_TEST) {
this.setAttribute('dir-type', 'ShortcutItem');
}
this.dirEntry_ = modelItem.entry; this.dirEntry_ = modelItem.entry;
this.modelItem_ = modelItem; this.modelItem_ = modelItem;
this.innerHTML = TREE_ITEM_INNER_HTML;
this.labelElement.id = labelId;
const icon = this.querySelector('.icon'); const icon = this.querySelector('.icon');
icon.classList.add('item-icon'); icon.classList.add('item-icon');
icon.setAttribute('volume-type-icon', 'shortcut'); icon.setAttribute('volume-type-icon', 'shortcut');
...@@ -1549,13 +1543,6 @@ class ShortcutItem extends cr.ui.TreeItem { ...@@ -1549,13 +1543,6 @@ class ShortcutItem extends cr.ui.TreeItem {
if (tree.contextMenuForRootItems) { if (tree.contextMenuForRootItems) {
this.setContextMenu_(tree.contextMenuForRootItems); this.setContextMenu_(tree.contextMenuForRootItems);
} }
this.label = modelItem.entry.name;
if (window.IN_TEST) {
this.setAttribute('dir-type', 'ShortcutItem');
this.setAttribute('entry-label', this.label);
}
} }
/** /**
...@@ -1637,18 +1624,21 @@ class ShortcutItem extends cr.ui.TreeItem { ...@@ -1637,18 +1624,21 @@ class ShortcutItem extends cr.ui.TreeItem {
}); });
} }
/**
* The DirectoryEntry corresponding to this DirectoryItem.
*/
get entry() { get entry() {
return this.dirEntry_; return this.dirEntry_;
} }
/**
* @type {!NavigationModelVolumeItem}
*/
get modelItem() { get modelItem() {
return this.modelItem_; return this.modelItem_;
} }
get labelElement() {
return this.firstElementChild.querySelector('.label');
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AndroidAppItem // AndroidAppItem
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment