Chromium Code Reviews| 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; | |
|
yoshiki
2013/05/24 09:56:16
Add the comment '// in px.'
hirono
2013/05/24 10:36:43
Done.
| |
| 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 /** | |
| 3859 * TextMeasure constructor. | |
| 3860 * | |
| 3861 * TextMeasure is a measure for text that returns the width of text. | |
|
yoshiki
2013/05/24 09:56:16
I think this approach (creating dummySpan and meas
hirono
2013/05/24 10:36:43
Done.
| |
| 3862 * | |
| 3863 * @param {HTMLElement} element Element that has styles of measured text. The | |
| 3864 * width of text is mesures like as it is rendered in this element. | |
| 3865 */ | |
| 3866 var TextMeasure = function(element) { | |
| 3867 this.dummySpan = document.createElement('span'); | |
|
yoshiki
2013/05/24 09:56:16
This is a private variable, so please add an under
hirono
2013/05/24 10:36:43
Done.
| |
| 3868 this.dummySpan = document.getElementsByTagName('body')[0] | |
|
yoshiki
2013/05/24 09:56:16
Pass FileManager.dialogDom_ or (dialogDom_.ownerDo
hirono
2013/05/24 10:36:43
How about using element.document?
|element| is alr
| |
| 3869 .appendChild(this.dummySpan); | |
| 3870 this.dummySpan.style.position = 'absolute'; | |
| 3871 this.dummySpan.style.visibility = 'hidden'; | |
| 3872 var styles = getComputedStyle(element, ''); | |
|
yoshiki
2013/05/24 09:58:33
window.getComputedStyle()
hirono
2013/05/24 10:36:43
Done.
| |
| 3873 var copiedStyles = ['fontSize', | |
|
yoshiki
2013/05/24 09:56:16
"attributesToBeCopied" (or something like it) is b
hirono
2013/05/24 10:36:43
attributes looks like HTML attributes. So 'stylesT
| |
| 3874 'fontStyle', | |
| 3875 'fontWeight', | |
| 3876 'fontFamily', | |
| 3877 'letterSpacing']; | |
| 3878 for (var i = 0; i < copiedStyles.length; i++) { | |
| 3879 console.log(copiedStyles[i] + ': ' + styles[copiedStyles[i]]); | |
|
yoshiki
2013/05/24 09:56:16
remove debug log
hirono
2013/05/24 10:36:43
Done.
| |
| 3880 this.dummySpan.style[copiedStyles[i]] = styles[copiedStyles[i]]; | |
| 3881 } | |
| 3882 }; | |
| 3883 | |
| 3884 TextMeasure.prototype.getWidth = function(text) { | |
| 3885 this.dummySpan.innerText = text; | |
| 3886 return this.dummySpan.getBoundingClientRect().width; | |
|
yoshiki
2013/05/24 09:56:16
getBoundingClientRect() returns null if the elemen
hirono
2013/05/24 10:36:43
Done.
| |
| 3887 }; | |
| 3888 | |
| 3835 })(); | 3889 })(); |
| OLD | NEW |