OLD | NEW |
---|---|
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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 if (loadTimeData.getBoolean('ASH')) | 986 if (loadTimeData.getBoolean('ASH')) |
987 this.dialogDom_.setAttribute('ash', 'true'); | 987 this.dialogDom_.setAttribute('ash', 'true'); |
988 | 988 |
989 this.filePopup_ = null; | 989 this.filePopup_ = null; |
990 | 990 |
991 this.searchBoxWrapper_ = | 991 this.searchBoxWrapper_ = |
992 this.dialogDom_.querySelector('.search-box-wrapper'); | 992 this.dialogDom_.querySelector('.search-box-wrapper'); |
993 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); | 993 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); |
994 this.searchBox_.addEventListener( | 994 this.searchBox_.addEventListener( |
995 'input', this.onSearchBoxUpdate_.bind(this)); | 995 'input', this.onSearchBoxUpdate_.bind(this)); |
996 this.searchTextMeasure_ = new TextMeasure(this.searchBox_); | |
997 if (util.platform.newUI()) { | |
998 this.searchIcon_ = this.dialogDom_.querySelector('#search-icon'); | |
999 this.searchIcon_.addEventListener( | |
1000 'click', | |
1001 function() { this.searchBox_.focus(); }.bind(this)); | |
1002 this.searchClearButton_ = | |
1003 this.dialogDom_.querySelector('#search-clear-button'); | |
1004 this.searchClearButton_.addEventListener( | |
1005 'click', | |
1006 function() { | |
1007 this.searchBox_.value = ''; | |
1008 this.onSearchBoxUpdate_(); | |
1009 }.bind(this)); | |
1010 } | |
996 this.lastSearchQuery_ = ''; | 1011 this.lastSearchQuery_ = ''; |
997 | 1012 |
998 var autocompleteList = new cr.ui.AutocompleteList(); | 1013 var autocompleteList = new cr.ui.AutocompleteList(); |
999 autocompleteList.id = 'autocomplete-list'; | 1014 autocompleteList.id = 'autocomplete-list'; |
1000 autocompleteList.autoExpands = true; | 1015 autocompleteList.autoExpands = true; |
1001 autocompleteList.requestSuggestions = | 1016 autocompleteList.requestSuggestions = |
1002 this.requestAutocompleteSuggestions_.bind(this); | 1017 this.requestAutocompleteSuggestions_.bind(this); |
1003 // function(item) {}.bind(this) does not work here, as it's a constructor. | 1018 // function(item) {}.bind(this) does not work here, as it's a constructor. |
1004 var self = this; | 1019 var self = this; |
1005 autocompleteList.itemConstructor = function(item) { | 1020 autocompleteList.itemConstructor = function(item) { |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2337 path.substring(rootPath.length); | 2352 path.substring(rootPath.length); |
2338 }; | 2353 }; |
2339 | 2354 |
2340 /** | 2355 /** |
2341 * Updates search box value when directory gets changed. | 2356 * Updates search box value when directory gets changed. |
2342 * @private | 2357 * @private |
2343 */ | 2358 */ |
2344 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { | 2359 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { |
2345 if (!this.searchBox_.disabled) { | 2360 if (!this.searchBox_.disabled) { |
2346 this.searchBox_.value = ''; | 2361 this.searchBox_.value = ''; |
2347 this.updateSearchBoxClass_(); | 2362 this.updateSearchBoxStyles_(); |
2348 } | 2363 } |
2349 }; | 2364 }; |
2350 | 2365 |
2351 /** | 2366 /** |
2352 * Update the gear menu. | 2367 * Update the gear menu. |
2353 * @private | 2368 * @private |
2354 */ | 2369 */ |
2355 FileManager.prototype.updateGearMenu_ = function() { | 2370 FileManager.prototype.updateGearMenu_ = function() { |
2356 var hideItemsForDrive = !this.isOnDrive(); | 2371 var hideItemsForDrive = !this.isOnDrive(); |
2357 this.syncButton.hidden = hideItemsForDrive; | 2372 this.syncButton.hidden = hideItemsForDrive; |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3413 | 3428 |
3414 /** | 3429 /** |
3415 * Invoked when the search box is changed. | 3430 * Invoked when the search box is changed. |
3416 * | 3431 * |
3417 * @param {Event} event The 'changed' event. | 3432 * @param {Event} event The 'changed' event. |
3418 * @private | 3433 * @private |
3419 */ | 3434 */ |
3420 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 3435 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
3421 var searchString = this.searchBox_.value; | 3436 var searchString = this.searchBox_.value; |
3422 | 3437 |
3423 this.updateSearchBoxClass_(); | 3438 this.updateSearchBoxStyles_(); |
3424 if (this.isOnDrive()) { | 3439 if (this.isOnDrive()) { |
3425 // When the search text is changed, finishes the search and showes back | 3440 // When the search text is changed, finishes the search and showes back |
3426 // the last directory by passing an empty string to | 3441 // the last directory by passing an empty string to |
3427 // {@code DirectoryModel.search()}. | 3442 // {@code DirectoryModel.search()}. |
3428 if (this.directoryModel_.isSearching() && | 3443 if (this.directoryModel_.isSearching() && |
3429 this.lastSearchQuery_ != searchString) { | 3444 this.lastSearchQuery_ != searchString) { |
3430 this.doSearch(''); | 3445 this.doSearch(''); |
3431 } | 3446 } |
3432 | 3447 |
3433 // On drive, incremental search is not invoked since we have an auto- | 3448 // On drive, incremental search is not invoked since we have an auto- |
3434 // complete suggestion instead. | 3449 // complete suggestion instead. |
3435 return; | 3450 return; |
3436 } | 3451 } |
3437 | 3452 |
3438 this.search_(searchString); | 3453 this.search_(searchString); |
3439 }; | 3454 }; |
3440 | 3455 |
3441 /** | 3456 /** |
3442 * Updates search box's CSS classes. | 3457 * Updates search box's CSS classes. |
3443 * These classes are refered from CSS. | 3458 * These classes are refered from CSS. |
3444 * | 3459 * |
3445 * @private | 3460 * @private |
3446 */ | 3461 */ |
3447 FileManager.prototype.updateSearchBoxClass_ = function() { | 3462 FileManager.prototype.updateSearchBoxStyles_ = function() { |
3448 this.searchBox_.classList.toggle('has-text', !!this.searchBox_.value); | 3463 if (!util.platform.newUI()) |
3464 return; | |
3465 var TEXT_BOX_PADDING = 16; // in px. | |
3466 this.searchBoxWrapper_.classList.toggle('has-text', | |
3467 !!this.searchBox_.value); | |
3468 var width = this.searchTextMeasure_.getWidth(this.searchBox_.value) + | |
3469 TEXT_BOX_PADDING; | |
3470 this.searchBox_.style.width = width + 'px'; | |
3449 }; | 3471 }; |
3450 | 3472 |
3451 /** | 3473 /** |
3452 * Search files and update the list with the search result. | 3474 * Search files and update the list with the search result. |
3453 * | 3475 * |
3454 * @param {string} searchString String to be searched with. | 3476 * @param {string} searchString String to be searched with. |
3455 * @private | 3477 * @private |
3456 */ | 3478 */ |
3457 FileManager.prototype.search_ = function(searchString) { | 3479 FileManager.prototype.search_ = function(searchString) { |
3458 var noResultsDiv = this.document_.getElementById('no-search-results'); | 3480 var noResultsDiv = this.document_.getElementById('no-search-results'); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3825 /** | 3847 /** |
3826 * Set the flag expressing whether the ctrl key is pressed or not. | 3848 * Set the flag expressing whether the ctrl key is pressed or not. |
3827 * @param {boolean} flag New value of the flag | 3849 * @param {boolean} flag New value of the flag |
3828 * @private | 3850 * @private |
3829 */ | 3851 */ |
3830 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3852 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
3831 this.ctrlKeyPressed_ = flag; | 3853 this.ctrlKeyPressed_ = flag; |
3832 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange(); | 3854 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange(); |
3833 this.document_.querySelector('#drive-reload').canExecuteChange(); | 3855 this.document_.querySelector('#drive-reload').canExecuteChange(); |
3834 }; | 3856 }; |
3857 | |
3858 /** | |
yoshiki
2013/05/24 14:49:54
nit: Please move this class to the first part of t
hirono
2013/05/27 01:58:28
Done.
| |
3859 * TextMeasure constructor. | |
3860 * | |
3861 * TextMeasure is a measure for text that returns the width of text. This | |
3862 * class has a dummy span element. When measuring the width of text, it sets | |
3863 * the text to the element and obtains the element's size by | |
3864 * getBoundingClientRect. | |
3865 * | |
3866 * @param {HTMLElement} element Element that has styles of measured text. The | |
3867 * width of text is mesures like as it is rendered in this element. | |
yoshiki
2013/05/24 14:49:54
nit: add '@constructor'
hirono
2013/05/27 01:58:28
Done.
| |
3868 */ | |
3869 var TextMeasure = function(element) { | |
3870 var doc = element.ownerDocument; | |
3871 this.dummySpan_ = doc.createElement('span'); | |
3872 this.dummySpan_ = doc.getElementsByTagName('body')[0] | |
3873 .appendChild(this.dummySpan_); | |
yoshiki
2013/05/24 14:49:54
nit: a dot should be at the last of the previous l
hirono
2013/05/27 01:58:28
Done.
| |
3874 this.dummySpan_.style.position = 'absolute'; | |
3875 this.dummySpan_.style.visibility = 'hidden'; | |
3876 var styles = window.getComputedStyle(element, ''); | |
3877 var stylesToBeCopied = ['fontSize', | |
3878 'fontStyle', | |
3879 'fontWeight', | |
3880 'fontFamily', | |
3881 'letterSpacing']; | |
3882 for (var i = 0; i < stylesToBeCopied.length; i++) { | |
3883 this.dummySpan_.style[stylesToBeCopied[i]] = styles[stylesToBeCopied[i]]; | |
3884 } | |
3885 }; | |
3886 | |
3887 /** | |
3888 * Measures the widht of text. | |
3889 * | |
3890 * @param {string} text Text that is measured the width. | |
3891 */ | |
3892 TextMeasure.prototype.getWidth = function(text) { | |
3893 this.dummySpan_.innerText = text; | |
3894 var rect = this.dummySpan_.getBoundingClientRect(); | |
3895 return rect ? rect.width : 0; | |
3896 }; | |
3897 | |
3835 })(); | 3898 })(); |
OLD | NEW |