refactor(core): remove animation utilities from DomAdapters (#32278)
PR Close #32278
This commit is contained in:
parent
7bcd42e7be
commit
bceeeba405
|
@ -522,12 +522,12 @@ describe('projection', () => {
|
||||||
const main = TestBed.createComponent(MainComp);
|
const main = TestBed.createComponent(MainComp);
|
||||||
|
|
||||||
const mainEl = main.nativeElement;
|
const mainEl = main.nativeElement;
|
||||||
const div1 = getDOM().firstChild(mainEl);
|
const div1 = getDOM().firstChild(mainEl) as Element;
|
||||||
const div2 = getDOM().createElement('div');
|
const div2 = getDOM().createElement('div');
|
||||||
getDOM().setAttribute(div2, 'class', 'redStyle');
|
getDOM().setAttribute(div2, 'class', 'redStyle');
|
||||||
getDOM().appendChild(mainEl, div2);
|
getDOM().appendChild(mainEl, div2);
|
||||||
expect(getDOM().getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
|
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
|
||||||
expect(getDOM().getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
|
expect(getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support emulated style encapsulation', () => {
|
it('should support emulated style encapsulation', () => {
|
||||||
|
@ -542,11 +542,11 @@ describe('projection', () => {
|
||||||
const main = TestBed.createComponent(MainComp);
|
const main = TestBed.createComponent(MainComp);
|
||||||
|
|
||||||
const mainEl = main.nativeElement;
|
const mainEl = main.nativeElement;
|
||||||
const div1 = getDOM().firstChild(mainEl);
|
const div1 = getDOM().firstChild(mainEl) as Element;
|
||||||
const div2 = getDOM().createElement('div');
|
const div2 = getDOM().createElement('div');
|
||||||
getDOM().appendChild(mainEl, div2);
|
getDOM().appendChild(mainEl, div2);
|
||||||
expect(getDOM().getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
|
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
|
||||||
expect(getDOM().getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
|
expect(getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||||
import {RequestOptions} from '@angular/http/src/base_request_options';
|
import {RequestOptions} from '@angular/http/src/base_request_options';
|
||||||
import {ContentType} from '@angular/http/src/enums';
|
import {ContentType} from '@angular/http/src/enums';
|
||||||
import {Headers} from '@angular/http/src/headers';
|
import {Headers} from '@angular/http/src/headers';
|
||||||
import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils';
|
import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils';
|
||||||
import {ArrayBuffer, Request} from '@angular/http/src/static_request';
|
import {ArrayBuffer, Request} from '@angular/http/src/static_request';
|
||||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('Request', () => {
|
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');
|
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', () => {
|
it('should serialize an ArrayBuffer to string via legacy encoding', () => {
|
||||||
const str = '\u89d2\u5ea6';
|
const str = '\u89d2\u5ea6';
|
||||||
expect(new Request({body: stringToArrayBuffer(str), url: '/'}).text()).toEqual(str);
|
expect(new Request({body: stringToArrayBuffer(str), url: '/'}).text()).toEqual(str);
|
||||||
|
|
|
@ -352,14 +352,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||||
}
|
}
|
||||||
resetBaseElement(): void { baseElement = null; }
|
resetBaseElement(): void { baseElement = null; }
|
||||||
getUserAgent(): string { return window.navigator.userAgent; }
|
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 {
|
performanceNow(): number {
|
||||||
// performance.now() is not available in all browsers, see
|
// performance.now() is not available in all browsers, see
|
||||||
// http://caniuse.com/#search=performance.now
|
// http://caniuse.com/#search=performance.now
|
||||||
|
|
|
@ -17,42 +17,7 @@ import {DomAdapter} from '../dom/dom_adapter';
|
||||||
* can introduce XSS risks.
|
* can introduce XSS risks.
|
||||||
*/
|
*/
|
||||||
export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
||||||
private _animationPrefix: string|null = null;
|
constructor() { super(); }
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
|
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
|
||||||
resolveAndSetHref(el: HTMLAnchorElement, baseUrl: string, href: string) {
|
resolveAndSetHref(el: HTMLAnchorElement, baseUrl: string, href: string) {
|
||||||
|
@ -62,9 +27,4 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
||||||
supportsNativeShadowDOM(): boolean {
|
supportsNativeShadowDOM(): boolean {
|
||||||
return typeof(<any>document.body).createShadowRoot === 'function';
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,13 +144,9 @@ export abstract class DomAdapter {
|
||||||
abstract getBaseHref(doc: Document): string|null;
|
abstract getBaseHref(doc: Document): string|null;
|
||||||
abstract resetBaseElement(): void;
|
abstract resetBaseElement(): void;
|
||||||
abstract getUserAgent(): string;
|
abstract getUserAgent(): string;
|
||||||
abstract setData(element: any, name: string, value: string): any;
|
|
||||||
abstract getComputedStyle(element: any): any;
|
// Used by AngularProfiler
|
||||||
abstract supportsWebAnimation(): boolean;
|
|
||||||
abstract performanceNow(): number;
|
abstract performanceNow(): number;
|
||||||
abstract getAnimationPrefix(): string;
|
|
||||||
abstract getTransitionEnd(): string;
|
|
||||||
abstract supportsAnimation(): boolean;
|
|
||||||
|
|
||||||
// Used by CookieXSRFStrategy
|
// Used by CookieXSRFStrategy
|
||||||
abstract supportsCookies(): boolean;
|
abstract supportsCookies(): boolean;
|
||||||
|
|
|
@ -179,3 +179,7 @@ export function setCookie(name: string, value: string) {
|
||||||
// not clear other cookies.
|
// not clear other cookies.
|
||||||
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
document.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function supportsWebAnimation(): boolean {
|
||||||
|
return typeof(<any>Element).prototype['animate'] === 'function';
|
||||||
|
}
|
||||||
|
|
|
@ -207,11 +207,7 @@ export class DominoAdapter extends BrowserDomAdapter {
|
||||||
getLocation(): Location { throw _notImplemented('getLocation'); }
|
getLocation(): Location { throw _notImplemented('getLocation'); }
|
||||||
getUserAgent(): string { return 'Fake user agent'; }
|
getUserAgent(): string { return 'Fake user agent'; }
|
||||||
|
|
||||||
supportsWebAnimation(): boolean { return false; }
|
|
||||||
performanceNow(): number { return Date.now(); }
|
performanceNow(): number { return Date.now(); }
|
||||||
getAnimationPrefix(): string { return ''; }
|
|
||||||
getTransitionEnd(): string { return 'transitionend'; }
|
|
||||||
supportsAnimation(): boolean { return true; }
|
|
||||||
|
|
||||||
getDistributedNodes(el: any): Node[] { throw _notImplemented('getDistributedNodes'); }
|
getDistributedNodes(el: any): Node[] { throw _notImplemented('getDistributedNodes'); }
|
||||||
|
|
||||||
|
|
|
@ -148,13 +148,7 @@ export class WorkerDomAdapter extends DomAdapter {
|
||||||
getBaseHref(doc: Document): string { throw 'not implemented'; }
|
getBaseHref(doc: Document): string { throw 'not implemented'; }
|
||||||
resetBaseElement(): void { throw 'not implemented'; }
|
resetBaseElement(): void { throw 'not implemented'; }
|
||||||
getUserAgent(): string { return 'Fake user agent'; }
|
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'; }
|
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; }
|
supportsCookies(): boolean { return false; }
|
||||||
getCookie(name: string): string { throw 'not implemented'; }
|
getCookie(name: string): string { throw 'not implemented'; }
|
||||||
|
|
Loading…
Reference in New Issue