opal-browser 0.2.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +78 -0
  3. data/.gitignore +3 -0
  4. data/CHANGELOG.md +11 -0
  5. data/Gemfile +17 -3
  6. data/LICENSE +2 -1
  7. data/README.md +131 -54
  8. data/Rakefile +29 -1
  9. data/config.ru +20 -3
  10. data/docs/polyfills.md +24 -0
  11. data/examples/2048/Gemfile +6 -0
  12. data/examples/2048/README.md +13 -0
  13. data/examples/2048/app/application.rb +169 -0
  14. data/examples/2048/config.ru +9 -0
  15. data/examples/canvas/Gemfile +6 -0
  16. data/examples/canvas/README.md +9 -0
  17. data/examples/canvas/app/application.rb +55 -0
  18. data/examples/canvas/config.ru +9 -0
  19. data/examples/component/Gemfile +6 -0
  20. data/examples/component/README.md +10 -0
  21. data/examples/component/app/application.rb +66 -0
  22. data/examples/component/config.ru +9 -0
  23. data/examples/integrations/README.md +24 -0
  24. data/examples/integrations/dynamic-rack-opal-sprockets-server/Gemfile +6 -0
  25. data/examples/integrations/dynamic-rack-opal-sprockets-server/README.md +16 -0
  26. data/examples/integrations/dynamic-rack-opal-sprockets-server/app/application.rb +6 -0
  27. data/examples/integrations/dynamic-rack-opal-sprockets-server/config.ru +9 -0
  28. data/examples/integrations/dynamic-roda-roda-sprockets/.gitignore +1 -0
  29. data/examples/integrations/dynamic-roda-roda-sprockets/Gemfile +7 -0
  30. data/examples/integrations/dynamic-roda-roda-sprockets/README.md +22 -0
  31. data/examples/integrations/dynamic-roda-roda-sprockets/Rakefile +4 -0
  32. data/examples/integrations/dynamic-roda-roda-sprockets/app/application.rb +6 -0
  33. data/examples/integrations/dynamic-roda-roda-sprockets/app.rb +32 -0
  34. data/examples/integrations/dynamic-roda-roda-sprockets/config.ru +3 -0
  35. data/examples/integrations/dynamic-roda-tilt/.gitignore +1 -0
  36. data/examples/integrations/dynamic-roda-tilt/Gemfile +8 -0
  37. data/examples/integrations/dynamic-roda-tilt/README.md +17 -0
  38. data/examples/integrations/dynamic-roda-tilt/Rakefile +6 -0
  39. data/examples/integrations/dynamic-roda-tilt/app/application.rb +6 -0
  40. data/examples/integrations/dynamic-roda-tilt/app.rb +50 -0
  41. data/examples/integrations/dynamic-roda-tilt/config.ru +3 -0
  42. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/Gemfile +7 -0
  43. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/README.md +16 -0
  44. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/app/application.rb +6 -0
  45. data/examples/integrations/dynamic-sinatra-opal-sprockets-server/config.ru +29 -0
  46. data/examples/integrations/static-bash/.gitignore +2 -0
  47. data/examples/integrations/static-bash/Gemfile +3 -0
  48. data/examples/integrations/static-bash/README.md +8 -0
  49. data/examples/integrations/static-bash/app/application.rb +6 -0
  50. data/examples/integrations/static-bash/build.sh +4 -0
  51. data/examples/integrations/static-bash/index.html +10 -0
  52. data/examples/integrations/static-bash-opal-parser/.gitignore +3 -0
  53. data/examples/integrations/static-bash-opal-parser/Gemfile +3 -0
  54. data/examples/integrations/static-bash-opal-parser/README.md +10 -0
  55. data/examples/integrations/static-bash-opal-parser/build.sh +4 -0
  56. data/examples/integrations/static-bash-opal-parser/index.html +19 -0
  57. data/examples/integrations/static-rake/.gitignore +1 -0
  58. data/examples/integrations/static-rake/Gemfile +4 -0
  59. data/examples/integrations/static-rake/README.md +7 -0
  60. data/examples/integrations/static-rake/Rakefile +10 -0
  61. data/examples/integrations/static-rake/app/application.rb +6 -0
  62. data/examples/integrations/static-rake/index.html +9 -0
  63. data/examples/integrations/static-rake-guard/.gitignore +1 -0
  64. data/examples/integrations/static-rake-guard/Gemfile +6 -0
  65. data/examples/integrations/static-rake-guard/Guardfile +3 -0
  66. data/examples/integrations/static-rake-guard/README.md +10 -0
  67. data/examples/integrations/static-rake-guard/Rakefile +10 -0
  68. data/examples/integrations/static-rake-guard/app/application.rb +6 -0
  69. data/examples/integrations/static-rake-guard/index.html +9 -0
  70. data/examples/svg/.gitignore +1 -0
  71. data/examples/svg/Gemfile +4 -0
  72. data/examples/svg/README.md +7 -0
  73. data/examples/svg/Rakefile +10 -0
  74. data/examples/svg/app/application.rb +11 -0
  75. data/examples/svg/index.html +17 -0
  76. data/examples/svg/index.svg +6 -0
  77. data/index.html.erb +2 -3
  78. data/opal/browser/audio/node.rb +121 -0
  79. data/opal/browser/audio/param_schedule.rb +43 -0
  80. data/opal/browser/audio.rb +66 -0
  81. data/opal/browser/blob.rb +94 -0
  82. data/opal/browser/canvas/data.rb +1 -1
  83. data/opal/browser/canvas/gradient.rb +1 -1
  84. data/opal/browser/canvas/style.rb +3 -1
  85. data/opal/browser/canvas/text.rb +1 -1
  86. data/opal/browser/canvas.rb +17 -3
  87. data/opal/browser/console.rb +3 -1
  88. data/opal/browser/cookies.rb +72 -34
  89. data/opal/browser/crypto.rb +79 -0
  90. data/opal/browser/css/declaration.rb +1 -1
  91. data/opal/browser/css/rule.rb +1 -1
  92. data/opal/browser/css/style_sheet.rb +2 -2
  93. data/opal/browser/css.rb +23 -7
  94. data/opal/browser/database/sql.rb +7 -8
  95. data/opal/browser/delay.rb +16 -0
  96. data/opal/browser/dom/attribute.rb +1 -1
  97. data/opal/browser/dom/builder.rb +29 -10
  98. data/opal/browser/dom/document.rb +81 -13
  99. data/opal/browser/dom/document_fragment.rb +18 -0
  100. data/opal/browser/dom/document_or_shadow_root.rb +19 -0
  101. data/opal/browser/dom/element/attributes.rb +28 -4
  102. data/opal/browser/dom/element/button.rb +31 -0
  103. data/opal/browser/dom/element/custom.rb +177 -0
  104. data/opal/browser/dom/element/data.rb +17 -2
  105. data/opal/browser/dom/element/editable.rb +47 -0
  106. data/opal/browser/dom/element/form.rb +38 -0
  107. data/opal/browser/dom/element/iframe.rb +37 -0
  108. data/opal/browser/dom/element/image.rb +2 -0
  109. data/opal/browser/dom/element/input.rb +36 -0
  110. data/opal/browser/dom/element/media.rb +17 -0
  111. data/opal/browser/dom/element/scroll.rb +106 -74
  112. data/opal/browser/dom/element/select.rb +6 -0
  113. data/opal/browser/dom/element/size.rb +12 -0
  114. data/opal/browser/dom/element/template.rb +2 -0
  115. data/opal/browser/dom/element/textarea.rb +2 -0
  116. data/opal/browser/dom/element.rb +194 -50
  117. data/opal/browser/dom/mutation_observer.rb +2 -2
  118. data/opal/browser/dom/node.rb +53 -13
  119. data/opal/browser/dom/node_set.rb +13 -2
  120. data/opal/browser/dom/shadow_root.rb +12 -0
  121. data/opal/browser/dom/text.rb +2 -2
  122. data/opal/browser/dom.rb +38 -5
  123. data/opal/browser/effects.rb +170 -4
  124. data/opal/browser/event/all.rb +26 -0
  125. data/opal/browser/event/animation.rb +2 -0
  126. data/opal/browser/event/audio_processing.rb +2 -0
  127. data/opal/browser/event/base.rb +35 -4
  128. data/opal/browser/event/before_unload.rb +2 -0
  129. data/opal/browser/event/clipboard.rb +9 -0
  130. data/opal/browser/event/close.rb +2 -0
  131. data/opal/browser/event/composition.rb +2 -0
  132. data/opal/browser/event/custom.rb +1 -1
  133. data/opal/browser/event/data_transfer.rb +95 -0
  134. data/opal/browser/event/device_light.rb +2 -0
  135. data/opal/browser/event/device_motion.rb +2 -0
  136. data/opal/browser/event/device_orientation.rb +2 -0
  137. data/opal/browser/event/device_proximity.rb +2 -0
  138. data/opal/browser/event/drag.rb +9 -5
  139. data/opal/browser/event/focus.rb +2 -0
  140. data/opal/browser/event/gamepad.rb +3 -1
  141. data/opal/browser/event/hash_change.rb +2 -0
  142. data/opal/browser/event/keyboard.rb +14 -1
  143. data/opal/browser/event/message.rb +2 -0
  144. data/opal/browser/event/mouse.rb +10 -6
  145. data/opal/browser/event/page_transition.rb +2 -0
  146. data/opal/browser/event/pop_state.rb +2 -0
  147. data/opal/browser/event/progress.rb +2 -0
  148. data/opal/browser/event/sensor.rb +2 -0
  149. data/opal/browser/event/storage.rb +2 -0
  150. data/opal/browser/event/touch.rb +2 -0
  151. data/opal/browser/event/wheel.rb +2 -0
  152. data/opal/browser/event.rb +26 -116
  153. data/opal/browser/event_source.rb +1 -1
  154. data/opal/browser/form_data.rb +225 -0
  155. data/opal/browser/history.rb +4 -8
  156. data/opal/browser/http/request.rb +32 -10
  157. data/opal/browser/http/response.rb +5 -1
  158. data/opal/browser/http.rb +0 -2
  159. data/opal/browser/immediate.rb +0 -2
  160. data/opal/browser/location.rb +7 -1
  161. data/opal/browser/navigator.rb +105 -4
  162. data/opal/browser/polyfill/visual_viewport.rb +216 -0
  163. data/opal/browser/screen.rb +2 -2
  164. data/opal/browser/setup/base.rb +6 -0
  165. data/opal/browser/setup/full.rb +13 -0
  166. data/opal/browser/setup/large.rb +17 -0
  167. data/opal/browser/setup/mini.rb +8 -0
  168. data/opal/browser/setup/traditional.rb +10 -0
  169. data/opal/browser/socket.rb +3 -3
  170. data/opal/browser/storage.rb +2 -2
  171. data/opal/browser/support.rb +46 -22
  172. data/opal/browser/utils.rb +94 -14
  173. data/opal/browser/version.rb +1 -1
  174. data/opal/browser/visual_viewport.rb +39 -0
  175. data/opal/browser/window/size.rb +14 -0
  176. data/opal/browser/window/view.rb +15 -0
  177. data/opal/browser/window.rb +29 -16
  178. data/opal/browser.rb +1 -11
  179. data/opal-browser.gemspec +3 -3
  180. data/spec/database/sql_spec.rb +43 -35
  181. data/spec/delay_spec.rb +15 -12
  182. data/spec/dom/document_spec.rb +10 -8
  183. data/spec/dom/element/custom_spec.rb +106 -0
  184. data/spec/dom/element/subclass_spec.rb +144 -0
  185. data/spec/dom/element_spec.rb +42 -0
  186. data/spec/dom/mutation_observer_spec.rb +12 -8
  187. data/spec/dom/node_spec.rb +48 -0
  188. data/spec/dom_spec.rb +8 -0
  189. data/spec/event_source_spec.rb +15 -12
  190. data/spec/{dom/event_spec.rb → event_spec.rb} +44 -15
  191. data/spec/history_spec.rb +23 -19
  192. data/spec/http_spec.rb +19 -31
  193. data/spec/immediate_spec.rb +5 -4
  194. data/spec/interval_spec.rb +18 -9
  195. data/spec/native_cached_wrapper_spec.rb +46 -0
  196. data/spec/runner.rb +37 -62
  197. data/spec/socket_spec.rb +15 -12
  198. data/spec/spec_helper.rb +2 -1
  199. data/spec/spec_helper_promise.rb.erb +25 -0
  200. metadata +120 -16
  201. data/.travis.yml +0 -74
  202. data/opal/browser/window/scroll.rb +0 -59
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Composition < UI
4
+ handles 'compositionend', 'compositionstart', 'compositionupdate'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Composition'
6
8
  end
