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.ignoreChangeEvents_) |
| 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 to ignore list change events. |
| 583 * Used to modify the list without processing selection change and lead |
| 584 * change events. |
| 585 * @type {boolean} |
| 586 * @private |
| 587 */ |
| 588 ignoreChangeEvents_: 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 28 matching lines...) Expand all Loading... |
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.ignoreChangeEvents_) |
| 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 ignoreChangeEvents: function(callback) { |
| 687 assert(!this.ignoreChangeEvents_); |
| 688 this.ignoreChangeEvents_ = true; |
| 689 callback(); |
| 690 this.ignoreChangeEvents_ = false; |
| 691 }, |
| 692 |
| 693 /** |
| 694 * Set the selected index without changing the focused element on the page. |
| 695 * Used to change the selected index when the list doesn't have focus (and |
| 696 * doesn't want to take focus). |
| 697 * @param {number} index The index to select. |
| 698 */ |
| 699 selectIndexWithoutFocusing: function(index) { |
| 700 // Remove focusability from old item. |
| 701 var oldItem = this.getListItemByIndex(this.selectionModel.leadIndex) || |
| 702 this.getInitialFocusableItem(); |
| 703 if (oldItem) { |
| 704 oldItem.setEditableValuesFocusable(false); |
| 705 oldItem.setStaticValuesFocusable(false); |
| 706 oldItem.setCloseButtonFocusable(false); |
| 707 oldItem.lead = false; |
| 708 } |
| 709 |
| 710 // Select the new item. |
| 711 this.ignoreChangeEvents(function() { |
| 712 this.selectionModel.selectedIndex = index; |
| 713 }.bind(this)); |
| 714 |
| 715 // Add focusability to new item. |
| 716 var newItem = this.getListItemByIndex(index); |
| 717 if (newItem) { |
| 718 if (newItem.isPlaceholder) |
| 719 newItem.setEditableValuesFocusable(true); |
| 720 else |
| 721 newItem.setStaticValuesFocusable(true); |
| 722 |
| 723 newItem.setCloseButtonFocusable(true); |
| 724 newItem.lead = true; |
| 725 } |
| 726 }, |
| 727 |
| 728 /** |
668 * Focus the placeholder's first input field. | 729 * Focus the placeholder's first input field. |
669 * Should only be called immediately after the list has been repopulated. | 730 * Should only be called immediately after the list has been repopulated. |
670 */ | 731 */ |
671 focusPlaceholder: function() { | 732 focusPlaceholder: function() { |
672 // Remove focusability from initial item. | 733 // Remove focusability from initial item. |
673 var item = this.getInitialFocusableItem(); | 734 var item = this.getInitialFocusableItem(); |
674 if (item) { | 735 if (item) { |
675 item.setStaticValuesFocusable(false); | 736 item.setStaticValuesFocusable(false); |
676 item.setCloseButtonFocusable(false); | 737 item.setCloseButtonFocusable(false); |
677 } | 738 } |
(...skipping 29 matching lines...) Expand all Loading... |
707 this.getListItemByIndex(0)); | 768 this.getListItemByIndex(0)); |
708 }, | 769 }, |
709 }; | 770 }; |
710 | 771 |
711 // Export | 772 // Export |
712 return { | 773 return { |
713 InlineEditableItem: InlineEditableItem, | 774 InlineEditableItem: InlineEditableItem, |
714 InlineEditableItemList: InlineEditableItemList, | 775 InlineEditableItemList: InlineEditableItemList, |
715 }; | 776 }; |
716 }); | 777 }); |
OLD | NEW |