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

Unified Diff: ui/file_manager/file_manager/foreground/js/text_measure.js

Issue 419063004: Files.app: Move the position of dummy element for measuring the size of text. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/css/file_manager.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/text_measure.js
diff --git a/ui/file_manager/file_manager/foreground/js/text_measure.js b/ui/file_manager/file_manager/foreground/js/text_measure.js
index a8db83ae5825ccdb0cbab3f26abefe92d9178772..8a2c935fad64ea335081ad883022856d8e523ff2 100644
--- a/ui/file_manager/file_manager/foreground/js/text_measure.js
+++ b/ui/file_manager/file_manager/foreground/js/text_measure.js
@@ -17,27 +17,30 @@
* width of text is measures like as it is rendered in this element.
*/
var TextMeasure = function(element) {
- var doc = element.ownerDocument;
- this.dummySpan_ = doc.createElement('span');
- this.dummySpan_ = doc.getElementsByTagName('body')[0].
- appendChild(this.dummySpan_);
- this.dummySpan_.style.position = 'absolute';
- this.dummySpan_.style.visibility = 'hidden';
+ this.dummySpan_ = createElementWithClassName('span', 'text-measure');
var styles = window.getComputedStyle(element, '');
- var stylesToBeCopied = [
- 'fontSize',
- 'fontStyle',
- 'fontWeight',
- 'fontFamily',
- 'letterSpacing'
- ];
- for (var i = 0; i < stylesToBeCopied.length; i++) {
- this.dummySpan_.style[stylesToBeCopied[i]] = styles[stylesToBeCopied[i]];
+ for (var i = 0; i < TextMeasure.STYLES_TO_BE_COPYED.length; i++) {
+ var name = TextMeasure.STYLES_TO_BE_COPYED[i];
+ this.dummySpan_.style[name] = styles[name];
}
+ element.ownerDocument.body.appendChild(this.dummySpan_);
Object.seal(this);
};
/**
+ * Style names to be copied to the measured dummy span.
+ * @type {Array.<String>}
+ * @const
+ */
+TextMeasure.STYLES_TO_BE_COPYED = Object.freeze([
+ 'fontSize',
+ 'fontStyle',
+ 'fontWeight',
+ 'fontFamily',
+ 'letterSpacing'
+]);
+
+/**
* Measures the width of text.
*
* @param {string} text Text that is measured the width.
« no previous file with comments | « ui/file_manager/file_manager/foreground/css/file_manager.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698