@@ -17,7 +17,7 @@ class Custom < Event
17
17
 
18
18
  if Browser.supports? 'Event.constructor'
19
19
  def self.construct(name, desc)
20
- `new CustomEvent(name, {
20
+ `return new CustomEvent(name, {
21
21
  bubbles: desc.bubbles,
22
22
  cancelable: desc.cancelable,
23
23
  detail: desc })`
@@ -0,0 +1,95 @@
1
+ require 'browser/blob'
2
+
3
+ module Browser; class Event
4
+
5
+ # {DataTransfer} is an object which manages included data to
6
+ # an event of type {Event::Drag} or {Event::Clipboard}.
7
+ class DataTransfer
8
+ include NativeCachedWrapper
9
+
10
+ # @!attribute [rw] effect
11
+ # @return [Symbol] Effect of this drop operation.
12
+ # Must be one of: :none, :copy, :link or :move.
13
+ def effect
14
+ `#@native.dropEffect`
15
+ end
16
+
17
+ def effect= (effect)
18
+ `#@native.dropEffect = #{effect}`
19
+ end
20
+
21
+ # Extract some text data from this {DataTransfer} instance.
22
+ def [] (type)
23
+ `#@native.getData(#{type})`
24
+ end
25
+
26
+ # Embed some text data in this {DataTransfer} instance.
27
+ def []= (type, value)
28
+ `#@native.setData(#{type}, #{Native.convert(value)})`
29
+ end
30
+
31
+ # Clear some (or all, if type is not specified) text data from
32
+ # this {DataTransfer} instance.
33
+ def clear (type=nil)
34
+ `#@native.clearData(#{type.to_n})`
35
+ end
36
+
37
+ # @!attribute [w] drag_image
38
+ # Sets a drag image for this {DataTransfer}. Use some
39
+ # {DOM::Element::Image} or {Canvas} as a value.
40
+ def drag_image= (image)
41
+ `#@native.setDragImage(#{Native.convert(image)})`
42
+ end
43
+
44
+ # @!attribute [r] files
45
+ # @return [Array<File>] list of files attached to this {DataTransfer}
46
+ def files
47
+ Native::Array.new(`#@native.files`).map { |f| File.new(f.to_n) }
48
+ end
49
+
50
+ # @!attribute [r] items
51
+ # @return [Array<Item>] list of items attached to this {DataTransfer}
52
+ def items
53
+ Native::Array.new(`#@native.items`).map { |i| Item.new(i.to_n) }
54
+ end
55
+
56
+ # An instance of `DataTransferItem`
57
+ class Item
58
+ include NativeCachedWrapper
59
+
60
+ # @!attribute [r] kind
61
+ # @return [Symbol] kind of an item: :string or :file
62
+ def kind
63
+ `#@native.kind`
64
+ end
65
+
66
+ def string?; kind == 'string'; end
67
+ def file?; kind == 'file' && to_file; end # Some files can't be resolved...
68
+
69
+ # @!attribute [r] type
70
+ # @return [String] mime type of an item
71
+ def type
72
+ `#@native.type`
73
+ end
74
+
75
+ # Convert to string and call back once ready, or return a
76
+ # promise if a block isn't given.
77
+ def to_string(&block)
78
+ promise = nil
79
+ if !block
80
+ promise = Promise.new
81
+ block = proc { |i| promise.resolve(i) }
82
+ end
83
+ `#@native.getAsString(#{block.to_n})`
84
+ return promise
85
+ end
86
+
87
+ # Convert to file or return nil if impossible
88
+ def to_file
89
+ as_file = `#@native.getAsFile()`
90
+ File.new(as_file) if as_file
91
+ end
92
+ end
93
+ end
94
+
95
+ end; end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class DeviceLight < Event
4
+ handles 'devicelight'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.DeviceLight'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class DeviceMotion < Event
4
+ handles 'devicemotion'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.DeviceMotion'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class DeviceOrientation < Event
4
+ handles 'deviceorientation'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.DeviceOrientation'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class DeviceProximity < Event
4
+ handles 'deviceproximity'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.DeviceProximity'
6
8
  end
