From 8577e5b248c2912e631553c4963017cb34d70e9a Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Tue, 7 May 2024 15:09:23 +1000 Subject: [PATCH] Editorial: cleanup fire an orientation event algorithm --- index.bs | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/index.bs b/index.bs index eb8edfa..f857c53 100644 --- a/index.bs +++ b/index.bs @@ -337,38 +337,38 @@ The requestPermission(absolute
-To fire an orientation event given a event name (a string), window (a {{Window}}) and absolute (a boolean): - - 1. Let orientation be null. - 1. Let topLevelTraversable be window's navigable's top-level traversable. - 1. Let virtualSensorType be "relative-orientation" if absolute is false, and "absolute-orientation" otherwise. - 1. If topLevelTraversable's virtual sensor mapping contains virtualSensorType: - 1. Let virtualSensor be topLevelTraversable's virtual sensor mapping[virtualSensorType]. - 1. If virtualSensor's can provide readings flag is true: - 1. Set orientation to the latest readings provided to virtualSensor with the "alpha", "beta", and "gamma" keys. +To fire an orientation event given a {{DOMString}} |event|, {{Window}} |window| and {{boolean}} |absolute|: + + 1. Let |orientation| be null. + 1. Let |topLevelTraversable| be |window|'s [=Window/navigable=]'s [=navigable/top-level traversable=]. + 1. Let |virtualSensorType| be "relative-orientation" if |absolute| is false, and "absolute-orientation" otherwise. + 1. If |topLevelTraversable|'s virtual sensor mapping contains |virtualSensorType|: + 1. Let |virtualSensor| be |topLevelTraversable|'s virtual sensor mapping[|virtualSensorType|]. + 1. If |virtualSensor|'s can provide readings flag is true: + 1. Set |orientation| to the latest readings provided to |virtualSensor| with the "alpha", "beta", and "gamma" keys. 1. Otherwise: - 1. If absolute is false: - 1. Set orientation to the device's relative orientation in the tridimensional plane. + 1. If |absolute| is false: + 1. Set |orientation| to the device's [=relative orientation=] in the tridimensional plane. 1. Otherwise: - 1. Set orientation to the device's absolute orientation in the tridimensional plane. - 1. Let permissions be null. - 1. If absolute is false: - 1. Set permissions to « "accelerometer", "gyroscope" ». + 1. Set |orientation| to the device's [=absolute orientation=] in the tridimensional plane. + 1. Let |permissions| be null. + 1. If |absolute| is false: + 1. Set |permissions| to « "accelerometer", "gyroscope" ». 1. Otherwise: - 1. Set permissions to « "accelerometer", "gyroscope", "magnetometer" ». - 1. Let environment be window's relevant settings object. + 1. Set |permissions| to « "accelerometer", "gyroscope", "magnetometer" ». + 1. Let |environment| be |window|'s relevant settings object. 1. Run these steps in parallel: - 1. For each permission name in permissions: - 1. Let state be the result of getting the current permission state with permission name and environment. - 1. If state is not "{{PermissionState/granted}}", return. - 1. Queue a global task on the device motion and orientation task source given window to run the following steps: - 1. Let z rotation be orientation's representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Z axis, or null if the implementation cannot provide an angle value. - 1. If z rotation is not null, limit z rotation's precision to 0.1 degrees. - 1. Let x rotation be orientation's representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the X' axis, or null if the implementation cannot provide an angle value. - 1. If x rotation is not null, limit x rotation's precision to 0.1 degrees. - 1. Let y rotation be orientation's representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Y'' axis, or null if the implementation cannot provide an angle value. - 1. If y rotation is not null, limit y rotation's precision to 0.1 degrees. - 1. Fire an event named event name at window, using {{DeviceOrientationEvent}}, with the {{DeviceOrientationEvent/alpha}} attribute initialized to z rotation, the {{DeviceOrientationEvent/beta}} attribute initialized to x rotation, the {{DeviceOrientationEvent/gamma}} attribute initialized to y rotation, and the {{DeviceOrientationEvent/absolute}} attribute initialized to absolute. + 1. [=list/For each=] |permission| in |permissions|: + 1. Let |state| be the result of getting the current permission state with |permission| and |environment|. + 1. If |state| is not "{{PermissionState/granted}}", return. + 1. [=Queue a global task=] on the [=device motion and orientation task source=] given |window| to run the following steps: + 1. Let |z| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Z axis, or null if the implementation cannot provide an angle value. + 1. If |z| is not null, limit |z|'s precision to 0.1 degrees. + 1. Let |x| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the X' axis, or null if the implementation cannot provide an angle value. + 1. If |x| is not null, limit |x|'s precision to 0.1 degrees. + 1. Let |y| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Y'' axis, or null if the implementation cannot provide an angle value. + 1. If |y| is not null, limit |y|'s precision to 0.1 degrees. + 1. [=Fire an event=] named |event| at |window|, using {{DeviceOrientationEvent}}, with the {{DeviceOrientationEvent/alpha}} attribute initialized to |z|, the {{DeviceOrientationEvent/beta}} attribute initialized to |x|, the {{DeviceOrientationEvent/gamma}} attribute initialized to |y|, and the {{DeviceOrientationEvent/absolute}} attribute initialized to |absolute|.