-
Notifications
You must be signed in to change notification settings - Fork 800
Feature: Accessibility Tree printing #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ce3dc97
5ccee16
72adcb4
add393f
46a7bed
756e61d
bea8bee
82da1b4
682e0e3
ef123fb
d7f263c
6e49f55
00190a9
36a78af
99b8640
a3bdbc0
ae8f52b
474241b
22f00df
5ae3069
dcf6078
595b2c2
3c98393
72ff99a
423f303
74b9a61
4a694f9
e6dc3ed
994fd57
90a01ad
beb9ae2
09fb3e5
f1f77d5
61f568f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,9 @@ | |
| # of patent rights can be found in the PATENTS file in the same directory. | ||
|
|
||
| import lldb | ||
|
|
||
| import re | ||
| import fblldbbase as fb | ||
| import fblldbobjecthelpers as objectHelpers | ||
|
|
||
| def flushCoreAnimationTransaction(): | ||
| lldb.debugger.HandleCommand('expr (void)[CATransaction flush]') | ||
|
|
@@ -84,6 +85,69 @@ def upwardsRecursiveDescription(view, maxDepth=0): | |
| builder = "" | ||
| for viewDescription in recursiveDescription: | ||
| builder += currentPrefix + viewDescription + "\n" | ||
| currentPrefix += " | " | ||
| currentPrefix += " | " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a mistaken edit, unless I'm missing something. |
||
|
|
||
| return builder | ||
|
|
||
| # GetObjectDescription will try to return the pointer. | ||
| # However on UIAccessibilityElements, the result will look like this: | ||
| # [UITableViewSectionElement]{0x79eb2280} section: 0 (isHeader: 1) | ||
| # [UITableViewCellAccessibilityElement - 0x79eac160] <..... | ||
| # So, just get the first hex address | ||
| def firstHexInDescription(object): | ||
| return re.findall(r'0x[0-9A-F]+', "{}".format(object), re.I)[0] | ||
|
|
||
| def evaluateIntegerExpression(expression): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a function by the same name in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure why int(s,16) was used in the other version. Are we sure it's not broken for values > 10? I think it's broken but went un-detected, since having more than 10 VC's is rare, where over 10 subviews is common.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I put in a fix for evaluating integers that prompted my method, and removed my method. I believe it should be working properly now. |
||
| output = fb.evaluateExpression('(int)(' + expression + ')', True).replace('\'', '') | ||
| return int (output, 10) | ||
|
|
||
| def accessibilityDescription(object): | ||
| if isAccessibilityElement(object): | ||
| return objectHelpers.displayObjectWithKeys(object, ["accessibilityLabel", "accessibilityValue", "accessibilityHint"]) | ||
| else: | ||
| return objectHelpers.displayObjectWithString(object, "isAccessibilityElement=NO") | ||
|
|
||
| def accessibilityElementCount(object): | ||
| cmd = "(int)[%s accessibilityElementCount]" % (object) | ||
| return evaluateIntegerExpression(cmd) | ||
|
|
||
| def isAccessibilityElement(object): | ||
| return fb.evaluateBooleanExpression('[(id)%s isAccessibilityElement]' % object) | ||
|
|
||
| def accessibilityElementAtIndex(object, index): | ||
| cmd = '(id)[%s accessibilityElementAtIndex:%s]' % (object, index) | ||
| obj = firstHexInDescription(fb.evaluateExpressionValue(cmd)) | ||
| return obj | ||
|
|
||
| def accessibilityChildren(object): | ||
| accessibilityCount = accessibilityElementCount(object) | ||
| aeChildren = [] | ||
| if accessibilityCount != 0x7fffffff: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0x7fffffff is NSNotFound (on 32 bit systems, whoops). This indicates that the view is not an accessibility container. If it returns 0, the traversal stops, if it returns 0x7fffffff, the subviews tree is traversed. I'm struggling with my python here, I imagine there's a cleaner way to represent it. |
||
| for i in range(0, accessibilityCount): | ||
| aeChildren.append(accessibilityElementAtIndex(object, i)) | ||
| return aeChildren | ||
|
|
||
| def subviews(view): | ||
| subviewResult = [] | ||
| responds = fb.evaluateBooleanExpression('[(id)%s respondsToSelector:(SEL)@selector(subviews)]' % view) | ||
| if responds: | ||
| subviews = fb.evaluateExpression('(id)[%s subviews]' % view) | ||
| subviewsCount = evaluateIntegerExpression('[(id)%s count]' % subviews) | ||
| if subviewsCount > 0: | ||
| for i in range(0, subviewsCount): | ||
| subview = fb.evaluateExpression('(id)[%s objectAtIndex:%i]' % (subviews, i)) | ||
| subviewResult.append(subview) | ||
| return subviewResult | ||
|
|
||
|
|
||
| def accessibilityRecursiveDescription(object, prefix="", childType=""): | ||
| print '%s%s%s' % (prefix, childType, accessibilityDescription(object)) | ||
| nextPrefix = prefix + ' |' | ||
| aeChildren = accessibilityChildren(object) | ||
| for ae in aeChildren: | ||
| accessibilityRecursiveDescription(ae, nextPrefix, 'A ') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Four space indent here. |
||
|
|
||
| if len(aeChildren) == 0: | ||
| for subview in subviews(object): | ||
| accessibilityRecursiveDescription(subview, nextPrefix, 'S ') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a triple-space between the sentences, not sure if intended. One is the norm in Chisel.