@@ -1,14 +1,16 @@
1
1
  module Browser; class Event
2
2
 
3
- # TODO: handle transfers
4
3
  class Drag < Event
4
+ handles 'drag', 'dragend', 'dragenter', 'dragexit', 'dragleave', 'dragover',
5
+ 'dragstart', 'drop'
6
+
5
7
  def self.supported?
6
8
  Browser.supports? 'Event.Drag'
7
9
  end
8
10
 
9
11
  class Definition < Definition
10
12
  class Client
11
- include Native
13
+ include Native::Wrapper
12
14
 
13
15
  def x=(value)
14
16
  `#@native.clientX = #{value}`
@@ -20,7 +22,7 @@ class Drag < Event
20
22
  end
21
23
 
22
24
  class Screen
23
- include Native
25
+ include Native::Wrapper
24
26
 
25
27
  def x=(value)
26
28
  `#@native.screenX = #{value}`
@@ -60,7 +62,7 @@ class Drag < Event
60
62
  end
61
63
 
62
64
  def transfer=(value)
63
- `#@native.dataTransfer = #{Native.convert(elem)}`
65
+ `#@native.dataTransfer = #{Native.convert(value)}`
64
66
  end
65
67
  end
66
68
 
@@ -110,9 +112,11 @@ class Drag < Event
110
112
  DOM(`#@native.relatedTarget`)
