From ea35f370cca3c6a5947798d4512f104d1831b8c5 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Fri, 17 Oct 2025 14:32:34 +0800 Subject: [PATCH] Standardize window.orientation API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Window interface extension with orientation attribute and onorientationchange handler - Integrate orientationchange event firing into existing screen orientation change steps - Map window.orientation values according to WHATWG compat spec algorithm - Support required values (-90, 0, 90) and optional 180° value - Remove device-specific restrictions to support device-independent web This moves window.orientation from WHATWG compat spec to Screen Orientation spec where it belongs conceptually, providing a single authoritative definition. Fixes #249 --- index.html | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/index.html b/index.html index 5b5f19c..cf817c1 100644 --- a/index.html +++ b/index.html @@ -312,6 +312,55 @@

+
+

+ Extensions to the `Window` interface +

+
+        partial interface Window {
+          readonly attribute short orientation;
+          attribute EventHandler onorientationchange;
+        };
+      
+
+

+ `orientation` attribute +

+

+ When getting the {{Window/orientation}} attribute, the [=user agent=] MUST run + the following steps: +

+
    +
  1. Let |orientationAngle| be the [=Screen/current orientation angle=]. +
  2. +
  3. If |orientationAngle| is less than 180, return |orientationAngle|. +
  4. +
  5. If |orientationAngle| is 180, and the [=user agent=] supports that value, + return |orientationAngle|, else return 0. +
  6. +
  7. If |orientationAngle| is greater than 180, return |orientationAngle| - 360. +
  8. +
+

+ User agents MUST support the `-90`, `0` and `90` values and MAY optionally support `180`. +

+

+ `0` represents the natural orientation, `-90` represents 90 degrees clockwise, + `90` represents 90 degrees counterclockwise, and `180` represents 180 degrees + from natural orientation. +

+
+
+

+ `onorientationchange` event handler attribute +

+

+ The {{Window/onorientationchange}} attribute is an [=event handler IDL attribute=] for + the {{Window/onorientationchange}} [=event handler=], whose [=event handler event type=] + is orientationchange. +

+
+

Extensions to the `Screen` interface @@ -801,6 +850,9 @@

  • [=Fire an event=] named "change" at |screenOrientation|.
  • +
  • [=Fire an event=] named "orientationchange" at |document|'s [=relevant global object=]. +
  • Let |descendantDocs| be an [=ordered set=] consisting of