| OLD | NEW |
| 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: 'cr-toolbar-search-field', | 6 is: 'cr-toolbar-search-field', |
| 7 | 7 |
| 8 behaviors: [CrSearchFieldBehavior], | 8 behaviors: [CrSearchFieldBehavior], |
| 9 | 9 |
| 10 properties: { | 10 properties: { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 /** @private */ | 43 /** @private */ |
| 44 searchFocused_: {type: Boolean, value: false}, | 44 searchFocused_: {type: Boolean, value: false}, |
| 45 }, | 45 }, |
| 46 | 46 |
| 47 listeners: { | 47 listeners: { |
| 48 // Deliberately uses 'click' instead of 'tap' to fix crbug.com/624356. | 48 // Deliberately uses 'click' instead of 'tap' to fix crbug.com/624356. |
| 49 'click': 'showSearch_', | 49 'click': 'showSearch_', |
| 50 }, | 50 }, |
| 51 | 51 |
| 52 /** @return {!HTMLInputElement} */ | 52 /** @return {!HTMLInputElement} */ |
| 53 getSearchInput: function() { return this.$.searchInput; }, | 53 getSearchInput: function() { |
| 54 return this.$.searchInput; |
| 55 }, |
| 54 | 56 |
| 55 /** | 57 /** |
| 56 * Sets the value of the search field. Overridden from CrSearchFieldBehavior. | 58 * Sets the value of the search field. Overridden from CrSearchFieldBehavior. |
| 57 * @param {string} value | 59 * @param {string} value |
| 58 * @param {boolean=} opt_noEvent Whether to prevent a 'search-changed' event | 60 * @param {boolean=} opt_noEvent Whether to prevent a 'search-changed' event |
| 59 * firing for this change. | 61 * firing for this change. |
| 60 */ | 62 */ |
| 61 setValue: function(value, opt_noEvent) { | 63 setValue: function(value, opt_noEvent) { |
| 62 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); | 64 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); |
| 63 this.onSearchInput_(); | 65 this.onSearchInput_(); |
| 64 }, | 66 }, |
| 65 | 67 |
| 66 /** @return {boolean} */ | 68 /** @return {boolean} */ |
| 67 isSearchFocused: function() { return this.searchFocused_; }, | 69 isSearchFocused: function() { |
| 70 return this.searchFocused_; |
| 71 }, |
| 68 | 72 |
| 69 showAndFocus: function() { | 73 showAndFocus: function() { |
| 70 this.showingSearch = true; | 74 this.showingSearch = true; |
| 71 this.focus_(); | 75 this.focus_(); |
| 72 }, | 76 }, |
| 73 | 77 |
| 74 /** @private */ | 78 /** @private */ |
| 75 focus_: function() { this.getSearchInput().focus(); }, | 79 focus_: function() { |
| 80 this.getSearchInput().focus(); |
| 81 }, |
| 76 | 82 |
| 77 /** | 83 /** |
| 78 * @param {boolean} narrow | 84 * @param {boolean} narrow |
| 79 * @return {number} | 85 * @return {number} |
| 80 * @private | 86 * @private |
| 81 */ | 87 */ |
| 82 computeIconTabIndex_: function(narrow) { return narrow ? 0 : -1; }, | 88 computeIconTabIndex_: function(narrow) { |
| 89 return narrow ? 0 : -1; |
| 90 }, |
| 83 | 91 |
| 84 /** | 92 /** |
| 85 * @return {boolean} | 93 * @return {boolean} |
| 86 * @private | 94 * @private |
| 87 */ | 95 */ |
| 88 computeIsSpinnerShown_: function() { | 96 computeIsSpinnerShown_: function() { |
| 89 return this.spinnerActive && this.showingSearch; | 97 return this.spinnerActive && this.showingSearch; |
| 90 }, | 98 }, |
| 91 | 99 |
| 92 /** @private */ | 100 /** @private */ |
| 93 onInputFocus_: function() { this.searchFocused_ = true; }, | 101 onInputFocus_: function() { |
| 102 this.searchFocused_ = true; |
| 103 }, |
| 94 | 104 |
| 95 /** @private */ | 105 /** @private */ |
| 96 onInputBlur_: function() { | 106 onInputBlur_: function() { |
| 97 this.searchFocused_ = false; | 107 this.searchFocused_ = false; |
| 98 if (!this.hasSearchText_) | 108 if (!this.hasSearchText_) |
| 99 this.showingSearch = false; | 109 this.showingSearch = false; |
| 100 }, | 110 }, |
| 101 | 111 |
| 102 /** | 112 /** |
| 103 * Update the state of the search field whenever the underlying input value | 113 * Update the state of the search field whenever the underlying input value |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 158 |
| 149 if (this.showingSearch) { | 159 if (this.showingSearch) { |
| 150 this.focus_(); | 160 this.focus_(); |
| 151 return; | 161 return; |
| 152 } | 162 } |
| 153 | 163 |
| 154 this.setValue(''); | 164 this.setValue(''); |
| 155 this.getSearchInput().blur(); | 165 this.getSearchInput().blur(); |
| 156 }, | 166 }, |
| 157 }); | 167 }); |
| OLD | NEW |