111
113
  end
112
114
 
115
+ # Returns a {DataTransfer} related to this event
116
+ #
113
117
  # @see https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
114
118
  def transfer
115
- raise NotImplementedError
119
+ DataTransfer.new(`#@native.dataTransfer`)
116
120
  end
117
121
  end
118
122
 
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Focus < UI
4
+ handles 'blur', 'focus', 'focusin', 'focusout'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Focus'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Gamepad < Event
4
+ handles 'gamepadconnected', 'gamepaddisconnected'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Gamepad'
6
8
  end
@@ -29,7 +31,7 @@ class Gamepad < Event
29
31
 
30
32
  if Browser.supports? 'Event.constructor'
31
33
  def self.construct(name, desc)
32
- `new GamepadEvent(#{name}, {
34
+ `return new GamepadEvent(#{name}, {
33
35
  bubbles: desc.bubbles,
34
36
  cancelable: desc.cancelable,
35
37
  gamepad: desc })`
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class HashChange < Event
4
+ handles 'hashchange'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.HashChange'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Keyboard < UI
4
+ handles 'keydown', 'keypress', 'keyup'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Keyboard'
6
8
  end
@@ -85,8 +87,19 @@ class Keyboard < UI
85
87
  alias_native :locale
86
88
  alias_native :repeat?, :repeat
87
89
 
90
+ # IE 11 at least has different names for those keys.
91
+ IE_MAP = {
92
+ 'Down' => 'ArrowDown',
93
+ 'Up' => 'ArrowUp',
94
+ 'Left' => 'ArrowLeft',
95
+ 'Right' => 'ArrowRight',
96
+ 'Esc' => 'Escape',
97
+ 'Del' => 'Delete'
98
+ }
99
+
88
100
  def key
89
- `#@native.key || #@native.keyIdentifier || nil`
101
+ key = `#@native.key || #@native.keyIdentifier || nil`
102
+ IE_MAP[key] || key
90
103
  end
