Class: Vigilem::DOM::KeyboardEvent
- Inherits:
-
W3C::DOM3::KeyboardEvent
- Object
- W3C::DOM4::Event
- W3C::DOM3::UIEvent
- W3C::DOM3::KeyboardEvent
- Vigilem::DOM::KeyboardEvent
- Defined in:
- lib/vigilem/dom/keyboard_event.rb
Overview
Constant Summary
Constants included from W3C::DOM3::KeyboardEvent::KeyLocations
W3C::DOM3::KeyboardEvent::KeyLocations::DOM_KEY_LOCATION_LEFT, W3C::DOM3::KeyboardEvent::KeyLocations::DOM_KEY_LOCATION_NUMPAD, W3C::DOM3::KeyboardEvent::KeyLocations::DOM_KEY_LOCATION_RIGHT, W3C::DOM3::KeyboardEvent::KeyLocations::DOM_KEY_LOCATION_STANDARD
Constants inherited from W3C::DOM4::Event
W3C::DOM4::Event::AT_TARGET, W3C::DOM4::Event::BUBBLING_PHASE, W3C::DOM4::Event::CAPTURING_PHASE, W3C::DOM4::Event::NONE
Instance Attribute Summary collapse
- #modifier_state ⇒ Hash readonly
-
#os_specific ⇒ Object
readonly
@todo, :chr.
Class Method Summary collapse
-
.alternative_key_names ⇒ Array<Array<Symbol>>
this is not a hash so that the values can be #joined as a regex the last value of each group is the DOM value without the prefix.
-
.shared_keyboard_and_mouse_event_init_key(key_name) ⇒ Symbol || NilClass
converts a common key to shared_keyboard_and_mouse_event_init_key dom_3 are not prefixed by keyModifierState.
-
.shared_keyboard_and_mouse_event_init_keys ⇒ Array<Symbol>
gets the keys for SharedKeyboardAndMouseEventInit.
-
.SharedKeyboardAndMouseEventInit(hsh_or_ary) ⇒ Hash
(also: shared_keyboard_and_mouse_event_init)
converts common names to SharedKeyboardAndMouseEventInit.
- .types ⇒ Array<String>
Instance Method Summary collapse
- #copy_to(key_type) ⇒ KeyboardEvent
-
#initialize(type, options = {}) ⇒ KeyboardEvent
constructor
@option :modifiers || :modifier_state.
- #inspect ⇒ String
-
#to_s ⇒ String
has @type @key @location, so the object can be distinguised from other KeyboardEvents.
Methods inherited from W3C::DOM3::KeyboardEvent
Methods inherited from W3C::DOM4::Event
#preventDefault, #stopImmediatePropagation, #stopPropagation
Constructor Details
#initialize(type, options = {}) ⇒ KeyboardEvent
@option :modifiers || :modifier_state
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 36 def initialize(type, ={}) raise TypeError, "invalid type `#{type}'" if strict = Vigilem::DOM.strict and not self.class.types.include?(type) @type = type @key = [:key] ||= '' if [:location] and strict and (kl = KeyLocations).constants.none? {|const| kl.const_get(const) == [:location] } raise ArgumentError, "invalid location `#{[:location]}'" end @location = [:location] ||= 0 @repeat = [:repeat] ||= false @os_specific = self.class.hash_frozen_clone([:os_specific] || {}) @modifier_state = self.class.hash_frozen_clone([:modifiers] || [:modifier_state] || {}) mod_dict = self.class.shared_keyboard_and_mouse_event_init(@modifier_state) super(type, mod_dict.merge()) end |
Instance Attribute Details
#modifier_state ⇒ Hash (readonly)
11 12 13 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 11 def modifier_state @modifier_state end |
#os_specific ⇒ Object (readonly)
@todo, :chr
11 12 13 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 11 def os_specific @os_specific end |
Class Method Details
.alternative_key_names ⇒ Array<Array<Symbol>>
this is not a hash so that the values can be #joined as a regex the last value of each group is the DOM value without the prefix
113 114 115 116 117 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 113 def alternative_key_names @alternative_key_names ||= [[:alt, :menu, :altKey], [:alt_graph, :AltGraph], [:caps_lock, :CapsLock], [:ctrl, :control, :ctrlKey], [:Fn], [:fn_lock, :FnLock], [:Hyper], [:meta, :metaKey], [:num_lock, :NumLock], [:OS], [:scroll_lock, :ScrollLock], [:shift, :shiftKey], [:Super], [:Symbol], [:symbol_lock, :SymbolLock]] end |
.shared_keyboard_and_mouse_event_init_key(key_name) ⇒ Symbol || NilClass
converts a common key to shared_keyboard_and_mouse_event_init_key dom_3 are not prefixed by keyModifierState
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 123 def shared_keyboard_and_mouse_event_init_key(key_name) key_group = alternative_key_names.find {|key_grp| /^(#{key_grp.join('|')})$/i =~ key_name.to_s } if key_group if @dom_3_attrs.include?(correct_key = key_group.last) correct_key else "keyModifierState#{correct_key}".to_sym end end end |
.shared_keyboard_and_mouse_event_init_keys ⇒ Array<Symbol>
gets the keys for SharedKeyboardAndMouseEventInit
137 138 139 140 141 142 143 144 145 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 137 def shared_keyboard_and_mouse_event_init_keys shared_keyboard_and_mouse_event_init_keys ||= alternative_key_names.map do |key_grp| if @dom_3_attrs.include?(correct_key = key_grp.last) correct_key else "keyModifierState#{correct_key}".to_sym end end end |
.SharedKeyboardAndMouseEventInit(hsh_or_ary) ⇒ Hash Also known as:
converts common names to SharedKeyboardAndMouseEventInit
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 150 def SharedKeyboardAndMouseEventInit(hsh_or_ary) hsh = if hsh_or_ary.is_a?(Hash) hsh_or_ary else Hash[hsh_or_ary.zip([true] * hsh_or_ary.size)] end alternative_key_names.each_with_object({}) do |key_grp, out_hash| skamei_name = shared_keyboard_and_mouse_event_init_key(key_grp.last) matched_usr_key = hsh.keys.find {|usr_key| usr_key =~ /^(#{key_grp.join('|')})$/i } out_hash[skamei_name] = !!hsh[matched_usr_key] end end |
.types ⇒ Array<String>
106 107 108 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 106 def types @types ||= %w(keyup keypress keydown) end |
Instance Method Details
#copy_to(key_type) ⇒ KeyboardEvent
84 85 86 87 88 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 84 def copy_to(key_type) copy = Support::Utils.deep_dup(self) copy.instance_variable_set(:@type, key_type.to_s) copy end |
#inspect ⇒ String
98 99 100 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 98 def inspect "<#{self.class}:0x#{self.object_id} #{instance_variables.map {|var| "#{var}=#{instance_variable_get(var).inspect}" }.sort_by {|name| name[1..2]}.join(' ')}>" end |
#to_s ⇒ String
has @type @key @location, so the object can be distinguised from other KeyboardEvents
92 93 94 |
# File 'lib/vigilem/dom/keyboard_event.rb', line 92 def to_s "#{super().chop} @type=#{@type.inspect} @key=#{@key.inspect} @location=#{location.inspect}>" end |