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

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 16018008: Files.app: Added an Esc key handler to the search box. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * This variable is checked in SelectFileDialogExtensionBrowserTest. 8 * This variable is checked in SelectFileDialogExtensionBrowserTest.
9 * @type {number} 9 * @type {number}
10 */ 10 */
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 if (loadTimeData.getBoolean('ASH')) 1042 if (loadTimeData.getBoolean('ASH'))
1043 this.dialogDom_.setAttribute('ash', 'true'); 1043 this.dialogDom_.setAttribute('ash', 'true');
1044 1044
1045 this.filePopup_ = null; 1045 this.filePopup_ = null;
1046 1046
1047 this.searchBoxWrapper_ = 1047 this.searchBoxWrapper_ =
1048 this.dialogDom_.querySelector('.search-box-wrapper'); 1048 this.dialogDom_.querySelector('.search-box-wrapper');
1049 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); 1049 this.searchBox_ = this.dialogDom_.querySelector('#search-box');
1050 this.searchBox_.addEventListener( 1050 this.searchBox_.addEventListener(
1051 'input', this.onSearchBoxUpdate_.bind(this)); 1051 'input', this.onSearchBoxUpdate_.bind(this));
1052 this.searchBox_.addEventListener(
1053 'keydown', this.onSearchBoxKeyDown_.bind(this));
1052 this.searchTextMeasure_ = new TextMeasure(this.searchBox_); 1054 this.searchTextMeasure_ = new TextMeasure(this.searchBox_);
1053 if (util.platform.newUI()) { 1055 if (util.platform.newUI()) {
1054 this.searchIcon_ = this.dialogDom_.querySelector('#search-icon'); 1056 this.searchIcon_ = this.dialogDom_.querySelector('#search-icon');
1055 this.searchIcon_.addEventListener( 1057 this.searchIcon_.addEventListener(
1056 'click', 1058 'click',
1057 function() { this.searchBox_.focus(); }.bind(this)); 1059 function() { this.searchBox_.focus(); }.bind(this));
1058 this.searchClearButton_ = 1060 this.searchClearButton_ =
1059 this.dialogDom_.querySelector('#search-clear-button'); 1061 this.dialogDom_.querySelector('#search-clear-button');
1060 this.searchClearButton_.addEventListener( 1062 this.searchClearButton_.addEventListener(
1061 'click', 1063 'click',
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 event.target.removeAttribute('checked'); 3493 event.target.removeAttribute('checked');
3492 3494
3493 var changeInfo = {}; 3495 var changeInfo = {};
3494 changeInfo[pref] = inverted ? !newValue : newValue; 3496 changeInfo[pref] = inverted ? !newValue : newValue;
3495 chrome.fileBrowserPrivate.setPreferences(changeInfo); 3497 chrome.fileBrowserPrivate.setPreferences(changeInfo);
3496 }; 3498 };
3497 3499
3498 /** 3500 /**
3499 * Invoked when the search box is changed. 3501 * Invoked when the search box is changed.
3500 * 3502 *
3501 * @param {Event} event The 'changed' event. 3503 * @param {Event} event The changed event.
3502 * @private 3504 * @private
3503 */ 3505 */
3504 FileManager.prototype.onSearchBoxUpdate_ = function(event) { 3506 FileManager.prototype.onSearchBoxUpdate_ = function(event) {
3505 var searchString = this.searchBox_.value; 3507 var searchString = this.searchBox_.value;
3506 3508
3507 this.updateSearchBoxStyles_(); 3509 this.updateSearchBoxStyles_();
3508 if (this.isOnDrive()) { 3510 if (this.isOnDrive()) {
3509 // When the search text is changed, finishes the search and showes back 3511 // When the search text is changed, finishes the search and showes back
3510 // the last directory by passing an empty string to 3512 // the last directory by passing an empty string to
3511 // {@code DirectoryModel.search()}. 3513 // {@code DirectoryModel.search()}.
3512 if (this.directoryModel_.isSearching() && 3514 if (this.directoryModel_.isSearching() &&
3513 this.lastSearchQuery_ != searchString) { 3515 this.lastSearchQuery_ != searchString) {
3514 this.doSearch(''); 3516 this.doSearch('');
3515 } 3517 }
3516 3518
3517 // On drive, incremental search is not invoked since we have an auto- 3519 // On drive, incremental search is not invoked since we have an auto-
3518 // complete suggestion instead. 3520 // complete suggestion instead.
3519 return; 3521 return;
3520 } 3522 }
3521 3523
3522 this.search_(searchString); 3524 this.search_(searchString);
3523 }; 3525 };
3524 3526
3525 /** 3527 /**
3528 * Handles special keys such as Escape on the search box.
3529 *
3530 * @param {Event} event The keydown event.
3531 * @private
3532 */
3533 FileManager.prototype.onSearchBoxKeyDown_ = function(event) {
3534 // Handle only Esc key now.
3535 if (event.keyCode != 27) return;
3536 if (this.searchBox_.value) return;
3537 var currentList = this.listType_ == FileManager.ListType.DETAIL ?
3538 this.table_.list : this.grid_;
3539 currentList.focus();
3540 if (currentList.dataModel.length != 0 &&
3541 currentList.selectionModel.selectedIndex == -1) {
3542 currentList.selectionModel.selectedIndex = 0;
3543 }
3544 };
3545
3546 /**
3526 * Updates search box's CSS classes. 3547 * Updates search box's CSS classes.
3527 * These classes are refered from CSS. 3548 * These classes are refered from CSS.
3528 * 3549 *
3529 * @private 3550 * @private
3530 */ 3551 */
3531 FileManager.prototype.updateSearchBoxStyles_ = function() { 3552 FileManager.prototype.updateSearchBoxStyles_ = function() {
3532 if (!util.platform.newUI()) 3553 if (!util.platform.newUI())
3533 return; 3554 return;
3534 var TEXT_BOX_PADDING = 16; // in px. 3555 var TEXT_BOX_PADDING = 16; // in px.
3535 this.searchBoxWrapper_.classList.toggle('has-text', 3556 this.searchBoxWrapper_.classList.toggle('has-text',
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
3917 * Set the flag expressing whether the ctrl key is pressed or not. 3938 * Set the flag expressing whether the ctrl key is pressed or not.
3918 * @param {boolean} flag New value of the flag 3939 * @param {boolean} flag New value of the flag
3919 * @private 3940 * @private
3920 */ 3941 */
3921 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { 3942 FileManager.prototype.setCtrlKeyPressed_ = function(flag) {
3922 this.ctrlKeyPressed_ = flag; 3943 this.ctrlKeyPressed_ = flag;
3923 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange(); 3944 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange();
3924 this.document_.querySelector('#drive-reload').canExecuteChange(); 3945 this.document_.querySelector('#drive-reload').canExecuteChange();
3925 }; 3946 };
3926 })(); 3947 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698