accessibility_core 0.1.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/.yardopts +2 -0
  2. data/History.markdown +33 -0
  3. data/README.markdown +11 -0
  4. data/Rakefile +18 -49
  5. data/ext/accessibility/bridge/{ext/accessibility/bridge/bridge.c → bridge.c} +136 -56
  6. data/ext/accessibility/bridge/bridge.h +132 -0
  7. data/ext/accessibility/bridge/{ext/accessibility/bridge/extconf.rb → extconf.rb} +1 -1
  8. data/ext/accessibility/core/core.c +21 -3
  9. data/ext/accessibility/core/extconf.rb +7 -1
  10. data/ext/accessibility/extras/extconf.rb +28 -0
  11. data/ext/accessibility/extras/extras.c +842 -0
  12. data/ext/accessibility/extras/extras.h +1 -0
  13. data/ext/accessibility/highlighter/extconf.rb +9 -2
  14. data/ext/accessibility/highlighter/highlighter.c +291 -1
  15. data/{ext/accessibility/bridge/lib → lib}/accessibility/bridge.rb +3 -3
  16. data/{ext/accessibility/bridge/lib → lib}/accessibility/bridge/common.rb +0 -0
  17. data/{ext/accessibility/bridge/lib → lib}/accessibility/bridge/macruby.rb +17 -0
  18. data/{ext/accessibility/bridge/lib → lib}/accessibility/bridge/mri.rb +10 -7
  19. data/lib/accessibility/core.rb +1 -1
  20. data/lib/accessibility/core/macruby.rb +1 -1
  21. data/lib/accessibility/core/version.rb +1 -1
  22. data/lib/accessibility/extras.rb +5 -0
  23. data/lib/accessibility/extras/common.rb +19 -0
  24. data/lib/accessibility/highlighter.rb +8 -0
  25. data/lib/accessibility/highlighter/macruby.rb +85 -0
  26. data/test/helper.rb +18 -28
  27. metadata +33 -56
  28. data/ext/accessibility/bridge/lib/accessibility/bridge/version.rb +0 -6
  29. data/ext/accessibility/bridge/test/array_test.rb +0 -31
  30. data/ext/accessibility/bridge/test/boxed_test.rb +0 -23
  31. data/ext/accessibility/bridge/test/cfrange_test.rb +0 -21
  32. data/ext/accessibility/bridge/test/cgpoint_test.rb +0 -54
  33. data/ext/accessibility/bridge/test/cgrect_test.rb +0 -60
  34. data/ext/accessibility/bridge/test/cgsize_test.rb +0 -54
  35. data/ext/accessibility/bridge/test/helper.rb +0 -19
  36. data/ext/accessibility/bridge/test/nsstring_test.rb +0 -22
  37. data/ext/accessibility/bridge/test/nsurl_test.rb +0 -17
  38. data/ext/accessibility/bridge/test/object_test.rb +0 -19
  39. data/ext/accessibility/bridge/test/range_test.rb +0 -16
  40. data/ext/accessibility/bridge/test/string_test.rb +0 -35
  41. data/ext/accessibility/bridge/test/uri_test.rb +0 -15
  42. data/ext/accessibility/core/bridge.h +0 -1
@@ -0,0 +1 @@
1
+ void Init_extras();
@@ -1,11 +1,12 @@
1
1
  require 'mkmf'
2
2
 
3
3
  $CFLAGS << ' -std=c99 -Wall -Werror -pedantic -ObjC'
4
- $LIBS << ' -framework CoreFoundation -framework Cocoa'
4
+ $LIBS << ' -framework CoreFoundation -framework ApplicationServices -framework Cocoa'
5
5
  $LIBS << ' -framework CoreGraphics' unless `sw_vers -productVersion`.to_f == 10.7
6
6
 
7
7
  if RUBY_ENGINE == 'macruby'
8
8
  $CFLAGS << ' -fobjc-gc'
9
+ $CFLAGS.sub! /-Werror/, ''
9
10
  else
10
11
  unless RbConfig::CONFIG["CC"].match /clang/
11
12
  clang = `which clang`.chomp
@@ -19,4 +20,10 @@ else
19
20
  $CFLAGS << ' -DNOT_MACRUBY'
20
21
  end
21
22
 
