Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 2275653002: MD Downloads: use "big search" box like MD history (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dl-menu-rtl
Patch Set: fix tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 function assert(condition, opt_message) { 4 function assert(condition, opt_message) {
5 if (!condition) { 5 if (!condition) {
6 var message = 'Assertion failed'; 6 var message = 'Assertion failed';
7 if (opt_message) message = message + ': ' + opt_message; 7 if (opt_message) message = message + ': ' + opt_message;
8 var error = new Error(message); 8 var error = new Error(message);
9 var global = function() { 9 var global = function() {
10 return this; 10 return this;
(...skipping 6009 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 } 6020 }
6021 }, 6021 },
6022 _altChanged: function(newValue, oldValue) { 6022 _altChanged: function(newValue, oldValue) {
6023 var label = this.getAttribute('aria-label'); 6023 var label = this.getAttribute('aria-label');
6024 if (!label || oldValue == label) { 6024 if (!label || oldValue == label) {
6025 this.setAttribute('aria-label', newValue); 6025 this.setAttribute('aria-label', newValue);
6026 } 6026 }
6027 } 6027 }
6028 }); 6028 });
6029 6029
6030 // Copyright 2016 The Chromium Authors. All rights reserved. 6030 Polymer({
6031 // Use of this source code is governed by a BSD-style license that can be 6031 is: 'iron-media-query',
6032 // found in the LICENSE file.
6033 var CrSearchFieldBehavior = {
6034 properties: { 6032 properties: {
6035 label: { 6033 queryMatches: {
6036 type: String,
6037 value: ''
6038 },
6039 clearLabel: {
6040 type: String,
6041 value: ''
6042 },
6043 showingSearch: {
6044 type: Boolean, 6034 type: Boolean,
6045 value: false, 6035 value: false,
6046 notify: true, 6036 readOnly: true,
6047 observer: 'showingSearchChanged_', 6037 notify: true
6048 reflectToAttribute: true
6049 }, 6038 },
6050 lastValue_: { 6039 query: {
6051 type: String, 6040 type: String,
6052 value: '' 6041 observer: 'queryChanged'
6042 },
6043 full: {
6044 type: Boolean,
6045 value: false
6046 },
6047 _boundMQHandler: {
6048 value: function() {
6049 return this.queryHandler.bind(this);
6050 }
6051 },
6052 _mq: {
6053 value: null
6053 } 6054 }
6054 }, 6055 },
6055 getSearchInput: function() {}, 6056 attached: function() {
6056 getValue: function() { 6057 this.style.display = 'none';
6057 return this.getSearchInput().value; 6058 this.queryChanged();
6058 }, 6059 },
6059 setValue: function(value) { 6060 detached: function() {
6060 this.getSearchInput().bindValue = value; 6061 this._remove();
6061 this.onValueChanged_(value);
6062 }, 6062 },
6063 showAndFocus: function() { 6063 _add: function() {
6064 this.showingSearch = true; 6064 if (this._mq) {
6065 this.focus_(); 6065 this._mq.addListener(this._boundMQHandler);
6066 }
6066 }, 6067 },
6067 focus_: function() { 6068 _remove: function() {
6068 this.getSearchInput().focus(); 6069 if (this._mq) {
6070 this._mq.removeListener(this._boundMQHandler);
6071 }
6072 this._mq = null;
6069 }, 6073 },
6070 onSearchTermSearch: function() { 6074 queryChanged: function() {
6071 this.onValueChanged_(this.getValue()); 6075 this._remove();
6072 }, 6076 var query = this.query;
6073 onValueChanged_: function(newValue) { 6077 if (!query) {
6074 if (newValue == this.lastValue_) return;
6075 this.fire('search-changed', newValue);
6076 this.lastValue_ = newValue;
6077 },
6078 onSearchTermKeydown: function(e) {
6079 if (e.key == 'Escape') this.showingSearch = false;
6080 },
6081 showingSearchChanged_: function() {
6082 if (this.showingSearch) {
6083 this.focus_();
6084 return; 6078 return;
6085 } 6079 }
6086 this.setValue(''); 6080 if (!this.full && query[0] !== '(') {
6087 this.getSearchInput().blur(); 6081 query = '(' + query + ')';
6082 }
6083 this._mq = window.matchMedia(query);
6084 this._add();
6085 this.queryHandler(this._mq);
6086 },
6087 queryHandler: function(mq) {
6088 this._setQueryMatches(mq.matches);
6088 } 6089 }
6089 }; 6090 });
6090 6091
6091 (function() { 6092 (function() {
6092 'use strict'; 6093 'use strict';
6093 Polymer.IronA11yAnnouncer = Polymer({ 6094 Polymer.IronA11yAnnouncer = Polymer({
6094 is: 'iron-a11y-announcer', 6095 is: 'iron-a11y-announcer',
6095 properties: { 6096 properties: {
6096 mode: { 6097 mode: {
6097 type: String, 6098 type: String,
6098 value: 'polite' 6099 value: 'polite'
6099 }, 6100 },
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
6536 var cls = 'add-on-content'; 6537 var cls = 'add-on-content';
6537 if (invalid) { 6538 if (invalid) {
6538 cls += ' is-invalid'; 6539 cls += ' is-invalid';
6539 } else if (focused) { 6540 } else if (focused) {
6540 cls += ' is-highlighted'; 6541 cls += ' is-highlighted';
6541 } 6542 }
6542 return cls; 6543 return cls;
6543 } 6544 }
6544 }); 6545 });
6545 6546
6546 // Copyright 2015 The Chromium Authors. All rights reserved. 6547 Polymer.PaperSpinnerBehavior = {
6548 listeners: {
6549 animationend: '__reset',
6550 webkitAnimationEnd: '__reset'
6551 },
6552 properties: {
6553 active: {
6554 type: Boolean,
6555 value: false,
6556 reflectToAttribute: true,
6557 observer: '__activeChanged'
6558 },
6559 alt: {
6560 type: String,
6561 value: 'loading',
6562 observer: '__altChanged'
6563 },
6564 __coolingDown: {
6565 type: Boolean,
6566 value: false
6567 }
6568 },
6569 __computeContainerClasses: function(active, coolingDown) {
6570 return [ active || coolingDown ? 'active' : '', coolingDown ? 'cooldown' : ' ' ].join(' ');
6571 },
6572 __activeChanged: function(active, old) {
6573 this.__setAriaHidden(!active);
6574 this.__coolingDown = !active && old;
6575 },
6576 __altChanged: function(alt) {
6577 if (alt === this.getPropertyInfo('alt').value) {
6578 this.alt = this.getAttribute('aria-label') || alt;
6579 } else {
6580 this.__setAriaHidden(alt === '');
6581 this.setAttribute('aria-label', alt);
6582 }
6583 },
6584 __setAriaHidden: function(hidden) {
6585 var attr = 'aria-hidden';
6586 if (hidden) {
6587 this.setAttribute(attr, 'true');
6588 } else {
6589 this.removeAttribute(attr);
6590 }
6591 },
6592 __reset: function() {
6593 this.active = false;
6594 this.__coolingDown = false;
6595 }
6596 };
6597
6598 Polymer({
6599 is: 'paper-spinner-lite',
6600 behaviors: [ Polymer.PaperSpinnerBehavior ]
6601 });
6602
6603 // Copyright 2016 The Chromium Authors. All rights reserved.
6547 // Use of this source code is governed by a BSD-style license that can be 6604 // Use of this source code is governed by a BSD-style license that can be
6548 // found in the LICENSE file. 6605 // found in the LICENSE file.
6549 var SearchField = Polymer({ 6606 var CrSearchFieldBehavior = {
6550 is: 'cr-search-field', 6607 properties: {
6608 label: {
6609 type: String,
6610 value: ''
6611 },
6612 clearLabel: {
6613 type: String,
6614 value: ''
6615 },
6616 showingSearch: {
6617 type: Boolean,
6618 value: false,
6619 notify: true,
6620 observer: 'showingSearchChanged_',
6621 reflectToAttribute: true
6622 },
6623 lastValue_: {
6624 type: String,
6625 value: ''
6626 }
6627 },
6628 getSearchInput: function() {},
6629 getValue: function() {
6630 return this.getSearchInput().value;
6631 },
6632 setValue: function(value) {
6633 this.getSearchInput().bindValue = value;
6634 this.onValueChanged_(value);
6635 },
6636 showAndFocus: function() {
6637 this.showingSearch = true;
6638 this.focus_();
6639 },
6640 focus_: function() {
6641 this.getSearchInput().focus();
6642 },
6643 onSearchTermSearch: function() {
6644 this.onValueChanged_(this.getValue());
6645 },
6646 onValueChanged_: function(newValue) {
6647 if (newValue == this.lastValue_) return;
6648 this.fire('search-changed', newValue);
6649 this.lastValue_ = newValue;
6650 },
6651 onSearchTermKeydown: function(e) {
6652 if (e.key == 'Escape') this.showingSearch = false;
6653 },
6654 showingSearchChanged_: function() {
6655 if (this.showingSearch) {
6656 this.focus_();
6657 return;
6658 }
6659 this.setValue('');
6660 this.getSearchInput().blur();
6661 }
6662 };
6663
6664 // Copyright 2016 The Chromium Authors. All rights reserved.
6665 // Use of this source code is governed by a BSD-style license that can be
6666 // found in the LICENSE file.
6667 Polymer({
6668 is: 'cr-toolbar-search-field',
6551 behaviors: [ CrSearchFieldBehavior ], 6669 behaviors: [ CrSearchFieldBehavior ],
6552 properties: { 6670 properties: {
6553 value_: String 6671 narrow: {
6672 type: Boolean,
6673 reflectToAttribute: true
6674 },
6675 label: String,
6676 clearLabel: String,
6677 spinnerActive: {
6678 type: Boolean,
6679 reflectToAttribute: true
6680 },
6681 hasSearchText_: Boolean
6682 },
6683 listeners: {
6684 tap: 'showSearch_',
6685 'searchInput.bind-value-changed': 'onBindValueChanged_'
6554 }, 6686 },
6555 getSearchInput: function() { 6687 getSearchInput: function() {
6556 return this.$.searchInput; 6688 return this.$.searchInput;
6557 }, 6689 },
6558 clearSearch_: function() { 6690 isSearchFocused: function() {
6559 this.setValue(''); 6691 return this.$.searchTerm.focused;
6560 this.getSearchInput().focus(); 6692 },
6561 }, 6693 computeIconTabIndex_: function(narrow) {
6562 toggleShowingSearch_: function() { 6694 return narrow ? 0 : -1;
6563 this.showingSearch = !this.showingSearch; 6695 },
6564 } 6696 isSpinnerShown_: function(spinnerActive, showingSearch) {
6565 }); 6697 return spinnerActive && showingSearch;
6566 6698 },
6699 onInputBlur_: function() {
6700 if (!this.hasSearchText_) this.showingSearch = false;
6701 },
6702 onBindValueChanged_: function() {
6703 var newValue = this.$.searchInput.bindValue;
6704 this.hasSearchText_ = newValue != '';
6705 if (newValue != '') this.showingSearch = true;
6706 },
6707 showSearch_: function(e) {
6708 if (e.target != this.$.clearSearch) this.showingSearch = true;
6709 },
6710 hideSearch_: function(e) {
6711 this.showingSearch = false;
6712 e.stopPropagation();
6713 }
6714 });
6715
6716 // Copyright 2016 The Chromium Authors. All rights reserved.
6717 // Use of this source code is governed by a BSD-style license that can be
6718 // found in the LICENSE file.
6719 Polymer({
6720 is: 'cr-toolbar',
6721 properties: {
6722 pageName: String,
6723 searchPrompt: String,
6724 clearLabel: String,
6725 menuLabel: String,
6726 spinnerActive: Boolean,
6727 showMenu: {
6728 type: Boolean,
6729 value: false
6730 },
6731 narrow_: {
6732 type: Boolean,
6733 reflectToAttribute: true
6734 },
6735 showingSearch_: {
6736 type: Boolean,
6737 reflectToAttribute: true
6738 }
6739 },
6740 getSearchField: function() {
6741 return this.$.search;
6742 },
6743 onMenuTap_: function(e) {
6744 this.fire('cr-menu-tap');
6745 }
6746 });
6747
6567 // Copyright 2015 The Chromium Authors. All rights reserved. 6748 // Copyright 2015 The Chromium Authors. All rights reserved.
6568 // Use of this source code is governed by a BSD-style license that can be 6749 // Use of this source code is governed by a BSD-style license that can be
6569 // found in the LICENSE file. 6750 // found in the LICENSE file.
6570 cr.define('downloads', function() { 6751 cr.define('downloads', function() {
6571 var Toolbar = Polymer({ 6752 var Toolbar = Polymer({
6572 is: 'downloads-toolbar', 6753 is: 'downloads-toolbar',
6573 properties: { 6754 properties: {
6574 downloadsShowing: { 6755 downloadsShowing: {
6575 reflectToAttribute: true, 6756 reflectToAttribute: true,
6576 type: Boolean, 6757 type: Boolean,
6577 value: false, 6758 value: false,
6578 observer: 'downloadsShowingChanged_' 6759 observer: 'downloadsShowingChanged_'
6760 },
6761 spinnerActive: {
6762 type: Boolean,
6763 notify: true
6579 } 6764 }
6580 }, 6765 },
6581 listeners: { 6766 listeners: {
6582 'paper-dropdown-close': 'onPaperDropdownClose_', 6767 'paper-dropdown-close': 'onPaperDropdownClose_',
6583 'paper-dropdown-open': 'onPaperDropdownOpen_' 6768 'paper-dropdown-open': 'onPaperDropdownOpen_'
6584 }, 6769 },
6585 canUndo: function() { 6770 canUndo: function() {
6586 return this.$['search-input'] != this.shadowRoot.activeElement; 6771 return !this.$.toolbar.getSearchField().isSearchFocused();
6587 }, 6772 },
6588 canClearAll: function() { 6773 canClearAll: function() {
6589 return !this.$['search-input'].getValue() && this.downloadsShowing; 6774 return !this.$.toolbar.getSearchField().getValue() && this.downloadsShowin g;
6590 }, 6775 },
6591 onFindCommand: function() { 6776 onFindCommand: function() {
6592 this.$['search-input'].showAndFocus(); 6777 this.$.toolbar.getSearchField().showAndFocus();
6593 }, 6778 },
6594 closeMoreActions_: function() { 6779 closeMoreActions_: function() {
6595 this.$.more.close(); 6780 this.$.more.close();
6596 }, 6781 },
6597 downloadsShowingChanged_: function() { 6782 downloadsShowingChanged_: function() {
6598 this.updateClearAll_(); 6783 this.updateClearAll_();
6599 }, 6784 },
6600 onClearAllTap_: function() { 6785 onClearAllTap_: function() {
6601 assert(this.canClearAll()); 6786 assert(this.canClearAll());
6602 downloads.ActionService.getInstance().clearAll(); 6787 downloads.ActionService.getInstance().clearAll();
6603 }, 6788 },
6604 onPaperDropdownClose_: function() { 6789 onPaperDropdownClose_: function() {
6605 window.removeEventListener('resize', assert(this.boundClose_)); 6790 window.removeEventListener('resize', assert(this.boundClose_));
6606 }, 6791 },
6607 onItemBlur_: function(e) { 6792 onItemBlur_: function(e) {
6608 var menu = this.$$('paper-menu'); 6793 var menu = this.$$('paper-menu');
6609 if (menu.items.indexOf(e.relatedTarget) >= 0) return; 6794 if (menu.items.indexOf(e.relatedTarget) >= 0) return;
6610 this.$.more.restoreFocusOnClose = false; 6795 this.$.more.restoreFocusOnClose = false;
6611 this.closeMoreActions_(); 6796 this.closeMoreActions_();
6612 this.$.more.restoreFocusOnClose = true; 6797 this.$.more.restoreFocusOnClose = true;
6613 }, 6798 },
6614 onPaperDropdownOpen_: function() { 6799 onPaperDropdownOpen_: function() {
6615 this.boundClose_ = this.boundClose_ || this.closeMoreActions_.bind(this); 6800 this.boundClose_ = this.boundClose_ || this.closeMoreActions_.bind(this);
6616 window.addEventListener('resize', this.boundClose_); 6801 window.addEventListener('resize', this.boundClose_);
6617 }, 6802 },
6618 onSearchChanged_: function(event) { 6803 onSearchChanged_: function(event) {
6619 downloads.ActionService.getInstance().search(event.detail); 6804 var actionService = downloads.ActionService.getInstance();
6805 actionService.search(event.detail);
6806 this.spinnerActive = actionService.isSearching();
6620 this.updateClearAll_(); 6807 this.updateClearAll_();
6621 }, 6808 },
6622 onOpenDownloadsFolderTap_: function() { 6809 onOpenDownloadsFolderTap_: function() {
6623 downloads.ActionService.getInstance().openDownloadsFolder(); 6810 downloads.ActionService.getInstance().openDownloadsFolder();
6624 }, 6811 },
6625 updateClearAll_: function() { 6812 updateClearAll_: function() {
6626 this.$$('#actions .clear-all').hidden = !this.canClearAll();
6627 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); 6813 this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
6628 } 6814 }
6629 }); 6815 });
6630 return { 6816 return {
6631 Toolbar: Toolbar 6817 Toolbar: Toolbar
6632 }; 6818 };
6633 }); 6819 });
6634 6820
6635 // Copyright 2015 The Chromium Authors. All rights reserved. 6821 // Copyright 2015 The Chromium Authors. All rights reserved.
6636 // Use of this source code is governed by a BSD-style license that can be 6822 // Use of this source code is governed by a BSD-style license that can be
6637 // found in the LICENSE file. 6823 // found in the LICENSE file.
6638 cr.define('downloads', function() { 6824 cr.define('downloads', function() {
6639 var Manager = Polymer({ 6825 var Manager = Polymer({
6640 is: 'downloads-manager', 6826 is: 'downloads-manager',
6641 properties: { 6827 properties: {
6642 hasDownloads_: { 6828 hasDownloads_: {
6643 observer: 'hasDownloadsChanged_', 6829 observer: 'hasDownloadsChanged_',
6644 type: Boolean 6830 type: Boolean
6645 }, 6831 },
6646 items_: { 6832 items_: {
6647 type: Array, 6833 type: Array,
6648 value: function() { 6834 value: function() {
6649 return []; 6835 return [];
6650 } 6836 }
6837 },
6838 spinnerActive_: {
6839 type: Boolean,
6840 notify: true
6651 } 6841 }
6652 }, 6842 },
6653 hostAttributes: { 6843 hostAttributes: {
6654 loading: true 6844 loading: true
6655 }, 6845 },
6656 listeners: { 6846 listeners: {
6657 'downloads-list.scroll': 'onListScroll_' 6847 'downloads-list.scroll': 'onListScroll_'
6658 }, 6848 },
6659 observers: [ 'itemsChanged_(items_.*)' ], 6849 observers: [ 'itemsChanged_(items_.*)' ],
6660 clearAll_: function() { 6850 clearAll_: function() {
6661 this.set('items_', []); 6851 this.set('items_', []);
6662 }, 6852 },
6663 hasDownloadsChanged_: function() { 6853 hasDownloadsChanged_: function() {
6664 if (loadTimeData.getBoolean('allowDeletingHistory')) this.$.toolbar.downlo adsShowing = this.hasDownloads_; 6854 if (loadTimeData.getBoolean('allowDeletingHistory')) this.$.toolbar.downlo adsShowing = this.hasDownloads_;
6665 if (this.hasDownloads_) { 6855 if (this.hasDownloads_) {
6666 this.$['downloads-list'].fire('iron-resize'); 6856 this.$['downloads-list'].fire('iron-resize');
6667 } else { 6857 } else {
6668 var isSearching = downloads.ActionService.getInstance().isSearching(); 6858 var isSearching = downloads.ActionService.getInstance().isSearching();
6669 var messageToShow = isSearching ? 'noSearchResults' : 'noDownloads'; 6859 var messageToShow = isSearching ? 'noSearchResults' : 'noDownloads';
6670 this.$['no-downloads'].querySelector('span').textContent = loadTimeData. getString(messageToShow); 6860 this.$['no-downloads'].querySelector('span').textContent = loadTimeData. getString(messageToShow);
6671 } 6861 }
6672 }, 6862 },
6673 insertItems_: function(index, list) { 6863 insertItems_: function(index, list) {
6674 this.splice.apply(this, [ 'items_', index, 0 ].concat(list)); 6864 this.splice.apply(this, [ 'items_', index, 0 ].concat(list));
6675 this.updateHideDates_(index, index + list.length); 6865 this.updateHideDates_(index, index + list.length);
6676 this.removeAttribute('loading'); 6866 this.removeAttribute('loading');
6867 this.spinnerActive_ = false;
6677 }, 6868 },
6678 itemsChanged_: function() { 6869 itemsChanged_: function() {
6679 this.hasDownloads_ = this.items_.length > 0; 6870 this.hasDownloads_ = this.items_.length > 0;
6680 }, 6871 },
6681 onCanExecute_: function(e) { 6872 onCanExecute_: function(e) {
6682 e = e; 6873 e = e;
6683 switch (e.command.id) { 6874 switch (e.command.id) {
6684 case 'undo-command': 6875 case 'undo-command':
6685 e.canExecute = this.$.toolbar.canUndo(); 6876 e.canExecute = this.$.toolbar.canUndo();
6686 break; 6877 break;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6749 }; 6940 };
6750 return { 6941 return {
6751 Manager: Manager 6942 Manager: Manager
6752 }; 6943 };
6753 }); 6944 });
6754 6945
6755 // Copyright 2015 The Chromium Authors. All rights reserved. 6946 // Copyright 2015 The Chromium Authors. All rights reserved.
6756 // Use of this source code is governed by a BSD-style license that can be 6947 // Use of this source code is governed by a BSD-style license that can be
6757 // found in the LICENSE file. 6948 // found in the LICENSE file.
6758 window.addEventListener('load', downloads.Manager.onLoad); 6949 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_downloads/compiled_resources2.gyp ('k') | chrome/browser/resources/md_downloads/manager.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698