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

Side by Side Diff: chrome/browser/resources/options/inline_editable_list.js

Issue 819193003: Fix list focus after tab key in chrome://settings/autofillEditAddress page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments on patch set 5. Created 5 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('options', function() { 5 cr.define('options', function() {
6 /** @const */ var DeletableItem = options.DeletableItem; 6 /** @const */ var DeletableItem = options.DeletableItem;
7 /** @const */ var DeletableItemList = options.DeletableItemList; 7 /** @const */ var DeletableItemList = options.DeletableItemList;
8 8
9 /** 9 /**
10 * Creates a new list item with support for inline editing. 10 * Creates a new list item with support for inline editing.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 DeletableItem.prototype.decorate.call(this); 78 DeletableItem.prototype.decorate.call(this);
79 79
80 this.editFields_ = []; 80 this.editFields_ = [];
81 this.addEventListener('mousedown', this.handleMouseDown_); 81 this.addEventListener('mousedown', this.handleMouseDown_);
82 this.addEventListener('keydown', this.handleKeyDown_); 82 this.addEventListener('keydown', this.handleKeyDown_);
83 this.addEventListener('focusin', this.handleFocusIn_); 83 this.addEventListener('focusin', this.handleFocusIn_);
84 }, 84 },
85 85
86 /** @override */ 86 /** @override */
87 selectionChanged: function() { 87 selectionChanged: function() {
88 this.updateEditState(); 88 if (this.parentNode.ignoreChangeEventsCount_ == 0)
bondd 2015/01/22 20:23:58 If you prefer, I could make an accessor getIgnoreC
89 this.updateEditState();
89 }, 90 },
90 91
91 /** 92 /**
92 * Called when this element gains or loses 'lead' status. Updates editing 93 * Called when this element gains or loses 'lead' status. Updates editing
93 * mode accordingly. 94 * mode accordingly.
94 */ 95 */
95 updateLeadState: function() { 96 updateLeadState: function() {
96 // Add focusability before call to updateEditState. 97 // Add focusability before call to updateEditState.
97 if (this.lead) { 98 if (this.lead) {
98 this.setEditableValuesFocusable(true); 99 this.setEditableValuesFocusable(true);
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 /** 572 /**
572 * @constructor 573 * @constructor
573 * @extends {options.DeletableItemList} 574 * @extends {options.DeletableItemList}
574 */ 575 */
575 var InlineEditableItemList = cr.ui.define('list'); 576 var InlineEditableItemList = cr.ui.define('list');
576 577
577 InlineEditableItemList.prototype = { 578 InlineEditableItemList.prototype = {
578 __proto__: DeletableItemList.prototype, 579 __proto__: DeletableItemList.prototype,
579 580
580 /** 581 /**
582 * List change events are ignored if ignoreChangeEventsCount_ > 0.
583 * Used to modify the list without processing selection change and lead
584 * change events.
585 * @type {number}
586 * @private
587 */
588 ignoreChangeEventsCount_: 0,
589
590 /**
581 * Focuses the input element of the placeholder if true. 591 * Focuses the input element of the placeholder if true.
582 * @type {boolean} 592 * @type {boolean}
583 * @private 593 * @private
584 */ 594 */
585 needsToFocusPlaceholder_: false, 595 needsToFocusPlaceholder_: false,
586 596
587 /** @override */ 597 /** @override */
588 decorate: function() { 598 decorate: function() {
589 DeletableItemList.prototype.decorate.call(this); 599 DeletableItemList.prototype.decorate.call(this);
590 this.setAttribute('inlineeditable', ''); 600 this.setAttribute('inlineeditable', '');
(...skipping 28 matching lines...) Expand all
619 leadItem.editing = false; 629 leadItem.editing = false;
620 // Remove focusability after making other changes. 630 // Remove focusability after making other changes.
621 if (!leadItem.isPlaceholder) 631 if (!leadItem.isPlaceholder)
622 leadItem.setEditableValuesFocusable(false); 632 leadItem.setEditableValuesFocusable(false);
623 } 633 }
624 } 634 }
625 }, 635 },
626 636
627 /** @override */ 637 /** @override */
628 handleLeadChange: function(e) { 638 handleLeadChange: function(e) {
639 if (this.ignoreChangeEventsCount_ > 0)
640 return;
641
629 DeletableItemList.prototype.handleLeadChange.call(this, e); 642 DeletableItemList.prototype.handleLeadChange.call(this, e);
630 643
631 var focusedColumnIndex = -1; 644 var focusedColumnIndex = -1;
632 if (e.oldValue != -1) { 645 if (e.oldValue != -1) {
633 var element = this.getListItemByIndex(e.oldValue); 646 var element = this.getListItemByIndex(e.oldValue);
634 if (element) { 647 if (element) {
635 focusedColumnIndex = element.focusedColumnIndex; 648 focusedColumnIndex = element.focusedColumnIndex;
636 element.updateLeadState(); 649 element.updateLeadState();
637 } 650 }
638 } 651 }
(...skipping 19 matching lines...) Expand all
658 if (item) { 671 if (item) {
659 item.setStaticValuesFocusable(true); 672 item.setStaticValuesFocusable(true);
660 item.setCloseButtonFocusable(true); 673 item.setCloseButtonFocusable(true);
661 if (item.isPlaceholder) 674 if (item.isPlaceholder)
662 item.setEditableValuesFocusable(true); 675 item.setEditableValuesFocusable(true);
663 } 676 }
664 } 677 }
665 }, 678 },
666 679
667 /** 680 /**
681 * Execute |callback| with list change events disabled. Selection change and
682 * lead change events will not be processed.
683 * @param {!Function} callback The function to execute.
684 * @protected
685 */
686 ignoreChangeEvents: function(callback) {
687 this.ignoreChangeEventsCount_++;
Dan Beam 2015/01/23 22:46:14 leaving as boolean and doing: assert(!this.igno
bondd 2015/01/29 19:01:02 Done.
688 callback();
689 this.ignoreChangeEventsCount_--;
690 },
691
692 /**
693 * Set the selected index without changing the focused element on the page.
694 * Used to change the selected index when the list doesn't have focus (and
695 * doesn't want to take focus).
696 * @param {number} index The index to select.
697 */
698 selectIndexWithoutFocusing: function(index) {
699 // Remove focusability from old item.
700 var oldItem = this.getListItemByIndex(this.selectionModel.leadIndex) ||
701 this.getInitialFocusableItem();
702 if (oldItem) {
703 oldItem.setEditableValuesFocusable(false);
704 oldItem.setStaticValuesFocusable(false);
705 oldItem.setCloseButtonFocusable(false);
706 oldItem.lead = false;
707 }
708
709 // Select the new item.
710 this.ignoreChangeEvents(function() {
711 this.selectionModel.selectedIndex = index;
712 }.bind(this));
713
714 // Add focusability to new item.
715 var newItem = this.getListItemByIndex(index);
716 if (newItem) {
717 if (newItem.isPlaceholder)
718 newItem.setEditableValuesFocusable(true);
719 else
720 newItem.setStaticValuesFocusable(true);
721
722 newItem.setCloseButtonFocusable(true);
723 newItem.lead = true;
724 }
725 },
726
727 /**
668 * Focus the placeholder's first input field. 728 * Focus the placeholder's first input field.
669 * Should only be called immediately after the list has been repopulated. 729 * Should only be called immediately after the list has been repopulated.
670 */ 730 */
671 focusPlaceholder: function() { 731 focusPlaceholder: function() {
672 // Remove focusability from initial item. 732 // Remove focusability from initial item.
673 var item = this.getInitialFocusableItem(); 733 var item = this.getInitialFocusableItem();
674 if (item) { 734 if (item) {
675 item.setStaticValuesFocusable(false); 735 item.setStaticValuesFocusable(false);
676 item.setCloseButtonFocusable(false); 736 item.setCloseButtonFocusable(false);
677 } 737 }
(...skipping 29 matching lines...) Expand all
707 this.getListItemByIndex(0)); 767 this.getListItemByIndex(0));
708 }, 768 },
709 }; 769 };
710 770
711 // Export 771 // Export
712 return { 772 return {
713 InlineEditableItem: InlineEditableItem, 773 InlineEditableItem: InlineEditableItem,
714 InlineEditableItemList: InlineEditableItemList, 774 InlineEditableItemList: InlineEditableItemList,
715 }; 775 };
716 }); 776 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698