22
- create_makefile 'accessibility/highlighter'
23
+ create_makefile 'accessibility/highlighter/highlighter'
24
+
25
+ # modify the bugger so we can depend on bridge.h properly
26
+ makefile = File.read 'Makefile'
27
+ makefile.gsub! '$(DLLIB): $(OBJS) Makefile', '$(DLLIB): $(OBJS) Makefile ../bridge/bridge.o ../extras/extras.o'
28
+ makefile.gsub! '$(Q) $(LDSHARED) -o $@', '$(Q) $(LDSHARED) -o $@ ../bridge/bridge.o ../extras/extras.o'
29
+ File.open('Makefile', 'w') { |f| f.write makefile }
@@ -1,7 +1,297 @@
1
1
  #include "ruby.h"
2
+ #import <Cocoa/Cocoa.h>
3
+ #include "../bridge/bridge.h"
4
+ #include "../extras/extras.h"
5
+
6
+
7
+ #ifdef NOT_MACRUBY
8
+
9
+ static VALUE rb_cHighlighter;
10
+ static VALUE rb_cColor;
11
+
12
+ static ID ivar_color;
13
+
14
+ static VALUE color_key;
15
+ static VALUE colour_key;
16
+ static VALUE timeout_key;
17
+
18
+
19
+ static
20
+ VALUE
21
+ wrap_window(NSWindow* window)
22
+ {
23
+ return Data_Wrap_Struct(rb_cHighlighter, NULL, objc_finalizer, (void*)window);
24
+ }
25
+
26
+ static
27
+ NSWindow*
28
+ unwrap_window(VALUE window)
29
+ {
30
+ NSWindow* nswindow;
31
+ Data_Get_Struct(window, NSWindow, nswindow);
32
+ return nswindow;
33
+ }
34
+
35
+ static
36
+ VALUE
37
+ wrap_color(NSColor* color)
38
+ {
39
+ return Data_Wrap_Struct(rb_cColor, NULL, objc_finalizer, (void*)color);
40
+ }
41
+
42
+ static
43
+ NSColor*
44
+ unwrap_color(VALUE color)
45
+ {
46
+ NSColor* nscolor;
47
+ Data_Get_Struct(color, NSColor, nscolor);
48
+ return nscolor;
49
+ }
50
+
51
+
52
+ static
53
+ CGRect
54
+ flip(CGRect rect)
55
+ {
56
+ double screen_height = NSMaxY([[NSScreen mainScreen] frame]);
57
+ rect.origin.y = screen_height - NSMaxY(rect);
58
+ return rect;
59
+ }
60
+
61
+ static
62
+ VALUE
63
+ rb_highlighter_new(int argc, VALUE* argv, VALUE self)
64
+ {
65
+ if (!argc)
66
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
67
+
68
+ CGRect bounds = unwrap_rect(coerce_to_rect(argv[0]));
69
+ bounds = flip(bounds); // we assume the rect is in the other co-ordinate system
70
+
71
+ NSWindow* window =
72
+ [[NSWindow alloc] initWithContentRect:bounds
73
+ styleMask:NSBorderlessWindowMask
74
+ backing:NSBackingStoreBuffered
75
+ defer:true];
76
+
77
+ NSColor* color = [NSColor magentaColor];
78
+
79
+ if (argc > 1) {
80
+ VALUE rb_color = rb_hash_lookup(argv[1], color_key);
81
+ if (rb_color == Qnil)
82
+ rb_color = rb_hash_lookup(argv[1], colour_key);
83
+ if (rb_color != Qnil)
84
+ color = unwrap_color(rb_color);
85
+ }
86
+
87
+ [window setOpaque:false];
88
+ [window setAlphaValue:0.20];
89
+ [window setLevel:NSStatusWindowLevel];
90
+ [window setBackgroundColor:color];
91
+ [window setIgnoresMouseEvents:true];
92
+ [window setFrame:bounds display:false];
93
+ [window makeKeyAndOrderFront:NSApp];
94
+ [window setReleasedWhenClosed:false];
95
+
96
+ if (argc > 1) {
97
+ VALUE rb_timeout = rb_hash_lookup(argv[1], timeout_key);
98
+ if (rb_timeout != Qnil) {
99
+ dispatch_time_t timeout = dispatch_time(
100
+ DISPATCH_TIME_NOW,
101
+ NUM2LL(rb_timeout) * NSEC_PER_SEC
102
+ );
103
+ dispatch_after(
104
+ timeout,
105
+ dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
106
+ ^(void) { [window close]; }
107
+ );
108
+ }
109
+ }
110
+
111
+ VALUE highlighter = wrap_window(window);
112
+ rb_ivar_set(highlighter, ivar_color, wrap_color(color));
113
+ return highlighter;
114
+ }
115
+
116
+ static
117
+ VALUE
118
+ rb_highlighter_stop(VALUE self)
119
+ {
120
+ [unwrap_window(self) close];
121
+ return self;
122
+ }
123
+
124
+ static
125
+ VALUE
126
+ rb_highlighter_color(VALUE self)
127
+ {
128
+ return wrap_color([unwrap_window(self) backgroundColor]);
129
+ }
130
+
131
+ static
132
+ VALUE
133
+ rb_highlighter_frame(VALUE self)
134
+ {
135
+ return wrap_rect([unwrap_window(self) frame]);
136
+ }
137
+
138
+ static
139
+ VALUE
140
+ rb_highlighter_is_visible(VALUE self)
141
+ {
142
+ return ([unwrap_window(self) isVisible] ? Qtrue : Qfalse);
143
+ }
144
+
145
+
146
+ /*
147
+ * @return [NSColor]
148
+ */
149
+ static VALUE rb_color_black(VALUE self) { return wrap_color([NSColor blackColor]); }
150
+ /*
151
+ * @return [NSColor]
152
+ */
153
+ static VALUE rb_color_blue(VALUE self) { return wrap_color([NSColor blueColor]); }
154
+ /*
155
+ * @return [NSColor]
156
+ */
157
+ static VALUE rb_color_brown(VALUE self) { return wrap_color([NSColor brownColor]); }
158
+ /*
159
+ * @return [NSColor]
160
+ */
161
+ static VALUE rb_color_clear(VALUE self) { return wrap_color([NSColor clearColor]); }
162
+ /*
163
+ * @return [NSColor]
164
+ */
165
+ static VALUE rb_color_cyan(VALUE self) { return wrap_color([NSColor cyanColor]); }
166
+ /*
167
+ * @return [NSColor]
168
+ */
169
+ static VALUE rb_color_dark_gray(VALUE self) { return wrap_color([NSColor darkGrayColor]); }
170
+ /*
171
+ * @return [NSColor]
172
+ */
173
+ static VALUE rb_color_gray(VALUE self) { return wrap_color([NSColor grayColor]); }
174
+ /*
175
+ * @return [NSColor]
176
+ */
177
+ static VALUE rb_color_green(VALUE self) { return wrap_color([NSColor greenColor]); }
178
+ /*
179
+ * @return [NSColor]
180
+ */
181
+ static VALUE rb_color_light_gray(VALUE self) { return wrap_color([NSColor lightGrayColor]); }
182
+ /*
183
+ * @return [NSColor]
184
+ */
185
+ static VALUE rb_color_magenta(VALUE self) { return wrap_color([NSColor magentaColor]); }
186
+ /*
187
+ * @return [NSColor]
188
+ */
189
+ static VALUE rb_color_orange(VALUE self) { return wrap_color([NSColor orangeColor]); }
190
+ /*
191
+ * @return [NSColor]
192
+ */
193
+ static VALUE rb_color_purple(VALUE self) { return wrap_color([NSColor purpleColor]); }
194
+ /*
195
+ * @return [NSColor]
196
+ */
197
+ static VALUE rb_color_red(VALUE self) { return wrap_color([NSColor redColor]); }
198
+ /*
199
+ * @return [NSColor]
200
+ */
201
+ static VALUE rb_color_white(VALUE self) { return wrap_color([NSColor whiteColor]); }
202
+ /*
203
+ * @return [NSColor]
204
+ */
205
+ static VALUE rb_color_yellow(VALUE self) { return wrap_color([NSColor yellowColor]); }
206
+
207
+ /* static */
208
+ /* VALUE */
209
+ /* rb_color_rgb(VALUE self, VALUE red_val, VALUE other_vals) */
210
+ /* { */
211
+ /* return Qnil; */
212
+ /* } */
213
+
214
+ /*
215
+ * @return [Boolean]
216
+ */
217
+ static
218
+ VALUE
219
+ rb_color_equality(VALUE self, VALUE other)
220
+ {
221
+ if (CLASS_OF(other) == rb_cColor)
222
+ if ([unwrap_color(self) isEqual:unwrap_color(other)])
223
+ return Qtrue;
224
+
225
+ return Qfalse;
226
+ }
227
+
228
+ #endif
229
+
2
230
 