91
104
 
92
105
  def code
@@ -3,6 +3,8 @@ require 'buffer'
3
3
  module Browser; class Event
4
4
 
5
5
  class Message < Event
6
+ handles 'message'
7
+
6
8
  def self.supported?
7
9
  Browser.supports? 'Event.Message'
8
10
  end
@@ -1,13 +1,17 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Mouse < UI
4
+ handles 'click', 'contextmenu', 'dblclick', 'mousedown', 'mouseenter',
5
+ 'mouseleave', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
6
+ 'show'
7
+
4
8
  def self.supported?
5
9
  not $$[:MouseEvent].nil?
6
10
  end
7
11
 
8
12
  class Definition < UI::Definition
9
13
  class Client
10
- include Native
14
+ include Native::Wrapper
11
15
 
12
16
  def x=(value)
13
17
  `#@native.clientX = #{value}`
@@ -19,7 +23,7 @@ class Mouse < UI
19
23
  end
20
24
 
21
25
  class Layer
22
- include Native
26
+ include Native::Wrapper
23
27
 
24
28
  def x=(value)
25
29
  `#@native.layerX = #{value}`
@@ -31,7 +35,7 @@ class Mouse < UI
31
35
  end
32
36
 
33
37
  class Offset
34
- include Native
38
+ include Native::Wrapper
35
39
 
