Skip to content

Add notifications/vibration types #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -9816,18 +9830,25 @@ interface NotificationEventMap {
}

interface Notification extends EventTarget {
readonly body: string | null;
readonly actions: ReadonlyArray<NotificationAction>;
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;
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<number>;
close(): void;
addEventListener<K extends keyof NotificationEventMap>(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -9838,7 +9859,9 @@ interface Notification extends EventTarget {
declare var Notification: {
prototype: Notification;
new(title: string, options?: NotificationOptions): Notification;
requestPermission(callback?: NotificationPermissionCallback): Promise<NotificationPermission>;
readonly maxActions: number;
readonly permission: NotificationPermission;
requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise<NotificationPermission>;
};

interface OES_element_index_uint {
Expand Down Expand Up @@ -10448,7 +10471,6 @@ interface PromiseRejectionEventInit extends EventInit {
}

interface PushManager {
readonly supportedContentEncodings: ReadonlyArray<string>;
getSubscription(): Promise<PushSubscription | null>;
permissionState(options?: PushSubscriptionOptionsInit): Promise<PushPermissionState>;
subscribe(options?: PushSubscriptionOptionsInit): Promise<PushSubscription>;
Expand All @@ -10457,6 +10479,7 @@ interface PushManager {
declare var PushManager: {
prototype: PushManager;
new(): PushManager;
readonly supportedContentEncodings: ReadonlyArray<string>;
};

interface PushSubscription {
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 31 additions & 7 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -995,18 +1009,25 @@ interface NotificationEventMap {
}

interface Notification extends EventTarget {
readonly body: string | null;
readonly actions: ReadonlyArray<NotificationAction>;
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;
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<number>;
close(): void;
addEventListener<K extends keyof NotificationEventMap>(type: K, listener: (this: Notification, ev: NotificationEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -1017,7 +1038,9 @@ interface Notification extends EventTarget {
declare var Notification: {
prototype: Notification;
new(title: string, options?: NotificationOptions): Notification;
requestPermission(callback?: NotificationPermissionCallback): Promise<NotificationPermission>;
readonly maxActions: number;
readonly permission: NotificationPermission;
requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise<NotificationPermission>;
};

interface NotificationEvent extends ExtendableEvent {
Expand Down Expand Up @@ -1195,7 +1218,6 @@ declare var PushEvent: {
};

interface PushManager {
readonly supportedContentEncodings: ReadonlyArray<string>;
getSubscription(): Promise<PushSubscription | null>;
permissionState(options?: PushSubscriptionOptionsInit): Promise<PushPermissionState>;
subscribe(options?: PushSubscriptionOptionsInit): Promise<PushSubscription>;
Expand All @@ -1204,6 +1226,7 @@ interface PushManager {
declare var PushManager: {
prototype: PushManager;
new(): PushManager;
readonly supportedContentEncodings: ReadonlyArray<string>;
};

interface PushMessageData {
Expand Down Expand Up @@ -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;
Expand Down
94 changes: 94 additions & 0 deletions inputfiles/idl/Notifications.widl
Original file line number Diff line number Diff line change
@@ -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<NotificationPermission> 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<unsigned long> 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<NotificationAction> 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<NotificationAction> 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<void> showNotification(DOMString title, optional NotificationOptions options);
Promise<sequence<Notification>> 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;
};
5 changes: 5 additions & 0 deletions inputfiles/idl/Vibration.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typedef (unsigned long or sequence<unsigned long>) VibratePattern;

partial interface Navigator {
boolean vibrate(VibratePattern pattern);
};
8 changes: 8 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions inputfiles/knownWorkerTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"MessageEvent",
"MessagePort",
"Notification",
"NotificationAction",
"Performance",
"PerformanceEntry",
"PerformanceEntryList",
Expand All @@ -80,6 +81,7 @@
"ServiceWorkerRegistration",
"SyncManager",
"URL",
"VibratePattern",
"WebSocket",
"Worker",
"XMLHttpRequest",
Expand Down
23 changes: 23 additions & 0 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
}
},
Expand Down
7 changes: 3 additions & 4 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const eventTypeMap: Record<string, string> = {

// 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;
}

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

function emitProperties(prefix: string, emitScope: EmitScope, i: Browser.Interface, conflictedMembers: Set<string>) {
// 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));
Expand Down
1 change: 1 addition & 0 deletions src/widlprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down