Skip to content

Commit 6ba5bfe

Browse files
saschanazsandersn
authored andcommitted
add DeviceMotion event types (#674)
1 parent 45da9a8 commit 6ba5bfe

5 files changed

Lines changed: 148 additions & 23 deletions

File tree

baselines/dom.generated.d.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,27 @@ interface DelayOptions extends AudioNodeOptions {
310310
maxDelayTime?: number;
311311
}
312312

313-
interface DeviceAccelerationDict {
313+
interface DeviceLightEventInit extends EventInit {
314+
value?: number;
315+
}
316+
317+
interface DeviceMotionEventAccelerationInit {
314318
x?: number | null;
315319
y?: number | null;
316320
z?: number | null;
317321
}
318322

319-
interface DeviceLightEventInit extends EventInit {
320-
value?: number;
323+
interface DeviceMotionEventInit extends EventInit {
324+
acceleration?: DeviceMotionEventAccelerationInit;
325+
accelerationIncludingGravity?: DeviceMotionEventAccelerationInit;
326+
interval?: number;
327+
rotationRate?: DeviceMotionEventRotationRateInit;
321328
}
322329

323-
interface DeviceMotionEventInit extends EventInit {
324-
acceleration?: DeviceAccelerationDict | null;
325-
accelerationIncludingGravity?: DeviceAccelerationDict | null;
326-
interval?: number | null;
327-
rotationRate?: DeviceRotationRateDict | null;
330+
interface DeviceMotionEventRotationRateInit {
331+
alpha?: number | null;
332+
beta?: number | null;
333+
gamma?: number | null;
328334
}
329335

330336
interface DeviceOrientationEventInit extends EventInit {
@@ -339,12 +345,6 @@ interface DevicePermissionDescriptor extends PermissionDescriptor {
339345
name: "camera" | "microphone" | "speaker";
340346
}
341347

342-
interface DeviceRotationRateDict {
343-
alpha?: number | null;
344-
beta?: number | null;
345-
gamma?: number | null;
346-
}
347-
348348
interface DocumentTimelineOptions {
349349
originTime?: number;
350350
}
@@ -4091,30 +4091,40 @@ declare var DeviceLightEvent: {
40914091

40924092
/** The DeviceMotionEvent provides web developers with information about the speed of changes for the device's position and orientation. */
40934093
interface DeviceMotionEvent extends Event {
4094-
readonly acceleration: DeviceAcceleration | null;
4095-
readonly accelerationIncludingGravity: DeviceAcceleration | null;
4096-
readonly interval: number | null;
4097-
readonly rotationRate: DeviceRotationRate | null;
4098-
initDeviceMotionEvent(type: string, bubbles: boolean, cancelable: boolean, acceleration: DeviceAccelerationDict | null, accelerationIncludingGravity: DeviceAccelerationDict | null, rotationRate: DeviceRotationRateDict | null, interval: number | null): void;
4094+
readonly acceleration: DeviceMotionEventAcceleration | null;
4095+
readonly accelerationIncludingGravity: DeviceMotionEventAcceleration | null;
4096+
readonly interval: number;
4097+
readonly rotationRate: DeviceMotionEventRotationRate | null;
40994098
}
41004099

41014100
declare var DeviceMotionEvent: {
41024101
prototype: DeviceMotionEvent;
4103-
new(typeArg: string, eventInitDict?: DeviceMotionEventInit): DeviceMotionEvent;
4102+
new(type: string, eventInitDict?: DeviceMotionEventInit): DeviceMotionEvent;
41044103
};
41054104

4105+
interface DeviceMotionEventAcceleration {
4106+
readonly x: number | null;
4107+
readonly y: number | null;
4108+
readonly z: number | null;
4109+
}
4110+
4111+
interface DeviceMotionEventRotationRate {
4112+
readonly alpha: number | null;
4113+
readonly beta: number | null;
4114+
readonly gamma: number | null;
4115+
}
4116+
41064117
/** The DeviceOrientationEvent provides web developers with information from the physical orientation of the device running the web page. */
41074118
interface DeviceOrientationEvent extends Event {
41084119
readonly absolute: boolean;
41094120
readonly alpha: number | null;
41104121
readonly beta: number | null;
41114122
readonly gamma: number | null;
4112-
initDeviceOrientationEvent(type: string, bubbles: boolean, cancelable: boolean, alpha: number | null, beta: number | null, gamma: number | null, absolute: boolean): void;
41134123
}
41144124

41154125
declare var DeviceOrientationEvent: {
41164126
prototype: DeviceOrientationEvent;
4117-
new(typeArg: string, eventInitDict?: DeviceOrientationEventInit): DeviceOrientationEvent;
4127+
new(type: string, eventInitDict?: DeviceOrientationEventInit): DeviceOrientationEvent;
41184128
};
41194129

41204130
/** Provides information about the rate at which the device is rotating around all three axes. */
@@ -16937,6 +16947,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
1693716947
"devicelight": DeviceLightEvent;
1693816948
"devicemotion": DeviceMotionEvent;
1693916949
"deviceorientation": DeviceOrientationEvent;
16950+
"deviceorientationabsolute": DeviceOrientationEvent;
1694016951
"drag": DragEvent;
1694116952
"dragend": DragEvent;
1694216953
"dragenter": DragEvent;
@@ -17059,6 +17070,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
1705917070
ondevicelight: ((this: Window, ev: DeviceLightEvent) => any) | null;
1706017071
ondevicemotion: ((this: Window, ev: DeviceMotionEvent) => any) | null;
1706117072
ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => any) | null;
17073+
ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null;
1706217074
onmousewheel: ((this: Window, ev: Event) => any) | null;
1706317075
onmsgesturechange: ((this: Window, ev: Event) => any) | null;
1706417076
onmsgesturedoubletap: ((this: Window, ev: Event) => any) | null;
@@ -18054,6 +18066,7 @@ declare var oncompassneedscalibration: ((this: Window, ev: Event) => any) | null
1805418066
declare var ondevicelight: ((this: Window, ev: DeviceLightEvent) => any) | null;
1805518067
declare var ondevicemotion: ((this: Window, ev: DeviceMotionEvent) => any) | null;
1805618068
declare var ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => any) | null;
18069+
declare var ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null;
1805718070
declare var onmousewheel: ((this: Window, ev: Event) => any) | null;
1805818071
declare var onmsgesturechange: ((this: Window, ev: Event) => any) | null;
1805918072
declare var onmsgesturedoubletap: ((this: Window, ev: Event) => any) | null;

inputfiles/addedTypes.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@
314314
]
315315
}
316316
},
317+
"DeviceMotionEventAcceleration": {
318+
"no-interface-object": 1
319+
},
320+
"DeviceMotionEventRotationRate": {
321+
"no-interface-object": 1
322+
},
317323
"RTCError": {
318324
"specs": "webrtc",
319325
"constructor": {
@@ -535,7 +541,15 @@
535541
],
536542
"override-index-signatures": [
537543
"[index: number]: Window"
538-
]
544+
],
545+
"events": {
546+
"event": [
547+
{
548+
"name": "deviceorientationabsolute",
549+
"type": "DeviceOrientationEvent"
550+
}
551+
]
552+
}
539553
},
540554
"URLSearchParams": {
541555
"name": "URLSearchParams",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
partial interface Window {
2+
[SecureContext] attribute EventHandler ondeviceorientation;
3+
};
4+
5+
[Constructor(DOMString type, optional DeviceOrientationEventInit eventInitDict), Exposed=Window, SecureContext]
6+
interface DeviceOrientationEvent : Event {
7+
readonly attribute double? alpha;
8+
readonly attribute double? beta;
9+
readonly attribute double? gamma;
10+
readonly attribute boolean absolute;
11+
12+
static Promise<PermissionState> requestPermission();
13+
};
14+
15+
dictionary DeviceOrientationEventInit : EventInit {
16+
double? alpha = null;
17+
double? beta = null;
18+
double? gamma = null;
19+
boolean absolute = false;
20+
};
21+
22+
enum PermissionState {
23+
"granted",
24+
"denied",
25+
};
26+
27+
partial interface Window {
28+
[SecureContext] attribute EventHandler ondeviceorientationabsolute;
29+
};
30+
31+
partial interface Window {
32+
attribute EventHandler oncompassneedscalibration;
33+
};
34+
35+
partial interface Window {
36+
[SecureContext] attribute EventHandler ondevicemotion;
37+
};
38+
39+
[SecureContext]
40+
interface DeviceMotionEventAcceleration {
41+
readonly attribute double? x;
42+
readonly attribute double? y;
43+
readonly attribute double? z;
44+
};
45+
46+
[SecureContext]
47+
interface DeviceMotionEventRotationRate {
48+
readonly attribute double? alpha;
49+
readonly attribute double? beta;
50+
readonly attribute double? gamma;
51+
};
52+
53+
[Constructor(DOMString type, optional DeviceMotionEventInit eventInitDict), Exposed=Window, SecureContext]
54+
interface DeviceMotionEvent : Event {
55+
readonly attribute DeviceMotionEventAcceleration? acceleration;
56+
readonly attribute DeviceMotionEventAcceleration? accelerationIncludingGravity;
57+
readonly attribute DeviceMotionEventRotationRate? rotationRate;
58+
readonly attribute double interval;
59+
60+
static Promise<PermissionState> requestPermission();
61+
};
62+
63+
dictionary DeviceMotionEventAccelerationInit {
64+
double? x = null;
65+
double? y = null;
66+
double? z = null;
67+
};
68+
69+
dictionary DeviceMotionEventRotationRateInit {
70+
double? alpha = null;
71+
double? beta = null;
72+
double? gamma = null;
73+
};
74+
75+
dictionary DeviceMotionEventInit : EventInit {
76+
DeviceMotionEventAccelerationInit acceleration;
77+
DeviceMotionEventAccelerationInit accelerationIncludingGravity;
78+
DeviceMotionEventRotationRateInit rotationRate;
79+
double interval = 0;
80+
};

inputfiles/idlSources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"url": "https://www.w3.org/TR/css-will-change/",
3737
"title": "CSS Will Change"
3838
},
39+
{
40+
"url": "https://w3c.github.io/deviceorientation/",
41+
"title": "DeviceOrientation Event"
42+
},
3943
{
4044
"url": "https://dom.spec.whatwg.org/",
4145
"title": "DOM"

inputfiles/removedTypes.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@
5858
}
5959
}
6060
},
61+
"DeviceMotionEvent": {
62+
"methods": {
63+
"method": {
64+
"requestPermission": null
65+
}
66+
}
67+
},
68+
"DeviceOrientationEvent": {
69+
"methods": {
70+
"method": {
71+
"requestPermission": null
72+
}
73+
}
74+
},
6175
"Document": {
6276
"methods": {
6377
"method": {

0 commit comments

Comments
 (0)