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

Side by Side Diff: chrome/browser/resources/md_bookmarks/folder_node.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 Polymer({ 5 Polymer({
6 is: 'bookmarks-folder-node', 6 is: 'bookmarks-folder-node',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.MouseFocusBehavior, 9 bookmarks.MouseFocusBehavior,
10 bookmarks.StoreClient, 10 bookmarks.StoreClient,
(...skipping 22 matching lines...) Expand all
33 /** @private */ 33 /** @private */
34 searchActive_: Boolean, 34 searchActive_: Boolean,
35 35
36 /** @private */ 36 /** @private */
37 isSelectedFolder_: { 37 isSelectedFolder_: {
38 type: Boolean, 38 type: Boolean,
39 value: false, 39 value: false,
40 reflectToAttribute: true, 40 reflectToAttribute: true,
41 computed: 'computeIsSelected_(itemId, selectedFolder_, searchActive_)' 41 computed: 'computeIsSelected_(itemId, selectedFolder_, searchActive_)'
42 }, 42 },
43
44 /** @private */
45 hasChildFolder_: {
46 type: Boolean,
47 computed: 'computeHasChildFolder_(item_.children)',
48 },
43 }, 49 },
44 50
45 listeners: { 51 listeners: {
46 'keydown': 'onKeydown_', 52 'keydown': 'onKeydown_',
47 }, 53 },
48 54
55 observers: [
56 'updateAriaExpanded_(hasChildFolder_, isClosed_)',
57 ],
58
49 /** @override */ 59 /** @override */
50 attached: function() { 60 attached: function() {
51 this.watch('item_', function(state) { 61 this.watch('item_', function(state) {
52 return state.nodes[this.itemId]; 62 return state.nodes[this.itemId];
53 }.bind(this)); 63 }.bind(this));
54 this.watch('isClosed_', function(state) { 64 this.watch('isClosed_', function(state) {
55 return state.closedFolders.has(this.itemId); 65 return state.closedFolders.has(this.itemId);
56 }.bind(this)); 66 }.bind(this));
57 this.watch('selectedFolder_', function(state) { 67 this.watch('selectedFolder_', function(state) {
58 return state.selectedFolder; 68 return state.selectedFolder;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 * @param {!HTMLElement} currentFocus 138 * @param {!HTMLElement} currentFocus
129 */ 139 */
130 changeKeyboardSelection_: function(xDirection, yDirection, currentFocus) { 140 changeKeyboardSelection_: function(xDirection, yDirection, currentFocus) {
131 var newFocusFolderNode = null; 141 var newFocusFolderNode = null;
132 var isChildFolderNodeFocused = 142 var isChildFolderNodeFocused =
133 currentFocus.tagName == 'BOOKMARKS-FOLDER-NODE'; 143 currentFocus.tagName == 'BOOKMARKS-FOLDER-NODE';
134 144
135 if (xDirection == 1) { 145 if (xDirection == 1) {
136 // The right arrow opens a folder if closed and goes to the first child 146 // The right arrow opens a folder if closed and goes to the first child
137 // otherwise. 147 // otherwise.
138 if (this.hasChildFolder_()) { 148 if (this.hasChildFolder_) {
139 if (this.isClosed_) { 149 if (this.isClosed_) {
140 this.dispatch( 150 this.dispatch(
141 bookmarks.actions.changeFolderOpen(this.item_.id, true)); 151 bookmarks.actions.changeFolderOpen(this.item_.id, true));
142 } else { 152 } else {
143 yDirection = 1; 153 yDirection = 1;
144 } 154 }
145 } 155 }
146 } else if (xDirection == -1) { 156 } else if (xDirection == -1) {
147 // The left arrow closes a folder if open and goes to the parent 157 // The left arrow closes a folder if open and goes to the parent
148 // otherwise. 158 // otherwise.
149 if (this.hasChildFolder_() && !this.isClosed_) { 159 if (this.hasChildFolder_ && !this.isClosed_) {
150 this.dispatch(bookmarks.actions.changeFolderOpen(this.item_.id, false)); 160 this.dispatch(bookmarks.actions.changeFolderOpen(this.item_.id, false));
151 } else { 161 } else {
152 var parentFolderNode = this.getParentFolderNode_(); 162 var parentFolderNode = this.getParentFolderNode_();
153 if (parentFolderNode.itemId != ROOT_NODE_ID) { 163 if (parentFolderNode.itemId != ROOT_NODE_ID) {
154 parentFolderNode.selectFolder_(); 164 parentFolderNode.selectFolder_();
155 parentFolderNode.getFocusTarget().focus(); 165 parentFolderNode.getFocusTarget().focus();
156 } 166 }
157 } 167 }
158 } 168 }
159 169
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 * @return {boolean} 320 * @return {boolean}
311 */ 321 */
312 computeIsSelected_: function(itemId, selectedFolder, searchActive) { 322 computeIsSelected_: function(itemId, selectedFolder, searchActive) {
313 return itemId == selectedFolder && !searchActive; 323 return itemId == selectedFolder && !searchActive;
314 }, 324 },
315 325
316 /** 326 /**
317 * @private 327 * @private
318 * @return {boolean} 328 * @return {boolean}
319 */ 329 */
320 hasChildFolder_: function() { 330 computeHasChildFolder_: function() {
321 return bookmarks.util.hasChildFolders(this.itemId, this.getState().nodes); 331 return bookmarks.util.hasChildFolders(this.itemId, this.getState().nodes);
322 }, 332 },
323 333
324 /** @private */ 334 /** @private */
325 depthChanged_: function() { 335 depthChanged_: function() {
326 this.style.setProperty('--node-depth', String(this.depth)); 336 this.style.setProperty('--node-depth', String(this.depth));
337 if (this.depth == -1)
338 this.$.descendants.removeAttribute('role');
327 }, 339 },
328 340
329 /** 341 /**
330 * @private 342 * @private
331 * @return {number} 343 * @return {number}
332 */ 344 */
333 getChildDepth_: function() { 345 getChildDepth_: function() {
334 return this.depth + 1; 346 return this.depth + 1;
335 }, 347 },
336 348
(...skipping 14 matching lines...) Expand all
351 return this.itemId == ROOT_NODE_ID; 363 return this.itemId == ROOT_NODE_ID;
352 }, 364 },
353 365
354 /** 366 /**
355 * @private 367 * @private
356 * @return {string} 368 * @return {string}
357 */ 369 */
358 getTabIndex_: function() { 370 getTabIndex_: function() {
359 return this.isSelectedFolder_ ? '0' : '-1'; 371 return this.isSelectedFolder_ ? '0' : '-1';
360 }, 372 },
373
374 /**
375 * Sets the 'aria-expanded' accessibility on nodes which need it. Note that
376 * aria-expanded="false" is different to having the attribute be undefined.
377 * @param {boolean} hasChildFolder
378 * @param {boolean} isClosed
379 * @private
380 */
381 updateAriaExpanded_: function(hasChildFolder, isClosed) {
382 if (hasChildFolder)
383 this.getFocusTarget().setAttribute('aria-expanded', String(!isClosed));
384 else
385 this.getFocusTarget().removeAttribute('aria-expanded');
386 },
361 }); 387 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/folder_node.html ('k') | chrome/browser/resources/md_bookmarks/item.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698