Commit d0083967 authored by John Lee's avatar John Lee Committed by Commit Bot

WebUI Tab Strip: Remove MRU sort order model

Bug: 989131
Change-Id: Ieeabc7f8ca34c7251955f9500b53e1d18bc2266c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935040
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719305}
parent d2fd6104
......@@ -51,10 +51,6 @@
<div id="tabsContainer"></div>
<div id="demoOptions">
<label>
<input type="checkbox" id="mruCheckbox">MRU model
</label>
<label>
<input type="checkbox" id="autoCloseCheckbox">Auto-close
</label>
......
......@@ -130,12 +130,6 @@ class TabListElement extends CustomElement {
if (loadTimeData.getBoolean('showDemoOptions')) {
this.shadowRoot.querySelector('#demoOptions').style.display = 'block';
const mruCheckbox = this.shadowRoot.querySelector('#mruCheckbox');
mruCheckbox.checked = tabStripOptions.mruEnabled;
mruCheckbox.addEventListener('change', () => {
tabStripOptions.mruEnabled = mruCheckbox.checked;
});
const autoCloseCheckbox =
this.shadowRoot.querySelector('#autoCloseCheckbox');
autoCloseCheckbox.checked = tabStripOptions.autoCloseEnabled;
......@@ -170,7 +164,7 @@ class TabListElement extends CustomElement {
this.tabsApi_.getTabs().then(tabs => {
tabs.forEach(tab => this.onTabCreated_(tab));
this.moveOrScrollToActiveTab_();
this.scrollToActiveTab_();
addWebUIListener('tab-created', tab => this.onTabCreated_(tab));
addWebUIListener(
......@@ -255,23 +249,6 @@ class TabListElement extends CustomElement {
}
}
/** @private */
moveOrScrollToActiveTab_() {
const activeTab = this.getActiveTab_();
if (!activeTab) {
return;
}
if (tabStripOptions.mruEnabled &&
!this.tabStripEmbedderProxy_.isVisible() && !activeTab.tab.pinned &&
this.tabsContainerElement_.firstChild !== activeTab) {
this.tabsApi_.moveTab(
activeTab.tab.id, this.pinnedTabsContainerElement_.childElementCount);
} else {
this.scrollToTab_(activeTab);
}
}
/**
* @param {!Event} event
* @private
......@@ -284,7 +261,7 @@ class TabListElement extends CustomElement {
/** @private */
onDocumentVisibilityChange_() {
this.moveOrScrollToActiveTab_();
this.scrollToActiveTab_();
Array.from(this.tabsContainerElement_.children)
.forEach((tabElement) => this.updateThumbnailTrackStatus_(tabElement));
}
......@@ -338,16 +315,6 @@ class TabListElement extends CustomElement {
return;
}
if (tabStripOptions.mruEnabled && !draggedItem.tab.pinned) {
// If MRU is enabled, unpinned tabs should not be draggable.
event.preventDefault();
return;
}
if (tabStripOptions.mruEnabled) {
assert(draggedItem.tab.pinned);
}
this.draggedItem_ = /** @type {!TabElement} */ (draggedItem);
this.draggedItem_.setDragging(true);
event.dataTransfer.effectAllowed = 'move';
......@@ -387,7 +354,7 @@ class TabListElement extends CustomElement {
if (newlyActiveTab) {
newlyActiveTab.tab = /** @type {!TabData} */ (
Object.assign({}, newlyActiveTab.tab, {active: true}));
this.moveOrScrollToActiveTab_();
this.scrollToActiveTab_();
}
}
......@@ -397,22 +364,9 @@ class TabListElement extends CustomElement {
*/
onTabCreated_(tab) {
const tabElement = this.createTabElement_(tab);
if (tabStripOptions.mruEnabled && tab.active && !tab.pinned &&
tab.index !== this.pinnedTabsContainerElement_.childElementCount) {
// Newly created active tabs should first be moved to the very beginning
// of the tab strip to enforce the tab strip's most recently used ordering
this.tabsApi_
.moveTab(tab.id, this.pinnedTabsContainerElement_.childElementCount)
.then(() => {
this.insertTabOrMoveTo_(
tabElement, this.pinnedTabsContainerElement_.childElementCount);
this.addAnimationPromise_(tabElement.slideIn());
});
} else {
this.insertTabOrMoveTo_(tabElement, tab.index);
this.addAnimationPromise_(tabElement.slideIn());
}
}
/**
* @param {number} tabId
......@@ -490,6 +444,16 @@ class TabListElement extends CustomElement {
}
}
/** @private */
scrollToActiveTab_() {
const activeTab = this.getActiveTab_();
if (!activeTab) {
return;
}
this.scrollToTab_(activeTab);
}
/**
* @param {!TabElement} tabElement
* @private
......
......@@ -9,5 +9,4 @@
*/
export const tabStripOptions = {
autoCloseEnabled: true,
mruEnabled: true,
};
......@@ -218,20 +218,6 @@ suite('TabList', () => {
assertEquals(tabElements[0].tab, prependedTab);
});
test('adds a new tab element to the start when it is active', async () => {
const newActiveTab = {
alertStates: [],
active: true,
id: 3,
index: 3,
title: 'New tab',
};
webUIListenerCallback('tab-created', newActiveTab);
const [tabId, newIndex] = await testTabsApiProxy.whenCalled('moveTab');
assertEquals(tabId, newActiveTab.id);
assertEquals(newIndex, 0);
});
test('removes a tab when tab is removed from current window', async () => {
const tabToRemove = tabs[0];
webUIListenerCallback('tab-removed', tabToRemove.id);
......@@ -400,22 +386,6 @@ suite('TabList', () => {
assertEquals(newIndex, dragOverIndex);
});
test(
'when the tab strip closes, the active tab should move to the start',
async () => {
// Mock activating the 2nd tab
webUIListenerCallback('tab-active-changed', tabs[1].id);
testTabsApiProxy.resetResolver('moveTab');
// Mock tab strip going from visible to hidden
testTabStripEmbedderProxy.setVisible(false);
document.dispatchEvent(new Event('visibilitychange'));
const [moveId, newIndex] = await testTabsApiProxy.whenCalled('moveTab');
assertEquals(moveId, tabs[1].id);
assertEquals(newIndex, 0);
});
test('tracks and untracks thumbnails based on viewport', async () => {
// Wait for slideIn animations to complete updating widths and reset
// resolvers to track new calls.
......
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