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