opal-browser 0.1.0.beta1 → 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +60 -0
- data/.yardopts +1 -1
- data/Gemfile +7 -2
- data/LICENSE +19 -0
- data/README.md +74 -10
- data/config.ru +2 -1
- data/index.html.erb +22 -0
- data/opal-browser.gemspec +9 -11
- data/opal/browser.rb +1 -1
- data/opal/browser/animation_frame.rb +66 -9
- data/opal/browser/canvas.rb +72 -18
- data/opal/browser/canvas/data.rb +1 -1
- data/opal/browser/console.rb +3 -37
- data/opal/browser/cookies.rb +80 -24
- data/opal/browser/css/declaration.rb +0 -5
- data/opal/browser/{timeout.rb → delay.rb} +13 -13
- data/opal/browser/dom.rb +0 -2
- data/opal/browser/dom/attribute.rb +6 -0
- data/opal/browser/dom/builder.rb +4 -8
- data/opal/browser/dom/character_data.rb +43 -7
- data/opal/browser/dom/document.rb +13 -11
- data/opal/browser/dom/element.rb +127 -29
- data/opal/browser/dom/element/image.rb +23 -0
- data/opal/browser/dom/element/offset.rb +27 -10
- data/opal/browser/dom/element/scroll.rb +32 -12
- data/opal/browser/dom/element/size.rb +29 -0
- data/opal/browser/dom/event.rb +88 -75
- data/opal/browser/dom/event/animation.rb +16 -4
- data/opal/browser/dom/event/audio_processing.rb +6 -4
- data/opal/browser/dom/event/base.rb +229 -64
- data/opal/browser/dom/event/before_unload.rb +6 -4
- data/opal/browser/dom/event/clipboard.rb +6 -4
- data/opal/browser/dom/event/close.rb +16 -4
- data/opal/browser/dom/event/composition.rb +16 -4
- data/opal/browser/dom/event/custom.rb +43 -8
- data/opal/browser/dom/event/device_light.rb +6 -4
- data/opal/browser/dom/event/device_motion.rb +17 -4
- data/opal/browser/dom/event/device_orientation.rb +16 -4
- data/opal/browser/dom/event/device_proximity.rb +6 -4
- data/opal/browser/dom/event/drag.rb +34 -28
- data/opal/browser/dom/event/focus.rb +21 -5
- data/opal/browser/dom/event/gamepad.rb +33 -20
- data/opal/browser/dom/event/hash_change.rb +6 -4
- data/opal/browser/dom/event/keyboard.rb +45 -23
- data/opal/browser/dom/event/message.rb +28 -8
- data/opal/browser/dom/event/mouse.rb +26 -25
- data/opal/browser/dom/event/page_transition.rb +6 -4
- data/opal/browser/dom/event/pop_state.rb +16 -4
- data/opal/browser/dom/event/progress.rb +16 -4
- data/opal/browser/dom/event/sensor.rb +6 -4
- data/opal/browser/dom/event/storage.rb +6 -4
- data/opal/browser/dom/event/touch.rb +10 -19
- data/opal/browser/dom/event/ui.rb +19 -3
- data/opal/browser/dom/event/wheel.rb +2 -2
- data/opal/browser/dom/mutation_observer.rb +65 -5
- data/opal/browser/dom/node.rb +164 -59
- data/opal/browser/dom/node_set.rb +4 -0
- data/opal/browser/dom/text.rb +16 -1
- data/opal/browser/event_source.rb +5 -2
- data/opal/browser/history.rb +51 -15
- data/opal/browser/http.rb +22 -7
- data/opal/browser/http/headers.rb +5 -0
- data/opal/browser/http/request.rb +40 -10
- data/opal/browser/immediate.rb +123 -9
- data/opal/browser/interval.rb +8 -13
- data/opal/browser/location.rb +13 -3
- data/opal/browser/navigator.rb +9 -6
- data/opal/browser/screen.rb +31 -5
- data/opal/browser/socket.rb +8 -4
- data/opal/browser/storage.rb +118 -33
- data/opal/browser/support.rb +232 -0
- data/opal/browser/utils.rb +24 -6
- data/opal/browser/version.rb +1 -1
- data/opal/browser/window.rb +1 -2
- data/opal/browser/window/scroll.rb +21 -11
- data/opal/browser/window/size.rb +16 -6
- data/opal/browser/window/view.rb +23 -5
- data/spec/dom/builder_spec.rb +19 -19
- data/spec/dom/document_spec.rb +6 -6
- data/spec/dom/element_spec.rb +5 -5
- data/spec/dom/event_spec.rb +20 -20
- data/spec/dom/mutation_observer_spec.rb +5 -5
- data/spec/dom/node_spec.rb +39 -27
- data/spec/dom_spec.rb +10 -8
- data/spec/event_source_spec.rb +12 -12
- data/spec/history_spec.rb +24 -15
- data/spec/http_spec.rb +18 -17
- data/spec/immediate_spec.rb +9 -7
- data/spec/runner.rb +114 -0
- data/spec/socket_spec.rb +8 -8
- data/spec/spec_helper.rb +1 -0
- data/spec/storage_spec.rb +6 -6
- data/spec/wgxpath.install.js +49 -0
- data/spec/window_spec.rb +2 -2
- metadata +21 -54
- data/opal/browser/compatibility.rb +0 -59
- data/opal/browser/compatibility/animation_frame.rb +0 -93
- data/opal/browser/compatibility/dom/document/window.rb +0 -15
- data/opal/browser/compatibility/dom/element/css.rb +0 -15
- data/opal/browser/compatibility/dom/element/matches.rb +0 -31
- data/opal/browser/compatibility/dom/element/offset.rb +0 -20
- data/opal/browser/compatibility/dom/element/scroll.rb +0 -25
- data/opal/browser/compatibility/dom/element/style.rb +0 -15
- data/opal/browser/compatibility/dom/mutation_observer.rb +0 -47
- data/opal/browser/compatibility/http/request.rb +0 -15
- data/opal/browser/compatibility/immediate.rb +0 -107
- data/opal/browser/compatibility/window/scroll.rb +0 -27
- data/opal/browser/compatibility/window/size.rb +0 -13
- data/opal/browser/compatibility/window/view.rb +0 -13
- data/opal/browser/dom/compatibility.rb +0 -8
- data/opal/browser/http/compatibility.rb +0 -1
- data/opal/browser/window/compatibility.rb +0 -3
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class HashChange < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.HashChange'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -15,9 +15,11 @@ class HashChange < Event
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if Browser.supports? 'Event.constructor'
|
19
|
+
def self.construct(name, desc)
|
20
|
+
`new HashChangeEvent(#{name}, #{desc})`
|
21
|
+
end
|
22
|
+
end if supported?
|
21
23
|
|
22
24
|
alias_native :old, :oldURL
|
23
25
|
alias_native :new, :newURL
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class Keyboard < UI
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.Keyboard'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < UI::Definition
|
@@ -37,31 +37,53 @@ class Keyboard < UI
|
|
37
37
|
def repeat!
|
38
38
|
`#@native.repeat = true`
|
39
39
|
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.create(name, &block)
|
43
|
-
new(`new KeyboardEvent(#{name}, #{Definition.new(&block)})`)
|
44
|
-
end
|
45
|
-
|
46
|
-
def alt?
|
47
|
-
`#@native.altKey`
|
48
|
-
end
|
49
|
-
|
50
|
-
def ctrl?
|
51
|
-
`#@native.ctrlKey`
|
52
|
-
end
|
53
40
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def shift?
|
59
|
-
`#@native.shiftKey`
|
41
|
+
def locale=(value)
|
42
|
+
`#@native.locale = value`
|
43
|
+
end
|
60
44
|
end
|
61
45
|
|
62
|
-
|
63
|
-
|
64
|
-
|
46
|
+
if Browser.supports? 'Event.constructor'
|
47
|
+
def self.construct(name, desc)
|
48
|
+
`new KeyboardEvent(#{name}, #{desc})`
|
49
|
+
end
|
50
|
+
elsif Browser.supports? 'Event.create'
|
51
|
+
def self.construct(name, desc)
|
52
|
+
%x{
|
53
|
+
var modifiers = "";
|
54
|
+
|
55
|
+
if (desc.altKey) {
|
56
|
+
modifiers += "Alt ";
|
57
|
+
}
|
58
|
+
|
59
|
+
if (desc.ctrlKey) {
|
60
|
+
modifiers += "Ctrl ";
|
61
|
+
}
|
62
|
+
|
63
|
+
if (desc.shiftKey) {
|
64
|
+
modifiers += "Shift" ;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (desc.metaKey) {
|
68
|
+
modifiers += "Meta ";
|
69
|
+
}
|
70
|
+
|
71
|
+
var event = document.createEvent("KeyboardEvent");
|
72
|
+
event.initKeyboardEvent(name, desc.bubbles, desc.cancelable,
|
73
|
+
desc.view || window, desc.which, 0,
|
74
|
+
modifiers, desc.repeat, desc.locale);
|
75
|
+
|
76
|
+
return event;
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end if supported?
|
80
|
+
|
81
|
+
alias_native :alt?, :altKey
|
82
|
+
alias_native :ctrl?, :ctrlKey
|
83
|
+
alias_native :meta?, :metaKey
|
84
|
+
alias_native :shift?, :shiftKey
|
85
|
+
alias_native :locale
|
86
|
+
alias_native :repeat?, :repeat
|
65
87
|
|
66
88
|
def key
|
67
89
|
`#@native.key || #@native.keyIdentifier || nil`
|
@@ -4,25 +4,45 @@ module Browser; module DOM; class Event
|
|
4
4
|
|
5
5
|
class Message < Event
|
6
6
|
def self.supported?
|
7
|
-
|
7
|
+
Browser.supports? 'Event.Message'
|
8
8
|
end
|
9
9
|
|
10
10
|
class Definition < Definition
|
11
11
|
def data=(value)
|
12
|
-
`#@native.data =
|
12
|
+
`#@native.data = value`
|
13
|
+
end
|
14
|
+
|
15
|
+
def origin=(value)
|
16
|
+
`#@native.origin = value`
|
13
17
|
end
|
14
|
-
end
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
def source=(value)
|
20
|
+
`#@native.source = #{Native.convert(value)}`
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
24
|
+
if Browser.supports? 'Event.constructor'
|
25
|
+
def self.construct(name, desc)
|
26
|
+
`new MessageEvent(#{name}, #{desc})`
|
27
|
+
end
|
28
|
+
elsif Browser.supports? 'Event.create'
|
29
|
+
def self.construct(name, desc)
|
30
|
+
%x{
|
31
|
+
var event = document.createEvent("MessageEvent");
|
32
|
+
event.initMessageEvent(name, desc.bubbles, desc.cancelable,
|
33
|
+
desc.data, desc.origin, "", desc.source || window);
|
34
|
+
|
35
|
+
return event;
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end if supported?
|
39
|
+
|
20
40
|
def data
|
21
41
|
%x{
|
22
|
-
if (#@native.data instanceof ArrayBuffer) {
|
42
|
+
if (window.ArrayBuffer && #@native.data instanceof ArrayBuffer) {
|
23
43
|
return #{Buffer.new(`#@native.data`)};
|
24
44
|
}
|
25
|
-
else if (#@native.data instanceof Blob) {
|
45
|
+
else if (window.Blob && #@native.data instanceof Blob) {
|
26
46
|
return #{Blob.new(`#@native.data`)};
|
27
47
|
}
|
28
48
|
else {
|
@@ -37,7 +57,7 @@ class Message < Event
|
|
37
57
|
%x{
|
38
58
|
var source = #@native.source;
|
39
59
|
|
40
|
-
if (source instanceof window.Window) {
|
60
|
+
if (window.Window && source instanceof window.Window) {
|
41
61
|
return #{Window.new(`source`)};
|
42
62
|
}
|
43
63
|
else {
|
@@ -139,31 +139,32 @@ class Mouse < UI
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
142
|
+
if Browser.supports? 'Event.constructor'
|
143
|
+
def self.construct(name, desc)
|
144
|
+
`new MouseEvent(#{name}, #{desc})`
|
145
|
+
end
|
146
|
+
elsif Browser.supports? 'Event.create'
|
147
|
+
def self.construct(name, desc)
|
148
|
+
%x{
|
149
|
+
var event = document.createEvent("MouseEvent");
|
150
|
+
event.initMouseEvent(name, desc.bubbles, desc.cancelable,
|
151
|
+
desc.view || window, desc.detail || 0,
|
152
|
+
desc.screenX || 0, desc.screenY || 0,
|
153
|
+
desc.clientX || 0, desc.clientY || 0,
|
154
|
+
desc.ctrlKey || false, desc.altKey || false,
|
155
|
+
desc.shiftKey || false, desc.metaKey || false,
|
156
|
+
desc.button || 0, desc.relatedTarget || null);
|
157
|
+
|
158
|
+
return event;
|
159
|
+
}
|
160
|
+
end
|
161
|
+
end if supported?
|
162
|
+
|
163
|
+
alias_native :alt?, :altKey
|
164
|
+
alias_native :ctrl?, :ctrlKey
|
165
|
+
alias_native :meta?, :metaKey
|
166
|
+
alias_native :shift?, :shiftKey
|
167
|
+
alias_native :button
|
167
168
|
|
168
169
|
def client
|
169
170
|
Position.new(`#@native.clientX`, `#@native.clientY`)
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class PageTransition < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.PageTransition'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -11,9 +11,11 @@ class PageTransition < Event
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if Browser.supports? 'Event.PageTransition'
|
15
|
+
def self.construct(name, desc)
|
16
|
+
`new PageTransitionEvent(name, desc)`
|
17
|
+
end
|
18
|
+
end if supported?
|
17
19
|
|
18
20
|
alias_native :persisted?, :persisted
|
19
21
|
end
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class PopState < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.PopState'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -11,9 +11,21 @@ class PopState < Event
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if Browser.supports? 'Event.constructor'
|
15
|
+
def self.construct(name, desc)
|
16
|
+
`new PopStateEvent(#{name}, #{desc})`
|
17
|
+
end
|
18
|
+
elsif Browser.supports? 'Event.create'
|
19
|
+
def self.construct(name, desc)
|
20
|
+
%x{
|
21
|
+
var event = document.createEvent('PopStateEvent');
|
22
|
+
event.initPopStateEvent(name, desc.bubbles, desc.cancelable,
|
23
|
+
desc.state);
|
24
|
+
|
25
|
+
return event;
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end if supported?
|
17
29
|
|
18
30
|
alias_native :state
|
19
31
|
end
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class Progress < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.Progress'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -19,9 +19,21 @@ class Progress < Event
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if Browser.supports? 'Event.constructor'
|
23
|
+
def self.construct(name, desc)
|
24
|
+
`new ProgressEvent(#{name}, #{desc})`
|
25
|
+
end
|
26
|
+
elsif Browser.supports? 'Event.create'
|
27
|
+
def self.construct(name, desc)
|
28
|
+
%x{
|
29
|
+
var event = document.createEvent("ProgressEvent");
|
30
|
+
event.initProgressEvent(name, desc.bubbles, desc.cancelable,
|
31
|
+
desc.computable, desc.loaded, desc.total);
|
32
|
+
|
33
|
+
return event;
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end if supported?
|
25
37
|
|
26
38
|
alias_native :computable?, :computableLength
|
27
39
|
alias_native :loaded
|
@@ -2,12 +2,14 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class Sensor < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.Sensor'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if Browser.supports? 'Event.constructor'
|
9
|
+
def self.construct(name, desc)
|
10
|
+
`new SensorEvent(#{name}, #{desc})`
|
11
|
+
end
|
12
|
+
end if supported?
|
11
13
|
end
|
12
14
|
|
13
15
|
end; end; end
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class Storage < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.Storage'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -27,9 +27,11 @@ class Storage < Event
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
if Browser.supports? 'Event.constructor'
|
31
|
+
def self.construct(name, desc)
|
32
|
+
`new StorageEvent(#{name}, #{desc})`
|
33
|
+
end
|
34
|
+
end if supported?
|
33
35
|
|
34
36
|
alias_native :key
|
35
37
|
alias_native :new, :newValue
|
@@ -2,7 +2,7 @@ module Browser; module DOM; class Event
|
|
2
2
|
|
3
3
|
class Touch < Event
|
4
4
|
def self.supported?
|
5
|
-
|
5
|
+
Browser.supports? 'Event.Touch'
|
6
6
|
end
|
7
7
|
|
8
8
|
class Definition < Definition
|
@@ -23,25 +23,16 @@ class Touch < Event
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
`#@native.altKey`
|
32
|
-
end
|
33
|
-
|
34
|
-
def ctrl?
|
35
|
-
`#@native.ctrlKey`
|
36
|
-
end
|
37
|
-
|
38
|
-
def meta?
|
39
|
-
`#@native.metaKey`
|
40
|
-
end
|
26
|
+
if Browser.supports? 'Event.constructor'
|
27
|
+
def self.construct(name, desc)
|
28
|
+
`new TouchEvent(#{name}, #{desc})`
|
29
|
+
end
|
30
|
+
end if supported?
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
alias_native :alt?, :altKey
|
33
|
+
alias_native :ctrl?, :ctrlKey
|
34
|
+
alias_native :meta?, :metaKey
|
35
|
+
alias_native :shift?, :shiftKey
|
45
36
|
|
46
37
|
# TODO: implement touches and targetTouches
|
47
38
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Browser; module DOM; class Event
|
2
2
|
|
3
3
|
class UI < Event
|
4
|
+
def self.supported?
|
5
|
+
Browser.supports? 'Event.UI'
|
6
|
+
end
|
7
|
+
|
4
8
|
class Definition < Definition
|
5
9
|
def detail=(value)
|
6
10
|
`#@native.detail = #{value}`
|
@@ -11,9 +15,21 @@ class UI < Event
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
if Browser.supports? 'Event.constructor'
|
19
|
+
def self.construct(name, desc)
|
20
|
+
`new UIEvent(#{name}, #{desc})`
|
21
|
+
end
|
22
|
+
elsif Browser.supports? 'Event.create'
|
23
|
+
def self.construct(name, desc)
|
24
|
+
%x{
|
25
|
+
var event = document.createEvent("UIEvent");
|
26
|
+
event.initUIEvent(name, desc.bubbles, desc.cancelable,
|
27
|
+
desc.view || window, desc.detail || 0);
|
28
|
+
|
29
|
+
return event;
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end if supported?
|
17
33
|
|
18
34
|
alias_native :detail
|
19
35
|
alias_native :view
|