Commit 51ef9834 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Do some cleanup in ui::AXNode.

- Make some member variables const.
- Initialize member variables in the header when possible.
- Make GetLanguage() const.
- Fix various nits.

Change-Id: Ib508052f2491955cc41554204a2010299bc2d4ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2092879Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarChris Hall <chrishall@chromium.org>
Commit-Queue: Chris Hall <chrishall@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748593}
parent e9092f2b
...@@ -28,9 +28,7 @@ AXNode::AXNode(AXNode::OwnerTree* tree, ...@@ -28,9 +28,7 @@ AXNode::AXNode(AXNode::OwnerTree* tree,
: tree_(tree), : tree_(tree),
index_in_parent_(index_in_parent), index_in_parent_(index_in_parent),
unignored_index_in_parent_(unignored_index_in_parent), unignored_index_in_parent_(unignored_index_in_parent),
unignored_child_count_(0), parent_(parent) {
parent_(parent),
language_info_(nullptr) {
data_.id = id; data_.id = id;
} }
...@@ -149,7 +147,7 @@ AXNode* AXNode::GetPreviousUnignoredSibling() const { ...@@ -149,7 +147,7 @@ AXNode* AXNode::GetPreviousUnignoredSibling() const {
// If the node is ignored, drill down to the ignored node's last child. // If the node is ignored, drill down to the ignored node's last child.
parent_node = child; parent_node = child;
before_first_child = parent_node->children().size() == 0; before_first_child = parent_node->children().empty();
index = parent_node->children().size() - 1; index = parent_node->children().size() - 1;
} else { } else {
// If the parent is not ignored and we are past all of its children, there // If the parent is not ignored and we are past all of its children, there
...@@ -253,7 +251,7 @@ void AXNode::Destroy() { ...@@ -253,7 +251,7 @@ void AXNode::Destroy() {
bool AXNode::IsDescendantOf(AXNode* ancestor) { bool AXNode::IsDescendantOf(AXNode* ancestor) {
if (this == ancestor) if (this == ancestor)
return true; return true;
else if (parent()) if (parent())
return parent()->IsDescendantOf(ancestor); return parent()->IsDescendantOf(ancestor);
return false; return false;
...@@ -262,8 +260,9 @@ bool AXNode::IsDescendantOf(AXNode* ancestor) { ...@@ -262,8 +260,9 @@ bool AXNode::IsDescendantOf(AXNode* ancestor) {
std::vector<int> AXNode::GetOrComputeLineStartOffsets() { std::vector<int> AXNode::GetOrComputeLineStartOffsets() {
std::vector<int> line_offsets; std::vector<int> line_offsets;
if (data().GetIntListAttribute(ax::mojom::IntListAttribute::kCachedLineStarts, if (data().GetIntListAttribute(ax::mojom::IntListAttribute::kCachedLineStarts,
&line_offsets)) &line_offsets)) {
return line_offsets; return line_offsets;
}
int start_offset = 0; int start_offset = 0;
ComputeLineStartOffsets(&line_offsets, &start_offset); ComputeLineStartOffsets(&line_offsets, &start_offset);
...@@ -326,7 +325,7 @@ void AXNode::ClearLanguageInfo() { ...@@ -326,7 +325,7 @@ void AXNode::ClearLanguageInfo() {
language_info_.reset(); language_info_.reset();
} }
std::string AXNode::GetLanguage() { std::string AXNode::GetLanguage() const {
// Walk up tree considering both detected and author declared languages. // Walk up tree considering both detected and author declared languages.
for (const AXNode* cur = this; cur; cur = cur->parent()) { for (const AXNode* cur = this; cur; cur = cur->parent()) {
// If language detection has assigned a language then we prefer that. // If language detection has assigned a language then we prefer that.
...@@ -342,7 +341,7 @@ std::string AXNode::GetLanguage() { ...@@ -342,7 +341,7 @@ std::string AXNode::GetLanguage() {
} }
} }
return base::EmptyString(); return std::string();
} }
std::ostream& operator<<(std::ostream& stream, const AXNode& node) { std::ostream& operator<<(std::ostream& stream, const AXNode& node) {
...@@ -896,7 +895,7 @@ AXNode* AXNode::GetOrderedSet() const { ...@@ -896,7 +895,7 @@ AXNode* AXNode::GetOrderedSet() const {
AXNode* AXNode::ComputeLastUnignoredChildRecursive() const { AXNode* AXNode::ComputeLastUnignoredChildRecursive() const {
DCHECK(!tree_->GetTreeUpdateInProgressState()); DCHECK(!tree_->GetTreeUpdateInProgressState());
if (children().size() == 0) if (children().empty())
return nullptr; return nullptr;
for (int i = static_cast<int>(children().size()) - 1; i >= 0; --i) { for (int i = static_cast<int>(children().size()) - 1; i >= 0; --i) {
...@@ -948,11 +947,8 @@ bool AXNode::IsInListMarker() const { ...@@ -948,11 +947,8 @@ bool AXNode::IsInListMarker() const {
return true; return true;
AXNode* grandparent_node = parent_node->GetUnignoredParent(); AXNode* grandparent_node = parent_node->GetUnignoredParent();
if (grandparent_node && return grandparent_node &&
grandparent_node->data().role == ax::mojom::Role::kListMarker) grandparent_node->data().role == ax::mojom::Role::kListMarker;
return true;
return false;
} }
} // namespace ui } // namespace ui
...@@ -295,7 +295,7 @@ class AX_EXPORT AXNode final { ...@@ -295,7 +295,7 @@ class AX_EXPORT AXNode final {
// This language code will be BCP 47. // This language code will be BCP 47.
// //
// Returns empty string if no appropriate language was found. // Returns empty string if no appropriate language was found.
std::string GetLanguage(); std::string GetLanguage() const;
// //
// Helper functions for tables, table rows, and table cells. // Helper functions for tables, table rows, and table cells.
...@@ -404,11 +404,11 @@ class AX_EXPORT AXNode final { ...@@ -404,11 +404,11 @@ class AX_EXPORT AXNode final {
// Finds and returns a pointer to ordered set containing node. // Finds and returns a pointer to ordered set containing node.
AXNode* GetOrderedSet() const; AXNode* GetOrderedSet() const;
OwnerTree* tree_; // Owns this. OwnerTree* const tree_; // Owns this.
size_t index_in_parent_; size_t index_in_parent_;
size_t unignored_index_in_parent_; size_t unignored_index_in_parent_;
size_t unignored_child_count_; size_t unignored_child_count_ = 0;
AXNode* parent_; AXNode* const parent_;
std::vector<AXNode*> children_; std::vector<AXNode*> children_;
AXNodeData data_; AXNodeData data_;
......
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