Commit a8f6993b authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Simplify last known ignored code

- Remove 2 member variables and 2 methods from AXObject, which were used
so that AXObject could calculate whether ignored changed.
- Remove repetitive code from AXObjectCacheImpl, whenever an
AXObject is created.

Bug: None
Change-Id: Iad38383819dd1d165169fd302a717f3e2bacb2b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383813
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803250}
parent 7a87fccd
......@@ -75,11 +75,7 @@ void AXMenuList::AddChildren() {
AXObjectCacheImpl& cache = AXObjectCache();
AXObject* popup = cache.GetOrCreate(ax::mojom::Role::kMenuListPopup);
if (!popup)
return;
To<AXMockObject>(popup)->SetParent(this);
AXObject* popup = cache.Create(ax::mojom::blink::Role::kMenuListPopup, this);
if (!popup->AccessibilityIsIncludedInTree()) {
cache.Remove(popup->AXObjectID());
return;
......
......@@ -520,8 +520,6 @@ AXObject::AXObject(AXObjectCacheImpl& ax_object_cache)
have_children_(false),
role_(ax::mojom::blink::Role::kUnknown),
aria_role_(ax::mojom::blink::Role::kUnknown),
last_known_is_ignored_value_(kDefaultBehavior),
last_known_is_ignored_but_included_in_tree_value_(kDefaultBehavior),
explicit_container_id_(0),
parent_(nullptr),
last_modification_count_(-1),
......@@ -546,6 +544,7 @@ AXObject::~AXObject() {
void AXObject::Init() {
role_ = DetermineAccessibilityRole();
UpdateCachedAttributeValuesIfNeeded();
}
void AXObject::Detach() {
......@@ -1231,9 +1230,22 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const {
cached_is_descendant_of_disabled_node_ = !!DisabledAncestor();
cached_has_inherited_presentational_role_ =
!!InheritsPresentationalRoleFrom();
cached_is_ignored_ = ComputeAccessibilityIsIgnored();
cached_is_ignored_but_included_in_tree_ =
cached_is_ignored_ && ComputeAccessibilityIsIgnoredButIncludedInTree();
bool is_ignored = ComputeAccessibilityIsIgnored();
bool is_ignored_but_included_in_tree =
is_ignored && ComputeAccessibilityIsIgnoredButIncludedInTree();
bool ignored_states_changed = false;
if (parent_) {
// Do not compute ignored changed if no parent, because this is the first
// time the object is being initialized, and because there are no
// ancestors to call ChildrenChanged() on anyway.
if (is_ignored != cached_is_ignored_ ||
is_ignored_but_included_in_tree !=
cached_is_ignored_but_included_in_tree_) {
ignored_states_changed = true;
}
}
cached_is_ignored_ = is_ignored;
cached_is_ignored_but_included_in_tree_ = is_ignored_but_included_in_tree;
cached_is_editable_root_ = ComputeIsEditableRoot();
// Compute live region root, which can be from any ARIA live value, including
// "off", or from an automatic ARIA live value, e.g. from role="status".
......@@ -1247,21 +1259,6 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const {
cached_aria_column_index_ = ComputeAriaColumnIndex();
cached_aria_row_index_ = ComputeAriaRowIndex();
bool ignored_states_changed = false;
if (cached_is_ignored_ != LastKnownIsIgnoredValue()) {
last_known_is_ignored_value_ =
cached_is_ignored_ ? kIgnoreObject : kIncludeObject;
ignored_states_changed = true;
}
if (cached_is_ignored_but_included_in_tree_ !=
LastKnownIsIgnoredButIncludedInTreeValue()) {
last_known_is_ignored_but_included_in_tree_value_ =
cached_is_ignored_but_included_in_tree_ ? kIncludeObject
: kIgnoreObject;
ignored_states_changed = true;
}
if (ignored_states_changed) {
if (AXObject* parent = ParentObjectIfExists())
parent->ChildrenChanged();
......@@ -1620,32 +1617,11 @@ const AXObject* AXObject::DatetimeAncestor(int max_levels_to_check) const {
}
bool AXObject::LastKnownIsIgnoredValue() const {
if (last_known_is_ignored_value_ == kDefaultBehavior) {
last_known_is_ignored_value_ =
AccessibilityIsIgnored() ? kIgnoreObject : kIncludeObject;
}
return last_known_is_ignored_value_ == kIgnoreObject;
}
void AXObject::SetLastKnownIsIgnoredValue(bool is_ignored) {
last_known_is_ignored_value_ = is_ignored ? kIgnoreObject : kIncludeObject;
return cached_is_ignored_;
}
bool AXObject::LastKnownIsIgnoredButIncludedInTreeValue() const {
if (last_known_is_ignored_but_included_in_tree_value_ == kDefaultBehavior) {
last_known_is_ignored_but_included_in_tree_value_ =
AccessibilityIsIgnoredButIncludedInTree() ? kIncludeObject
: kIgnoreObject;
}
return last_known_is_ignored_but_included_in_tree_value_ == kIncludeObject;
}
void AXObject::SetLastKnownIsIgnoredButIncludedInTreeValue(
bool is_ignored_but_included_in_tree) {
last_known_is_ignored_but_included_in_tree_value_ =
is_ignored_but_included_in_tree ? kIncludeObject : kIgnoreObject;
return cached_is_ignored_but_included_in_tree_;
}
bool AXObject::HasInheritedPresentationalRole() const {
......
......@@ -540,9 +540,7 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
const AXObject* DatetimeAncestor(int max_levels_to_check = 3) const;
const AXObject* DisabledAncestor() const;
bool LastKnownIsIgnoredValue() const;
void SetLastKnownIsIgnoredValue(bool);
bool LastKnownIsIgnoredButIncludedInTreeValue() const;
void SetLastKnownIsIgnoredButIncludedInTreeValue(bool);
bool HasInheritedPresentationalRole() const;
bool IsPresentationalChild() const;
bool CanBeActiveDescendant() const;
......@@ -1196,8 +1194,6 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
mutable bool have_children_;
ax::mojom::blink::Role role_;
ax::mojom::blink::Role aria_role_;
mutable AXObjectInclusion last_known_is_ignored_value_;
mutable AXObjectInclusion last_known_is_ignored_but_included_in_tree_value_;
LayoutRect explicit_element_rect_;
AXID explicit_container_id_;
......
......@@ -356,9 +356,6 @@ AXObject* AXObjectCacheImpl::Get(const Node* node) {
new_obj->SetAXObjectID(node_id);
objects_.Set(node_id, new_obj);
new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
return new_obj;
}
......@@ -540,9 +537,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(Node* node) {
DCHECK(!HashTraits<AXID>::IsDeletedValue(ax_id));
node_object_mapping_.Set(node, ax_id);
new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
MaybeNewRelationTarget(node, new_obj);
return new_obj;
......@@ -592,9 +586,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(LayoutObject* layout_object) {
layout_object_mapping_.Set(layout_object, axid);
new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
if (node && node->GetLayoutObject() == layout_object) {
AXID prev_axid = node_object_mapping_.at(node);
if (prev_axid != 0 && prev_axid != axid) {
......@@ -624,20 +615,18 @@ AXObject* AXObjectCacheImpl::GetOrCreate(
inline_text_box_object_mapping_.Set(inline_text_box, axid);
new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
return new_obj;
}
AXObject* AXObjectCacheImpl::GetOrCreate(ax::mojom::blink::Role role) {
AXObject* AXObjectCacheImpl::Create(ax::mojom::blink::Role role,
AXObject* parent) {
AXObject* obj = nullptr;
switch (role) {
case ax::mojom::Role::kSliderThumb:
case ax::mojom::blink::Role::kSliderThumb:
obj = MakeGarbageCollected<AXSliderThumb>(*this);
break;
case ax::mojom::Role::kMenuListPopup:
case ax::mojom::blink::Role::kMenuListPopup:
DCHECK(use_ax_menu_list_);
obj = MakeGarbageCollected<AXMenuListPopup>(*this);
break;
......@@ -649,6 +638,7 @@ AXObject* AXObjectCacheImpl::GetOrCreate(ax::mojom::blink::Role role) {
return nullptr;
GetOrCreateAXID(obj);
obj->SetParent(parent);
obj->Init();
return obj;
......
......@@ -175,8 +175,9 @@ class MODULES_EXPORT AXObjectCacheImpl
AXObject* ObjectFromAXID(AXID id) const { return objects_.at(id); }
AXObject* Root();
// used for objects without backing elements
AXObject* GetOrCreate(ax::mojom::blink::Role);
// Used for objects without backing DOM nodes, layout objects, etc.
AXObject* Create(ax::mojom::blink::Role, AXObject* parent);
AXObject* GetOrCreate(AccessibleNode*);
AXObject* GetOrCreate(LayoutObject*) override;
AXObject* GetOrCreate(const Node*);
......
......@@ -83,9 +83,7 @@ void AXSlider::AddChildren() {
AXObjectCacheImpl& cache = AXObjectCache();
AXSliderThumb* thumb = static_cast<AXSliderThumb*>(
cache.GetOrCreate(ax::mojom::Role::kSliderThumb));
thumb->SetParent(this);
AXObject* thumb = cache.Create(ax::mojom::blink::Role::kSliderThumb, this);
// Before actually adding the value indicator to the hierarchy,
// allow the platform to make a final decision about it.
......
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