36
40
  def x=(value)
37
41
  `#@native.offsetX = #{value}`
@@ -43,7 +47,7 @@ class Mouse < UI
43
47
  end
44
48
 
45
49
  class Page
46
- include Native
50
+ include Native::Wrapper
47
51
 
48
52
  def x=(value)
49
53
  `#@native.pageX = #{value}`
@@ -55,7 +59,7 @@ class Mouse < UI
55
59
  end
56
60
 
57
61
  class Screen
58
- include Native
62
+ include Native::Wrapper
59
63
 
60
64
  def x=(value)
61
65
  `#@native.screenX = #{value}`
@@ -67,7 +71,7 @@ class Mouse < UI
67
71
  end
68
72
 
69
73
  class Ancestor
70
- include Native
74
+ include Native::Wrapper
71
75
 
72
76
  def x=(value)
73
77
  `#@native.x = #{value}`
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class PageTransition < Event
4
+ handles 'pagehide', 'pageshow'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.PageTransition'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class PopState < Event
4
+ handles 'popstate'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.PopState'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Progress < Event
4
+ handles 'progress', 'load', 'loadend', 'loadstart'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Progress'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Sensor < Event
4
+ handles 'compassneedscalibration', 'userproximity'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Sensor'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Storage < Event
4
+ handles 'storage'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Storage'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Touch < Event
4
+ handles 'touchcancel', 'touchend', 'touchleave', 'touchmove', 'touchstart'
5
+
4
6
  def self.supported?
5
7
  Browser.supports? 'Event.Touch'
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module Browser; class Event
2
2
 
3
3
  class Wheel < UI
4
+ handles 'wheel', 'mousewheel'
5
+
4
6
  def self.supported?
5
7
  not $$[:WheelEvent].nil?
6
8
  end
@@ -1,31 +1,4 @@
1
1
  require 'browser/event/base'
2
- require 'browser/event/ui'
3
- require 'browser/event/mouse'
4
- require 'browser/event/keyboard'
5
- require 'browser/event/focus'
6
- require 'browser/event/wheel'
7
- require 'browser/event/composition'
8
- require 'browser/event/animation'
9
- require 'browser/event/audio_processing'
10
- require 'browser/event/before_unload'
11
- require 'browser/event/composition'
12
- require 'browser/event/clipboard'
13
- require 'browser/event/device_light'
14
- require 'browser/event/device_motion'
15
- require 'browser/event/device_orientation'
16
- require 'browser/event/device_proximity'
17
- require 'browser/event/drag'
18
- require 'browser/event/gamepad'
19
- require 'browser/event/hash_change'
20
- require 'browser/event/progress'
21
- require 'browser/event/page_transition'
22
- require 'browser/event/pop_state'
23
- require 'browser/event/storage'
24
- require 'browser/event/touch'
25
- require 'browser/event/sensor'
26
- require 'browser/event/custom'
27
- require 'browser/event/message'
28
- require 'browser/event/close'
29
2
 
30
3
  module Browser
31
4
 
@@ -41,98 +14,30 @@ class Event
41
14
  (aliases[name] || name).gsub(?:, '')
42
15
  end
43
16
 
