Commit 3f02b163 authored by Martin Robinson's avatar Martin Robinson Committed by Commit Bot

Expose text-position text attribute to ATK

Orca would like to use this text attribute to detect when text is
expressed with a superscript or subscript. This matches the behavior of
Firefox's ATK support.

Bug: 1014198
Change-Id: I034437426252ca54774e0cef2aca8442eb72f3c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862439
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarJoanmarie Diggs <jdiggs@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707872}
parent 65d2d9db
......@@ -12,7 +12,7 @@
++++[text] name='over' offset=0 style=italic underline=single
++++[text] name=' ' offset=0
++++[text] name='dog' offset=0 weight=700 style=italic underline=single
++[section] selectable-text offset=0 offset=7 weight=700 offset=11 offset=12 style=italic offset=18 offset=19 underline=single offset=28 offset=29 offset=41 offset=42 offset=51 offset=52
++[section] selectable-text offset=0 offset=7 weight=700 offset=11 offset=12 style=italic offset=18 offset=19 underline=single offset=28 offset=29 offset=41 offset=42 text-position=sub offset=51 offset=52 text-position=super
++++[text] name='Normal' offset=0
++++[text] name=' ' offset=0
++++[text] name='bold' offset=0 weight=700
......@@ -23,8 +23,7 @@
++++[text] name=' ' offset=0
++++[text] name='line-through' offset=0
++++[text] name=' ' offset=0
++++[subscript] name='subscript' offset=0
++++[subscript] name='subscript' offset=0 text-position=sub
++++[text] name=' ' offset=0
++++[superscript] name='superscript' offset=0
<-- End-of-file -->
++++[superscript] name='superscript' offset=0 text-position=super
......@@ -12,6 +12,7 @@
@AURALINUX-ALLOW:underline=*
@AURALINUX-ALLOW:hypertext=*
@AURALINUX-ALLOW:offset=*
@AURALINUX-ALLOW:text-position=*
-->
<!DOCTYPE html>
<html>
......
......@@ -351,18 +351,25 @@ AtkObject* GetActiveDescendantOfCurrentFocused() {
return nullptr;
}
void PrependTextAttributeToSet(const AtkTextAttribute attribute,
void PrependTextAttributeToSet(const std::string& attribute,
const std::string& value,
AtkAttributeSet** attributes) {
DCHECK(attributes);
AtkAttribute* new_attribute =
static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
new_attribute->name = g_strdup(atk_text_attribute_get_name(attribute));
new_attribute->name = g_strdup(attribute.c_str());
new_attribute->value = g_strdup(value.c_str());
*attributes = g_slist_prepend(*attributes, new_attribute);
}
void PrependAtkTextAttributeToSet(const AtkTextAttribute attribute,
const std::string& value,
AtkAttributeSet** attributes) {
PrependTextAttributeToSet(atk_text_attribute_get_name(attribute), value,
attributes);
}
std::string ToAtkTextAttributeColor(const std::string color) {
// The platform-independent color string is in the form "rgb(r, g, b)",
// but ATK expects a string like "r, g, b". We convert the string here
......@@ -376,41 +383,44 @@ AtkAttributeSet* ToAtkAttributeSet(const TextAttributeList& attributes) {
AtkAttributeSet* copied_attributes = nullptr;
for (const auto& attribute : attributes) {
if (attribute.first == "background-color") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_BG_COLOR,
ToAtkTextAttributeColor(attribute.second),
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_BG_COLOR,
ToAtkTextAttributeColor(attribute.second),
&copied_attributes);
} else if (attribute.first == "color") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_FG_COLOR,
ToAtkTextAttributeColor(attribute.second),
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_FG_COLOR,
ToAtkTextAttributeColor(attribute.second),
&copied_attributes);
} else if (attribute.first == "font-family") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_FAMILY_NAME, attribute.second,
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_FAMILY_NAME, attribute.second,
&copied_attributes);
} else if (attribute.first == "font-size") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_SIZE, attribute.second,
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_SIZE, attribute.second,
&copied_attributes);
} else if (attribute.first == "font-weight" && attribute.second == "bold") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_WEIGHT, "700",
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_WEIGHT, "700",
&copied_attributes);
} else if (attribute.first == "font-style") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_STYLE, "italic",
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_STYLE, "italic",
&copied_attributes);
} else if (attribute.first == "text-line-through-style") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_STRIKETHROUGH, "true",
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_STRIKETHROUGH, "true",
&copied_attributes);
} else if (attribute.first == "text-underline-style") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_UNDERLINE, "single",
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_UNDERLINE, "single",
&copied_attributes);
} else if (attribute.first == "invalid") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_INVALID, attribute.second,
&copied_attributes);
PrependTextAttributeToSet(ATK_TEXT_ATTR_UNDERLINE, "error",
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_INVALID, attribute.second,
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_UNDERLINE, "error",
&copied_attributes);
} else if (attribute.first == "language") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_LANGUAGE, attribute.second,
&copied_attributes);
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_LANGUAGE, attribute.second,
&copied_attributes);
} else if (attribute.first == "writing-mode") {
PrependTextAttributeToSet(ATK_TEXT_ATTR_DIRECTION, attribute.second,
PrependAtkTextAttributeToSet(ATK_TEXT_ATTR_DIRECTION, attribute.second,
&copied_attributes);
} else if (attribute.first == "text-position") {
PrependTextAttributeToSet(attribute.first, attribute.second,
&copied_attributes);
}
}
......
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