| 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 /** | 5 /** |
| 6 * @fileoverview 'settings-search-engine-entry' is a component for showing a | 6 * @fileoverview 'settings-search-engine-entry' is a component for showing a |
| 7 * search engine with its name, domain and query URL. | 7 * search engine with its name, domain and query URL. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-search-engine-entry', | 10 is: 'settings-search-engine-entry', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @type {!SearchEngine} */ | 13 /** @type {!SearchEngine} */ |
| 14 engine: Object, | 14 engine: Object, |
| 15 | 15 |
| 16 /** @private {boolean} */ | |
| 17 showEditSearchEngineDialog_: Boolean, | |
| 18 | |
| 19 /** @type {boolean} */ | 16 /** @type {boolean} */ |
| 20 isDefault: { | 17 isDefault: { |
| 21 reflectToAttribute: true, | 18 reflectToAttribute: true, |
| 22 type: Boolean, | 19 type: Boolean, |
| 23 computed: 'computeIsDefault_(engine)' | 20 computed: 'computeIsDefault_(engine)' |
| 24 }, | 21 }, |
| 22 |
| 23 /** @private {boolean} */ |
| 24 showDots_: { |
| 25 reflectToAttribute: true, |
| 26 type: Boolean, |
| 27 computed: 'computeShowDots_(engine.canBeDefault,' + |
| 28 'engine.canBeEdited,' + |
| 29 'engine.canBeRemoved)', |
| 30 }, |
| 31 |
| 32 /** @private {boolean} */ |
| 33 showEditSearchEngineDialog_: Boolean, |
| 25 }, | 34 }, |
| 26 | 35 |
| 27 /** @private {settings.SearchEnginesBrowserProxy} */ | 36 /** @private {settings.SearchEnginesBrowserProxy} */ |
| 28 browserProxy_: null, | 37 browserProxy_: null, |
| 29 | 38 |
| 30 /** @override */ | 39 /** @override */ |
| 31 created: function() { | 40 created: function() { |
| 32 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); | 41 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); |
| 33 }, | 42 }, |
| 34 | 43 |
| 44 /** @private */ |
| 45 closePopupMenu_: function() { |
| 46 this.$$('dialog[is=cr-action-menu]').close(); |
| 47 }, |
| 48 |
| 35 /** | 49 /** |
| 36 * @return {boolean} | 50 * @return {boolean} |
| 37 * @private | 51 * @private |
| 38 */ | 52 */ |
| 39 computeIsDefault_: function() { | 53 computeIsDefault_: function() { |
| 40 return this.engine.default; | 54 return this.engine.default; |
| 41 }, | 55 }, |
| 42 | 56 |
| 57 /** |
| 58 * @param {boolean} canBeDefault |
| 59 * @param {boolean} canBeEdited |
| 60 * @param {boolean} canBeRemoved |
| 61 * @return {boolean} Whether to show the dots menu. |
| 62 * @private |
| 63 */ |
| 64 computeShowDots_: function(canBeDefault, canBeEdited, canBeRemoved) { |
| 65 return canBeDefault || canBeEdited || canBeRemoved; |
| 66 }, |
| 67 |
| 68 /** |
| 69 * @param {?string} url The icon URL if available. |
| 70 * @return {string} A set of icon URLs. |
| 71 * @private |
| 72 */ |
| 73 getIconSet_: function(url) { |
| 74 // Force default icon, if no |engine.iconURL| is available. |
| 75 return cr.icon.getFavicon(url || ''); |
| 76 }, |
| 77 |
| 43 /** @private */ | 78 /** @private */ |
| 44 onDeleteTap_: function() { | 79 onDeleteTap_: function() { |
| 45 this.browserProxy_.removeSearchEngine(this.engine.modelIndex); | 80 this.browserProxy_.removeSearchEngine(this.engine.modelIndex); |
| 46 this.closePopupMenu_(); | 81 this.closePopupMenu_(); |
| 47 }, | 82 }, |
| 48 | 83 |
| 49 /** @private */ | 84 /** @private */ |
| 85 onDotsTap_: function() { |
| 86 /** @type {!CrActionMenuElement} */ ( |
| 87 this.$$('dialog[is=cr-action-menu]')).showAt( |
| 88 assert(this.$$('paper-icon-button'))); |
| 89 }, |
| 90 |
| 91 /** @private */ |
| 50 onEditTap_: function() { | 92 onEditTap_: function() { |
| 51 this.closePopupMenu_(); | 93 this.closePopupMenu_(); |
| 52 | 94 |
| 53 this.showEditSearchEngineDialog_ = true; | 95 this.showEditSearchEngineDialog_ = true; |
| 54 this.async(function() { | 96 this.async(function() { |
| 55 var dialog = this.$$('settings-search-engine-dialog'); | 97 var dialog = this.$$('settings-search-engine-dialog'); |
| 56 // Register listener to detect when the dialog is closed. Flip the boolean | 98 // Register listener to detect when the dialog is closed. Flip the boolean |
| 57 // once closed to force a restamp next time it is shown such that the | 99 // once closed to force a restamp next time it is shown such that the |
| 58 // previous dialog's contents are cleared. | 100 // previous dialog's contents are cleared. |
| 59 dialog.addEventListener('close', function() { | 101 dialog.addEventListener('close', function() { |
| 60 this.showEditSearchEngineDialog_ = false; | 102 this.showEditSearchEngineDialog_ = false; |
| 61 }.bind(this)); | 103 }.bind(this)); |
| 62 }.bind(this)); | 104 }.bind(this)); |
| 63 }, | 105 }, |
| 64 | 106 |
| 65 /** @private */ | 107 /** @private */ |
| 66 onMakeDefaultTap_: function() { | 108 onMakeDefaultTap_: function() { |
| 67 this.closePopupMenu_(); | 109 this.closePopupMenu_(); |
| 68 this.browserProxy_.setDefaultSearchEngine(this.engine.modelIndex); | 110 this.browserProxy_.setDefaultSearchEngine(this.engine.modelIndex); |
| 69 }, | 111 }, |
| 70 | |
| 71 /** @private */ | |
| 72 closePopupMenu_: function() { | |
| 73 this.$$('dialog[is=cr-action-menu]').close(); | |
| 74 }, | |
| 75 | |
| 76 /** | |
| 77 * @param {?string} url The icon URL if available. | |
| 78 * @return {string} A set of icon URLs. | |
| 79 * @private | |
| 80 */ | |
| 81 getIconSet_: function(url) { | |
| 82 // Force default icon, if no |engine.iconURL| is available. | |
| 83 return cr.icon.getFavicon(url || ''); | |
| 84 }, | |
| 85 | |
| 86 /** @private */ | |
| 87 onDotsTap_: function() { | |
| 88 /** @type {!CrActionMenuElement} */ ( | |
| 89 this.$$('dialog[is=cr-action-menu]')).showAt( | |
| 90 assert(this.$$('paper-icon-button'))); | |
| 91 }, | |
| 92 }); | 112 }); |
| OLD | NEW |