From bf18e81c191a801e4ace0776d6ea170287f94b3f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 14 Apr 2018 07:57:31 +0900 Subject: [PATCH 1/2] add notifications/vibration types --- baselines/dom.generated.d.ts | 34 +++++++++-- baselines/webworker.generated.d.ts | 34 +++++++++-- inputfiles/idl/Notifications.widl | 94 ++++++++++++++++++++++++++++++ inputfiles/idl/Vibration.widl | 5 ++ inputfiles/idlSources.json | 8 +++ inputfiles/knownWorkerTypes.json | 2 + inputfiles/overridingTypes.json | 23 ++++++++ 7 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 inputfiles/idl/Notifications.widl create mode 100644 inputfiles/idl/Vibration.widl diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 5a2f78143..03dfabd02 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -962,18 +962,32 @@ interface MutationObserverInit { subtree?: boolean; } +interface NotificationAction { + action: string; + icon?: string; + title: string; +} + interface NotificationEventInit extends ExtendableEventInit { action?: string; notification: Notification; } interface NotificationOptions { + actions?: NotificationAction[]; + badge?: string; body?: string; data?: any; dir?: NotificationDirection; icon?: string; + image?: string; lang?: string; + renotify?: boolean; + requireInteraction?: boolean; + silent?: boolean; tag?: string; + timestamp?: number; + vibrate?: VibratePattern; } interface ObjectURLOptions { @@ -9816,18 +9830,27 @@ interface NotificationEventMap { } interface Notification extends EventTarget { - readonly body: string | null; + readonly actions: ReadonlyArray; + readonly badge: string; + readonly body: string; readonly data: any; readonly dir: NotificationDirection; - readonly icon: string | null; - readonly lang: string | null; + readonly icon: string; + readonly image: string; + readonly lang: string; + readonly maxActions: number; onclick: ((this: Notification, ev: Event) => any) | null; onclose: ((this: Notification, ev: Event) => any) | null; onerror: ((this: Notification, ev: Event) => any) | null; onshow: ((this: Notification, ev: Event) => any) | null; readonly permission: NotificationPermission; - readonly tag: string | null; + readonly renotify: boolean; + readonly requireInteraction: boolean; + readonly silent: boolean; + readonly tag: string; + readonly timestamp: number; readonly title: string; + readonly vibrate: ReadonlyArray; close(): void; addEventListener(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -9838,7 +9861,7 @@ interface Notification extends EventTarget { declare var Notification: { prototype: Notification; new(title: string, options?: NotificationOptions): Notification; - requestPermission(callback?: NotificationPermissionCallback): Promise; + requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise; }; interface OES_element_index_uint { @@ -16487,6 +16510,7 @@ type RequestInfo = Request | string; type DOMHighResTimeStamp = number; type PerformanceEntryList = PerformanceEntry[]; type PushMessageDataInit = BufferSource | string; +type VibratePattern = number | number[]; type BufferSource = ArrayBufferView | ArrayBuffer; type DOMTimeStamp = number; type FormDataEntryValue = File | string; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 9e75c4f1f..28c11b427 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -98,18 +98,32 @@ interface MessageEventInit extends EventInit { source?: object | null; } +interface NotificationAction { + action: string; + icon?: string; + title: string; +} + interface NotificationEventInit extends ExtendableEventInit { action?: string; notification: Notification; } interface NotificationOptions { + actions?: NotificationAction[]; + badge?: string; body?: string; data?: any; dir?: NotificationDirection; icon?: string; + image?: string; lang?: string; + renotify?: boolean; + requireInteraction?: boolean; + silent?: boolean; tag?: string; + timestamp?: number; + vibrate?: VibratePattern; } interface ObjectURLOptions { @@ -995,18 +1009,27 @@ interface NotificationEventMap { } interface Notification extends EventTarget { - readonly body: string | null; + readonly actions: ReadonlyArray; + readonly badge: string; + readonly body: string; readonly data: any; readonly dir: NotificationDirection; - readonly icon: string | null; - readonly lang: string | null; + readonly icon: string; + readonly image: string; + readonly lang: string; + readonly maxActions: number; onclick: ((this: Notification, ev: Event) => any) | null; onclose: ((this: Notification, ev: Event) => any) | null; onerror: ((this: Notification, ev: Event) => any) | null; onshow: ((this: Notification, ev: Event) => any) | null; readonly permission: NotificationPermission; - readonly tag: string | null; + readonly renotify: boolean; + readonly requireInteraction: boolean; + readonly silent: boolean; + readonly tag: string; + readonly timestamp: number; readonly title: string; + readonly vibrate: ReadonlyArray; close(): void; addEventListener(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; @@ -1017,7 +1040,7 @@ interface Notification extends EventTarget { declare var Notification: { prototype: Notification; new(title: string, options?: NotificationOptions): Notification; - requestPermission(callback?: NotificationPermissionCallback): Promise; + requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise; }; interface NotificationEvent extends ExtendableEvent { @@ -1782,6 +1805,7 @@ type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStrea type RequestInfo = Request | string; type PerformanceEntryList = PerformanceEntry[]; type PushMessageDataInit = BufferSource | string; +type VibratePattern = number | number[]; type BufferSource = ArrayBufferView | ArrayBuffer; type FormDataEntryValue = File | string; type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey; diff --git a/inputfiles/idl/Notifications.widl b/inputfiles/idl/Notifications.widl new file mode 100644 index 000000000..7a1f52c36 --- /dev/null +++ b/inputfiles/idl/Notifications.widl @@ -0,0 +1,94 @@ +[Constructor(DOMString title, optional NotificationOptions options), + Exposed=(Window,Worker)] +interface Notification : EventTarget { + static readonly attribute NotificationPermission permission; + [Exposed=Window] static Promise requestPermission(optional NotificationPermissionCallback deprecatedCallback); + + static readonly attribute unsigned long maxActions; + + attribute EventHandler onclick; + attribute EventHandler onshow; + attribute EventHandler onerror; + attribute EventHandler onclose; + + readonly attribute DOMString title; + readonly attribute NotificationDirection dir; + readonly attribute DOMString lang; + readonly attribute DOMString body; + readonly attribute DOMString tag; + readonly attribute USVString image; + readonly attribute USVString icon; + readonly attribute USVString badge; + [SameObject] readonly attribute FrozenArray vibrate; + readonly attribute DOMTimeStamp timestamp; + readonly attribute boolean renotify; + readonly attribute boolean silent; + readonly attribute boolean requireInteraction; + [SameObject] readonly attribute any data; + [SameObject] readonly attribute FrozenArray actions; + + void close(); +}; + +dictionary NotificationOptions { + NotificationDirection dir = "auto"; + DOMString lang = ""; + DOMString body = ""; + DOMString tag = ""; + USVString image; + USVString icon; + USVString badge; + VibratePattern vibrate; + DOMTimeStamp timestamp; + boolean renotify = false; + boolean silent = false; + boolean requireInteraction = false; + any data = null; + sequence actions = []; +}; + +enum NotificationPermission { + "default", + "denied", + "granted" +}; + +enum NotificationDirection { + "auto", + "ltr", + "rtl" +}; + +dictionary NotificationAction { + required DOMString action; + required DOMString title; + USVString icon; +}; + +callback NotificationPermissionCallback = void (NotificationPermission permission); + +dictionary GetNotificationOptions { + DOMString tag = ""; +}; + +partial interface ServiceWorkerRegistration { + Promise showNotification(DOMString title, optional NotificationOptions options); + Promise> getNotifications(optional GetNotificationOptions filter); +}; + +[Constructor(DOMString type, NotificationEventInit eventInitDict), + Exposed=ServiceWorker] +interface NotificationEvent : ExtendableEvent { + readonly attribute Notification notification; + readonly attribute DOMString action; +}; + +dictionary NotificationEventInit : ExtendableEventInit { + required Notification notification; + DOMString action = ""; +}; + +partial interface ServiceWorkerGlobalScope { + attribute EventHandler onnotificationclick; + attribute EventHandler onnotificationclose; +}; diff --git a/inputfiles/idl/Vibration.widl b/inputfiles/idl/Vibration.widl new file mode 100644 index 000000000..5b2ffa13a --- /dev/null +++ b/inputfiles/idl/Vibration.widl @@ -0,0 +1,5 @@ +typedef (unsigned long or sequence) VibratePattern; + +partial interface Navigator { + boolean vibrate(VibratePattern pattern); +}; diff --git a/inputfiles/idlSources.json b/inputfiles/idlSources.json index 851af4610..b8c7645be 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -23,6 +23,10 @@ "url": "https://w3c.github.io/navigation-timing/", "title": "Navigation Timing" }, + { + "url": "https://notifications.spec.whatwg.org/", + "title": "Notifications" + }, { "url": "https://w3c.github.io/performance-timeline/", "title": "Performance Timeline" @@ -43,6 +47,10 @@ "url": "https://www.w3.org/TR/user-timing-2/", "title": "User Timing" }, + { + "url": "https://www.w3.org/TR/vibration/", + "title": "Vibration" + }, { "url": "https://wicg.github.io/BackgroundSync/spec/", "title": "Web Background Synchronization" diff --git a/inputfiles/knownWorkerTypes.json b/inputfiles/knownWorkerTypes.json index 4d168a262..d862c0ae0 100644 --- a/inputfiles/knownWorkerTypes.json +++ b/inputfiles/knownWorkerTypes.json @@ -56,6 +56,7 @@ "MessageEvent", "MessagePort", "Notification", + "NotificationAction", "Performance", "PerformanceEntry", "PerformanceEntryList", @@ -80,6 +81,7 @@ "ServiceWorkerRegistration", "SyncManager", "URL", + "VibratePattern", "WebSocket", "Worker", "XMLHttpRequest", diff --git a/inputfiles/overridingTypes.json b/inputfiles/overridingTypes.json index 20fff32f9..c5974cb51 100644 --- a/inputfiles/overridingTypes.json +++ b/inputfiles/overridingTypes.json @@ -2189,6 +2189,29 @@ } ] } + }, + "Notification": { + "name": "Notification", + "events": { + "event": [ + { + "name": "click", + "type": "Event" + }, + { + "name": "close", + "type": "Event" + }, + { + "name": "error", + "type": "Event" + }, + { + "name": "show", + "type": "Event" + } + ] + } } } }, From edf436472c819d706614246dc1ec42bc79e19952 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sat, 14 Apr 2018 12:11:14 +0900 Subject: [PATCH 2/2] support static attributes --- baselines/dom.generated.d.ts | 6 +++--- baselines/webworker.generated.d.ts | 6 +++--- src/emitter.ts | 7 +++---- src/widlprocess.ts | 1 + 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 03dfabd02..e288240a6 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -9838,12 +9838,10 @@ interface Notification extends EventTarget { readonly icon: string; readonly image: string; readonly lang: string; - readonly maxActions: number; onclick: ((this: Notification, ev: Event) => any) | null; onclose: ((this: Notification, ev: Event) => any) | null; onerror: ((this: Notification, ev: Event) => any) | null; onshow: ((this: Notification, ev: Event) => any) | null; - readonly permission: NotificationPermission; readonly renotify: boolean; readonly requireInteraction: boolean; readonly silent: boolean; @@ -9861,6 +9859,8 @@ interface Notification extends EventTarget { declare var Notification: { prototype: Notification; new(title: string, options?: NotificationOptions): Notification; + readonly maxActions: number; + readonly permission: NotificationPermission; requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise; }; @@ -10471,7 +10471,6 @@ interface PromiseRejectionEventInit extends EventInit { } interface PushManager { - readonly supportedContentEncodings: ReadonlyArray; getSubscription(): Promise; permissionState(options?: PushSubscriptionOptionsInit): Promise; subscribe(options?: PushSubscriptionOptionsInit): Promise; @@ -10480,6 +10479,7 @@ interface PushManager { declare var PushManager: { prototype: PushManager; new(): PushManager; + readonly supportedContentEncodings: ReadonlyArray; }; interface PushSubscription { diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 28c11b427..5f5cd3a64 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -1017,12 +1017,10 @@ interface Notification extends EventTarget { readonly icon: string; readonly image: string; readonly lang: string; - readonly maxActions: number; onclick: ((this: Notification, ev: Event) => any) | null; onclose: ((this: Notification, ev: Event) => any) | null; onerror: ((this: Notification, ev: Event) => any) | null; onshow: ((this: Notification, ev: Event) => any) | null; - readonly permission: NotificationPermission; readonly renotify: boolean; readonly requireInteraction: boolean; readonly silent: boolean; @@ -1040,6 +1038,8 @@ interface Notification extends EventTarget { declare var Notification: { prototype: Notification; new(title: string, options?: NotificationOptions): Notification; + readonly maxActions: number; + readonly permission: NotificationPermission; requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise; }; @@ -1218,7 +1218,6 @@ declare var PushEvent: { }; interface PushManager { - readonly supportedContentEncodings: ReadonlyArray; getSubscription(): Promise; permissionState(options?: PushSubscriptionOptionsInit): Promise; subscribe(options?: PushSubscriptionOptionsInit): Promise; @@ -1227,6 +1226,7 @@ interface PushManager { declare var PushManager: { prototype: PushManager; new(): PushManager; + readonly supportedContentEncodings: ReadonlyArray; }; interface PushMessageData { diff --git a/src/emitter.ts b/src/emitter.ts index 241f113cf..1d3e51089 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -43,7 +43,7 @@ const eventTypeMap: Record = { // Used to decide if a member should be emitted given its static property and // the intended scope level. -function matchScope(scope: EmitScope, x: Browser.Method) { +function matchScope(scope: EmitScope, x: { static?: 1 | undefined }) { return scope === EmitScope.All || (scope === EmitScope.StaticOnly) === !!x.static; } @@ -618,10 +618,9 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { } function emitProperties(prefix: string, emitScope: EmitScope, i: Browser.Interface, conflictedMembers: Set) { - // Note: the schema file shows the property doesn't have "static" attribute, - // therefore all properties are emited for the instance type. - if (emitScope !== EmitScope.StaticOnly && i.properties) { + if (i.properties) { mapToArray(i.properties.property) + .filter(m => matchScope(emitScope, m)) .filter(p => !isCovariantEventHandler(i, p)) .sort(compareName) .forEach(p => emitProperty(prefix, i, emitScope, p, conflictedMembers)); diff --git a/src/widlprocess.ts b/src/widlprocess.ts index 0974da4be..4f3a90ab2 100644 --- a/src/widlprocess.ts +++ b/src/widlprocess.ts @@ -172,6 +172,7 @@ function convertAttribute(attribute: webidl2.AttributeMemberType): Browser.Prope return { name: attribute.name, ...convertIdlType(attribute.idlType), + static: attribute.static ? 1 : undefined, "read-only": attribute.readonly ? 1 : undefined, "event-handler": attribute.idlType.idlType === "EventHandler" ? attribute.name.slice(2) : undefined }