44
- def self.class_for(name)
45
- case name_for(name)
46
- when 'animationend', 'animationiteration', 'animationstart'
47
- Animation
48
-
49
- when 'audioprocess'
50
- AudioProcessing
51
-
52
- when 'beforeunload'
53
- BeforeUnload
54
-
55
- when 'compositionend', 'compositionstart', 'compositionupdate'
56
- Composition
57
-
58
- when 'copy', 'cut'
59
- Clipboard
60
-
61
- when 'devicelight'
62
- DeviceLight
63
-
64
- when 'devicemotion'
65
- DeviceMotion
66
-
67
- when 'deviceorientation'
68
- DeviceOrientation
69
-
70
- when 'deviceproximity'
71
- DeviceProximity
72
-
73
- when 'drag', 'dragend', 'dragleave', 'dragover', 'dragstart', 'drop'
74
- Drag
75
-
76
- when 'gamepadconnected', 'gamepaddisconnected'
77
- Gamepad
78
-
79
- when 'hashchange'
80
- HashChange
81
-
82
- when 'load', 'loadend', 'loadstart'
83
- Progress
84
-
85
- when 'pagehide', 'pageshow'
86
- PageTransition
87
-
88
- when 'popstate'
89
- PopState
90
-
91
- when 'storage'
92
- Storage
93
-
94
- when 'touchcancel', 'touchend', 'touchleave', 'touchmove', 'touchstart'
95
- Touch
96
-
97
- when 'compassneedscalibration', 'userproximity'
98
- Sensor
99
-
100
- when 'message'
101
- Message
102
-
103
- when 'close'
104
- Close
105
-
106
- when 'click', 'contextmenu', 'dblclick', 'mousedown', 'mouseenter',
107
- 'mouseleave', 'mousemove', 'mouseout', 'mouseover', 'mouseup',
108
- 'show'
109
- Mouse
110
-
111
- when 'keydown', 'keypress', 'keyup'
112
- Keyboard
113
-
114
- when 'blur', 'focus', 'focusin', 'focusout'
115
- Focus
17
+ def self.handlers
18
+ @handlers ||= {}
19
+ end
116
20
 
117
- when 'wheel'
118
- Wheel
21
+ def self.handles(*events)
22
+ events.each { |event| Event.handlers[event] = self }
23
+ end
119
24
 
120
- when 'abort', 'afterprint', 'beforeprint', 'cached', 'canplay',
121
- 'canplaythrough', 'change', 'chargingchange', 'chargingtimechange',
122
- 'checking', 'close', 'dischargingtimechange', 'DOMContentLoaded',
123
- 'downloading', 'durationchange', 'emptied', 'ended', 'error',
124
- 'fullscreenchange', 'fullscreenerror', 'input', 'invalid',
125
- 'levelchange', 'loadeddata', 'loadedmetadata', 'noupdate', 'obsolete',
126
- 'offline', 'online', 'open', 'orientationchange', 'pause',
127
- 'pointerlockchange', 'pointerlockerror', 'play', 'playing',
128
- 'ratechange', 'readystatechange', 'reset', 'seeked', 'seeking',
129
- 'stalled', 'submit', 'success', 'suspend', 'timeupdate', 'updateready',
130
- 'visibilitychange', 'volumechange', 'waiting'
131
- Event
25
+ # Those events don't have interesting properties to warrant a custom class
26
+ # or are not currently implemented.
27
+ handles 'abort', 'afterprint', 'beforeprint', 'cached', 'canplay',
28
+ 'canplaythrough', 'change', 'chargingchange', 'chargingtimechange',
29
+ 'checking', 'close', 'dischargingtimechange', 'DOMContentLoaded',
30
+ 'downloading', 'durationchange', 'emptied', 'ended', 'error',
31
+ 'fullscreenchange', 'fullscreenerror', 'input', 'invalid',
32
+ 'levelchange', 'loadeddata', 'loadedmetadata', 'noupdate', 'obsolete',
33
+ 'offline', 'online', 'open', 'orientationchange', 'pause',
34
+ 'pointerlockchange', 'pointerlockerror', 'play', 'playing',
35
+ 'ratechange', 'readystatechange', 'reset', 'seeked', 'seeking',
36
+ 'stalled', 'submit', 'success', 'suspend', 'timeupdate', 'updateready',
37
+ 'visibilitychange', 'volumechange', 'waiting'
132
38
 
133
- else
134
- Custom
135
- end
39
+ def self.class_for(name)
40
+ @handlers[name_for(name)] || Custom
136
41
  end
137
42
 
138
43
  def self.supported?
@@ -251,3 +156,8 @@ class Event
251
156
  end
252
157
 
253
158
  end
159
+
160
+ require 'browser/event/ui'
161
+ require 'browser/event/mouse'
162
+ require 'browser/event/keyboard'
163
+ require 'browser/event/custom'
@@ -9,7 +9,7 @@ class EventSource
9
9
  Browser.supports? :EventSource
10
10
  end
11
11
 
12
- include Native
12
+ include Native::Wrapper
13
13
  include Event::Target
14
14
 
15
15
  target {|value|