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

@ -522,12 +522,12 @@ describe('projection', () => {
const main = TestBed.createComponent(MainComp);
const mainEl = main.nativeElement;
const div1 = getDOM().firstChild(mainEl);
const div1 = getDOM().firstChild(mainEl) as Element;
const div2 = getDOM().createElement('div');
getDOM().setAttribute(div2, 'class', 'redStyle');
getDOM().appendChild(mainEl, div2);
expect(getDOM().getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getDOM().getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
});
it('should support emulated style encapsulation', () => {
@ -542,11 +542,11 @@ describe('projection', () => {
const main = TestBed.createComponent(MainComp);
const mainEl = main.nativeElement;
const div1 = getDOM().firstChild(mainEl);
const div1 = getDOM().firstChild(mainEl) as Element;
const div2 = getDOM().createElement('div');
getDOM().appendChild(mainEl, div2);
expect(getDOM().getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getDOM().getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
});
}

View File

@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {supportsWebAnimation} from '@angular/platform-browser/testing/src/browser_util';
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {RequestOptions} from '@angular/http/src/base_request_options';
import {ContentType} from '@angular/http/src/enums';
import {Headers} from '@angular/http/src/headers';
import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils';
import {ArrayBuffer, Request} from '@angular/http/src/static_request';
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
{
describe('Request', () => {
@ -121,7 +121,7 @@ import {ɵgetDOM as getDOM} from '@angular/platform-browser';
expect(req.url).toBe('http://test.com?a=1&b=2');
});
if (getDOM().supportsWebAnimation()) {
if (supportsWebAnimation()) {
it('should serialize an ArrayBuffer to string via legacy encoding', () => {
const str = '\u89d2\u5ea6';
expect(new Request({body: stringToArrayBuffer(str), url: '/'}).text()).toEqual(str);

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;

View File

@ -179,3 +179,7 @@ export function setCookie(name: string, value: string) {
// not clear other cookies.
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
}
export function supportsWebAnimation(): boolean {
return typeof(<any>Element).prototype['animate'] === 'function';
}

View File

@ -207,11 +207,7 @@ export class DominoAdapter extends BrowserDomAdapter {
getLocation(): Location { throw _notImplemented('getLocation'); }
getUserAgent(): string { return 'Fake user agent'; }
supportsWebAnimation(): boolean { return false; }
performanceNow(): number { return Date.now(); }
getAnimationPrefix(): string { return ''; }
getTransitionEnd(): string { return 'transitionend'; }
supportsAnimation(): boolean { return true; }
getDistributedNodes(el: any): Node[] { throw _notImplemented('getDistributedNodes'); }

View File

@ -148,13 +148,7 @@ export class WorkerDomAdapter extends DomAdapter {
getBaseHref(doc: Document): string { throw 'not implemented'; }
resetBaseElement(): void { throw 'not implemented'; }
getUserAgent(): string { return 'Fake user agent'; }
setData(element: any, name: string, value: string) { throw 'not implemented'; }
getComputedStyle(element: any): any { throw 'not implemented'; }
performanceNow(): number { throw 'not implemented'; }
getAnimationPrefix(): string { throw 'not implemented'; }
getTransitionEnd(): string { throw 'not implemented'; }
supportsAnimation(): boolean { throw 'not implemented'; }
supportsWebAnimation(): boolean { throw 'not implemented'; }
supportsCookies(): boolean { return false; }
getCookie(name: string): string { throw 'not implemented'; }