Commit 4335a96e authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Improve PosInSet and SetSize functionality

Build on PosInSet and SetSize functions in ax_node.cc to handle
invalid or erroneous assignment. SetSize should not allow decreasing
assignments, while PosInSet should not allow decreasing nor duplicate
assignments among nodes in the same container.

Change-Id: I07b0e9c493439aca9ef50ecfe3c3f5bbf7a7ce7a
Reviewed-on: https://chromium-review.googlesource.com/c/1343374
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610920}
parent 184fd278
This diff is collapsed.
...@@ -181,13 +181,9 @@ class AX_EXPORT AXNode final { ...@@ -181,13 +181,9 @@ class AX_EXPORT AXNode final {
return data().GetHtmlAttribute(attribute, value); return data().GetHtmlAttribute(attribute, value);
} }
// Finds the position of this node within its container, relative to others // PosInSet and SetSize public methods
// with the same role. int32_t GetPosInSet();
// Returns 1-based index if present in container, and 0 if not. int32_t GetSetSize();
int32_t PosInSet() const;
// Calculates the number of elements within node's container that have the
// same role as node. Returns 0 if the node is not present wihtin a container.
int32_t SetSize() const;
const std::string& GetInheritedStringAttribute( const std::string& GetInheritedStringAttribute(
ax::mojom::StringAttribute attribute) const; ax::mojom::StringAttribute attribute) const;
...@@ -255,16 +251,21 @@ class AX_EXPORT AXNode final { ...@@ -255,16 +251,21 @@ class AX_EXPORT AXNode final {
void IdVectorToNodeVector(std::vector<int32_t>& ids, void IdVectorToNodeVector(std::vector<int32_t>& ids,
std::vector<AXNode*>* nodes) const; std::vector<AXNode*>* nodes) const;
// Helpers for PosInset and SetSize // Helpers for GetPosInSet and GetSetSize.
// Returns true if the PosInSet or SetSize attributes are used in node's role // Returns true if the role of parent container matches the role of node.
// Returns false otherwise.
bool ContainerRoleMatches(AXNode* parent) const;
// Returns true if the node's role uses PosInSet and SetSize
// Returns false otherwise.
bool IsSetSizePosInSetUsedInRole() const; bool IsSetSizePosInSetUsedInRole() const;
// Calculates 0-based index of first element with PosInSet assigned. // Finds and returns a pointer to node's container.
// Returns -1 if no elements assign PosInSet AXNode* GetContainer() const;
int32_t FirstAssignedPosInSet() const; // Populates items vector with all nodes within container whose roles match.
// Calculates node's position relative to first PosInSet-assigned element. void PopulateContainerItems(AXNode* container,
// Returns node's 0-based index within container (relative to nodes with the AXNode* local_parent,
// same role) if no element assigned PosInSet std::vector<AXNode*>& items) const;
int32_t RelativePosFromFirstAssigned(int32_t earliest_index) const; // Computes pos_in_set and set_size values for this node.
void ComputeSetSizePosInSet(int32_t* out_pos_in_set, int32_t* out_set_size);
OwnerTree* tree_; // Owns this. OwnerTree* tree_; // Owns this.
int index_in_parent_; int index_in_parent_;
......
This diff is collapsed.
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