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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 */ | 71 */ |
72 var DialogType = { | 72 var DialogType = { |
73 SELECT_FOLDER: 'folder', | 73 SELECT_FOLDER: 'folder', |
74 SELECT_SAVEAS_FILE: 'saveas-file', | 74 SELECT_SAVEAS_FILE: 'saveas-file', |
75 SELECT_OPEN_FILE: 'open-file', | 75 SELECT_OPEN_FILE: 'open-file', |
76 SELECT_OPEN_MULTI_FILE: 'open-multi-file', | 76 SELECT_OPEN_MULTI_FILE: 'open-multi-file', |
77 FULL_PAGE: 'full-page' | 77 FULL_PAGE: 'full-page' |
78 }; | 78 }; |
79 | 79 |
80 /** | 80 /** |
| 81 * TextMeasure constructor. |
| 82 * |
| 83 * TextMeasure is a measure for text that returns the width of text. This |
| 84 * class has a dummy span element. When measuring the width of text, it sets |
| 85 * the text to the element and obtains the element's size by |
| 86 * getBoundingClientRect. |
| 87 * |
| 88 * @constructor |
| 89 * @param {HTMLElement} element Element that has styles of measured text. The |
| 90 * width of text is mesures like as it is rendered in this element. |
| 91 */ |
| 92 var TextMeasure = function(element) { |
| 93 var doc = element.ownerDocument; |
| 94 this.dummySpan_ = doc.createElement('span'); |
| 95 this.dummySpan_ = doc.getElementsByTagName('body')[0]. |
| 96 appendChild(this.dummySpan_); |
| 97 this.dummySpan_.style.position = 'absolute'; |
| 98 this.dummySpan_.style.visibility = 'hidden'; |
| 99 var styles = window.getComputedStyle(element, ''); |
| 100 var stylesToBeCopied = [ |
| 101 'fontSize', |
| 102 'fontStyle', |
| 103 'fontWeight', |
| 104 'fontFamily', |
| 105 'letterSpacing' |
| 106 ]; |
| 107 for (var i = 0; i < stylesToBeCopied.length; i++) { |
| 108 this.dummySpan_.style[stylesToBeCopied[i]] = styles[stylesToBeCopied[i]]; |
| 109 } |
| 110 }; |
| 111 |
| 112 /** |
| 113 * Measures the widht of text. |
| 114 * |
| 115 * @param {string} text Text that is measured the width. |
| 116 * @return {number} Width of the specified text. |
| 117 */ |
| 118 TextMeasure.prototype.getWidth = function(text) { |
| 119 this.dummySpan_.innerText = text; |
| 120 var rect = this.dummySpan_.getBoundingClientRect(); |
| 121 return rect ? rect.width : 0; |
| 122 }; |
| 123 |
| 124 /** |
81 * @param {string} type Dialog type. | 125 * @param {string} type Dialog type. |
82 * @return {boolean} Whether the type is modal. | 126 * @return {boolean} Whether the type is modal. |
83 */ | 127 */ |
84 DialogType.isModal = function(type) { | 128 DialogType.isModal = function(type) { |
85 return type == DialogType.SELECT_FOLDER || | 129 return type == DialogType.SELECT_FOLDER || |
86 type == DialogType.SELECT_SAVEAS_FILE || | 130 type == DialogType.SELECT_SAVEAS_FILE || |
87 type == DialogType.SELECT_OPEN_FILE || | 131 type == DialogType.SELECT_OPEN_FILE || |
88 type == DialogType.SELECT_OPEN_MULTI_FILE; | 132 type == DialogType.SELECT_OPEN_MULTI_FILE; |
89 }; | 133 }; |
90 | 134 |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 if (loadTimeData.getBoolean('ASH')) | 1042 if (loadTimeData.getBoolean('ASH')) |
999 this.dialogDom_.setAttribute('ash', 'true'); | 1043 this.dialogDom_.setAttribute('ash', 'true'); |
1000 | 1044 |
1001 this.filePopup_ = null; | 1045 this.filePopup_ = null; |
1002 | 1046 |
1003 this.searchBoxWrapper_ = | 1047 this.searchBoxWrapper_ = |
1004 this.dialogDom_.querySelector('.search-box-wrapper'); | 1048 this.dialogDom_.querySelector('.search-box-wrapper'); |
1005 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); | 1049 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); |
1006 this.searchBox_.addEventListener( | 1050 this.searchBox_.addEventListener( |
1007 'input', this.onSearchBoxUpdate_.bind(this)); | 1051 'input', this.onSearchBoxUpdate_.bind(this)); |
| 1052 this.searchTextMeasure_ = new TextMeasure(this.searchBox_); |
| 1053 if (util.platform.newUI()) { |
| 1054 this.searchIcon_ = this.dialogDom_.querySelector('#search-icon'); |
| 1055 this.searchIcon_.addEventListener( |
| 1056 'click', |
| 1057 function() { this.searchBox_.focus(); }.bind(this)); |
| 1058 this.searchClearButton_ = |
| 1059 this.dialogDom_.querySelector('#search-clear-button'); |
| 1060 this.searchClearButton_.addEventListener( |
| 1061 'click', |
| 1062 function() { |
| 1063 this.searchBox_.value = ''; |
| 1064 this.onSearchBoxUpdate_(); |
| 1065 }.bind(this)); |
| 1066 } |
1008 this.lastSearchQuery_ = ''; | 1067 this.lastSearchQuery_ = ''; |
1009 | 1068 |
1010 var autocompleteList = new cr.ui.AutocompleteList(); | 1069 var autocompleteList = new cr.ui.AutocompleteList(); |
1011 autocompleteList.id = 'autocomplete-list'; | 1070 autocompleteList.id = 'autocomplete-list'; |
1012 autocompleteList.autoExpands = true; | 1071 autocompleteList.autoExpands = true; |
1013 autocompleteList.requestSuggestions = | 1072 autocompleteList.requestSuggestions = |
1014 this.requestAutocompleteSuggestions_.bind(this); | 1073 this.requestAutocompleteSuggestions_.bind(this); |
1015 // function(item) {}.bind(this) does not work here, as it's a constructor. | 1074 // function(item) {}.bind(this) does not work here, as it's a constructor. |
1016 var self = this; | 1075 var self = this; |
1017 autocompleteList.itemConstructor = function(item) { | 1076 autocompleteList.itemConstructor = function(item) { |
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 path.substring(rootPath.length); | 2421 path.substring(rootPath.length); |
2363 }; | 2422 }; |
2364 | 2423 |
2365 /** | 2424 /** |
2366 * Updates search box value when directory gets changed. | 2425 * Updates search box value when directory gets changed. |
2367 * @private | 2426 * @private |
2368 */ | 2427 */ |
2369 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { | 2428 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { |
2370 if (!this.searchBox_.disabled) { | 2429 if (!this.searchBox_.disabled) { |
2371 this.searchBox_.value = ''; | 2430 this.searchBox_.value = ''; |
2372 this.updateSearchBoxClass_(); | 2431 this.updateSearchBoxStyles_(); |
2373 } | 2432 } |
2374 }; | 2433 }; |
2375 | 2434 |
2376 /** | 2435 /** |
2377 * Update the gear menu. | 2436 * Update the gear menu. |
2378 * @private | 2437 * @private |
2379 */ | 2438 */ |
2380 FileManager.prototype.updateGearMenu_ = function() { | 2439 FileManager.prototype.updateGearMenu_ = function() { |
2381 var hideItemsForDrive = !this.isOnDrive(); | 2440 var hideItemsForDrive = !this.isOnDrive(); |
2382 this.syncButton.hidden = hideItemsForDrive; | 2441 this.syncButton.hidden = hideItemsForDrive; |
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3438 | 3497 |
3439 /** | 3498 /** |
3440 * Invoked when the search box is changed. | 3499 * Invoked when the search box is changed. |
3441 * | 3500 * |
3442 * @param {Event} event The 'changed' event. | 3501 * @param {Event} event The 'changed' event. |
3443 * @private | 3502 * @private |
3444 */ | 3503 */ |
3445 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 3504 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
3446 var searchString = this.searchBox_.value; | 3505 var searchString = this.searchBox_.value; |
3447 | 3506 |
3448 this.updateSearchBoxClass_(); | 3507 this.updateSearchBoxStyles_(); |
3449 if (this.isOnDrive()) { | 3508 if (this.isOnDrive()) { |
3450 // When the search text is changed, finishes the search and showes back | 3509 // When the search text is changed, finishes the search and showes back |
3451 // the last directory by passing an empty string to | 3510 // the last directory by passing an empty string to |
3452 // {@code DirectoryModel.search()}. | 3511 // {@code DirectoryModel.search()}. |
3453 if (this.directoryModel_.isSearching() && | 3512 if (this.directoryModel_.isSearching() && |
3454 this.lastSearchQuery_ != searchString) { | 3513 this.lastSearchQuery_ != searchString) { |
3455 this.doSearch(''); | 3514 this.doSearch(''); |
3456 } | 3515 } |
3457 | 3516 |
3458 // On drive, incremental search is not invoked since we have an auto- | 3517 // On drive, incremental search is not invoked since we have an auto- |
3459 // complete suggestion instead. | 3518 // complete suggestion instead. |
3460 return; | 3519 return; |
3461 } | 3520 } |
3462 | 3521 |
3463 this.search_(searchString); | 3522 this.search_(searchString); |
3464 }; | 3523 }; |
3465 | 3524 |
3466 /** | 3525 /** |
3467 * Updates search box's CSS classes. | 3526 * Updates search box's CSS classes. |
3468 * These classes are refered from CSS. | 3527 * These classes are refered from CSS. |
3469 * | 3528 * |
3470 * @private | 3529 * @private |
3471 */ | 3530 */ |
3472 FileManager.prototype.updateSearchBoxClass_ = function() { | 3531 FileManager.prototype.updateSearchBoxStyles_ = function() { |
3473 this.searchBox_.classList.toggle('has-text', !!this.searchBox_.value); | 3532 if (!util.platform.newUI()) |
| 3533 return; |
| 3534 var TEXT_BOX_PADDING = 16; // in px. |
| 3535 this.searchBoxWrapper_.classList.toggle('has-text', |
| 3536 !!this.searchBox_.value); |
| 3537 var width = this.searchTextMeasure_.getWidth(this.searchBox_.value) + |
| 3538 TEXT_BOX_PADDING; |
| 3539 this.searchBox_.style.width = width + 'px'; |
3474 }; | 3540 }; |
3475 | 3541 |
3476 /** | 3542 /** |
3477 * Search files and update the list with the search result. | 3543 * Search files and update the list with the search result. |
3478 * | 3544 * |
3479 * @param {string} searchString String to be searched with. | 3545 * @param {string} searchString String to be searched with. |
3480 * @private | 3546 * @private |
3481 */ | 3547 */ |
3482 FileManager.prototype.search_ = function(searchString) { | 3548 FileManager.prototype.search_ = function(searchString) { |
3483 var noResultsDiv = this.document_.getElementById('no-search-results'); | 3549 var noResultsDiv = this.document_.getElementById('no-search-results'); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3851 * Set the flag expressing whether the ctrl key is pressed or not. | 3917 * Set the flag expressing whether the ctrl key is pressed or not. |
3852 * @param {boolean} flag New value of the flag | 3918 * @param {boolean} flag New value of the flag |
3853 * @private | 3919 * @private |
3854 */ | 3920 */ |
3855 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3921 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
3856 this.ctrlKeyPressed_ = flag; | 3922 this.ctrlKeyPressed_ = flag; |
3857 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange(); | 3923 this.document_.querySelector('#drive-clear-local-cache').canExecuteChange(); |
3858 this.document_.querySelector('#drive-reload').canExecuteChange(); | 3924 this.document_.querySelector('#drive-reload').canExecuteChange(); |
3859 }; | 3925 }; |
3860 })(); | 3926 })(); |
OLD | NEW |