AXElements 0.6.0beta2 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -2
- data/README.markdown +152 -88
- data/Rakefile +8 -103
- data/docs/Debugging.markdown +9 -2
- data/docs/KeyboardEvents.markdown +114 -49
- data/docs/Setting.markdown +1 -0
- data/docs/images/next_version.png +0 -0
- data/ext/accessibility/key_coder/extconf.rb +22 -0
- data/ext/accessibility/key_coder/key_coder.c +113 -0
- data/lib/AXElements.rb +2 -0
- data/lib/accessibility/core.rb +897 -0
- data/lib/accessibility/debug.rb +168 -0
- data/lib/accessibility/dsl.rb +697 -0
- data/lib/accessibility/enumerators.rb +104 -0
- data/lib/accessibility/errors.rb +32 -0
- data/lib/accessibility/factory.rb +153 -0
- data/lib/accessibility/graph.rb +150 -0
- data/lib/{ax_elements/inspector.rb → accessibility/pp_inspector.rb} +39 -28
- data/lib/accessibility/qualifier.rb +158 -0
- data/lib/accessibility/string.rb +494 -0
- data/lib/accessibility/translator.rb +178 -0
- data/lib/accessibility/version.rb +7 -0
- data/lib/accessibility.rb +79 -0
- data/lib/ax/application.rb +234 -0
- data/lib/{ax_elements/elements → ax}/button.rb +2 -0
- data/lib/ax/element.rb +518 -0
- data/lib/{ax_elements/elements → ax}/radio_button.rb +2 -0
- data/lib/ax/row.rb +37 -0
- data/lib/{ax_elements/elements → ax}/static_text.rb +2 -0
- data/lib/ax/systemwide.rb +86 -0
- data/lib/ax_elements/awesome_print.rb +25 -0
- data/lib/ax_elements/exception_workaround.rb +8 -0
- data/lib/ax_elements/nsarray_compat.rb +64 -0
- data/lib/ax_elements/vendor/inflection_data.rb +65 -0
- data/lib/ax_elements/vendor/inflections.rb +172 -0
- data/lib/ax_elements/vendor/inflector.rb +306 -0
- data/lib/ax_elements.rb +14 -25
- data/lib/minitest/ax_elements.rb +112 -12
- data/lib/mouse.rb +72 -46
- data/lib/rspec/expectations/ax_elements.rb +133 -6
- data/rakelib/doc.rake +13 -0
- data/rakelib/ext.rake +61 -0
- data/rakelib/gem.rake +28 -0
- data/rakelib/test.rake +53 -0
- data/test/helper.rb +11 -97
- data/test/integration/accessibility/test_core.rb +18 -0
- data/test/integration/accessibility/test_debug.rb +44 -0
- data/test/integration/accessibility/test_dsl.rb +225 -0
- data/test/integration/accessibility/test_enumerators.rb +122 -0
- data/test/integration/accessibility/test_errors.rb +38 -0
- data/test/integration/accessibility/test_notifications.rb +22 -0
- data/test/integration/accessibility/test_qualifier.rb +148 -0
- data/test/integration/ax/test_application.rb +56 -0
- data/test/integration/ax/test_element.rb +46 -0
- data/test/integration/ax/test_row.rb +23 -0
- data/test/integration/ax_elements/test_nsarray_compat.rb +43 -0
- data/test/integration/minitest/test_ax_elements.rb +98 -0
- data/test/integration/rspec/expectations/test_ax_elements.rb +58 -0
- data/test/integration/test_mouse.rb +35 -0
- data/test/sanity/accessibility/test_core.rb +553 -0
- data/test/sanity/accessibility/test_debug.rb +63 -0
- data/test/sanity/accessibility/test_dsl.rb +75 -0
- data/test/sanity/accessibility/test_errors.rb +10 -0
- data/test/sanity/accessibility/test_factory.rb +88 -0
- data/test/sanity/accessibility/test_pp_inspector.rb +110 -0
- data/test/sanity/accessibility/test_qualifier.rb +13 -0
- data/test/sanity/accessibility/test_string.rb +238 -0
- data/test/sanity/accessibility/test_translator.rb +145 -0
- data/test/sanity/ax/test_application.rb +90 -0
- data/test/sanity/ax/test_element.rb +80 -0
- data/test/sanity/ax/test_systemwide.rb +66 -0
- data/test/sanity/ax_elements/test_nsarray_compat.rb +16 -0
- data/test/sanity/ax_elements/test_nsobject_inspect.rb +11 -0
- data/test/sanity/minitest/test_ax_elements.rb +15 -0
- data/test/sanity/rspec/expectations/test_ax_elements.rb +12 -0
- data/test/sanity/test_ax_elements.rb +10 -0
- data/test/sanity/test_mouse.rb +19 -0
- metadata +111 -93
- data/LICENSE.txt +0 -25
- data/ext/key_coder/extconf.rb +0 -6
- data/ext/key_coder/key_coder.m +0 -77
- data/lib/ax_elements/accessibility/enumerators.rb +0 -104
- data/lib/ax_elements/accessibility/graph.rb +0 -118
- data/lib/ax_elements/accessibility/language.rb +0 -347
- data/lib/ax_elements/accessibility/qualifier.rb +0 -73
- data/lib/ax_elements/accessibility.rb +0 -166
- data/lib/ax_elements/core.rb +0 -541
- data/lib/ax_elements/element.rb +0 -593
- data/lib/ax_elements/elements/application.rb +0 -88
- data/lib/ax_elements/elements/row.rb +0 -30
- data/lib/ax_elements/elements/systemwide.rb +0 -46
- data/lib/ax_elements/macruby_extensions.rb +0 -255
- data/lib/ax_elements/notification.rb +0 -37
- data/lib/ax_elements/version.rb +0 -9
- data/test/elements/test_application.rb +0 -72
- data/test/elements/test_row.rb +0 -27
- data/test/elements/test_systemwide.rb +0 -38
- data/test/test_accessibility.rb +0 -127
- data/test/test_blankness.rb +0 -26
- data/test/test_core.rb +0 -448
- data/test/test_element.rb +0 -939
- data/test/test_enumerators.rb +0 -81
- data/test/test_inspector.rb +0 -130
- data/test/test_language.rb +0 -157
- data/test/test_macruby_extensions.rb +0 -303
- data/test/test_mouse.rb +0 -5
- data/test/test_search_semantics.rb +0 -143
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'accessibility/version'
|
2
|
+
framework 'Cocoa'
|
3
|
+
|
4
|
+
##
|
5
|
+
# Collection of utility methods helpful when trying to debug issues.
|
6
|
+
module Accessibility::Debug
|
7
|
+
|
8
|
+
# Initialize the DEBUG value
|
9
|
+
@on = ENV.fetch 'AXDEBUG', $DEBUG
|
10
|
+
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
##
|
15
|
+
# Whether or not to turn on DEBUG features in AXElements. The
|
16
|
+
# value is initially inherited from `$DEBUG` but can be overridden
|
17
|
+
# by an environment variable named `AXDEBUG` or changed dynamically
|
18
|
+
# at runtime.
|
19
|
+
#
|
20
|
+
# @return [Boolean]
|
21
|
+
attr_accessor :on
|
22
|
+
alias_method :on?, :on
|
23
|
+
|
24
|
+
##
|
25
|
+
# Get a list of elements, starting with an element you give, and riding
|
26
|
+
# the hierarchy up to the top level object (i.e. the {AX::Application}).
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
#
|
30
|
+
# element = AX::DOCK.list.application_dock_item
|
31
|
+
# path_for element
|
32
|
+
# # => [AX::ApplicationDockItem, AX::List, AX::Application]
|
33
|
+
#
|
34
|
+
# @param [AX::Element]
|
35
|
+
# @return [Array<AX::Element>] the path in ascending order
|
36
|
+
def path *elements
|
37
|
+
element = elements.last
|
38
|
+
return path(elements << element.parent) if element.respond_to? :parent
|
39
|
+
return elements
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# @note This is an unfinished feature
|
44
|
+
#
|
45
|
+
# Make a `dot` format graph of the tree, meant for graphing with
|
46
|
+
# GraphViz.
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
def graph_subtree root
|
50
|
+
require 'accessibility/graph'
|
51
|
+
dot = Accessibility::Graph.new(root)
|
52
|
+
dot.build!
|
53
|
+
dot.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Dump a tree to the console, indenting for each level down the
|
58
|
+
# tree that we go, and inspecting each element.
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
#
|
62
|
+
# puts subtree_for app
|
63
|
+
#
|
64
|
+
# @return [String]
|
65
|
+
def text_subtree element
|
66
|
+
output = element.inspect + "\n"
|
67
|
+
# @todo should use each_child_with_level instead
|
68
|
+
enum = Accessibility::Enumerators::DepthFirst.new element
|
69
|
+
enum.each_with_level do |element, depth|
|
70
|
+
output << "\t"*depth + element.inspect + "\n"
|
71
|
+
end
|
72
|
+
output
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Highlight an element on screen. You can optionally specify the
|
77
|
+
# highlight colour or pass a timeout to automatically have the
|
78
|
+
# highlighter disappear.
|
79
|
+
#
|
80
|
+
# The highlighter is actually a window, so if you do not set a
|
81
|
+
# timeout, you will need to call `#stop` or `#close` on the `NSWindow`
|
82
|
+
# object that this method returns in order to get rid of the
|
83
|
+
# highlighter.
|
84
|
+
#
|
85
|
+
# You could use this method to highlight an arbitrary number of
|
86
|
+
# elements on screen, with a rainbow of colours for debugging.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
#
|
90
|
+
# highlighter = highlight window.outline
|
91
|
+
# highlight window.outline.row, colour: NSColor.greenColor, timeout: 5
|
92
|
+
# highlighter.stop
|
93
|
+
#
|
94
|
+
# @param [AX::Element]
|
95
|
+
# @param [Hash] opts
|
96
|
+
# @option opts [Number] :timeout
|
97
|
+
# @option opts [NSColor] :colour
|
98
|
+
# @return [NSWindow]
|
99
|
+
def highlight element, opts = {}
|
100
|
+
app = NSApplication.sharedApplication
|
101
|
+
colour = opts[:colour] || opts[:color] || NSColor.magentaColor
|
102
|
+
window = highlight_window_for element.bounds, colour
|
103
|
+
kill window, after: opts[:timeout] if opts.has_key? :timeout
|
104
|
+
window
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
# @param [NSWindow]
|
111
|
+
# @param [Number]
|
112
|
+
def kill window, after: time
|
113
|
+
@kill_queue ||= Dispatch::Queue.new 'com.marketcircle.AXElements'
|
114
|
+
@kill_queue.async do
|
115
|
+
sleep time
|
116
|
+
window.close
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Create the window that acts as the highlighted portion of the screen.
|
122
|
+
#
|
123
|
+
# @param [NSRect]
|
124
|
+
# @param [NSColor]
|
125
|
+
# @return [NSWindow]
|
126
|
+
def highlight_window_for bounds, colour
|
127
|
+
bounds.flip!
|
128
|
+
window = NSWindow.alloc.initWithContentRect bounds,
|
129
|
+
styleMask: NSBorderlessWindowMask,
|
130
|
+
backing: NSBackingStoreBuffered,
|
131
|
+
defer: true
|
132
|
+
|
133
|
+
window.setOpaque false
|
134
|
+
window.setAlphaValue 0.20
|
135
|
+
window.setLevel NSStatusWindowLevel
|
136
|
+
window.setBackgroundColor colour
|
137
|
+
window.setIgnoresMouseEvents true
|
138
|
+
window.setFrame bounds, display: false
|
139
|
+
window.makeKeyAndOrderFront NSApp
|
140
|
+
def window.stop
|
141
|
+
close
|
142
|
+
end
|
143
|
+
window
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
##
|
151
|
+
# AXElements extensions to `CGRect`.
|
152
|
+
class CGRect
|
153
|
+
##
|
154
|
+
# Treats the rect as belonging to one co-ordinate system and then
|
155
|
+
# converts it to the other system.
|
156
|
+
#
|
157
|
+
# This is useful because accessibility API's expect to work with
|
158
|
+
# the flipped co-ordinate system (origin in top left), but AppKit
|
159
|
+
# prefers to use the cartesian co-ordinate system (origin in bottom
|
160
|
+
# left).
|
161
|
+
#
|
162
|
+
# @return [CGRect]
|
163
|
+
def flip!
|
164
|
+
screen_height = NSMaxY(NSScreen.mainScreen.frame)
|
165
|
+
origin.y = screen_height - NSMaxY(self)
|
166
|
+
self
|
167
|
+
end
|
168
|
+
end
|