3
231
  void
4
232
  Init_highlighter()
5
233
  {
6
- }
234
+ Init_bridge();
235
+ Init_extras();
236
+
237
+ #ifdef NOT_MACRUBY
238
+
239
+ // force initialization or NSWindow won't work
240
+ [NSApplication sharedApplication];
241
+
242
+ // TODO: can we replace this bs with dispatch_once?
243
+ rb_mAccessibility = rb_define_module("Accessibility");
244
+ rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));
245
+ rb_cCGSize = rb_const_get(rb_cObject, rb_intern("CGSize"));
246
+ rb_cCGRect = rb_const_get(rb_cObject, rb_intern("CGRect"));
247
+
248
+
249
+ rb_cHighlighter = rb_define_class_under(rb_mAccessibility, "Highlighter", rb_cObject);
250
+
251
+ rb_define_singleton_method(rb_cHighlighter, "new", rb_highlighter_new, -1);
252
+
253
+ rb_define_method(rb_cHighlighter, "stop", rb_highlighter_stop, 0);
254
+ rb_define_method(rb_cHighlighter, "color", rb_highlighter_color, 0);
255
+ rb_define_method(rb_cHighlighter, "frame", rb_highlighter_frame, 0);
256
+ rb_define_method(rb_cHighlighter, "visible?", rb_highlighter_is_visible, 0);
7
257
 
