Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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.changeEventsDisabled_) |
|
James Hawkins
2015/01/15 16:10:44
An object should not be accessing private data of
Dan Beam
2015/01/21 18:18:07
[closure's] @private is file-level
| |
| 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 Loading... | |
| 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 * Whether list change events are disabled. | |
| 583 * Used to modify the list without processing selection change and lead | |
| 584 * change events. | |
| 585 * @type {boolean} | |
| 586 * @private | |
| 587 */ | |
| 588 changeEventsDisabled_: false, | |
| 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 27 matching lines...) Expand all Loading... | |
| 618 leadItem.setCloseButtonFocusable(true); | 628 leadItem.setCloseButtonFocusable(true); |
| 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) { |
|
Dan Beam
2015/01/21 18:18:07
where is this subscribed? can we just turn off no
| |
| 639 if (this.changeEventsDisabled_) | |
| 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 Loading... | |
| 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 executeWithChangeEventsDisabled: function(callback) { | |
| 687 this.changeEventsDisabled_ = true; | |
| 688 callback(); | |
| 689 this.changeEventsDisabled_ = false; | |
| 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 setSelectedIndexWithoutFocusing: 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.executeWithChangeEventsDisabled(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 Loading... | |
| 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 }); |
| OLD | NEW |