提交 4151e3e1 编写于 作者: M Matt Bierner

Move convertToPixels into sizeUtils

上级 e7e32aff
...@@ -467,14 +467,6 @@ export function getComputedStyle(el: HTMLElement): CSSStyleDeclaration { ...@@ -467,14 +467,6 @@ export function getComputedStyle(el: HTMLElement): CSSStyleDeclaration {
return document.defaultView!.getComputedStyle(el, null); return document.defaultView!.getComputedStyle(el, null);
} }
// Adapted from WinJS
// Converts a CSS positioning string for the specified element to pixels.
const convertToPixels: (element: HTMLElement, value: string) => number = (function () {
return function (element: HTMLElement, value: string): number {
return parseFloat(value) || 0;
};
})();
export function getClientArea(element: HTMLElement): Dimension { export function getClientArea(element: HTMLElement): Dimension {
// Try with DOM clientWidth / clientHeight // Try with DOM clientWidth / clientHeight
...@@ -501,6 +493,12 @@ export function getClientArea(element: HTMLElement): Dimension { ...@@ -501,6 +493,12 @@ export function getClientArea(element: HTMLElement): Dimension {
} }
class SizeUtils { class SizeUtils {
// Adapted from WinJS
// Converts a CSS positioning string for the specified element to pixels.
private static convertToPixels(element: HTMLElement, value: string): number {
return parseFloat(value) || 0;
}
private static getDimension(element: HTMLElement, cssPropertyName: string, jsPropertyName: string): number { private static getDimension(element: HTMLElement, cssPropertyName: string, jsPropertyName: string): number {
let computedStyle: CSSStyleDeclaration = getComputedStyle(element); let computedStyle: CSSStyleDeclaration = getComputedStyle(element);
let value = '0'; let value = '0';
...@@ -512,7 +510,7 @@ class SizeUtils { ...@@ -512,7 +510,7 @@ class SizeUtils {
value = (<any>computedStyle).getAttribute(jsPropertyName); value = (<any>computedStyle).getAttribute(jsPropertyName);
} }
} }
return convertToPixels(element, value); return SizeUtils.convertToPixels(element, value);
} }
static getBorderLeftWidth(element: HTMLElement): number { static getBorderLeftWidth(element: HTMLElement): number {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册