| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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: 'history-toolbar', | 6 is: 'history-toolbar', |
| 7 properties: { | 7 properties: { |
| 8 // Number of history items currently selected. | 8 // Number of history items currently selected. |
| 9 count: { | 9 count: { |
| 10 type: Number, | 10 type: Number, |
| 11 value: 0, | 11 value: 0, |
| 12 observer: 'changeToolbarView_' | 12 observer: 'changeToolbarView_' |
| 13 }, | 13 }, |
| 14 |
| 14 // True if 1 or more history items are selected. When this value changes | 15 // True if 1 or more history items are selected. When this value changes |
| 15 // the background colour changes. | 16 // the background colour changes. |
| 16 itemsSelected_: { | 17 itemsSelected_: { |
| 17 type: Boolean, | 18 type: Boolean, |
| 18 value: false, | 19 value: false, |
| 19 reflectToAttribute: true | 20 reflectToAttribute: true |
| 21 }, |
| 22 |
| 23 // The search term associated with the current results shown. Also used to |
| 24 // determine whether results need to be refreshed (i.e. if it changes). |
| 25 searchTerm: { |
| 26 type: String, |
| 27 value: '' |
| 20 } | 28 } |
| 21 }, | 29 }, |
| 22 | 30 |
| 23 /** | 31 /** |
| 24 * Changes the toolbar background color depending on whether any history items | 32 * Changes the toolbar background color depending on whether any history items |
| 25 * are currently selected. | 33 * are currently selected. |
| 26 * @private | 34 * @private |
| 27 */ | 35 */ |
| 28 changeToolbarView_: function() { | 36 changeToolbarView_: function() { |
| 29 this.itemsSelected_ = this.count > 0; | 37 this.itemsSelected_ = this.count > 0; |
| 30 }, | 38 }, |
| 31 | 39 |
| 40 /** |
| 41 * If the search term has changed reload for the new search. |
| 42 */ |
| 43 onSearchTermSearch: function(searchTerm) { |
| 44 if (searchTerm != this.searchTerm) |
| 45 this.fire('refresh-results', {search: searchTerm}); |
| 46 this.searchTerm = searchTerm; |
| 47 }, |
| 48 |
| 49 attached: function() { |
| 50 this.async(function() { |
| 51 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); |
| 52 this.$['search-input'].setDelegate(this.searchFieldDelegate_); |
| 53 }); |
| 54 }, |
| 55 |
| 32 onClearSelectionTap_: function() { | 56 onClearSelectionTap_: function() { |
| 33 this.fire('unselect-all'); | 57 this.fire('unselect-all'); |
| 34 }, | 58 }, |
| 35 | 59 |
| 36 numberOfItemsSelected_: function(count) { | 60 numberOfItemsSelected_: function(count) { |
| 37 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; | 61 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; |
| 38 } | 62 } |
| 39 }); | 63 }); |
| 64 |
| 65 /** |
| 66 * @constructor |
| 67 * @implements {SearchFieldDelegate} |
| 68 * @param {!Object} toolbar This history-toolbar. |
| 69 */ |
| 70 function ToolbarSearchFieldDelegate(toolbar) { |
| 71 this.toolbar_ = toolbar; |
| 72 } |
| 73 |
| 74 ToolbarSearchFieldDelegate.prototype = { |
| 75 /** @override */ |
| 76 onSearchTermSearch: function(searchTerm) { |
| 77 this.toolbar_.onSearchTermSearch(searchTerm); |
| 78 } |
| 79 }; |
| OLD | NEW |