 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| 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 cr.define('downloads', function() { | 5 cr.define('downloads', function() { | 
| 6 var Toolbar = Polymer({ | 6 var Toolbar = Polymer({ | 
| 7 is: 'downloads-toolbar', | 7 is: 'downloads-toolbar', | 
| 8 | 8 | 
| 9 /** @param {!downloads.ActionService} actionService */ | 9 /** @param {!downloads.ActionService} actionService */ | 
| 10 setActionService: function(actionService) { | 10 setActionService: function(actionService) { | 
| 11 /** @private {!downloads.ActionService} */ | 11 /** @private {!downloads.ActionService} */ | 
| 12 this.actionService_ = actionService; | 12 this.actionService_ = actionService; | 
| 13 }, | 13 }, | 
| 14 | 14 | 
| 15 properties: { | 15 properties: { | 
| 16 canClearAll: { | 16 downloadsShowing: { | 
| 17 type: Boolean, | 17 type: Boolean, | 
| 18 value: false, | 18 value: false, | 
| 19 observer: 'onDownloadsShowingChange_', | |
| 19 }, | 20 }, | 
| 20 | 21 | 
| 21 showingSearch_: { | 22 showingSearch_: { | 
| 22 type: Boolean, | 23 type: Boolean, | 
| 23 value: false, | 24 value: false, | 
| 24 }, | 25 }, | 
| 25 }, | 26 }, | 
| 26 | 27 | 
| 27 /** @return {boolean} Whether removal can be undone. */ | 28 /** @return {boolean} Whether removal can be undone. */ | 
| 28 canUndo: function() { | 29 canUndo: function() { | 
| 29 return this.$['search-term'] != document.activeElement; | 30 return !this.$['search-term'].shadowRoot.activeElement; | 
| 
Dan Beam
2015/07/29 04:43:41
til: http://www.w3.org/TR/shadow-dom/#active-eleme
 | |
| 31 }, | |
| 32 | |
| 33 /** @return {boolean} Whether "Clear all" should be allowed. */ | |
| 34 canClearAll: function() { | |
| 35 return !this.$['search-term'].value && this.downloadsShowing; | |
| 36 }, | |
| 37 | |
| 38 ready: function() { | |
| 39 var term = this.$['search-term']; | |
| 40 term.addEventListener('input', this.onSearchTermInput_.bind(this)); | |
| 41 term.addEventListener('keydown', this.onSearchTermKeydown_.bind(this)); | |
| 30 }, | 42 }, | 
| 31 | 43 | 
| 32 /** @private */ | 44 /** @private */ | 
| 33 onClearAllClick_: function() { | 45 onClearAllClick_: function() { | 
| 46 assert(this.canClearAll()); | |
| 34 this.actionService_.clearAll(); | 47 this.actionService_.clearAll(); | 
| 35 }, | 48 }, | 
| 36 | 49 | 
| 37 /** @private */ | 50 /** @private */ | 
| 51 onDownloadsShowingChange_: function() { | |
| 52 this.updateClearAll_(); | |
| 
michaelpg
2015/07/30 02:48:16
Consider using Polymer features instead of calling
 | |
| 53 }, | |
| 54 | |
| 55 /** @private */ | |
| 56 onSearchTermInput_: function() { | |
| 57 this.actionService_.search(this.$['search-term'].value); | |
| 58 this.updateClearAll_(); | |
| 59 }, | |
| 60 | |
| 61 /** @private */ | |
| 62 onSearchTermKeydown_: function(e) { | |
| 63 assert(this.showingSearch_); | |
| 64 if (e.keyIdentifier == 'U+001B') // Escape. | |
| 65 this.toggleShowingSearch_(); | |
| 66 }, | |
| 67 | |
| 68 /** @private */ | |
| 38 onOpenDownloadsFolderClick_: function() { | 69 onOpenDownloadsFolderClick_: function() { | 
| 39 this.actionService_.openDownloadsFolder(); | 70 this.actionService_.openDownloadsFolder(); | 
| 40 }, | 71 }, | 
| 41 | 72 | 
| 42 /** @private */ | 73 /** @private */ | 
| 43 toggleShowingSearch_: function() { | 74 toggleShowingSearch_: function() { | 
| 44 this.showingSearch_ = !this.showingSearch_; | 75 this.showingSearch_ = !this.showingSearch_; | 
| 76 | |
| 77 if (this.showingSearch_) { | |
| 78 this.$['search-term'].focus(); | |
| 79 } else { | |
| 80 this.$['search-term'].value = ''; | |
| 81 this.onSearchTermInput_(); | |
| 82 } | |
| 83 }, | |
| 84 | |
| 85 /** @private */ | |
| 86 updateClearAll_: function() { | |
| 87 this.$['clear-all'].hidden = !this.canClearAll(); | |
| 45 }, | 88 }, | 
| 46 }); | 89 }); | 
| 47 | 90 | 
| 48 return {Toolbar: Toolbar}; | 91 return {Toolbar: Toolbar}; | 
| 49 }); | 92 }); | 
| OLD | NEW |