Commit 619e1a82 authored by Alexander Surkov's avatar Alexander Surkov Committed by Commit Bot

ax_dump_tree: implement AXValue serialization

AXValue is used to serialize as a generic object which generates bulky output like <AXValue 0x7fcfd5d12ac0> {value = w:1324.000000 h:714.000000 type = kAXValueCGSizeType}.
It's nicer to have a shorten and readable format like {x: int, y: int}

Bug: 1124366
Change-Id: I7a19604baa8f860f1a6bbfe144ec4c0d4f4d923d
AX-Relnotes: n/a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418472
Commit-Queue: Alexander Surkov <asurkov@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809380}
parent f64b9b43
...@@ -104,6 +104,9 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase { ...@@ -104,6 +104,9 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase {
base::Value PopulateSize(const BrowserAccessibilityCocoa*) const; base::Value PopulateSize(const BrowserAccessibilityCocoa*) const;
base::Value PopulatePosition(const BrowserAccessibilityCocoa*) const; base::Value PopulatePosition(const BrowserAccessibilityCocoa*) const;
base::Value PopulatePoint(NSPoint) const;
base::Value PopulateSize(NSSize) const;
base::Value PopulateRect(NSRect) const;
base::Value PopulateRange(NSRange) const; base::Value PopulateRange(NSRange) const;
base::Value PopulateTextPosition( base::Value PopulateTextPosition(
BrowserAccessibilityPosition::AXPositionInstance::pointer, BrowserAccessibilityPosition::AXPositionInstance::pointer,
...@@ -388,6 +391,39 @@ base::Value AccessibilityTreeFormatterMac::PopulateObject( ...@@ -388,6 +391,39 @@ base::Value AccessibilityTreeFormatterMac::PopulateObject(
return PopulateTextMarkerRange(value, line_indexer); return PopulateTextMarkerRange(value, line_indexer);
} }
// AXValue
if (CFGetTypeID(value) == AXValueGetTypeID()) {
AXValueType type = AXValueGetType(static_cast<AXValueRef>(value));
switch (type) {
case kAXValueCGPointType: {
NSPoint point;
if (AXValueGetValue(static_cast<AXValueRef>(value), type, &point)) {
return PopulatePoint(point);
}
} break;
case kAXValueCGSizeType: {
NSSize size;
if (AXValueGetValue(static_cast<AXValueRef>(value), type, &size)) {
return PopulateSize(size);
}
} break;
case kAXValueCGRectType: {
NSRect rect;
if (AXValueGetValue(static_cast<AXValueRef>(value), type, &rect)) {
return PopulateRect(rect);
}
} break;
case kAXValueCFRangeType: {
NSRange range;
if (AXValueGetValue(static_cast<AXValueRef>(value), type, &range)) {
return PopulateRange(range);
}
} break;
default:
break;
}
}
// Accessible object // Accessible object
if (IsBrowserAccessibilityCocoa(value) || IsAXUIElement(value)) { if (IsBrowserAccessibilityCocoa(value) || IsAXUIElement(value)) {
return base::Value(NodeToLineIndex(value, line_indexer)); return base::Value(NodeToLineIndex(value, line_indexer));
...@@ -398,6 +434,32 @@ base::Value AccessibilityTreeFormatterMac::PopulateObject( ...@@ -398,6 +434,32 @@ base::Value AccessibilityTreeFormatterMac::PopulateObject(
SysNSStringToUTF16([NSString stringWithFormat:@"%@", value])); SysNSStringToUTF16([NSString stringWithFormat:@"%@", value]));
} }
base::Value AccessibilityTreeFormatterMac::PopulatePoint(
NSPoint point_value) const {
base::Value point(base::Value::Type::DICTIONARY);
point.SetIntPath("x", static_cast<int>(point_value.x));
point.SetIntPath("y", static_cast<int>(point_value.y));
return point;
}
base::Value AccessibilityTreeFormatterMac::PopulateSize(
NSSize size_value) const {
base::Value size(base::Value::Type::DICTIONARY);
size.SetIntPath("w", static_cast<int>(size_value.width));
size.SetIntPath("h", static_cast<int>(size_value.height));
return size;
}
base::Value AccessibilityTreeFormatterMac::PopulateRect(
NSRect rect_value) const {
base::Value rect(base::Value::Type::DICTIONARY);
rect.SetIntPath("x", static_cast<int>(rect_value.origin.x));
rect.SetIntPath("y", static_cast<int>(rect_value.origin.y));
rect.SetIntPath("w", static_cast<int>(rect_value.size.width));
rect.SetIntPath("h", static_cast<int>(rect_value.size.height));
return rect;
}
base::Value AccessibilityTreeFormatterMac::PopulateRange( base::Value AccessibilityTreeFormatterMac::PopulateRange(
NSRange node_range) const { NSRange node_range) const {
base::Value range(base::Value::Type::DICTIONARY); base::Value range(base::Value::Type::DICTIONARY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment