refactor(core): remove animation utilities from DomAdapters (#32278)

PR Close #32278
This commit is contained in:
Kara Erickson
2019-08-22 17:49:43 -07:00
committed by atscott
parent 7bcd42e7be
commit bceeeba405
8 changed files with 15 additions and 73 deletions

View File

@ -352,14 +352,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
resetBaseElement(): void { baseElement = null; }
getUserAgent(): string { return window.navigator.userAgent; }
setData(element: Element, name: string, value: string) {
this.setAttribute(element, 'data-' + name, value);
}
getComputedStyle(element: any): any { return getComputedStyle(element); }
// TODO(tbosch): move this into a separate environment class once we have it
supportsWebAnimation(): boolean {
return typeof(<any>Element).prototype['animate'] === 'function';
}
performanceNow(): number {
// performance.now() is not available in all browsers, see
// http://caniuse.com/#search=performance.now

View File

@ -17,42 +17,7 @@ import {DomAdapter} from '../dom/dom_adapter';
* can introduce XSS risks.
*/
export abstract class GenericBrowserDomAdapter extends DomAdapter {
private _animationPrefix: string|null = null;
private _transitionEnd: string|null = null;
constructor() {
super();
try {
const element = this.createElement('div', document);
if (this.getStyle(element, 'animationName') != null) {
this._animationPrefix = '';
} else {
const domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
for (let i = 0; i < domPrefixes.length; i++) {
if (this.getStyle(element, domPrefixes[i] + 'AnimationName') != null) {
this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
break;
}
}
}
const transEndEventNames: {[key: string]: string} = {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'oTransitionEnd otransitionend',
transition: 'transitionend'
};
Object.keys(transEndEventNames).forEach((key: string) => {
if (this.getStyle(element, key) != null) {
this._transitionEnd = transEndEventNames[key];
}
});
} catch {
this._animationPrefix = null;
this._transitionEnd = null;
}
}
constructor() { super(); }
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
resolveAndSetHref(el: HTMLAnchorElement, baseUrl: string, href: string) {
@ -62,9 +27,4 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
supportsNativeShadowDOM(): boolean {
return typeof(<any>document.body).createShadowRoot === 'function';
}
getAnimationPrefix(): string { return this._animationPrefix ? this._animationPrefix : ''; }
getTransitionEnd(): string { return this._transitionEnd ? this._transitionEnd : ''; }
supportsAnimation(): boolean {
return this._animationPrefix != null && this._transitionEnd != null;
}
}

View File

@ -144,13 +144,9 @@ export abstract class DomAdapter {
abstract getBaseHref(doc: Document): string|null;
abstract resetBaseElement(): void;
abstract getUserAgent(): string;
abstract setData(element: any, name: string, value: string): any;
abstract getComputedStyle(element: any): any;
abstract supportsWebAnimation(): boolean;
// Used by AngularProfiler
abstract performanceNow(): number;
abstract getAnimationPrefix(): string;
abstract getTransitionEnd(): string;
abstract supportsAnimation(): boolean;
// Used by CookieXSRFStrategy
abstract supportsCookies(): boolean;