Commit bfebb9cb authored by Martin Robinson's avatar Martin Robinson Committed by Commit Bot

Prevent stale ATK hyperlink indices

Instead of calculating ATK hyperlink indices and constantly having to
keep them up to date, always attempt to calculate them when queried via
the API. This prevents them from ever being stale.

Bug: 999631
Change-Id: I769c778baa513b52cc6a50d1b6d92b51594f4c09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789590Reviewed-by: default avatarJoanmarie Diggs <jdiggs@igalia.com>
Commit-Queue: Martin Robinson <mrobinson@igalia.com>
Cr-Commit-Position: refs/heads/master@{#695565}
parent ebd17763
......@@ -291,6 +291,19 @@ TEST_F(BrowserAccessibilityAuraLinuxTest, TestComplexHypertext) {
g_object_unref(root_atk_object);
text1.SetName(text1_name + text1_name);
AXEventNotificationDetails event_bundle;
event_bundle.updates.resize(1);
event_bundle.updates[0].nodes.push_back(text1);
event_bundle.updates[0].nodes.push_back(root);
ASSERT_TRUE(manager->OnAccessibilityEvents(event_bundle));
// The hypertext offsets should reflect the new length of the static text.
verify_atk_link_text(combo_box_value.c_str(), 0, 28);
verify_atk_link_text(check_box_name.c_str(), 1, 44);
verify_atk_link_text(button_text_name.c_str(), 2, 45);
verify_atk_link_text(link_text_name.c_str(), 3, 46);
manager.reset();
}
......
......@@ -12,8 +12,6 @@ namespace ui {
struct _AXPlatformAtkHyperlinkPrivate {
AXPlatformNodeAuraLinux* platform_node = nullptr;
base::Optional<int> end_index;
base::Optional<int> start_index;
};
static gpointer kAXPlatformAtkHyperlinkParentClass = nullptr;
......@@ -84,13 +82,17 @@ static gboolean AXPlatformAtkHyperlinkIsSelectedLink(
static int AXPlatformAtkHyperlinkGetStartIndex(AtkHyperlink* atk_hyperlink) {
g_return_val_if_fail(IS_AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink), 0);
AXPlatformAtkHyperlink* link = AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink);
return link->priv->start_index ? *link->priv->start_index : 0;
base::Optional<std::pair<int, int>> indices =
link->priv->platform_node->GetEmbeddedObjectIndices();
return indices.has_value() ? indices->first : 0;
}
static int AXPlatformAtkHyperlinkGetEndIndex(AtkHyperlink* atk_hyperlink) {
g_return_val_if_fail(IS_AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink), 0);
AXPlatformAtkHyperlink* link = AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink);
return link->priv->end_index ? *link->priv->end_index : 0;
base::Optional<std::pair<int, int>> indices =
link->priv->platform_node->GetEmbeddedObjectIndices();
return indices.has_value() ? indices->second : 0;
}
static void AXPlatformAtkHyperlinkClassInit(AtkHyperlinkClass* klass) {
......@@ -231,14 +233,6 @@ void ax_platform_atk_hyperlink_set_object(
atk_hyperlink->priv->platform_node = platform_node;
}
void ax_platform_atk_hyperlink_set_indices(
AXPlatformAtkHyperlink* atk_hyperlink,
int start_index,
int end_index) {
atk_hyperlink->priv->start_index = start_index;
atk_hyperlink->priv->end_index = end_index;
}
static void AXPlatformAtkHyperlinkInit(AXPlatformAtkHyperlink* self, gpointer) {
AXPlatformAtkHyperlinkPrivate* priv =
G_TYPE_INSTANCE_GET_PRIVATE(self, ax_platform_atk_hyperlink_get_type(),
......
......@@ -46,10 +46,6 @@ struct _AXPlatformAtkHyperlinkClass {
GType ax_platform_atk_hyperlink_get_type(void) G_GNUC_CONST;
void ax_platform_atk_hyperlink_set_object(AXPlatformAtkHyperlink* hyperlink,
AXPlatformNodeAuraLinux* obj);
void ax_platform_atk_hyperlink_set_indices(
AXPlatformAtkHyperlink* atk_hyperlink,
int start_index,
int end_index);
G_END_DECLS
......
......@@ -3448,6 +3448,14 @@ AXPlatformNodeAuraLinux::GetEmbeddedObjectIndicesForId(int id) {
UTF16ToUnicodeOffsetInText(offset->first + 1));
}
base::Optional<std::pair<int, int>>
AXPlatformNodeAuraLinux::GetEmbeddedObjectIndices() {
auto* parent = AtkObjectToAXPlatformNodeAuraLinux(GetParent());
if (!parent)
return base::nullopt;
return parent->GetEmbeddedObjectIndicesForId(GetUniqueId());
}
void AXPlatformNodeAuraLinux::UpdateHypertext() {
EnsureAtkObjectIsValid();
AXHypertext old_hypertext = hypertext_;
......@@ -3819,20 +3827,6 @@ AtkHyperlink* AXPlatformNodeAuraLinux::GetAtkHyperlink() {
ATK_HYPERLINK(g_object_new(AX_PLATFORM_ATK_HYPERLINK_TYPE, 0));
ax_platform_atk_hyperlink_set_object(
AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink_), this);
auto* parent = AtkObjectToAXPlatformNodeAuraLinux(GetParent());
if (!parent)
return atk_hyperlink_;
base::Optional<std::pair<int, int>> indices =
parent->GetEmbeddedObjectIndicesForId(GetUniqueId());
if (!indices.has_value())
return atk_hyperlink_;
ax_platform_atk_hyperlink_set_indices(
AX_PLATFORM_ATK_HYPERLINK(atk_hyperlink_), indices->first,
indices->second);
return atk_hyperlink_;
}
......
......@@ -221,6 +221,11 @@ class AX_EXPORT AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// return it, otherwise return base::nullopt;
base::Optional<FindInPageResultInfo> GetSelectionOffsetsFromFindInPage();
// Get the embedded object ("hyperlink") indices for this object in the
// parent. If this object doesn't have a parent or isn't embedded, return
// nullopt.
base::Optional<std::pair<int, int>> GetEmbeddedObjectIndices();
std::string accessible_name_;
protected:
......
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