Announce text attributes in VoiceOver.
It is essential for users of VoiceOver on the Mac platform to have
access to stylistic information for all the text on a web page. This
change exposes font size, foreground color, background color, bold,
italic, underline, and strikethrough text attributes to AT users. "When
text attributes change:" needs to be set to "Speak Attributes" in
VoiceOver Utility to observe this change.
A later change will expose the remaining text attributes.
bold, italic, underline and strikethrough in VoiceOver.
Bug: 958811
Change-Id: I4f291fdd27466a71d2e65dff8add64475bd820f8
AX-Relnotes: Announce font size, foreground color, background color,
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4313423
Reviewed-by: David Tseng <[email protected]>
Commit-Queue: Sara Tang <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1119570}
diff --git a/content/browser/accessibility/dump_accessibility_scripts_browsertest.cc b/content/browser/accessibility/dump_accessibility_scripts_browsertest.cc
index 95e004a..97bedcfa 100644
--- a/content/browser/accessibility/dump_accessibility_scripts_browsertest.cc
+++ b/content/browser/accessibility/dump_accessibility_scripts_browsertest.cc
@@ -456,6 +456,23 @@
RunTypedTest<kMacAttributedString>("suggestion.html");
}
+IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest, AttributedStringBold) {
+ RunTypedTest<kMacAttributedString>("bold.html");
+}
+
+IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest, AttributedStringItalic) {
+ RunTypedTest<kMacAttributedString>("italic.html");
+}
+
+IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest,
+ AttributedStringStrikethrough) {
+ RunTypedTest<kMacAttributedString>("strikethrough.html");
+}
+
+IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest, AttributedStringUnderline) {
+ RunTypedTest<kMacAttributedString>("underline.html");
+}
+
IN_PROC_BROWSER_TEST_P(DumpAccessibilityScriptTest, ChromeAXNodeId) {
RunTypedTest<kMacAttributes>("chrome-ax-node-id.html");
}
diff --git a/content/test/data/accessibility/mac/attributed-string/bold-expected.txt b/content/test/data/accessibility/mac/attributed-string/bold-expected.txt
new file mode 100644
index 0000000..89226d68
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/bold-expected.txt
@@ -0,0 +1,2 @@
+tr_bold={anchor: {:2, 0, down}, focus: {:2, 17, down}}
+bold.AXAttributedStringForTextMarkerRange(tr_bold)={This text is : {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}, bold: {AXFont: {AXFontBold: 1, AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/bold.html b/content/test/data/accessibility/mac/attributed-string/bold.html
new file mode 100644
index 0000000..c91323e5
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/bold.html
@@ -0,0 +1,7 @@
+<!--
+@SCRIPT:
+ tr_bold:= bold.AXTextMarkerRangeForUIElement(bold)
+ bold.AXAttributedStringForTextMarkerRange(tr_bold)
+-->
+<!DOCTYPE html>
+<div id="bold">This text is <b>bold</b></div>
diff --git a/content/test/data/accessibility/mac/attributed-string/deletion-expected.txt b/content/test/data/accessibility/mac/attributed-string/deletion-expected.txt
index 1cb677e..e90763c 100644
--- a/content/test/data/accessibility/mac/attributed-string/deletion-expected.txt
+++ b/content/test/data/accessibility/mac/attributed-string/deletion-expected.txt
@@ -1,4 +1,2 @@
tr_deletion={anchor: {:2, 0, down}, focus: {:2, 12, down}}
-deletion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_deletion)='Deleted Text{
- AXIsSuggestedDeletion = 1;
-}'
+deletion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_deletion)={Deleted Text: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestedDeletion: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/insertion-expected.txt b/content/test/data/accessibility/mac/attributed-string/insertion-expected.txt
index d3e29ad..5d94f0a 100644
--- a/content/test/data/accessibility/mac/attributed-string/insertion-expected.txt
+++ b/content/test/data/accessibility/mac/attributed-string/insertion-expected.txt
@@ -1,4 +1,2 @@
tr_insertion={anchor: {:2, 0, down}, focus: {:2, 13, down}}
-insertion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_insertion)='Inserted Text{
- AXIsSuggestedInsertion = 1;
-}'
+insertion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_insertion)={Inserted Text: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestedInsertion: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/italic-expected.txt b/content/test/data/accessibility/mac/attributed-string/italic-expected.txt
new file mode 100644
index 0000000..136a521
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/italic-expected.txt
@@ -0,0 +1,2 @@
+tr_italic={anchor: {:2, 0, down}, focus: {:2, 19, down}}
+italic.AXAttributedStringForTextMarkerRange(tr_italic)={This text is : {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}, italic: {AXFont: {AXFontItalic: 1, AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/italic.html b/content/test/data/accessibility/mac/attributed-string/italic.html
new file mode 100644
index 0000000..52a7a90
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/italic.html
@@ -0,0 +1,7 @@
+<!--
+@SCRIPT:
+ tr_italic:= italic.AXTextMarkerRangeForUIElement(italic)
+ italic.AXAttributedStringForTextMarkerRange(tr_italic)
+-->
+<!DOCTYPE html>
+<div id="italic">This text is <i>italic</i></div>
diff --git a/content/test/data/accessibility/mac/attributed-string/mark-expected.txt b/content/test/data/accessibility/mac/attributed-string/mark-expected.txt
index 10c3500..cec2f7a 100644
--- a/content/test/data/accessibility/mac/attributed-string/mark-expected.txt
+++ b/content/test/data/accessibility/mac/attributed-string/mark-expected.txt
@@ -1,4 +1,2 @@
tr_mark={anchor: {:2, 0, down}, focus: {:2, 9, down}}
-mark.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_mark)='Mark Text{
- AXHighlight = 1;
-}'
+mark.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_mark)={Mark Text: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXHighlight: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/nested-suggestion-insertion-deletion-expected.txt b/content/test/data/accessibility/mac/attributed-string/nested-suggestion-insertion-deletion-expected.txt
index 7231a9d..4f0f544 100644
--- a/content/test/data/accessibility/mac/attributed-string/nested-suggestion-insertion-deletion-expected.txt
+++ b/content/test/data/accessibility/mac/attributed-string/nested-suggestion-insertion-deletion-expected.txt
@@ -1,8 +1,2 @@
tr_suggestion={anchor: {:2, 0, down}, focus: {:2, 37, down}}
-suggestion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_suggestion)='Suggested Insertion{
- AXIsSuggestedInsertion = 1;
- AXIsSuggestion = 1;
-}Suggested Deletion{
- AXIsSuggestedDeletion = 1;
- AXIsSuggestion = 1;
-}'
+suggestion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_suggestion)={Suggested Deletion: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestedDeletion: 1, AXIsSuggestion: 1}, Suggested Insertion: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestedInsertion: 1, AXIsSuggestion: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/strikethrough-expected.txt b/content/test/data/accessibility/mac/attributed-string/strikethrough-expected.txt
new file mode 100644
index 0000000..c2a59f2
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/strikethrough-expected.txt
@@ -0,0 +1,2 @@
+tr_strikethrough={anchor: {:2, 0, down}, focus: {:2, 26, down}}
+strikethrough.AXAttributedStringForTextMarkerRange(tr_strikethrough)={This text is : {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}, strikethrough: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestedDeletion: 1, AXStrikethrough: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/strikethrough.html b/content/test/data/accessibility/mac/attributed-string/strikethrough.html
new file mode 100644
index 0000000..b948140
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/strikethrough.html
@@ -0,0 +1,7 @@
+<!--
+@SCRIPT:
+ tr_strikethrough:= strikethrough.AXTextMarkerRangeForUIElement(strikethrough)
+ strikethrough.AXAttributedStringForTextMarkerRange(tr_strikethrough)
+-->
+<!DOCTYPE html>
+<div id="strikethrough">This text is <s>strikethrough</s></div>
diff --git a/content/test/data/accessibility/mac/attributed-string/suggestion-expected.txt b/content/test/data/accessibility/mac/attributed-string/suggestion-expected.txt
index 3dd5081..da4db6e 100644
--- a/content/test/data/accessibility/mac/attributed-string/suggestion-expected.txt
+++ b/content/test/data/accessibility/mac/attributed-string/suggestion-expected.txt
@@ -1,4 +1,2 @@
tr_suggestion={anchor: {:2, 0, down}, focus: {:2, 15, down}}
-suggestion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_suggestion)='Suggestion Text{
- AXIsSuggestion = 1;
-}'
+suggestion.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, tr_suggestion)={Suggestion Text: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXIsSuggestion: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/underline-expected.txt b/content/test/data/accessibility/mac/attributed-string/underline-expected.txt
new file mode 100644
index 0000000..c8aad5e1
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/underline-expected.txt
@@ -0,0 +1,2 @@
+tr_underline={anchor: {:2, 0, down}, focus: {:2, 22, down}}
+underline.AXAttributedStringForTextMarkerRange(tr_underline)={This text is : {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}, underline: {AXFont: {AXFontSize: 16}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)', AXUnderline: 1}}
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/attributed-string/underline.html b/content/test/data/accessibility/mac/attributed-string/underline.html
new file mode 100644
index 0000000..d50ed5b48
--- /dev/null
+++ b/content/test/data/accessibility/mac/attributed-string/underline.html
@@ -0,0 +1,7 @@
+<!--
+@SCRIPT:
+ tr_underline:= underline.AXTextMarkerRangeForUIElement(underline)
+ underline.AXAttributedStringForTextMarkerRange(tr_underline)
+-->
+<!DOCTYPE html>
+<div id="underline">This text is <u>underline</u></div>
diff --git a/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-range-expected.txt b/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-range-expected.txt
index 4b51107..8e51bad 100644
--- a/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-range-expected.txt
+++ b/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-range-expected.txt
@@ -1,5 +1,4 @@
input.accessibilityParameterizedAttributeNames.has(AXAttributedStringForRange)='yes'
-input.accessibilityAttributeValue(AXAttributedStringForRange, {loc: 0, len: 8})='mispeled{
-}'
+input.accessibilityAttributeValue(AXAttributedStringForRange, {loc: 0, len: 8})={mispeled: {AXFont: {AXFontSize: 13}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}}
not_applicable.accessibilityParameterizedAttributeNames.has(AXAttributedStringForRange)='no'
-not_applicable.accessibilityAttributeValue(AXAttributedStringForRange, {loc: 0, len: 8})=NULL
+not_applicable.accessibilityAttributeValue(AXAttributedStringForRange, {loc: 0, len: 8})=NULL
\ No newline at end of file
diff --git a/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-text-marker-range-expected.txt b/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-text-marker-range-expected.txt
index 65f0029e..ad29645 100644
--- a/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-text-marker-range-expected.txt
+++ b/content/test/data/accessibility/mac/parameterized-attributes/ax-attributed-string-for-text-marker-range-expected.txt
@@ -1,4 +1,3 @@
input.accessibilityParameterizedAttributeNames.has(AXAttributedStringForTextMarkerRange)='yes'
text_range={anchor: {:3, 0, down}, focus: {:3, 8, down}}
-input.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, text_range)='mispeled{
-}'
+input.accessibilityAttributeValue(AXAttributedStringForTextMarkerRange, text_range)={mispeled: {AXFont: {AXFontSize: 13}, AXForegroundColor: 'CGColor(0.00, 0.00, 0.00, 1.00)'}}
\ No newline at end of file
diff --git a/ui/accessibility/ax_position.h b/ui/accessibility/ax_position.h
index 998e63d..af0a50ab7 100644
--- a/ui/accessibility/ax_position.h
+++ b/ui/accessibility/ax_position.h
@@ -4407,6 +4407,22 @@
return GetAnchor()->GetRole();
}
+ AXTextAttributes GetTextAttributes() const {
+ // Check either the current anchor or its parent for text attributes.
+ AXTextAttributes current_anchor_text_attributes =
+ !IsNullPosition() ? GetAnchor()->GetTextAttributes()
+ : AXTextAttributes();
+ if (current_anchor_text_attributes.IsUnset()) {
+ AXPositionInstance parent_position =
+ AsTreePosition()->CreateParentPosition(
+ ax::mojom::MoveDirection::kBackward);
+ if (!parent_position->IsNullPosition()) {
+ return parent_position->GetAnchor()->GetTextAttributes();
+ }
+ }
+ return current_anchor_text_attributes;
+ }
+
protected:
AXPosition()
: kind_(AXPositionKind::NULL_POSITION),
@@ -4683,21 +4699,6 @@
ax::mojom::Role GetRole(AXNode* node) const { return node->GetRole(); }
- AXTextAttributes GetTextAttributes() const {
- // Check either the current anchor or its parent for text attributes.
- AXTextAttributes current_anchor_text_attributes =
- !IsNullPosition() ? GetAnchor()->GetTextAttributes()
- : AXTextAttributes();
- if (current_anchor_text_attributes.IsUnset()) {
- AXPositionInstance parent_position =
- AsTreePosition()->CreateParentPosition(
- ax::mojom::MoveDirection::kBackward);
- if (!parent_position->IsNullPosition())
- return parent_position->GetAnchor()->GetTextAttributes();
- }
- return current_anchor_text_attributes;
- }
-
const std::vector<int32_t>& GetWordStartOffsets() const {
if (IsNullPosition()) {
static const base::NoDestructor<std::vector<int32_t>> empty_word_starts;
diff --git a/ui/accessibility/ax_text_attributes.cc b/ui/accessibility/ax_text_attributes.cc
index ce95eeca..545a978 100644
--- a/ui/accessibility/ax_text_attributes.cc
+++ b/ui/accessibility/ax_text_attributes.cc
@@ -75,4 +75,11 @@
marker_types.size() == 0 && highlight_types.size() == 0;
}
+bool AXTextAttributes::HasTextStyle(
+ ax::mojom::TextStyle text_style_enum) const {
+ return text_style != kUnsetValue &&
+ (static_cast<uint32_t>(text_style) &
+ (1U << static_cast<uint32_t>(text_style_enum))) != 0;
+}
+
} // namespace ui
diff --git a/ui/accessibility/ax_text_attributes.h b/ui/accessibility/ax_text_attributes.h
index c298023..4c05e5a1e 100644
--- a/ui/accessibility/ax_text_attributes.h
+++ b/ui/accessibility/ax_text_attributes.h
@@ -9,6 +9,7 @@
#include <vector>
#include "ui/accessibility/ax_base_export.h"
+#include "ui/accessibility/ax_enums.mojom-shared.h"
namespace ui {
@@ -36,6 +37,8 @@
bool IsUnset() const;
+ bool HasTextStyle(const ax::mojom::TextStyle text_style_enum) const;
+
int32_t background_color = kUnsetValue;
int32_t color = kUnsetValue;
int32_t invalid_state = kUnsetValue;
diff --git a/ui/accessibility/platform/DEPS b/ui/accessibility/platform/DEPS
index 301ade0..eb35f397 100644
--- a/ui/accessibility/platform/DEPS
+++ b/ui/accessibility/platform/DEPS
@@ -2,6 +2,9 @@
"atk_util_auralinux_x11\.cc": [
"+ui/events/x",
],
+ "ax_platform_node_cocoa\.mm": [
+ "+skia/ext",
+ ],
"ax_platform_node_win\.cc": [
"+skia/ext",
]
diff --git a/ui/accessibility/platform/ax_platform_node_cocoa.mm b/ui/accessibility/platform/ax_platform_node_cocoa.mm
index 4d43b44..bfe3733 100644
--- a/ui/accessibility/platform/ax_platform_node_cocoa.mm
+++ b/ui/accessibility/platform/ax_platform_node_cocoa.mm
@@ -12,6 +12,7 @@
#include "base/no_destructor.h"
#include "base/strings/sys_string_conversions.h"
#include "base/trace_event/trace_event.h"
+#include "skia/ext/skia_utils_mac.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_range.h"
@@ -807,6 +808,89 @@
range:leafRange];
}
+ ui::AXTextAttributes text_attrs =
+ leafTextRange.anchor()->GetTextAttributes();
+
+ NSMutableDictionary* fontAttributes = [NSMutableDictionary dictionary];
+
+ // TODO(crbug.com/958811): Implement NSAccessibilityFontFamilyKey.
+ // TODO(crbug.com/958811): Implement NSAccessibilityFontNameKey.
+ // TODO(crbug.com/958811): Implement NSAccessibilityVisibleNameKey.
+
+ if (text_attrs.font_size != ui::AXTextAttributes::kUnsetValue) {
+ [fontAttributes setValue:@(text_attrs.font_size)
+ forKey:NSAccessibilityFontSizeKey];
+ }
+
+ if (text_attrs.HasTextStyle(ax::mojom::TextStyle::kBold)) {
+ [fontAttributes setValue:@YES forKey:@"AXFontBold"];
+ }
+
+ if (text_attrs.HasTextStyle(ax::mojom::TextStyle::kItalic)) {
+ [fontAttributes setValue:@YES forKey:@"AXFontItalic"];
+ }
+
+ [attributedString addAttribute:NSAccessibilityFontTextAttribute
+ value:fontAttributes
+ range:leafRange];
+
+ if (text_attrs.color != ui::AXTextAttributes::kUnsetValue) {
+ [attributedString addAttribute:NSAccessibilityForegroundColorTextAttribute
+ value:(__bridge id)skia::SkColorToSRGBNSColor(
+ SkColor(text_attrs.color))
+ .CGColor
+ range:leafRange];
+ } else {
+ [attributedString
+ removeAttribute:NSAccessibilityForegroundColorTextAttribute
+ range:leafRange];
+ }
+
+ if (text_attrs.background_color != ui::AXTextAttributes::kUnsetValue) {
+ [attributedString addAttribute:NSAccessibilityBackgroundColorTextAttribute
+ value:(__bridge id)skia::SkColorToSRGBNSColor(
+ SkColor(text_attrs.background_color))
+ .CGColor
+ range:leafRange];
+ } else {
+ [attributedString
+ removeAttribute:NSAccessibilityBackgroundColorTextAttribute
+ range:leafRange];
+ }
+
+ // TODO(crbug.com/958811): Implement
+ // NSAccessibilitySuperscriptTextAttribute.
+ // TODO(crbug.com/958811): Implement NSAccessibilityShadowTextAttribute.
+
+ if (text_attrs.underline_style != ui::AXTextAttributes::kUnsetValue) {
+ [attributedString addAttribute:NSAccessibilityUnderlineTextAttribute
+ value:@YES
+ range:leafRange];
+ } else {
+ [attributedString removeAttribute:NSAccessibilityUnderlineTextAttribute
+ range:leafRange];
+ }
+
+ // TODO(crbug.com/958811): Implement
+ // NSAccessibilityUnderlineColorTextAttribute.
+
+ if (text_attrs.strikethrough_style != ui::AXTextAttributes::kUnsetValue) {
+ [attributedString addAttribute:NSAccessibilityStrikethroughTextAttribute
+ value:@YES
+ range:leafRange];
+ } else {
+ [attributedString
+ removeAttribute:NSAccessibilityStrikethroughTextAttribute
+ range:leafRange];
+ }
+
+ // TODO(crbug.com/958811): Implement
+ // NSAccessibilityStrikethroughColorTextAttribute.
+
+ // TODO(crbug.com/958811): Implement NSAccessibilityLinkTextAttribute.
+ // TODO(crbug.com/958811): Implement
+ // NSAccessibilityAutocorrectedTextAttribute.
+
anchorStartOffset += leafTextLength;
}
[attributedString endEditing];
diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.h b/ui/accessibility/platform/inspect/ax_transform_mac.h
index c7b961a..ff9b3d93 100644
--- a/ui/accessibility/platform/inspect/ax_transform_mac.h
+++ b/ui/accessibility/platform/inspect/ax_transform_mac.h
@@ -37,6 +37,16 @@
// Returns the base::Value representation of the given AXTextMarkerRange.
base::Value AXTextMarkerRangeToBaseValue(id, const AXTreeIndexerMac*);
+// Returns the base::Value::Dict representation of the given NSAttributedString.
+COMPONENT_EXPORT(AX_PLATFORM)
+base::Value NSAttributedStringToBaseValue(NSAttributedString*,
+ const AXTreeIndexerMac*);
+
+// Returns the base::Value representation of CGColorRef in the form CGColor(r,
+// g, b, a).
+COMPONENT_EXPORT(AX_PLATFORM)
+base::Value CGColorRefToBaseValue(CGColorRef color);
+
// Returns the base::Value representation of nil.
COMPONENT_EXPORT(AX_PLATFORM) base::Value AXNilToBaseValue();
diff --git a/ui/accessibility/platform/inspect/ax_transform_mac.mm b/ui/accessibility/platform/inspect/ax_transform_mac.mm
index 2b4c110a..7bcf2ea 100644
--- a/ui/accessibility/platform/inspect/ax_transform_mac.mm
+++ b/ui/accessibility/platform/inspect/ax_transform_mac.mm
@@ -62,6 +62,16 @@
}
}
+ // NSAttributedString
+ if ([value isKindOfClass:[NSAttributedString class]]) {
+ return NSAttributedStringToBaseValue((NSAttributedString*)value, indexer);
+ }
+
+ // CGColorRef
+ if (CFGetTypeID(value) == CGColorGetTypeID()) {
+ return base::Value(CGColorRefToBaseValue(static_cast<CGColorRef>(value)));
+ }
+
// AXValue
if (CFGetTypeID(value) == AXValueGetTypeID()) {
AXValueType type = AXValueGetType(static_cast<AXValueRef>(value));
@@ -181,6 +191,40 @@
return base::Value(std::move(value));
}
+base::Value NSAttributedStringToBaseValue(NSAttributedString* attr_string,
+ const AXTreeIndexerMac* indexer) {
+ __block base::Value::Dict result;
+
+ [attr_string
+ enumerateAttributesInRange:NSMakeRange(0, [attr_string length])
+ options:
+ NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
+ usingBlock:^(NSDictionary* attrs, NSRange nsRange,
+ BOOL* stop) {
+ __block base::Value::Dict base_attrs;
+ [attrs enumerateKeysAndObjectsUsingBlock:^(
+ NSString* key, id attr, BOOL* dict_stop) {
+ base_attrs.Set(
+ std::string(base::SysNSStringToUTF8(key)),
+ AXNSObjectToBaseValue(attr, indexer));
+ }];
+
+ result.Set(std::string(base::SysNSStringToUTF8(
+ [[attr_string string]
+ substringWithRange:nsRange])),
+ std::move(base_attrs));
+ }];
+ return base::Value(std::move(result));
+}
+
+base::Value CGColorRefToBaseValue(CGColorRef color) {
+ const CGFloat* color_components = CGColorGetComponents(color);
+ return base::Value(base::SysNSStringToUTF16(
+ [NSString stringWithFormat:@"CGColor(%1.2f, %1.2f, %1.2f, %1.2f)",
+ color_components[0], color_components[1],
+ color_components[2], color_components[3]]));
+}
+
base::Value AXNilToBaseValue() {
return base::Value(kNilValue);
}