diff options
Diffstat (limited to 'chromium/ui/accessibility/ax_node_data.cc')
-rw-r--r-- | chromium/ui/accessibility/ax_node_data.cc | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/chromium/ui/accessibility/ax_node_data.cc b/chromium/ui/accessibility/ax_node_data.cc index 1780711a1ae..789e9e01feb 100644 --- a/chromium/ui/accessibility/ax_node_data.cc +++ b/chromium/ui/accessibility/ax_node_data.cc @@ -570,17 +570,42 @@ AXNodeTextStyles AXNodeData::GetTextStyles() const { } void AXNodeData::SetName(const std::string& name) { + DCHECK_NE(role, ax::mojom::Role::kNone) + << "A valid role is required before setting the name attribute, because " + "the role is used for setting the required NameFrom attribute."; + auto iter = std::find_if(string_attributes.begin(), string_attributes.end(), [](const auto& string_attribute) { return string_attribute.first == ax::mojom::StringAttribute::kName; }); + if (iter == string_attributes.end()) { string_attributes.push_back( std::make_pair(ax::mojom::StringAttribute::kName, name)); } else { iter->second = name; } + + if (HasIntAttribute(ax::mojom::IntAttribute::kNameFrom)) + return; + // Since this method is mostly used by tests which don't always set the + // "NameFrom" attribute, we need to set it here to the most likely value if + // not set, otherwise code that tries to calculate the node's inner text, its + // hypertext, or even its value, might not know whether to include the name in + // the result or not. + // + // For example, if there is a text field, but it is empty, i.e. it has no + // value, its value could be its name if "NameFrom" is set to "kPlaceholder" + // or to "kContents" but not if it's set to "kAttribute". Similarly, if there + // is a button without any unignored children, it's name can only be + // equivalent to its inner text if "NameFrom" is set to "kContents" or to + // "kValue", but not if it is set to "kAttribute". + if (IsText(role)) { + SetNameFrom(ax::mojom::NameFrom::kContents); + } else { + SetNameFrom(ax::mojom::NameFrom::kAttribute); + } } void AXNodeData::SetName(const base::string16& name) { @@ -729,7 +754,7 @@ ax::mojom::CheckedState AXNodeData::GetCheckedState() const { } void AXNodeData::SetCheckedState(ax::mojom::CheckedState checked_state) { - if (HasIntAttribute(ax::mojom::IntAttribute::kCheckedState)) + if (HasCheckedState()) RemoveIntAttribute(ax::mojom::IntAttribute::kCheckedState); if (checked_state != ax::mojom::CheckedState::kNone) { AddIntAttribute(ax::mojom::IntAttribute::kCheckedState, @@ -737,6 +762,10 @@ void AXNodeData::SetCheckedState(ax::mojom::CheckedState checked_state) { } } +bool AXNodeData::HasCheckedState() const { + return HasIntAttribute(ax::mojom::IntAttribute::kCheckedState); +} + ax::mojom::DefaultActionVerb AXNodeData::GetDefaultActionVerb() const { return static_cast<ax::mojom::DefaultActionVerb>( GetIntAttribute(ax::mojom::IntAttribute::kDefaultActionVerb)); @@ -1001,21 +1030,6 @@ bool AXNodeData::SupportsExpandCollapse() const { return ui::SupportsExpandCollapse(role); } -bool AXNodeData::IsContainedInActiveLiveRegion() const { - if (!HasStringAttribute(ax::mojom::StringAttribute::kContainerLiveStatus)) - return false; - - if (base::CompareCaseInsensitiveASCII( - GetStringAttribute(ax::mojom::StringAttribute::kContainerLiveStatus), - "off") == 0) - return false; - - if (GetBoolAttribute(ax::mojom::BoolAttribute::kContainerLiveBusy)) - return false; - - return true; -} - std::string AXNodeData::ToString() const { std::string result; @@ -1539,6 +1553,9 @@ std::string AXNodeData::ToString() const { case ax::mojom::BoolAttribute::kSelected: result += " selected=" + value; break; + case ax::mojom::BoolAttribute::kSelectedFromFocus: + result += " selected_from_focus=" + value; + break; case ax::mojom::BoolAttribute::kSupportsTextLocation: result += " supports_text_location=" + value; break; |