atspi 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.yardopts +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/atspi.gemspec +23 -0
- data/bin/console +7 -0
- data/lib/atspi/accessible/action.rb +45 -0
- data/lib/atspi/accessible/children/selected.rb +32 -0
- data/lib/atspi/accessible/children.rb +72 -0
- data/lib/atspi/accessible/descendants/attribute_filter.rb +32 -0
- data/lib/atspi/accessible/descendants/interface_filter.rb +24 -0
- data/lib/atspi/accessible/descendants/name_filter.rb +18 -0
- data/lib/atspi/accessible/descendants/options.rb +49 -0
- data/lib/atspi/accessible/descendants/role_filter.rb +23 -0
- data/lib/atspi/accessible/descendants/state_filter.rb +23 -0
- data/lib/atspi/accessible/descendants.rb +278 -0
- data/lib/atspi/accessible/document.rb +26 -0
- data/lib/atspi/accessible/extents.rb +129 -0
- data/lib/atspi/accessible/hyperlink/anchor.rb +30 -0
- data/lib/atspi/accessible/hyperlink.rb +31 -0
- data/lib/atspi/accessible/image.rb +35 -0
- data/lib/atspi/accessible/selectable.rb +47 -0
- data/lib/atspi/accessible/table/cell/columns.rb +44 -0
- data/lib/atspi/accessible/table/cell/rows.rb +44 -0
- data/lib/atspi/accessible/table/cell.rb +18 -0
- data/lib/atspi/accessible/table/cells.rb +37 -0
- data/lib/atspi/accessible/table/column.rb +59 -0
- data/lib/atspi/accessible/table/columns/selected.rb +42 -0
- data/lib/atspi/accessible/table/columns.rb +34 -0
- data/lib/atspi/accessible/table/row.rb +59 -0
- data/lib/atspi/accessible/table/rows/selected.rb +42 -0
- data/lib/atspi/accessible/table/rows.rb +31 -0
- data/lib/atspi/accessible/table.rb +50 -0
- data/lib/atspi/accessible/text/caret.rb +31 -0
- data/lib/atspi/accessible/text/character.rb +45 -0
- data/lib/atspi/accessible/text/editable.rb +90 -0
- data/lib/atspi/accessible/text/hyperlink.rb +19 -0
- data/lib/atspi/accessible/text/hypertext.rb +29 -0
- data/lib/atspi/accessible/text/offset.rb +59 -0
- data/lib/atspi/accessible/text/range.rb +66 -0
- data/lib/atspi/accessible/text/selection.rb +48 -0
- data/lib/atspi/accessible/text.rb +120 -0
- data/lib/atspi/accessible/value.rb +47 -0
- data/lib/atspi/accessible.rb +267 -0
- data/lib/atspi/application.rb +46 -0
- data/lib/atspi/collection.rb +60 -0
- data/lib/atspi/desktop.rb +52 -0
- data/lib/atspi/extents.rb +28 -0
- data/lib/atspi/libatspi.rb +7 -0
- data/lib/atspi/requires.rb +76 -0
- data/lib/atspi/selectable_collection/selected.rb +23 -0
- data/lib/atspi/selectable_collection.rb +32 -0
- data/lib/atspi/state_set.rb +141 -0
- data/lib/atspi/version.rb +4 -0
- data/lib/atspi/window.rb +33 -0
- data/lib/atspi.rb +58 -0
- metadata +132 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
module ATSPI
|
2
|
+
class Accessible::Text
|
3
|
+
# Represents a range in a {Text}.
|
4
|
+
class Range
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
# @api private
|
8
|
+
def initialize(text_native, range_native)
|
9
|
+
@text_native = text_native
|
10
|
+
@range_native = range_native
|
11
|
+
end
|
12
|
+
|
13
|
+
# @!group Attributes
|
14
|
+
# @return [Offset] its start offset
|
15
|
+
#
|
16
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#AtspiRange-struct struct AtspiRange
|
17
|
+
def start
|
18
|
+
Offset.new(@text_native, @range_native.start_offset)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Offset] its end offset
|
22
|
+
#
|
23
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#AtspiRange-struct struct AtspiRange
|
24
|
+
def end
|
25
|
+
Offset.new(@text_native, @range_native.end_offset)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Integer] its length
|
29
|
+
def length
|
30
|
+
self.end.to_i - start.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param relative_to [Symbol] coordinate system derived from
|
34
|
+
# libatspi's {https://developer.gnome.org/libatspi/stable/libatspi-atspi-constants.html#AtspiCoordType AtspiCoordType enum}
|
35
|
+
# by removing the prefix +ATSPI_COORD_TYPE+ and making it lowercase
|
36
|
+
#
|
37
|
+
# @return [Extents] its extents
|
38
|
+
#
|
39
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-range-extents atspi_text_get_range_extents
|
40
|
+
def extents(relative_to:)
|
41
|
+
Extents.new(@text_native.range_extents(start.to_i, self.end.to_i, relative_to))
|
42
|
+
end
|
43
|
+
# @!endgroup
|
44
|
+
|
45
|
+
# @!group Representations
|
46
|
+
# @return [String] its string representation
|
47
|
+
#
|
48
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#AtspiTextRange-struct struct AtspiTextRange
|
49
|
+
def to_s
|
50
|
+
if @range_native.respond_to? :content
|
51
|
+
@range_native.content
|
52
|
+
else
|
53
|
+
@text_native.text(start.to_i, self.end.to_i)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [String] itself as an inspectable string
|
58
|
+
def inspect
|
59
|
+
text_s = to_s[0..20] << (length > 20 ? '…' : '')
|
60
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @to_s=#{text_s.inspect} @length=#{length} " <<
|
61
|
+
"@start=#{start} @end=#{self.end} @extents=#{extents(relative_to: :screen).inspect}>"
|
62
|
+
end
|
63
|
+
# @!endgroup
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ATSPI
|
2
|
+
class Accessible::Text
|
3
|
+
# Represents a selected range in a {Text}.
|
4
|
+
class Selection < Range
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
# @api private
|
8
|
+
def initialize(text_native, idx)
|
9
|
+
@text_native = text_native
|
10
|
+
@idx = idx
|
11
|
+
@range_native = @text_native.selection(idx)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @!group Actions
|
15
|
+
# Deselects itself.
|
16
|
+
#
|
17
|
+
# @return [true,false] indicating success
|
18
|
+
#
|
19
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-remove-selection atspi_text_remove_selection
|
20
|
+
def deselect
|
21
|
+
@text_native.remove_selection(@idx)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Moves its start to the given offset.
|
25
|
+
#
|
26
|
+
# @param new_start_offset [responds to #to_i]
|
27
|
+
#
|
28
|
+
# @return [true,false] indicating success
|
29
|
+
#
|
30
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-set-selection atspi_text_set_selection
|
31
|
+
def move_start_to(new_start_offset)
|
32
|
+
@text_native.set_selection(@idx, new_start_offset.to_i, self.end)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Moves its end to the given offset.
|
36
|
+
#
|
37
|
+
# @param new_end_offset [responds to #to_i]
|
38
|
+
#
|
39
|
+
# @return [true,false] indicating success
|
40
|
+
#
|
41
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-set-selection atspi_text_set_selection
|
42
|
+
def move_end_to(new_end_offset)
|
43
|
+
@text_native.set_selection(@idx, start, new_end_offset.to_i)
|
44
|
+
end
|
45
|
+
# @!endgroup
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
class ATSPI::Accessible
|
2
|
+
# Wraps libatspi's {https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html text interface},
|
3
|
+
# {https://developer.gnome.org/libatspi/stable/libatspi-atspi-editabletext.html editable_text interface} and
|
4
|
+
# {https://developer.gnome.org/libatspi/stable/libatspi-atspi-hypertext.html hypertext interface}.
|
5
|
+
class Text
|
6
|
+
extend Forwardable
|
7
|
+
include Editable
|
8
|
+
include Hypertext
|
9
|
+
|
10
|
+
# @api private
|
11
|
+
def initialize(native)
|
12
|
+
@native = native
|
13
|
+
end
|
14
|
+
|
15
|
+
# @!group Attributes & States
|
16
|
+
# @return [Integer] its length
|
17
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-character-count atspi_text_get_character_count
|
18
|
+
def length
|
19
|
+
@native.character_count
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Caret] its caret/cursor
|
23
|
+
def caret
|
24
|
+
Caret.new(@native)
|
25
|
+
end
|
26
|
+
alias_method :cursor, :caret
|
27
|
+
|
28
|
+
# @return [Array<Selection>] its selected text ranges
|
29
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-n-selections atspi_text_get_n_selections
|
30
|
+
def selections
|
31
|
+
@native.n_selections.times.map do |idx|
|
32
|
+
Selection.new(@native, idx)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
# @!endgroup
|
36
|
+
|
37
|
+
# @!group Geometric Access
|
38
|
+
# @param x [Integer]
|
39
|
+
# @param y [Integer]
|
40
|
+
# @param relative_to [Symbol] coordinate system derived from
|
41
|
+
# libatspi's {https://developer.gnome.org/libatspi/stable/libatspi-atspi-constants.html#AtspiCoordType AtspiCoordType enum}
|
42
|
+
# by removing the prefix +ATSPI_COORD_TYPE+ and making it lowercase
|
43
|
+
#
|
44
|
+
# @return [Offset] the offset at the given point
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# text.offset_at(1243, 323, relative_to: :screen) # => #<ATSPI::Accessible::Text::Offset:0x112779814 … >
|
48
|
+
#
|
49
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-offset-at-point atspi_text_get_offset_at_point
|
50
|
+
def offset_at(x, y, relative_to:)
|
51
|
+
Offset.new(@native, @native.offset_at_point(x, y, relative_to))
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param x [Integer] x position of the rectangle
|
55
|
+
# @param y [Integer] y position of the rectangle
|
56
|
+
# @param width [Integer] width of the rectangle
|
57
|
+
# @param height [Integer] height of the rectangle
|
58
|
+
# @param relative_to [Symbol] coordinate system derived from
|
59
|
+
# libatspi's {https://developer.gnome.org/libatspi/stable/libatspi-atspi-constants.html#AtspiCoordType AtspiCoordType enum}
|
60
|
+
# by removing the prefix +ATSPI_COORD_TYPE+ and making it lowercase
|
61
|
+
# @param clip_x [Symbol] how to treat characters intersecting the
|
62
|
+
# rectangle in x direction. derived from libatspi's
|
63
|
+
# {https://developer.gnome.org/libatspi/stable/libatspi-atspi-constants.html#AtspiTextClipType AtspiTextClipType enum}
|
64
|
+
# by removing the prefix +ATSPI_TEXT_CLIP_+ and making it lowercase
|
65
|
+
#
|
66
|
+
# @return [Array<Range>] the ranges inside the given rectangle
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# ranges_in(200, 300, 543, 322, relative_to: :window, clip_x: :both, clip_y: :min) # => [#<ATSPI::Accessible::Text::Range:0xea30bc14 … >, …]
|
70
|
+
#
|
71
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-bounded-ranges atspi_text_get_bounded_ranges
|
72
|
+
def ranges_in(x, y, width, height, relative_to:, clip_x: :none, clip_y: :none)
|
73
|
+
@native.bounded_ranges(x, y, width, height, relative_to, clip_x, clip_y).map do |range|
|
74
|
+
Range.new(@native, range)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
# @!endgroup
|
78
|
+
|
79
|
+
# @!group Actions
|
80
|
+
# Selects the text between the given offsets.
|
81
|
+
#
|
82
|
+
# @param from [responds to #to_i] start offset
|
83
|
+
# @param to [responds to #to_i] end offset
|
84
|
+
#
|
85
|
+
# @return [true,false] indicating success
|
86
|
+
#
|
87
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-add-selection atspi_text_add_selection
|
88
|
+
def select(from: 0, to: length)
|
89
|
+
@native.add_selection(from.to_i, to.to_i)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Deselects the entire text.
|
93
|
+
#
|
94
|
+
# To deselect a single selection do it via {Selection#deselect}.
|
95
|
+
#
|
96
|
+
# @return [true,false] indicating success
|
97
|
+
def deselect
|
98
|
+
selections.reverse.map(&:deselect).all?
|
99
|
+
end
|
100
|
+
# @!endgroup
|
101
|
+
|
102
|
+
# @!group Representations
|
103
|
+
# @param from [responds to #to_i] start offset
|
104
|
+
# @param to [responds to #to_i] end offset
|
105
|
+
#
|
106
|
+
# @return [String] its string representation
|
107
|
+
#
|
108
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-text.html#atspi-text-get-text atspi_text_get_text
|
109
|
+
def to_s(from: 0, to: length)
|
110
|
+
@native.text(from.to_i, to.to_i)
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [String] itself as an inspectable string
|
114
|
+
def inspect
|
115
|
+
text_s = to_s(from: 0, to: 20) << (length > 20 ? '…' : '')
|
116
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @to_s=#{text_s.inspect} @length=#{length}>"
|
117
|
+
end
|
118
|
+
# @!endgroup
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ATSPI
|
2
|
+
# Wraps libatspi's AtspiValue[https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html]
|
3
|
+
class Accessible::Value
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
# @api private
|
7
|
+
def initialize(native)
|
8
|
+
@native = native
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Float] its minimum
|
12
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-get-minimum-value atspi_value_get_minimum_value
|
13
|
+
def minimum
|
14
|
+
@native.minimum_value
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Float] its maximum
|
18
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-get-maximum-value atspi_value_get_maximum_value
|
19
|
+
def maximum
|
20
|
+
@native.maximum_value
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Float] its current value
|
24
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-get-current-value atspi_value_get_current_value
|
25
|
+
def current
|
26
|
+
@native.current_value
|
27
|
+
end
|
28
|
+
|
29
|
+
# Sets its value to the given one.
|
30
|
+
# @return [true,false] indicating success
|
31
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-set-current-value atspi_value_set_current_value
|
32
|
+
def set_to(value)
|
33
|
+
@native.set_current_value(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Float] its minimum increment
|
37
|
+
# @see https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-get-minimum-increment atspi_value_get_minimum_increment
|
38
|
+
def step
|
39
|
+
@native.minimum_increment
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] itself as an inspectable string
|
43
|
+
def inspect
|
44
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @min=#{min} @cur=#{cur} @max=#{max} @incr=#{incr}>"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
Libatspi.load_class :Accessible
|
2
|
+
|
3
|
+
module ATSPI
|
4
|
+
# Wraps libatspi's AtspiAccessible[https://developer.gnome.org/libatspi/stable/AtspiAccessible.html]
|
5
|
+
#
|
6
|
+
# The entry point to get ATSPI::Accessibles or one of it sub types are
|
7
|
+
# {ATSPI.desktops ATSPI.desktops} and {ATSPI.applications ATSPI.applications}.
|
8
|
+
# From there, accessibles are gotten via Tree & Traversal methods like
|
9
|
+
# {#parent}, {#children} or {#descendants}.
|
10
|
+
#
|
11
|
+
# Most methods correspond directly to the method in libatspi. Some have an
|
12
|
+
# extended or beautified interface that is documented here.
|
13
|
+
class Accessible
|
14
|
+
extend Forwardable
|
15
|
+
include Extents
|
16
|
+
include Selectable
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# @api private
|
20
|
+
def new(native)
|
21
|
+
if self == Accessible
|
22
|
+
native and (new_mapped(native) or super)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def new_mapped(native)
|
31
|
+
case native.role
|
32
|
+
when :desktop_frame then Desktop.new(native)
|
33
|
+
when :application then Application.new(native)
|
34
|
+
when :frame then Window.new(native)
|
35
|
+
else nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def initialize(native)
|
42
|
+
@native = native
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :native
|
46
|
+
private :native
|
47
|
+
|
48
|
+
# @!group Identification
|
49
|
+
# @return [Desktop] its desktop. That is the {#parent} of its {#application}.
|
50
|
+
delegate :desktop => :application
|
51
|
+
|
52
|
+
# @return [Application] its application
|
53
|
+
#
|
54
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-application atspi_accessible_get_application
|
55
|
+
def application
|
56
|
+
Application.new(@native.application)
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Window] its top level window. It is a {#children child} of its {#application} and has
|
60
|
+
# the {#role} :frame.
|
61
|
+
delegate :window => :parent
|
62
|
+
|
63
|
+
# @return [Integer] the index in the collection of its {#parent} {#children}
|
64
|
+
#
|
65
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-index-in-parent atspi_accessible_get_index_in_parent
|
66
|
+
delegate :index_in_parent => :@native
|
67
|
+
alias_method :index, :index_in_parent
|
68
|
+
|
69
|
+
# @return [Array<Integer>] the list of {#index_in_parent} of all its
|
70
|
+
# ancestors until reaching its {#window}, exclusive.
|
71
|
+
def path
|
72
|
+
parent.path + [*index_in_parent]
|
73
|
+
end
|
74
|
+
# @!endgroup
|
75
|
+
|
76
|
+
# @!group Attributes & States
|
77
|
+
# @return [String] its name
|
78
|
+
#
|
79
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-name atspi_accessible_get_name
|
80
|
+
delegate :name => :@native
|
81
|
+
|
82
|
+
# @return [String] its description
|
83
|
+
#
|
84
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-description atspi_accessible_get_description
|
85
|
+
delegate :description => :@native
|
86
|
+
|
87
|
+
# @return [Symbol] its role derived from libatspi's {AtspiRole enum}[https://developer.gnome.org/libatspi/stable/libatspi-atspi-constants.html#AtspiRole]
|
88
|
+
# by removing the prefix +ATSPI_ROLE_+ and making it lowercase.
|
89
|
+
#
|
90
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-role atspi_accessible_get_role
|
91
|
+
delegate :role => :@native
|
92
|
+
|
93
|
+
# @return [String] its role as string
|
94
|
+
#
|
95
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-role-name atspi_accessible_get_role_name
|
96
|
+
delegate :role_name => :@native
|
97
|
+
|
98
|
+
# @return [String] its role as a localized string
|
99
|
+
#
|
100
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-localized-role-name atspi_accessible_get_localized_role_name
|
101
|
+
delegate :localized_role_name => :@native
|
102
|
+
|
103
|
+
# @return [String] its toolkit's name
|
104
|
+
#
|
105
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-toolkit-name atspi_accessible_get_toolkit_name
|
106
|
+
delegate :toolkit_name => :@native
|
107
|
+
|
108
|
+
# @return [String] its toolkit's version
|
109
|
+
#
|
110
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-toolkit-version atspi_accessible_get_toolkit_version
|
111
|
+
delegate :toolkit_version => :@native
|
112
|
+
|
113
|
+
# @return [StateSet] its states
|
114
|
+
#
|
115
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-state-set atspi_accessible_get_state_set
|
116
|
+
def states
|
117
|
+
StateSet.new_from_native(@native.state_set)
|
118
|
+
end
|
119
|
+
|
120
|
+
# @return [Hash<String => String>] its attributes
|
121
|
+
#
|
122
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-attributes atspi_accessible_get_attributes
|
123
|
+
def attributes
|
124
|
+
@native.attributes.to_h
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [Array<String>] the interfaces it implements
|
128
|
+
#
|
129
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-interfaces atspi_accessible_get_interfaces
|
130
|
+
def interfaces
|
131
|
+
@native.interfaces.to_a
|
132
|
+
end
|
133
|
+
# @!endgroup
|
134
|
+
|
135
|
+
# @!group Tree & Traversal
|
136
|
+
# @return [Accessible] its parent
|
137
|
+
#
|
138
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-parent atspi_accessible_get_parent
|
139
|
+
def parent
|
140
|
+
Accessible.new(@native.get_parent)
|
141
|
+
end
|
142
|
+
|
143
|
+
# @return [Children] its children
|
144
|
+
def children
|
145
|
+
Children.new(@native)
|
146
|
+
end
|
147
|
+
|
148
|
+
# @return [Descendants, []] its descendants. It will be an empty array it
|
149
|
+
# does not implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-collection collection interface}
|
150
|
+
#
|
151
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-collection atspi_accessible_get_collection
|
152
|
+
def descendants
|
153
|
+
if @native.collection_iface
|
154
|
+
Descendants.new(@native)
|
155
|
+
else
|
156
|
+
[]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# @return [Hash<Symbol => Array<Accessible>>] its relations to other
|
161
|
+
# accessibles. Keys name the relation type and values are relation
|
162
|
+
# targets.
|
163
|
+
#
|
164
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-relation-set atspi_accessible_get_relation_set
|
165
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiRelation.html atspi-relation
|
166
|
+
def relations
|
167
|
+
@native.relation_set.to_a.inject({}) do |relations, relation|
|
168
|
+
type = relation.relation_type
|
169
|
+
targets = relation.n_targets.times.map{ |idx| Accessible.new(relation.target(idx)) }
|
170
|
+
relations.merge!(type => targets)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
# @!endgroup
|
174
|
+
|
175
|
+
# @!group Actions
|
176
|
+
# @return [Array<Action>] the actions it supports. The array will be empty
|
177
|
+
# if it does not implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-action action interface}.
|
178
|
+
#
|
179
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-action atspi_accessible_get_action_iface
|
180
|
+
def actions
|
181
|
+
if @native.action_iface
|
182
|
+
@native.n_actions.times.map{ |idx| Action.new(@native, idx) }
|
183
|
+
else
|
184
|
+
[]
|
185
|
+
end
|
186
|
+
end
|
187
|
+
# @!endgroup
|
188
|
+
|
189
|
+
# @!group Representative for
|
190
|
+
# @return [Document, nil] its document. It will be nil if it does not
|
191
|
+
# implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-document document interface}.
|
192
|
+
#
|
193
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-document atspi_accessible_get_document_iface
|
194
|
+
def document
|
195
|
+
if @native.document_iface
|
196
|
+
Document.new(@native)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# @return [Text, nil] its text. It will be nil if it does not
|
201
|
+
# implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-text text interface}.
|
202
|
+
#
|
203
|
+
# @note The {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-editable-text editable_text interface}
|
204
|
+
# and {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-hypertext hypertext interface} are
|
205
|
+
# available through {Text}, too.
|
206
|
+
#
|
207
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-text atspi_accessible_get_text_iface
|
208
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-editable-text atspi_accessible_get_editable_text_iface
|
209
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-hypertext atspi_accessible_get_hypertext_iface
|
210
|
+
def text
|
211
|
+
if @native.text_iface
|
212
|
+
Text.new(@native)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# @return [Hyperlink, nil] its hyperlink. It will be nil if it does not
|
217
|
+
# have a {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-hyperlink hyperlink}.
|
218
|
+
#
|
219
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-hyperlink atspi_accessible_get_hyperlink
|
220
|
+
def hyperlink
|
221
|
+
if hyperlink = @native.hyperlink
|
222
|
+
Hyperlink.new(hyperlink)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
alias_method :link, :hyperlink
|
226
|
+
|
227
|
+
# @return [Image, nil] its image. It will be nil if it does not
|
228
|
+
# implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-image image interface}.
|
229
|
+
#
|
230
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-image atspi_accessible_get_image_iface
|
231
|
+
def image
|
232
|
+
if @native.image_iface
|
233
|
+
Image.new(@native)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# @return [Value, nil] its image. It will be nil if it does not
|
238
|
+
# implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-value value interface}.
|
239
|
+
#
|
240
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-value atspi_accessible_get_value_iface
|
241
|
+
def value
|
242
|
+
if @native.value_iface
|
243
|
+
Value.new(@native)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# @return [Table, nil] its table. It will be nil if it does not
|
248
|
+
# implement the {https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-table table interface}.
|
249
|
+
#
|
250
|
+
# @see https://developer.gnome.org/libatspi/stable/AtspiAccessible.html#atspi-accessible-get-table atspi_accessible_get_table_iface
|
251
|
+
def table
|
252
|
+
if @native.table_iface
|
253
|
+
Table.new(@native)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
# @!endgroup
|
257
|
+
|
258
|
+
# @!group Representations
|
259
|
+
# @return [String] itself as an inspectable string
|
260
|
+
def inspect
|
261
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @desktop=#{desktop.index} " <<
|
262
|
+
"@application=#{application.name} @window=#{window.name} @path=#{path.join('/')} " <<
|
263
|
+
"@name=#{name.inspect} @role=#{role.inspect} @extents=#{extents(relative_to: :screen).inspect}>"
|
264
|
+
end
|
265
|
+
# @!endgroup
|
266
|
+
end
|
267
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ATSPI
|
2
|
+
# Applications are Accessibles having a few exceptions.
|
3
|
+
class Application < Accessible
|
4
|
+
# @!group Identification
|
5
|
+
# It has no path.
|
6
|
+
# @return [[]]
|
7
|
+
def path
|
8
|
+
[]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Its desktop is its parent
|
12
|
+
# @return [Desktop]
|
13
|
+
def desktop
|
14
|
+
parent
|
15
|
+
end
|
16
|
+
|
17
|
+
# Its application is itself
|
18
|
+
# @return [self]
|
19
|
+
def application
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# It belongs to no window
|
24
|
+
# @return nil
|
25
|
+
def window
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
# @!endgroup
|
29
|
+
|
30
|
+
# @!group Tree & Traversal
|
31
|
+
# Its windows are its children.
|
32
|
+
# @param (see Accessible#children)
|
33
|
+
# @return (see Accessible#children)
|
34
|
+
def windows
|
35
|
+
children
|
36
|
+
end
|
37
|
+
# @!endgroup
|
38
|
+
|
39
|
+
# @!group Representations
|
40
|
+
# @return [String] itself as an inspectable string
|
41
|
+
def inspect
|
42
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @desktop=#{desktop.index} @name=#{name.inspect}>"
|
43
|
+
end
|
44
|
+
# @!endgroup
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ATSPI
|
2
|
+
# Included in classes representing a collection that can be iterated over.
|
3
|
+
# A Collection is an Enumerable adjusted to the what we can efficiently get
|
4
|
+
# from libatspi. In particular, it provides access to items by index and
|
5
|
+
# from the end of the collection.
|
6
|
+
module Collection
|
7
|
+
include Enumerable
|
8
|
+
# @!group Enumerable interface
|
9
|
+
# prerequisite for Enumerable
|
10
|
+
def each
|
11
|
+
count.times.each do |idx|
|
12
|
+
yield at(idx)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param idx [Integer]
|
17
|
+
# @return [Object] item at index +idx+
|
18
|
+
def at(idx)
|
19
|
+
if idx.between?(0, count-1)
|
20
|
+
yield idx
|
21
|
+
elsif idx.between?(-count, -1)
|
22
|
+
yield count+idx
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# alias for {#at}
|
29
|
+
def [](idx)
|
30
|
+
at(idx)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [0] default size of collection
|
34
|
+
def count
|
35
|
+
0
|
36
|
+
end
|
37
|
+
# alias for {#count}
|
38
|
+
def size; count end
|
39
|
+
# alias for {#count}
|
40
|
+
def length; count end
|
41
|
+
|
42
|
+
# @param n [Integer] number of items to return
|
43
|
+
# @return [Object,Array<Object>] item(s) from the end
|
44
|
+
def last(n = 1)
|
45
|
+
if n > 1
|
46
|
+
[n,count].min.downto(1).map{ |idx| at(-idx) }
|
47
|
+
else
|
48
|
+
at(-1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
# @!endgroup
|
52
|
+
|
53
|
+
# @!group Representation
|
54
|
+
# @return [String] instance as inspectable string
|
55
|
+
def inspect
|
56
|
+
"#<#{self.class.name}:0x#{'%x14' % __id__} @count=#{count}>"
|
57
|
+
end
|
58
|
+
# @!endgroup
|
59
|
+
end
|
60
|
+
end
|