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() { ...@@ -75,11 +75,7 @@ void AXMenuList::AddChildren() {
AXObjectCacheImpl& cache = AXObjectCache(); AXObjectCacheImpl& cache = AXObjectCache();
AXObject* popup = cache.GetOrCreate(ax::mojom::Role::kMenuListPopup); AXObject* popup = cache.Create(ax::mojom::blink::Role::kMenuListPopup, this);
if (!popup)
return;
To<AXMockObject>(popup)->SetParent(this);
if (!popup->AccessibilityIsIncludedInTree()) { if (!popup->AccessibilityIsIncludedInTree()) {
cache.Remove(popup->AXObjectID()); cache.Remove(popup->AXObjectID());
return; return;
......
...@@ -520,8 +520,6 @@ AXObject::AXObject(AXObjectCacheImpl& ax_object_cache) ...@@ -520,8 +520,6 @@ AXObject::AXObject(AXObjectCacheImpl& ax_object_cache)
have_children_(false), have_children_(false),
role_(ax::mojom::blink::Role::kUnknown), role_(ax::mojom::blink::Role::kUnknown),
aria_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), explicit_container_id_(0),
parent_(nullptr), parent_(nullptr),
last_modification_count_(-1), last_modification_count_(-1),
...@@ -546,6 +544,7 @@ AXObject::~AXObject() { ...@@ -546,6 +544,7 @@ AXObject::~AXObject() {
void AXObject::Init() { void AXObject::Init() {
role_ = DetermineAccessibilityRole(); role_ = DetermineAccessibilityRole();
UpdateCachedAttributeValuesIfNeeded();
} }
void AXObject::Detach() { void AXObject::Detach() {
...@@ -1231,9 +1230,22 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const { ...@@ -1231,9 +1230,22 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const {
cached_is_descendant_of_disabled_node_ = !!DisabledAncestor(); cached_is_descendant_of_disabled_node_ = !!DisabledAncestor();
cached_has_inherited_presentational_role_ = cached_has_inherited_presentational_role_ =
!!InheritsPresentationalRoleFrom(); !!InheritsPresentationalRoleFrom();
cached_is_ignored_ = ComputeAccessibilityIsIgnored(); bool is_ignored = ComputeAccessibilityIsIgnored();
cached_is_ignored_but_included_in_tree_ = bool is_ignored_but_included_in_tree =
cached_is_ignored_ && ComputeAccessibilityIsIgnoredButIncludedInTree(); 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(); cached_is_editable_root_ = ComputeIsEditableRoot();
// Compute live region root, which can be from any ARIA live value, including // 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". // "off", or from an automatic ARIA live value, e.g. from role="status".
...@@ -1247,21 +1259,6 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const { ...@@ -1247,21 +1259,6 @@ void AXObject::UpdateCachedAttributeValuesIfNeeded() const {
cached_aria_column_index_ = ComputeAriaColumnIndex(); cached_aria_column_index_ = ComputeAriaColumnIndex();
cached_aria_row_index_ = ComputeAriaRowIndex(); 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 (ignored_states_changed) {
if (AXObject* parent = ParentObjectIfExists()) if (AXObject* parent = ParentObjectIfExists())
parent->ChildrenChanged(); parent->ChildrenChanged();
...@@ -1620,32 +1617,11 @@ const AXObject* AXObject::DatetimeAncestor(int max_levels_to_check) const { ...@@ -1620,32 +1617,11 @@ const AXObject* AXObject::DatetimeAncestor(int max_levels_to_check) const {
} }
bool AXObject::LastKnownIsIgnoredValue() const { bool AXObject::LastKnownIsIgnoredValue() const {
if (last_known_is_ignored_value_ == kDefaultBehavior) { return cached_is_ignored_;
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;
} }
bool AXObject::LastKnownIsIgnoredButIncludedInTreeValue() const { bool AXObject::LastKnownIsIgnoredButIncludedInTreeValue() const {
if (last_known_is_ignored_but_included_in_tree_value_ == kDefaultBehavior) { return cached_is_ignored_but_included_in_tree_;
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;
} }
bool AXObject::HasInheritedPresentationalRole() const { bool AXObject::HasInheritedPresentationalRole() const {
......
...@@ -540,9 +540,7 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> { ...@@ -540,9 +540,7 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
const AXObject* DatetimeAncestor(int max_levels_to_check = 3) const; const AXObject* DatetimeAncestor(int max_levels_to_check = 3) const;
const AXObject* DisabledAncestor() const; const AXObject* DisabledAncestor() const;
bool LastKnownIsIgnoredValue() const; bool LastKnownIsIgnoredValue() const;
void SetLastKnownIsIgnoredValue(bool);
bool LastKnownIsIgnoredButIncludedInTreeValue() const; bool LastKnownIsIgnoredButIncludedInTreeValue() const;
void SetLastKnownIsIgnoredButIncludedInTreeValue(bool);
bool HasInheritedPresentationalRole() const; bool HasInheritedPresentationalRole() const;
bool IsPresentationalChild() const; bool IsPresentationalChild() const;
bool CanBeActiveDescendant() const; bool CanBeActiveDescendant() const;
...@@ -1196,8 +1194,6 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> { ...@@ -1196,8 +1194,6 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
mutable bool have_children_; mutable bool have_children_;
ax::mojom::blink::Role role_; ax::mojom::blink::Role role_;
ax::mojom::blink::Role aria_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_; LayoutRect explicit_element_rect_;
AXID explicit_container_id_; AXID explicit_container_id_;
......
...@@ -356,9 +356,6 @@ AXObject* AXObjectCacheImpl::Get(const Node* node) { ...@@ -356,9 +356,6 @@ AXObject* AXObjectCacheImpl::Get(const Node* node) {
new_obj->SetAXObjectID(node_id); new_obj->SetAXObjectID(node_id);
objects_.Set(node_id, new_obj); objects_.Set(node_id, new_obj);
new_obj->Init(); new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
return new_obj; return new_obj;
} }
...@@ -540,9 +537,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(Node* node) { ...@@ -540,9 +537,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(Node* node) {
DCHECK(!HashTraits<AXID>::IsDeletedValue(ax_id)); DCHECK(!HashTraits<AXID>::IsDeletedValue(ax_id));
node_object_mapping_.Set(node, ax_id); node_object_mapping_.Set(node, ax_id);
new_obj->Init(); new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
MaybeNewRelationTarget(node, new_obj); MaybeNewRelationTarget(node, new_obj);
return new_obj; return new_obj;
...@@ -592,9 +586,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(LayoutObject* layout_object) { ...@@ -592,9 +586,6 @@ AXObject* AXObjectCacheImpl::GetOrCreate(LayoutObject* layout_object) {
layout_object_mapping_.Set(layout_object, axid); layout_object_mapping_.Set(layout_object, axid);
new_obj->Init(); new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
if (node && node->GetLayoutObject() == layout_object) { if (node && node->GetLayoutObject() == layout_object) {
AXID prev_axid = node_object_mapping_.at(node); AXID prev_axid = node_object_mapping_.at(node);
if (prev_axid != 0 && prev_axid != axid) { if (prev_axid != 0 && prev_axid != axid) {
...@@ -624,20 +615,18 @@ AXObject* AXObjectCacheImpl::GetOrCreate( ...@@ -624,20 +615,18 @@ AXObject* AXObjectCacheImpl::GetOrCreate(
inline_text_box_object_mapping_.Set(inline_text_box, axid); inline_text_box_object_mapping_.Set(inline_text_box, axid);
new_obj->Init(); new_obj->Init();
new_obj->SetLastKnownIsIgnoredValue(new_obj->AccessibilityIsIgnored());
new_obj->SetLastKnownIsIgnoredButIncludedInTreeValue(
new_obj->AccessibilityIsIgnoredButIncludedInTree());
return new_obj; return new_obj;
} }
AXObject* AXObjectCacheImpl::GetOrCreate(ax::mojom::blink::Role role) { AXObject* AXObjectCacheImpl::Create(ax::mojom::blink::Role role,
AXObject* parent) {
AXObject* obj = nullptr; AXObject* obj = nullptr;
switch (role) { switch (role) {
case ax::mojom::Role::kSliderThumb: case ax::mojom::blink::Role::kSliderThumb:
obj = MakeGarbageCollected<AXSliderThumb>(*this); obj = MakeGarbageCollected<AXSliderThumb>(*this);
break; break;
case ax::mojom::Role::kMenuListPopup: case ax::mojom::blink::Role::kMenuListPopup:
DCHECK(use_ax_menu_list_); DCHECK(use_ax_menu_list_);
obj = MakeGarbageCollected<AXMenuListPopup>(*this); obj = MakeGarbageCollected<AXMenuListPopup>(*this);
break; break;
...@@ -649,6 +638,7 @@ AXObject* AXObjectCacheImpl::GetOrCreate(ax::mojom::blink::Role role) { ...@@ -649,6 +638,7 @@ AXObject* AXObjectCacheImpl::GetOrCreate(ax::mojom::blink::Role role) {
return nullptr; return nullptr;
GetOrCreateAXID(obj); GetOrCreateAXID(obj);
obj->SetParent(parent);
obj->Init(); obj->Init();
return obj; return obj;
......
...@@ -175,8 +175,9 @@ class MODULES_EXPORT AXObjectCacheImpl ...@@ -175,8 +175,9 @@ class MODULES_EXPORT AXObjectCacheImpl
AXObject* ObjectFromAXID(AXID id) const { return objects_.at(id); } AXObject* ObjectFromAXID(AXID id) const { return objects_.at(id); }
AXObject* Root(); AXObject* Root();
// used for objects without backing elements // Used for objects without backing DOM nodes, layout objects, etc.
AXObject* GetOrCreate(ax::mojom::blink::Role); AXObject* Create(ax::mojom::blink::Role, AXObject* parent);
AXObject* GetOrCreate(AccessibleNode*); AXObject* GetOrCreate(AccessibleNode*);
AXObject* GetOrCreate(LayoutObject*) override; AXObject* GetOrCreate(LayoutObject*) override;
AXObject* GetOrCreate(const Node*); AXObject* GetOrCreate(const Node*);
......
...@@ -83,9 +83,7 @@ void AXSlider::AddChildren() { ...@@ -83,9 +83,7 @@ void AXSlider::AddChildren() {
AXObjectCacheImpl& cache = AXObjectCache(); AXObjectCacheImpl& cache = AXObjectCache();
AXSliderThumb* thumb = static_cast<AXSliderThumb*>( AXObject* thumb = cache.Create(ax::mojom::blink::Role::kSliderThumb, this);
cache.GetOrCreate(ax::mojom::Role::kSliderThumb));
thumb->SetParent(this);
// Before actually adding the value indicator to the hierarchy, // Before actually adding the value indicator to the hierarchy,
// allow the platform to make a final decision about it. // 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