258
+ rb_define_alias(rb_cHighlighter, "colour", "color");
259
+
260
+ ivar_color = rb_intern("color");
261
+
262
+ color_key = ID2SYM(rb_intern("color"));
263
+ colour_key = ID2SYM(rb_intern("colour")); // fuck yeah, Canada
264
+ timeout_key = ID2SYM(rb_intern("timeout"));
265
+
266
+
267
+ /*
268
+ * Document-class: NSColor
269
+ *
270
+ * A subset of Cocoa's `NSColor` class.
271
+ *
272
+ * See [Apple's Developer Reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSColor_Class/Reference/Reference.html)
273
+ * for documentation on the methods available in this class.
274
+ */
275
+ rb_cColor = rb_define_class("NSColor", rb_cObject);
276
+
277
+ rb_define_singleton_method(rb_cColor, "blackColor", rb_color_black, 0);
278
+ rb_define_singleton_method(rb_cColor, "blueColor", rb_color_blue, 0);
279
+ rb_define_singleton_method(rb_cColor, "brownColor", rb_color_brown, 0);
280
+ rb_define_singleton_method(rb_cColor, "clearColor", rb_color_clear, 0);
281
+ rb_define_singleton_method(rb_cColor, "cyanColor", rb_color_cyan, 0);
282
+ rb_define_singleton_method(rb_cColor, "darkGrayColor", rb_color_dark_gray, 0);
283
+ rb_define_singleton_method(rb_cColor, "grayColor", rb_color_gray, 0);
284
+ rb_define_singleton_method(rb_cColor, "greenColor", rb_color_green, 0);
285
+ rb_define_singleton_method(rb_cColor, "lightGrayColor", rb_color_light_gray, 0);
286
+ rb_define_singleton_method(rb_cColor, "magentaColor", rb_color_magenta, 0);
287
+ rb_define_singleton_method(rb_cColor, "orangeColor", rb_color_orange, 0);
288
+ rb_define_singleton_method(rb_cColor, "purpleColor", rb_color_purple, 0);
289
+ rb_define_singleton_method(rb_cColor, "redColor", rb_color_red, 0);
290
+ rb_define_singleton_method(rb_cColor, "whiteColor", rb_color_white, 0);
291
+ rb_define_singleton_method(rb_cColor, "yellowColor", rb_color_yellow, 0);
292
+ //rb_define_singleton_method(rb_cColor, "colorWithSRGBRed", rb_color_rgb, 2);
293
+
294
+ rb_define_method(rb_cColor, "==", rb_color_equality, 1);
295
+
296
+ #endif
297
+ }
@@ -1,6 +1,7 @@
1
- require 'accessibility/bridge/version'
1
+ require 'accessibility/core/version'
2
2
 
