Class: Accessibility::Console::Tree
- Defined in:
- lib/project/motion-accessibility-console/tree.rb
Instance Attribute Summary collapse
-
#subviews ⇒ Object
Returns the value of attribute subviews.
-
#superview ⇒ Object
Returns the value of attribute superview.
-
#view ⇒ Object
Returns the value of attribute view.
Class Method Summary collapse
- .accessible_view?(view) ⇒ Boolean
- .build(view = nil, superview = nil) ⇒ Object
- .ignore_view?(view) ⇒ Boolean
Instance Method Summary collapse
- #==(other) ⇒ Object
- #browsable_nodes ⇒ Object
- #copy ⇒ Object
- #display_view(index = nil) ⇒ Object
- #find(request) ⇒ Object
-
#initialize(options = {}) ⇒ Tree
constructor
A new instance of Tree.
- #inspect ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Tree
Returns a new instance of Tree.
7 8 9 10 11 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 7 def initialize(={}) @view=[:view] @subviews=[:subviews]||[] @superview=[:superview] end |
Instance Attribute Details
#subviews ⇒ Object
Returns the value of attribute subviews.
5 6 7 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 5 def subviews @subviews end |
#superview ⇒ Object
Returns the value of attribute superview.
5 6 7 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 5 def superview @superview end |
#view ⇒ Object
Returns the value of attribute view.
5 6 7 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 5 def view @view end |
Class Method Details
.accessible_view?(view) ⇒ Boolean
82 83 84 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 82 def self.accessible_view?(view) return view.accessibility_element?||view.accessibility_label||view.accessibility_value||view.accessibility_traits end |
.build(view = nil, superview = nil) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 101 def self.build(view=nil, superview=nil) tree=self.new view=UIApplication.sharedApplication.keyWindow if view.nil? subviews=[] view.subviews.each do |subview| subview_tree=self.build(subview, tree) if self.ignore_view?(subview) subview_tree.subviews.each {|v| v.superview=tree} subviews=subviews+subview_tree.subviews else subviews<<subview_tree end end tree.view=view tree.subviews=subviews tree.superview=superview tree end |
.ignore_view?(view) ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 86 def self.ignore_view?(view) return true if view.subviews.empty?&&!self.accessible_view?(view) if view.superview sv=view.superview while sv&&self.ignore_view?(sv) sv=sv.superview end return true if A11y::Console.touchable_type(sv) return true if view.class==UIImageView&&A11y::Ignored_ImageViews.member?(sv.class.to_s) end class_name=view.class.to_s return true if class_name=~/^_/ A11y::Ignored_Views.member?(class_name) end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 21 def ==(other) return false if other.nil? return false if self.superview&&other.superview&&self.superview.view!=other.superview.view return false unless self.view==other.view return false unless self.subviews.size==other.subviews.size self.subviews.each_index {|index| return false unless self.subviews[index]==other.subviews[index]} return true end |
#browsable_nodes ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 30 def browsable_nodes nodes=[@superview] if @subviews if A11y::Reverse_Views.member?(@view.class.to_s) nodes+=@subviews.reverse else nodes+=@subviews end end nodes end |
#copy ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 13 def copy other=A11y::Console::Tree.new other.superview=self.superview if superview other.view=self.view if view self.subviews.each {|subview| other.subviews<<subview.clone} other end |
#display_view(index = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 51 def display_view(index=nil) display=Array.new control=@view.class.to_s control=nil if A11y::View_Names[control] control="Superview #{control}" if index==0 if @view.class==UITableViewCell label=@view.subviews.first while label&&!label.kind_of?(UILabel) label=label.subviews.first end raise "Could not find the UITableViewCell's label" unless label.kind_of?(UILabel) name=label.text elsif @view.class==UITextField name=@view.text else name=A11y::View_Names[@view.class.to_s]||@view.accessibility_value||@view.accessibility_label if @view.accessibility_element?||view.superclass==UIControl end display<<index.to_s display<<"Touchable" if A11y::Console.touchable_type(@view) display<<control if control display<<name if name if index if index>0 and not(@subviews.empty?) indicator="with #{@subviews.length} subview" indicator+="s" if @subviews.length>1 end display<<indicator end display.join(" ") end |
#find(request) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 120 def find(request) found=nil if request.kind_of?(Fixnum) raise "Invalid number" unless request>=0&&request<browsable_nodes.length found=browsable_nodes[request] elsif request.kind_of?(String) results=[] browsable_nodes.each do |node| next if node.nil? next unless node.view.accessibility_label pattern=Regexp.new(request,true) compare=node.view.accessibility_label=~pattern next if compare.nil? if node.view.accessibility_label.downcase==request.downcase return node else results<<node end end raise "\"#{request}\" could refer to more than one view." if results.length>1 found=results.first else raise "Unknown request: #{request}: #{request.class}" unless request.respond_to?(:superview) found=request end found end |
#inspect ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/project/motion-accessibility-console/tree.rb', line 42 def inspect nodes=@subviews.collect {|tree| tree.inspect} return @view.class.to_s if @subviews.empty? result="[#{@view.class}" result+=" #{nodes.join(" ")}" unless nodes.empty? result+="]" result end |