 Chromium Code Reviews
 Chromium Code Reviews Issue 1264553002:
  Re-connect search on MD downloads  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@dl-misc6
    
  
    Issue 1264553002:
  Re-connect search on MD downloads  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@dl-misc6| Index: chrome/browser/resources/md_downloads/toolbar.js | 
| diff --git a/chrome/browser/resources/md_downloads/toolbar.js b/chrome/browser/resources/md_downloads/toolbar.js | 
| index 61716d47eac61a494e248b9b6b674a1fe190cbea..647778d647d8a868721d4b233c62dfa5c73ba549 100644 | 
| --- a/chrome/browser/resources/md_downloads/toolbar.js | 
| +++ b/chrome/browser/resources/md_downloads/toolbar.js | 
| @@ -13,9 +13,10 @@ cr.define('downloads', function() { | 
| }, | 
| properties: { | 
| - canClearAll: { | 
| + downloadsShowing: { | 
| type: Boolean, | 
| value: false, | 
| + observer: 'onDownloadsShowingChange_', | 
| }, | 
| showingSearch_: { | 
| @@ -26,15 +27,45 @@ cr.define('downloads', function() { | 
| /** @return {boolean} Whether removal can be undone. */ | 
| canUndo: function() { | 
| - return this.$['search-term'] != document.activeElement; | 
| + return !this.$['search-term'].shadowRoot.activeElement; | 
| 
Dan Beam
2015/07/29 04:43:41
til: http://www.w3.org/TR/shadow-dom/#active-eleme
 | 
| + }, | 
| + | 
| + /** @return {boolean} Whether "Clear all" should be allowed. */ | 
| + canClearAll: function() { | 
| + return !this.$['search-term'].value && this.downloadsShowing; | 
| + }, | 
| + | 
| + ready: function() { | 
| + var term = this.$['search-term']; | 
| + term.addEventListener('input', this.onSearchTermInput_.bind(this)); | 
| + term.addEventListener('keydown', this.onSearchTermKeydown_.bind(this)); | 
| }, | 
| /** @private */ | 
| onClearAllClick_: function() { | 
| + assert(this.canClearAll()); | 
| this.actionService_.clearAll(); | 
| }, | 
| /** @private */ | 
| + onDownloadsShowingChange_: function() { | 
| + this.updateClearAll_(); | 
| 
michaelpg
2015/07/30 02:48:16
Consider using Polymer features instead of calling
 | 
| + }, | 
| + | 
| + /** @private */ | 
| + onSearchTermInput_: function() { | 
| + this.actionService_.search(this.$['search-term'].value); | 
| + this.updateClearAll_(); | 
| + }, | 
| + | 
| + /** @private */ | 
| + onSearchTermKeydown_: function(e) { | 
| + assert(this.showingSearch_); | 
| + if (e.keyIdentifier == 'U+001B') // Escape. | 
| + this.toggleShowingSearch_(); | 
| + }, | 
| + | 
| + /** @private */ | 
| onOpenDownloadsFolderClick_: function() { | 
| this.actionService_.openDownloadsFolder(); | 
| }, | 
| @@ -42,6 +73,18 @@ cr.define('downloads', function() { | 
| /** @private */ | 
| toggleShowingSearch_: function() { | 
| this.showingSearch_ = !this.showingSearch_; | 
| + | 
| + if (this.showingSearch_) { | 
| + this.$['search-term'].focus(); | 
| + } else { | 
| + this.$['search-term'].value = ''; | 
| + this.onSearchTermInput_(); | 
| + } | 
| + }, | 
| + | 
| + /** @private */ | 
| + updateClearAll_: function() { | 
| + this.$['clear-all'].hidden = !this.canClearAll(); | 
| }, | 
| }); |