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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 var DialogType = { | 63 var DialogType = { |
64 SELECT_FOLDER: 'folder', | 64 SELECT_FOLDER: 'folder', |
65 SELECT_UPLOAD_FOLDER: 'upload-folder', | 65 SELECT_UPLOAD_FOLDER: 'upload-folder', |
66 SELECT_SAVEAS_FILE: 'saveas-file', | 66 SELECT_SAVEAS_FILE: 'saveas-file', |
67 SELECT_OPEN_FILE: 'open-file', | 67 SELECT_OPEN_FILE: 'open-file', |
68 SELECT_OPEN_MULTI_FILE: 'open-multi-file', | 68 SELECT_OPEN_MULTI_FILE: 'open-multi-file', |
69 FULL_PAGE: 'full-page' | 69 FULL_PAGE: 'full-page' |
70 }; | 70 }; |
71 | 71 |
72 /** | 72 /** |
73 * TextMeasure constructor. | |
74 * | |
75 * TextMeasure is a measure for text that returns the width of text. This | |
76 * class has a dummy span element. When measuring the width of text, it sets | |
77 * the text to the element and obtains the element's size by | |
78 * getBoundingClientRect. | |
79 * | |
80 * @constructor | |
81 * @param {HTMLElement} element Element that has styles of measured text. The | |
82 * width of text is mesures like as it is rendered in this element. | |
83 */ | |
84 var TextMeasure = function(element) { | |
85 var doc = element.ownerDocument; | |
86 this.dummySpan_ = doc.createElement('span'); | |
87 this.dummySpan_ = doc.getElementsByTagName('body')[0]. | |
88 appendChild(this.dummySpan_); | |
89 this.dummySpan_.style.position = 'absolute'; | |
90 this.dummySpan_.style.visibility = 'hidden'; | |
91 var styles = window.getComputedStyle(element, ''); | |
92 var stylesToBeCopied = [ | |
93 'fontSize', | |
94 'fontStyle', | |
95 'fontWeight', | |
96 'fontFamily', | |
97 'letterSpacing' | |
98 ]; | |
99 for (var i = 0; i < stylesToBeCopied.length; i++) { | |
100 this.dummySpan_.style[stylesToBeCopied[i]] = styles[stylesToBeCopied[i]]; | |
101 } | |
102 }; | |
103 | |
104 /** | |
105 * Measures the widht of text. | |
106 * | |
107 * @param {string} text Text that is measured the width. | |
108 * @return {number} Width of the specified text. | |
109 */ | |
110 TextMeasure.prototype.getWidth = function(text) { | |
111 this.dummySpan_.innerText = text; | |
112 var rect = this.dummySpan_.getBoundingClientRect(); | |
113 return rect ? rect.width : 0; | |
114 }; | |
115 | |
116 /** | |
117 * @param {string} type Dialog type. | 73 * @param {string} type Dialog type. |
118 * @return {boolean} Whether the type is modal. | 74 * @return {boolean} Whether the type is modal. |
119 */ | 75 */ |
120 DialogType.isModal = function(type) { | 76 DialogType.isModal = function(type) { |
121 return type == DialogType.SELECT_FOLDER || | 77 return type == DialogType.SELECT_FOLDER || |
122 type == DialogType.SELECT_UPLOAD_FOLDER || | 78 type == DialogType.SELECT_UPLOAD_FOLDER || |
123 type == DialogType.SELECT_SAVEAS_FILE || | 79 type == DialogType.SELECT_SAVEAS_FILE || |
124 type == DialogType.SELECT_OPEN_FILE || | 80 type == DialogType.SELECT_OPEN_FILE || |
125 type == DialogType.SELECT_OPEN_MULTI_FILE; | 81 type == DialogType.SELECT_OPEN_MULTI_FILE; |
126 }; | 82 }; |
(...skipping 3860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3987 */ | 3943 */ |
3988 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3944 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
3989 this.ctrlKeyPressed_ = flag; | 3945 this.ctrlKeyPressed_ = flag; |
3990 // Before the DOM is constructed, the key event can be handled. | 3946 // Before the DOM is constructed, the key event can be handled. |
3991 var cacheClearCommand = | 3947 var cacheClearCommand = |
3992 this.document_.querySelector('#drive-clear-local-cache'); | 3948 this.document_.querySelector('#drive-clear-local-cache'); |
3993 if (cacheClearCommand) | 3949 if (cacheClearCommand) |
3994 cacheClearCommand.canExecuteChange(); | 3950 cacheClearCommand.canExecuteChange(); |
3995 }; | 3951 }; |
3996 })(); | 3952 })(); |
OLD | NEW |