Class: Dommy::UIEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/dommy/event.rb

Overview

UIEvent — the base for user-interface events (MouseEvent, KeyboardEvent, CompositionEvent, …), adding view (the associated window) and detail. Carries the legacy initUIEvent, which — like initEvent — is a no-op while the event is being dispatched.

Constant Summary

Constants inherited from Event

Event::AT_TARGET, Event::BUBBLING_PHASE, Event::CAPTURING_PHASE, Event::NONE

Instance Attribute Summary

Attributes inherited from Event

#type

Instance Method Summary collapse

Methods inherited from Event

#__internal_clear_propagation_flags__, #__internal_mark_trusted__, #__internal_prepare_for_dispatch__, #__internal_record_path__, #__internal_run_passive__, #__internal_set_current_target__, #__internal_set_dispatch_flag__, #__internal_set_event_phase__, #__js_set__, #bubbles?, #default_prevented?, #immediate_propagation_stopped?, #init_event, #propagation_stopped?

Methods included from Bridge::Methods

included

Constructor Details

#initialize(type, init = nil) ⇒ UIEvent

Returns a new instance of UIEvent.



640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/dommy/event.rb', line 640

def initialize(type, init = nil)
  super
  @view = read_init(init, "view")
  # WebIDL: `view` is `Window?`, so a present non-null value that isn't a
  # Window is a TypeError during dictionary conversion.
  unless @view.nil? || (defined?(Bridge::UNDEFINED) && @view.equal?(Bridge::UNDEFINED)) ||
         @view.is_a?(Dommy::Window)
    raise Bridge::TypeError, "'view' member must be a Window or null"
  end
  @view = nil if defined?(Bridge::UNDEFINED) && @view.equal?(Bridge::UNDEFINED)
  @detail = (read_init(init, "detail") || 0).to_i
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/dommy/event.rb', line 662

def __js_call__(method, args)
  case method
  when "initUIEvent"
    # Deprecated initUIEvent(type, bubbles=false, cancelable=false, view=null,
    # detail=0). Mandatory type; a no-op while dispatching.
    raise Bridge::TypeError, "initUIEvent requires a type argument" if args.empty?

    unless @dispatch_flag
      init_event(args[0], args[1], args[2])
      @view = args[3]
      @detail = (args[4] || 0).to_i
    end
    nil
  else
    super
  end
end

#__js_get__(key) ⇒ Object



653
654
655
656
657
658
659
# File 'lib/dommy/event.rb', line 653

def __js_get__(key)
  case key
  when "view" then @view
  when "detail" then @detail
  else super
  end
end