Commit 544ed115 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

WebUI: cr-toast-manager, allow buttons to be slotted in through cr-toast-manager

Change-Id: I0f745eed2a39b74b5925a97e00891d148f8321bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935930Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719435}
parent 5a513860
......@@ -78,6 +78,12 @@
</div>
<bookmarks-router></bookmarks-router>
<bookmarks-command-manager></bookmarks-command-manager>
<cr-toast-manager duration="10000" on-undo-click="onUndoClick_"
undo-label="$i18n{undo}" undo-description="$i18n{undoDescription}">
<cr-toast-manager duration="100000000">
<dom-if>
<template>
<cr-button on-click="onUndoClick_" aria-label="$i18n{undoDescription}">
$i18n{undo}
</cr-button>
</template>
</dom-if>
</cr-toast-manager>
......@@ -4,6 +4,7 @@
import 'chrome://resources/cr_components/managed_footnote/managed_footnote.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import 'chrome://resources/cr_elements/cr_splitter/cr_splitter.m.js';
import './folder_node.js';
......
......@@ -15,12 +15,13 @@ import './edit_dialog.js';
import './shared_style.js';
import './strings.m.js';
import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isMac} from 'chrome://resources/js/cr.m.js';
import {KeyboardShortcutList} from 'chrome://resources/js/cr/ui/keyboard_shortcut_list.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {flush, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {IronA11yAnnouncer} from 'chrome://resources/polymer/v3_0/iron-a11y-announcer/iron-a11y-announcer.js';
import {afterNextRender, flush, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {deselectItems, selectAll, selectFolder} from './actions.js';
import {highlightUpdatedItems, trackUpdatedItems} from './api_listener.js';
......@@ -139,6 +140,10 @@ export const CommandManager = Polymer({
addDocumentListenerForCommand('cut', Command.CUT);
addDocumentListenerForCommand('copy', Command.COPY);
addDocumentListenerForCommand('paste', Command.PASTE);
afterNextRender(this, function() {
IronA11yAnnouncer.requestAvailability();
});
},
detached: function() {
......@@ -383,7 +388,7 @@ export const CommandManager = Polymer({
}
case Command.UNDO:
chrome.bookmarkManagerPrivate.undo();
getInstance().hide();
getToastManager().hide();
break;
case Command.REDO:
chrome.bookmarkManagerPrivate.redo();
......@@ -421,7 +426,11 @@ export const CommandManager = Polymer({
case Command.SORT:
chrome.bookmarkManagerPrivate.sortChildren(
assert(state.selectedFolder));
getInstance().show(loadTimeData.getString('toastFolderSorted'), true);
getToastManager().querySelector('dom-if').if = true;
getToastManager().show(loadTimeData.getString('toastFolderSorted'));
this.fire('iron-announce', {
text: loadTimeData.getString('undoDescription'),
});
break;
case Command.ADD_BOOKMARK:
/** @type {!BookmarksEditDialogElement} */ (this.$.editDialog.get())
......@@ -822,8 +831,13 @@ export const CommandManager = Polymer({
p.collapsible = !!p.arg;
return p;
});
getInstance().showForStringPieces(pieces, canUndo);
getToastManager().querySelector('dom-if').if = canUndo;
getToastManager().showForStringPieces(pieces);
if (canUndo) {
this.fire('iron-announce', {
text: loadTimeData.getString('undoDescription'),
});
}
},
/**
......
......@@ -16,13 +16,14 @@ import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js';
import 'chrome://resources/polymer/v3_0/paper-progress/paper-progress.js';
import 'chrome://resources/polymer/v3_0/paper-styles/color.js';
import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {FocusRowBehavior} from 'chrome://resources/js/cr/ui/focus_row_behavior.m.js';
import {focusWithoutInk} from 'chrome://resources/js/cr/ui/focus_without_ink.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {HTMLEscape} from 'chrome://resources/js/util.m.js';
import {beforeNextRender, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {IronA11yAnnouncer} from 'chrome://resources/polymer/v3_0/iron-a11y-announcer/iron-a11y-announcer.js';
import {afterNextRender, beforeNextRender, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js';
import {DangerType, States} from './constants.js';
......@@ -136,6 +137,13 @@ Polymer({
/** @private {boolean} */
restoreFocusAfterCancel_: false,
/** @override */
attached: function() {
afterNextRender(this, function() {
IronA11yAnnouncer.requestAvailability();
});
},
/** @override */
ready: function() {
this.mojoHandler_ = BrowserProxy.getInstance().handler;
......@@ -552,13 +560,16 @@ Polymer({
// Make the file name collapsible.
p.collapsible = !!p.arg;
});
getInstance().showForStringPieces(
getToastManager().showForStringPieces(
/**
* @type {!Array<{collapsible: boolean,
* value: string,
* arg: (string|null)}>}
*/
(pieces), true);
(pieces));
this.fire('iron-announce', {
text: loadTimeData.getString('undoDescription'),
});
this.mojoHandler_.remove(this.data.id);
},
......
......@@ -118,6 +118,8 @@
</div>
</div>
</div>
<cr-toast-manager on-undo-click="onUndoClick_" undo-label="$i18n{undo}"
undo-description="$i18n{undoDescription}" duration="10000">
<cr-toast-manager duration="10000">
<cr-button aria-label="$i18n{undoDescription}" on-click="onUndoClick_">
$i18n{undo}
</cr-button>
</cr-toast-manager>
......@@ -6,20 +6,21 @@ import './strings.m.js';
import './item.js';
import './toolbar.js';
import 'chrome://resources/cr_components/managed_footnote/managed_footnote.m.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import 'chrome://resources/cr_elements/cr_page_host_style_css.m.js';
import 'chrome://resources/cr_elements/hidden_style_css.m.js';
import 'chrome://resources/cr_elements/shared_style_css.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import 'chrome://resources/polymer/v3_0/iron-list/iron-list.js';
import {CrToastManagerElement} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {FindShortcutBehavior} from 'chrome://resources/js/find_shortcut_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {PromiseResolver} from 'chrome://resources/js/promise_resolver.m.js';
import {queryRequiredElement} from 'chrome://resources/js/util.m.js';
import {IronA11yAnnouncer} from 'chrome://resources/polymer/v3_0/iron-a11y-announcer/iron-a11y-announcer.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {afterNextRender, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js';
import {States} from './constants.js';
......@@ -142,6 +143,10 @@ Polymer({
});
this.searchService_.loadMore();
afterNextRender(this, function() {
IronA11yAnnouncer.requestAvailability();
});
},
/** @override */
......@@ -202,7 +207,6 @@ Polymer({
state != States.IN_PROGRESS && state != States.PAUSED);
if (this.inSearchMode_) {
IronA11yAnnouncer.requestAvailability();
this.fire('iron-announce', {
text: this.items_.length == 0 ?
this.noDownloadsText_() :
......@@ -254,14 +258,6 @@ Polymer({
}
},
/**
* @return {!CrToastManagerElement}
* @private
*/
getToastManagerInstance_: function() {
return /** @type {!CrToastManagerElement} */ (this.$$('cr-toast-manager'));
},
/** @private */
onClearAllCommand_() {
if (!this.$.toolbar.canClearAll()) {
......@@ -269,8 +265,10 @@ Polymer({
}
this.mojoHandler_.clearAll();
this.getToastManagerInstance_().show(
loadTimeData.getString('toastClearedAll'), true);
getToastManager().show(loadTimeData.getString('toastClearedAll'));
this.fire('iron-announce', {
text: loadTimeData.getString('undoDescription'),
});
},
/** @private */
......@@ -279,7 +277,7 @@ Polymer({
return;
}
this.getToastManagerInstance_().hide();
getToastManager().hide();
this.mojoHandler_.undo();
},
......@@ -319,7 +317,7 @@ Polymer({
/** @private */
onUndoClick_: function() {
this.getToastManagerInstance_().hide();
getToastManager().hide();
this.mojoHandler_.undo();
},
......
......@@ -12,7 +12,7 @@ import 'chrome://resources/js/util.m.js';
import 'chrome://resources/polymer/v3_0/paper-styles/color.js';
import './strings.m.js';
import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -80,7 +80,10 @@ Polymer({
assert(this.canClearAll());
this.mojoHandler_.clearAll();
this.$.moreActionsMenu.close();
getInstance().show(loadTimeData.getString('toastClearedAll'), true);
getToastManager().show(loadTimeData.getString('toastClearedAll'));
this.fire('iron-announce', {
text: loadTimeData.getString('undoDescription'),
});
},
/** @private */
......
......@@ -4,7 +4,7 @@
import './manager.js';
export {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
export {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
export {ActivityLogPageState} from './activity_log/activity_log_history.js';
export {ARG_URL_PLACEHOLDER} from './activity_log/activity_log_stream_item.js';
// <if expr="chromeos">
......
......@@ -19,7 +19,7 @@ import 'chrome://resources/polymer/v3_0/iron-flex-layout/iron-flex-layout-classe
import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js';
import 'chrome://resources/polymer/v3_0/paper-tooltip/paper-tooltip.js';
import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
......@@ -246,16 +246,16 @@ Polymer({
this.isReloading_ = true;
const toastManager = getInstance();
const toastManager = getToastManager();
// Keep the toast open indefinitely.
toastManager.duration = 0;
toastManager.show(this.i18n('itemReloading'), false);
toastManager.show(this.i18n('itemReloading'));
this.delegate.reloadItem(this.data.id)
.then(
() => {
toastManager.hide();
toastManager.duration = 3000;
toastManager.show(this.i18n('itemReloaded'), false);
toastManager.show(this.i18n('itemReloaded'));
this.isReloading_ = false;
},
loadError => {
......
......@@ -11,7 +11,7 @@ import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import 'chrome://resources/polymer/v3_0/paper-styles/color.js';
import './pack_dialog.js';
import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {listenOnce} from 'chrome://resources/js/util.m.js';
import {IronA11yAnnouncer} from 'chrome://resources/polymer/v3_0/iron-a11y-announcer/iron-a11y-announcer.js';
......@@ -184,15 +184,15 @@ Polymer({
this.isUpdating_ = true;
const toastManager = getInstance();
const toastManager = getToastManager();
// Keep the toast open indefinitely.
toastManager.duration = 0;
toastManager.show(this.i18n('toolbarUpdatingToast'), false);
toastManager.show(this.i18n('toolbarUpdatingToast'));
this.delegate.updateAllExtensions().then(
() => {
toastManager.hide();
toastManager.duration = 3000;
toastManager.show(this.i18n('toolbarUpdateDone'), false);
toastManager.show(this.i18n('toolbarUpdateDone'));
this.isUpdating_ = false;
},
() => {
......
......@@ -179,11 +179,11 @@
</settings-password-prompt-dialog>
</template>
</if>
<cr-toast-manager on-undo-click="onUndoButtonTap_"
undo-label="$i18n{undoRemovePassword}"
undo-description="$i18n{undoDescription}"
duration="[[toastDuration_]]">
<cr-toast-manager duration="5000">
<cr-button aria-label="$i18n{undoDescription}"
on-click="onUndoButtonClick_">$i18n{undoRemovePassword}</cr-button>
</cr-toast-manager>
<div class="settings-box block first">
<h2>$i18n{passwordExceptionsHeading}</h2>
</div>
......
......@@ -68,15 +68,6 @@ Polymer({
value: () => [],
},
/**
* Duration of the undo toast in ms
* @private
*/
toastDuration_: {
type: Number,
value: 5000,
},
/** @override */
subpageRoute: {
type: Object,
......@@ -294,8 +285,8 @@ Polymer({
* @type {function(!Array<PasswordManagerProxy.ExceptionEntry>):void}
*/
(this.setPasswordExceptionsListener_));
if (cr.toastManager.getInstance().isToastOpen) {
cr.toastManager.getInstance().hide();
if (cr.toastManager.getToastManager().isToastOpen) {
cr.toastManager.getToastManager().hide();
}
},
......@@ -427,9 +418,10 @@ Polymer({
onMenuRemovePasswordTap_: function() {
this.passwordManager_.removeSavedPassword(
this.activePassword.item.entry.id);
cr.toastManager.getInstance().show(
this.i18n('passwordDeleted'),
/* showUndo */ true);
cr.toastManager.getToastManager().show(this.i18n('passwordDeleted'));
this.fire('iron-announce', {
text: this.i18n('undoDescription'),
});
/** @type {CrActionMenuElement} */ (this.$.menu).close();
},
......@@ -449,10 +441,12 @@ Polymer({
}
},
onUndoButtonTap_: function() {
/** @private */
onUndoButtonClick_: function() {
this.passwordManager_.undoRemoveSavedPasswordOrException();
cr.toastManager.getInstance().hide();
cr.toastManager.getToastManager().hide();
},
/**
* Fires an event that should delete the password exception.
* @param {!ExceptionEntryEntryEvent} e The polymer event.
......
......@@ -34,7 +34,7 @@ js_modulizer("modulize") {
namespace_rewrites = [
"cr.isMac|isMac",
"cr.isWindows|isWindows",
"cr.toastManager.getInstance|getInstance",
"cr.toastManager.getToastManager|getToastManager",
"MockInteractions.blur|blur",
"MockInteractions.downAndUp|downAndUp",
"MockInteractions.keyDownOn|keyDownOn",
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
// clang-format off
// #import {getInstance} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
// #import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
// #import {eventToPromise} from '../test_util.m.js';
// clang-format on
......@@ -16,34 +16,17 @@ suite('cr-toast-manager', () => {
document.body.appendChild(toastManager);
});
test('getInstance', () => {
assertEquals(toastManager, cr.toastManager.getInstance());
test('getToastManager', () => {
assertEquals(toastManager, cr.toastManager.getToastManager());
});
test('simple show/hide', function() {
toastManager.show('test', false);
test('simple show/hide', () => {
assertFalse(toastManager.isToastOpen);
toastManager.show('test');
assertEquals('test', toastManager.$.content.textContent);
assertTrue(toastManager.$.button.hidden);
toastManager.hide();
toastManager.show('test', true);
assertFalse(toastManager.$.button.hidden);
assertTrue(toastManager.isToastOpen);
toastManager.hide();
const whenDone =
new Promise(resolve => window.requestAnimationFrame(resolve));
return whenDone.then(() => {
assertEquals(
'hidden', window.getComputedStyle(toastManager.$.button).visibility);
});
});
test('undo-click fired when undo button is clicked', async () => {
toastManager.show('test', true);
const wait = test_util.eventToPromise('undo-click', toastManager);
toastManager.$.button.click();
await wait;
assertFalse(toastManager.isToastOpen);
});
test('showForStringPieces', () => {
......@@ -52,7 +35,7 @@ suite('cr-toast-manager', () => {
{value: 'folder', collapsible: true},
{value: '\' copied', collapsible: false},
];
toastManager.showForStringPieces(pieces, false);
toastManager.showForStringPieces(pieces);
const elements = toastManager.$.content.querySelectorAll('span');
assertEquals(3, elements.length);
assertFalse(elements[0].classList.contains('collapsible'));
......@@ -64,13 +47,4 @@ suite('cr-toast-manager', () => {
toastManager.duration = 3;
assertEquals(3, toastManager.$.toast.duration);
});
test('undo description and label', () => {
toastManager.undoDescription = 'description';
const button = toastManager.$$('#button[aria-label="description"]');
assertTrue(!!button);
assertEquals('', button.textContent.trim());
toastManager.undoLabel = 'undo';
assertEquals('undo', button.textContent.trim());
});
});
......@@ -165,7 +165,6 @@ suite('manager tests', function() {
// Simulate 'alt+c' key combo.
keyDownOn(document, null, 'alt', isMac ? 'ç' : 'c');
assertTrue(toastManager.isToastOpen);
assertFalse(toastManager.isUndoButtonHidden);
});
test('toast is hidden when undo-command is fired', () => {
......@@ -180,7 +179,7 @@ suite('manager tests', function() {
test('toast is hidden when undo is clicked', () => {
toastManager.show('');
assertTrue(toastManager.isToastOpen);
toastManager.dispatchEvent(new Event('undo-click'));
manager.$$('cr-toast-manager cr-button').click();
assertFalse(toastManager.isToastOpen);
});
});
......@@ -59,6 +59,5 @@ suite('toolbar tests', function() {
toolbar.hasClearableDownloads = true;
toolbar.$$('#moreActionsMenu button').click();
assertTrue(toastManager.isToastOpen);
assertFalse(toastManager.isUndoButtonHidden);
});
});
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {getInstance} from 'chrome://extensions/extensions.js';
import {getToastManager} from 'chrome://extensions/extensions.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isChromeOS, isMac} from 'chrome://resources/js/cr.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -111,7 +111,7 @@ suite(extension_toolbar_tests.suiteName, function() {
return mockDelegate.whenCalled('loadUnpacked');
})
.then(function() {
const toastManager = getInstance();
const toastManager = getToastManager();
assertFalse(toastManager.isToastOpen);
toolbar.$.updateNow.click();
// Simulate user rapidly clicking update button multiple times.
......
......@@ -562,7 +562,7 @@ cr.define('settings_passwords_section', function() {
const passwordEntry = FakeDataMaker.passwordEntry('goo.gl', 'bart', 1);
const passwordsSection = elementFactory.createPasswordsSection(
passwordManager, [passwordEntry], []);
const toastManager = cr.toastManager.getInstance();
const toastManager = cr.toastManager.getToastManager();
// Click the remove button on the first password and assert that an undo
// toast is shown.
......
......@@ -36,8 +36,8 @@ polymer_modulizer("cr_toast_manager") {
html_type = "dom-module"
auto_imports = [ "ui/webui/resources/html/assert.html|assert" ]
namespace_rewrites = [
"cr.toastManager.setInstance|setInstance",
"cr.toastManager.CrToastManagerElement|CrToastManagerElement",
"cr.toastManager.getToastManager|getToastManager",
]
}
......
......@@ -4,7 +4,6 @@
<link rel="import" href="../../html/assert.html">
<link rel="import" href="../../html/cr.html">
<link rel="import" href="../../html/event_tracker.html">
<link rel="import" href="../cr_button/cr_button.html">
<link rel="import" href="cr_toast.html">
<dom-module id="cr-toast-manager">
......@@ -32,10 +31,7 @@
</style>
<cr-toast id="toast" duration="[[duration]]">
<div id="content" class="elided-text"></div>
<cr-button id="button" hidden$="[[!showUndo_]]" on-click="onUndoClick_"
aria-label$="[[undoDescription]]">
[[undoLabel]]
</cr-button>
<slot></slot>
</cr-toast>
</template>
<script src="cr_toast_manager.js"></script>
......
......@@ -9,12 +9,12 @@ cr.define('cr.toastManager', () => {
/* eslint-enable */
/** @return {!cr.toastManager.CrToastManagerElement} */
/* #export */ function getInstance() {
/* #export */ function getToastManager() {
return assert(toastManagerInstance);
}
/** @param {?cr.toastManager.CrToastManagerElement} instance */
/* #export */ function setInstance(instance) {
function setInstance(instance) {
assert(!instance || !toastManagerInstance);
toastManagerInstance = instance;
}
......@@ -31,13 +31,6 @@ cr.define('cr.toastManager', () => {
type: Number,
value: 0,
},
/** @private */
showUndo_: Boolean,
undoDescription: String,
undoLabel: String,
},
/** @return {boolean} */
......@@ -45,37 +38,27 @@ cr.define('cr.toastManager', () => {
return this.$.toast.open;
},
/** @return {boolean} */
get isUndoButtonHidden() {
return this.$.button.hidden;
},
/** @override */
attached: function() {
cr.toastManager.setInstance(this);
setInstance(this);
},
/** @override */
detached: function() {
cr.toastManager.setInstance(null);
setInstance(null);
},
/**
* @param {string} label The label to display inside the toast.
* @param {boolean} showUndo Whether the undo button should be shown.
*/
show: function(label, showUndo) {
/** @param {string} label The label to display inside the toast. */
show: function(label) {
this.$.content.textContent = label;
this.showInternal_(showUndo);
this.$.toast.show();
this.showInternal_();
},
/**
* Shows the toast, making certain text fragments collapsible.
* @param {!Array<!{value: string, collapsible: boolean}>} pieces
* @param {boolean} showUndo Whether the undo button should be shown.
*/
showForStringPieces: function(pieces, showUndo) {
showForStringPieces: function(pieces) {
const content = this.$.content;
content.textContent = '';
pieces.forEach(function(p) {
......@@ -92,41 +75,26 @@ cr.define('cr.toastManager', () => {
content.appendChild(span);
});
this.showInternal_(showUndo);
this.showInternal_();
},
/**
* @param {boolean} showUndo Whether the undo button should be shown.
* @private
*/
showInternal_: function(showUndo) {
this.showUndo_ = showUndo;
/** @private */
showInternal_: function() {
Polymer.IronA11yAnnouncer.requestAvailability();
this.fire('iron-announce', {
text: this.$.content.textContent,
});
if (showUndo && this.undoDescription) {
this.fire('iron-announce', {
text: this.undoDescription,
});
}
this.$.toast.show();
},
hide: function() {
this.$.toast.hide();
},
/** @private */
onUndoClick_: function() {
this.fire('undo-click');
},
});
// #cr_define_end
return {
CrToastManagerElement: CrToastManagerElement,
getInstance: getInstance,
setInstance: setInstance,
getToastManager: getToastManager,
};
});
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