Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/resources/md_bookmarks/toast_manager.js

Issue 2955563002: MD Bookmarks: Initial screenreader accessibility improvements (Closed)
Patch Set: Privatize and rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Element which shows toasts. 6 * @fileoverview Element which shows toasts.
7 */ 7 */
8 cr.define('bookmarks', function() { 8 cr.define('bookmarks', function() {
9 9
10 var ToastManager = Polymer({ 10 var ToastManager = Polymer({
11 is: 'bookmarks-toast-manager', 11 is: 'bookmarks-toast-manager',
12 12
13 properties: { 13 properties: {
14 duration: { 14 duration: {
15 type: Number, 15 type: Number,
16 value: 0, 16 value: 0,
17 }, 17 },
18 18
19 /** @private */ 19 /** @private */
20 open_: { 20 open_: {
21 type: Boolean, 21 type: Boolean,
22 reflectToAttribute: true, 22 observer: 'openChanged_',
23 value: false,
23 }, 24 },
24 25
25 /** @private */ 26 /** @private */
26 showUndo_: Boolean, 27 showUndo_: Boolean,
27 }, 28 },
28 29
29 /** @private {bookmarks.TimerProxy} */ 30 /** @private {bookmarks.TimerProxy} */
30 timerProxy_: new bookmarks.TimerProxy(), 31 timerProxy_: new bookmarks.TimerProxy(),
31 32
32 /** @private {number|null} */ 33 /** @private {number|null} */
33 hideTimeoutId_: null, 34 hideTimeoutId_: null,
34 35
35 /** @override */ 36 /** @override */
36 attached: function() { 37 attached: function() {
37 assert(ToastManager.instance_ == null); 38 assert(ToastManager.instance_ == null);
38 ToastManager.instance_ = this; 39 ToastManager.instance_ = this;
40 Polymer.RenderStatus.afterNextRender(this, function() {
41 Polymer.IronA11yAnnouncer.requestAvailability();
42 });
39 }, 43 },
40 44
41 /** @override */ 45 /** @override */
42 detached: function() { 46 detached: function() {
43 ToastManager.instance_ = null; 47 ToastManager.instance_ = null;
44 }, 48 },
45 49
46 /** 50 /**
47 * @param {string} label The label to display inside the toast. 51 * @param {string} label The label to display inside the toast.
48 * @param {boolean} showUndo Whether the undo button should be shown. 52 * @param {boolean} showUndo Whether the undo button should be shown.
(...skipping 26 matching lines...) Expand all
75 this.showInternal_(showUndo); 79 this.showInternal_(showUndo);
76 }, 80 },
77 81
78 /** 82 /**
79 * @param {boolean} showUndo Whether the undo button should be shown. 83 * @param {boolean} showUndo Whether the undo button should be shown.
80 * @private 84 * @private
81 */ 85 */
82 showInternal_: function(showUndo) { 86 showInternal_: function(showUndo) {
83 this.open_ = true; 87 this.open_ = true;
84 this.showUndo_ = showUndo; 88 this.showUndo_ = showUndo;
89 this.fire('iron-announce', {text: this.$.content.textContent});
85 90
86 if (!this.duration) 91 if (!this.duration)
87 return; 92 return;
88 93
89 if (this.hideTimeoutId_ != null) 94 if (this.hideTimeoutId_ != null)
90 this.timerProxy_.clearTimeout(this.hideTimeoutId_); 95 this.timerProxy_.clearTimeout(this.hideTimeoutId_);
91 96
92 this.hideTimeoutId_ = this.timerProxy_.setTimeout(function() { 97 this.hideTimeoutId_ = this.timerProxy_.setTimeout(function() {
93 this.open_ = false; 98 this.hide();
94 this.hideTimeoutId_ = null; 99 this.hideTimeoutId_ = null;
95 }.bind(this), this.duration); 100 }.bind(this), this.duration);
96 }, 101 },
97 102
98 hide: function() { 103 hide: function() {
99 this.open_ = false; 104 this.open_ = false;
105 // Hide the undo button to prevent it from being accessed with tab.
106 this.showUndo_ = false;
100 }, 107 },
101 108
102 /** @private */ 109 /** @private */
103 onUndoTap_: function() { 110 onUndoTap_: function() {
104 // Will hide the toast. 111 // Will hide the toast.
105 this.fire('command-undo'); 112 this.fire('command-undo');
106 }, 113 },
114
115 /** @private */
116 openChanged_: function() {
117 this.$.toast.setAttribute('aria-hidden', String(!this.open_));
118 },
107 }); 119 });
108 120
109 /** @private {?bookmarks.ToastManager} */ 121 /** @private {?bookmarks.ToastManager} */
110 ToastManager.instance_ = null; 122 ToastManager.instance_ = null;
111 123
112 /** @return {!bookmarks.ToastManager} */ 124 /** @return {!bookmarks.ToastManager} */
113 ToastManager.getInstance = function() { 125 ToastManager.getInstance = function() {
114 return assert(ToastManager.instance_); 126 return assert(ToastManager.instance_);
115 }; 127 };
116 128
117 return { 129 return {
118 ToastManager: ToastManager, 130 ToastManager: ToastManager,
119 }; 131 };
120 }); 132 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/toast_manager.html ('k') | chrome/browser/resources/md_bookmarks/toolbar.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698