Skip to content

Commit 9c824b7

Browse files
authored
Merge pull request #438 from saschanaz/n10n
Add notifications/vibration types
2 parents a4d3ea3 + edf4364 commit 9c824b7

9 files changed

+198
-18
lines changed

baselines/dom.generated.d.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -962,18 +962,32 @@ interface MutationObserverInit {
962962
subtree?: boolean;
963963
}
964964

965+
interface NotificationAction {
966+
action: string;
967+
icon?: string;
968+
title: string;
969+
}
970+
965971
interface NotificationEventInit extends ExtendableEventInit {
966972
action?: string;
967973
notification: Notification;
968974
}
969975

970976
interface NotificationOptions {
977+
actions?: NotificationAction[];
978+
badge?: string;
971979
body?: string;
972980
data?: any;
973981
dir?: NotificationDirection;
974982
icon?: string;
983+
image?: string;
975984
lang?: string;
985+
renotify?: boolean;
986+
requireInteraction?: boolean;
987+
silent?: boolean;
976988
tag?: string;
989+
timestamp?: number;
990+
vibrate?: VibratePattern;
977991
}
978992

979993
interface ObjectURLOptions {
@@ -9816,18 +9830,25 @@ interface NotificationEventMap {
98169830
}
98179831

98189832
interface Notification extends EventTarget {
9819-
readonly body: string | null;
9833+
readonly actions: ReadonlyArray<NotificationAction>;
9834+
readonly badge: string;
9835+
readonly body: string;
98209836
readonly data: any;
98219837
readonly dir: NotificationDirection;
9822-
readonly icon: string | null;
9823-
readonly lang: string | null;
9838+
readonly icon: string;
9839+
readonly image: string;
9840+
readonly lang: string;
98249841
onclick: ((this: Notification, ev: Event) => any) | null;
98259842
onclose: ((this: Notification, ev: Event) => any) | null;
98269843
onerror: ((this: Notification, ev: Event) => any) | null;
98279844
onshow: ((this: Notification, ev: Event) => any) | null;
9828-
readonly permission: NotificationPermission;
9829-
readonly tag: string | null;
9845+
readonly renotify: boolean;
9846+
readonly requireInteraction: boolean;
9847+
readonly silent: boolean;
9848+
readonly tag: string;
9849+
readonly timestamp: number;
98309850
readonly title: string;
9851+
readonly vibrate: ReadonlyArray<number>;
98319852
close(): void;
98329853
addEventListener<K extends keyof NotificationEventMap>(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
98339854
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
@@ -9838,7 +9859,9 @@ interface Notification extends EventTarget {
98389859
declare var Notification: {
98399860
prototype: Notification;
98409861
new(title: string, options?: NotificationOptions): Notification;
9841-
requestPermission(callback?: NotificationPermissionCallback): Promise<NotificationPermission>;
9862+
readonly maxActions: number;
9863+
readonly permission: NotificationPermission;
9864+
requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise<NotificationPermission>;
98429865
};
98439866

98449867
interface OES_element_index_uint {
@@ -10448,7 +10471,6 @@ interface PromiseRejectionEventInit extends EventInit {
1044810471
}
1044910472

1045010473
interface PushManager {
10451-
readonly supportedContentEncodings: ReadonlyArray<string>;
1045210474
getSubscription(): Promise<PushSubscription | null>;
1045310475
permissionState(options?: PushSubscriptionOptionsInit): Promise<PushPermissionState>;
1045410476
subscribe(options?: PushSubscriptionOptionsInit): Promise<PushSubscription>;
@@ -10457,6 +10479,7 @@ interface PushManager {
1045710479
declare var PushManager: {
1045810480
prototype: PushManager;
1045910481
new(): PushManager;
10482+
readonly supportedContentEncodings: ReadonlyArray<string>;
1046010483
};
1046110484

1046210485
interface PushSubscription {
@@ -16487,6 +16510,7 @@ type RequestInfo = Request | string;
1648716510
type DOMHighResTimeStamp = number;
1648816511
type PerformanceEntryList = PerformanceEntry[];
1648916512
type PushMessageDataInit = BufferSource | string;
16513+
type VibratePattern = number | number[];
1649016514
type BufferSource = ArrayBufferView | ArrayBuffer;
1649116515
type DOMTimeStamp = number;
1649216516
type FormDataEntryValue = File | string;

baselines/webworker.generated.d.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,32 @@ interface MessageEventInit extends EventInit {
9898
source?: object | null;
9999
}
100100

101+
interface NotificationAction {
102+
action: string;
103+
icon?: string;
104+
title: string;
105+
}
106+
101107
interface NotificationEventInit extends ExtendableEventInit {
102108
action?: string;
103109
notification: Notification;
104110
}
105111

106112
interface NotificationOptions {
113+
actions?: NotificationAction[];
114+
badge?: string;
107115
body?: string;
108116
data?: any;
109117
dir?: NotificationDirection;
110118
icon?: string;
119+
image?: string;
111120
lang?: string;
121+
renotify?: boolean;
122+
requireInteraction?: boolean;
123+
silent?: boolean;
112124
tag?: string;
125+
timestamp?: number;
126+
vibrate?: VibratePattern;
113127
}
114128

115129
interface ObjectURLOptions {
@@ -995,18 +1009,25 @@ interface NotificationEventMap {
9951009
}
9961010

9971011
interface Notification extends EventTarget {
998-
readonly body: string | null;
1012+
readonly actions: ReadonlyArray<NotificationAction>;
1013+
readonly badge: string;
1014+
readonly body: string;
9991015
readonly data: any;
10001016
readonly dir: NotificationDirection;
1001-
readonly icon: string | null;
1002-
readonly lang: string | null;
1017+
readonly icon: string;
1018+
readonly image: string;
1019+
readonly lang: string;
10031020
onclick: ((this: Notification, ev: Event) => any) | null;
10041021
onclose: ((this: Notification, ev: Event) => any) | null;
10051022
onerror: ((this: Notification, ev: Event) => any) | null;
10061023
onshow: ((this: Notification, ev: Event) => any) | null;
1007-
readonly permission: NotificationPermission;
1008-
readonly tag: string | null;
1024+
readonly renotify: boolean;
1025+
readonly requireInteraction: boolean;
1026+
readonly silent: boolean;
1027+
readonly tag: string;
1028+
readonly timestamp: number;
10091029
readonly title: string;
1030+
readonly vibrate: ReadonlyArray<number>;
10101031
close(): void;
10111032
addEventListener<K extends keyof NotificationEventMap>(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
10121033
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
@@ -1017,7 +1038,9 @@ interface Notification extends EventTarget {
10171038
declare var Notification: {
10181039
prototype: Notification;
10191040
new(title: string, options?: NotificationOptions): Notification;
1020-
requestPermission(callback?: NotificationPermissionCallback): Promise<NotificationPermission>;
1041+
readonly maxActions: number;
1042+
readonly permission: NotificationPermission;
1043+
requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise<NotificationPermission>;
10211044
};
10221045

10231046
interface NotificationEvent extends ExtendableEvent {
@@ -1195,7 +1218,6 @@ declare var PushEvent: {
11951218
};
11961219

11971220
interface PushManager {
1198-
readonly supportedContentEncodings: ReadonlyArray<string>;
11991221
getSubscription(): Promise<PushSubscription | null>;
12001222
permissionState(options?: PushSubscriptionOptionsInit): Promise<PushPermissionState>;
12011223
subscribe(options?: PushSubscriptionOptionsInit): Promise<PushSubscription>;
@@ -1204,6 +1226,7 @@ interface PushManager {
12041226
declare var PushManager: {
12051227
prototype: PushManager;
12061228
new(): PushManager;
1229+
readonly supportedContentEncodings: ReadonlyArray<string>;
12071230
};
12081231

12091232
interface PushMessageData {
@@ -1782,6 +1805,7 @@ type BodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStrea
17821805
type RequestInfo = Request | string;
17831806
type PerformanceEntryList = PerformanceEntry[];
17841807
type PushMessageDataInit = BufferSource | string;
1808+
type VibratePattern = number | number[];
17851809
type BufferSource = ArrayBufferView | ArrayBuffer;
17861810
type FormDataEntryValue = File | string;
17871811
type IDBValidKey = number | string | Date | BufferSource | IDBArrayKey;

inputfiles/idl/Notifications.widl

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[Constructor(DOMString title, optional NotificationOptions options),
2+
Exposed=(Window,Worker)]
3+
interface Notification : EventTarget {
4+
static readonly attribute NotificationPermission permission;
5+
[Exposed=Window] static Promise<NotificationPermission> requestPermission(optional NotificationPermissionCallback deprecatedCallback);
6+
7+
static readonly attribute unsigned long maxActions;
8+
9+
attribute EventHandler onclick;
10+
attribute EventHandler onshow;
11+
attribute EventHandler onerror;
12+
attribute EventHandler onclose;
13+
14+
readonly attribute DOMString title;
15+
readonly attribute NotificationDirection dir;
16+
readonly attribute DOMString lang;
17+
readonly attribute DOMString body;
18+
readonly attribute DOMString tag;
19+
readonly attribute USVString image;
20+
readonly attribute USVString icon;
21+
readonly attribute USVString badge;
22+
[SameObject] readonly attribute FrozenArray<unsigned long> vibrate;
23+
readonly attribute DOMTimeStamp timestamp;
24+
readonly attribute boolean renotify;
25+
readonly attribute boolean silent;
26+
readonly attribute boolean requireInteraction;
27+
[SameObject] readonly attribute any data;
28+
[SameObject] readonly attribute FrozenArray<NotificationAction> actions;
29+
30+
void close();
31+
};
32+
33+
dictionary NotificationOptions {
34+
NotificationDirection dir = "auto";
35+
DOMString lang = "";
36+
DOMString body = "";
37+
DOMString tag = "";
38+
USVString image;
39+
USVString icon;
40+
USVString badge;
41+
VibratePattern vibrate;
42+
DOMTimeStamp timestamp;
43+
boolean renotify = false;
44+
boolean silent = false;
45+
boolean requireInteraction = false;
46+
any data = null;
47+
sequence<NotificationAction> actions = [];
48+
};
49+
50+
enum NotificationPermission {
51+
"default",
52+
"denied",
53+
"granted"
54+
};
55+
56+
enum NotificationDirection {
57+
"auto",
58+
"ltr",
59+
"rtl"
60+
};
61+
62+
dictionary NotificationAction {
63+
required DOMString action;
64+
required DOMString title;
65+
USVString icon;
66+
};
67+
68+
callback NotificationPermissionCallback = void (NotificationPermission permission);
69+
70+
dictionary GetNotificationOptions {
71+
DOMString tag = "";
72+
};
73+
74+
partial interface ServiceWorkerRegistration {
75+
Promise<void> showNotification(DOMString title, optional NotificationOptions options);
76+
Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
77+
};
78+
79+
[Constructor(DOMString type, NotificationEventInit eventInitDict),
80+
Exposed=ServiceWorker]
81+
interface NotificationEvent : ExtendableEvent {
82+
readonly attribute Notification notification;
83+
readonly attribute DOMString action;
84+
};
85+
86+
dictionary NotificationEventInit : ExtendableEventInit {
87+
required Notification notification;
88+
DOMString action = "";
89+
};
90+
91+
partial interface ServiceWorkerGlobalScope {
92+
attribute EventHandler onnotificationclick;
93+
attribute EventHandler onnotificationclose;
94+
};

inputfiles/idl/Vibration.widl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef (unsigned long or sequence<unsigned long>) VibratePattern;
2+
3+
partial interface Navigator {
4+
boolean vibrate(VibratePattern pattern);
5+
};

inputfiles/idlSources.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"url": "https://w3c.github.io/navigation-timing/",
2424
"title": "Navigation Timing"
2525
},
26+
{
27+
"url": "https://notifications.spec.whatwg.org/",
28+
"title": "Notifications"
29+
},
2630
{
2731
"url": "https://w3c.github.io/performance-timeline/",
2832
"title": "Performance Timeline"
@@ -43,6 +47,10 @@
4347
"url": "https://www.w3.org/TR/user-timing-2/",
4448
"title": "User Timing"
4549
},
50+
{
51+
"url": "https://www.w3.org/TR/vibration/",
52+
"title": "Vibration"
53+
},
4654
{
4755
"url": "https://wicg.github.io/BackgroundSync/spec/",
4856
"title": "Web Background Synchronization"

inputfiles/knownWorkerTypes.json

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"MessageEvent",
5757
"MessagePort",
5858
"Notification",
59+
"NotificationAction",
5960
"Performance",
6061
"PerformanceEntry",
6162
"PerformanceEntryList",
@@ -80,6 +81,7 @@
8081
"ServiceWorkerRegistration",
8182
"SyncManager",
8283
"URL",
84+
"VibratePattern",
8385
"WebSocket",
8486
"Worker",
8587
"XMLHttpRequest",

inputfiles/overridingTypes.json

+23
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,29 @@
21892189
}
21902190
]
21912191
}
2192+
},
2193+
"Notification": {
2194+
"name": "Notification",
2195+
"events": {
2196+
"event": [
2197+
{
2198+
"name": "click",
2199+
"type": "Event"
2200+
},
2201+
{
2202+
"name": "close",
2203+
"type": "Event"
2204+
},
2205+
{
2206+
"name": "error",
2207+
"type": "Event"
2208+
},
2209+
{
2210+
"name": "show",
2211+
"type": "Event"
2212+
}
2213+
]
2214+
}
21922215
}
21932216
}
21942217
},

src/emitter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const eventTypeMap: Record<string, string> = {
4343

4444
// Used to decide if a member should be emitted given its static property and
4545
// the intended scope level.
46-
function matchScope(scope: EmitScope, x: Browser.Method) {
46+
function matchScope(scope: EmitScope, x: { static?: 1 | undefined }) {
4747
return scope === EmitScope.All || (scope === EmitScope.StaticOnly) === !!x.static;
4848
}
4949

@@ -618,10 +618,9 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) {
618618
}
619619

620620
function emitProperties(prefix: string, emitScope: EmitScope, i: Browser.Interface, conflictedMembers: Set<string>) {
621-
// Note: the schema file shows the property doesn't have "static" attribute,
622-
// therefore all properties are emited for the instance type.
623-
if (emitScope !== EmitScope.StaticOnly && i.properties) {
621+
if (i.properties) {
624622
mapToArray(i.properties.property)
623+
.filter(m => matchScope(emitScope, m))
625624
.filter(p => !isCovariantEventHandler(i, p))
626625
.sort(compareName)
627626
.forEach(p => emitProperty(prefix, i, emitScope, p, conflictedMembers));

src/widlprocess.ts

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function convertAttribute(attribute: webidl2.AttributeMemberType): Browser.Prope
172172
return {
173173
name: attribute.name,
174174
...convertIdlType(attribute.idlType),
175+
static: attribute.static ? 1 : undefined,
175176
"read-only": attribute.readonly ? 1 : undefined,
176177
"event-handler": attribute.idlType.idlType === "EventHandler" ? attribute.name.slice(2) : undefined
177178
}

0 commit comments

Comments
 (0)