3
- if RUBY_ENGINE == 'macruby'
3
+
4
+ if defined? MACRUBY_REVISION
4
5
 
5
6
  ##
6
7
  # Whether or not we are running on MacRuby
@@ -30,4 +31,3 @@ else
30
31
  require 'accessibility/bridge/mri'
31
32
 
32
33
  end
33
-
@@ -183,3 +183,20 @@ class NSArray
183
183
  map do |obj| obj.to_ruby end
184
184
  end
185
185
  end
186
+
187
+ ##
188
+ # `accessibility-core` extensions to `Object`
189
+ class Object
190
+
191
+ ##
192
+ # Spin the run loop for the given number of seconds
193
+ #
194
+ # The script will effectively be paused while the run loop
195
+ # is "spinning".
196
+ #
197
+ # @param seconds [Number]
198
+ def spin seconds
199
+ CFRunLoopRunInMode(KCFRunLoopDefaultMode, seconds, false)
200
+ end
201
+
202
+ end
@@ -1,6 +1,7 @@
1
1
  ##
2
2
  # A structure that contains a point in a two-dimensional coordinate system
3
- CGPoint = Struct.new(:x, :y) do
3
+ CGPoint = Struct.new(:x, :y)
4
+ class CGPoint
4
5
 
5
6
  # @param x [Number]
6
7
  # @param y [Number]
@@ -10,11 +11,11 @@ CGPoint = Struct.new(:x, :y) do
10
11
 
11
12
  # @!attribute [rw] x
12
13
  # The `x` co-ordinate of the screen point
13
- # @return [Number]
14
+ # @return [Float]
14
15
 
15
16
  # @!attribute [rw] y
16
17
  # The `y` co-ordinate of the screen point
17
- # @return [Number]
18
+ # @return [Float]
18
19
 
19
20
  ##
20
21
  # Return a nice string representation of the point
@@ -31,7 +32,8 @@ end
31
32
 
32
33
  ##
33
34
  # A structure that contains the size of a rectangle in a 2D co-ordinate system
34
- CGSize = Struct.new(:width, :height) do
35
+ CGSize = Struct.new(:width, :height)
36
+ class CGSize
35
37
 
36
38
  # @param width [Number]
37
39
  # @param height [Number]
@@ -41,11 +43,11 @@ CGSize = Struct.new(:width, :height) do
41
43
 
42
44
  # @!attribute [rw] width
43
45
  # The `width` of the box
44
- # @return [Number]
46
+ # @return [Float]
45
47
 
46
48
  # @!attribute [rw] height
47
49
  # The `heighth` of the box
48
- # @return [Number]
50
+ # @return [Float]
49
51
 
50
52
  ##
51
53
  # Return a nice string representation of the size
@@ -62,7 +64,8 @@ end
62
64
 
63
65
  ##
64
66
  # Complete definition of a rectangle in a 2D coordinate system
65
- CGRect = Struct.new(:origin, :size) do
67
+ CGRect = Struct.new(:origin, :size)
68
+ class CGRect
66
69
 
67
70
  # @param origin [CGPoint,#to_point]
68
71
  # @param size [CGSize,#to_size]
@@ -7,6 +7,6 @@ require 'accessibility/core/version'
7
7
  if on_macruby?
8
8
  require 'accessibility/core/macruby'
9
9
  else
10
- require 'accessibility/core.bundle'
10
+ require 'accessibility/core/core.bundle'
11
11
  end
12
12
 
@@ -159,7 +159,7 @@ module Accessibility::Element
159
159
  # The `:zomg` setting will be too fast in almost all cases, but
160
160
  # it is fun to watch.
161
161
  #
162
- # @param [Number,Symbol]
162
+ # @param value [Number,Symbol]
163
163
  def self.key_rate= value
164
164
  @key_rate = case value
165
165
  when :very_slow then 0.9
@@ -6,6 +6,6 @@ module Accessibility
6
6
  # Namespace for `accessibility_core` specific classes
7
7
  module Core
8
8
  # return [String]
9
- VERSION = '0.1.2'
9
+ VERSION = '0.3.1'
10
10
  end
11
11
  end
@@ -0,0 +1,5 @@
1
+ require 'accessibility/bridge'
2
+
3
+ require 'accessibility/extras/common'
4
+ framework 'Cocoa' if on_macruby?
5
+ require 'accessibility/extras/extras.bundle'