Class: Dommy::ScreenOrientation

Inherits:
Object
  • Object
show all
Includes:
Bridge::Methods
Defined in:
lib/dommy/screen.rb

Overview

screen.orientation — the ScreenOrientation interface. Reports a fixed orientation from the viewport aspect ratio; lock/unlock are no-ops (a headless browser cannot rotate), lock still returning a resolved Promise so callers that await screen.orientation.lock(...) proceed.

Instance Method Summary collapse

Methods included from Bridge::Methods

included

Constructor Details

#initialize(window) ⇒ ScreenOrientation

Returns a new instance of ScreenOrientation.



59
60
61
# File 'lib/dommy/screen.rb', line 59

def initialize(window)
  @window = window
end

Instance Method Details

#__js_call__(method, _args) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/dommy/screen.rb', line 80

def __js_call__(method, _args)
  case method
  when "lock"
    PromiseValue.resolve(@window, nil)
  when "unlock", "addEventListener", "removeEventListener"
    nil
  when "dispatchEvent"
    true
  end
end

#__js_get__(key) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/dommy/screen.rb', line 63

def __js_get__(key)
  case key
  when "type"
    @window.inner_width >= @window.inner_height ? "landscape-primary" : "portrait-primary"
  when "angle"
    0
  else
    Bridge::ABSENT
  end
end

#__js_set__(_key, _value) ⇒ Object



74
75
76
# File 'lib/dommy/screen.rb', line 74

def __js_set__(_key, _value)
  Bridge::UNHANDLED
end