On Wed Nov 9 23:19:58 2022 +0000, Esme Povirk wrote:
What I'm trying to get at here is: I think you might have 2 different functions that are logically coupled, meaning you have to look at both functions to evaluate the correctness of either one. That makes the code harder to understand and maintain.
The only part of `get_sibling_node_for_tree` that is logically coupled to `traverse_uia_node_tree` is the `at_root_level` argument. The operation that `get_sibling_node_for_tree` implements also gets used by `UiaNavigate` when navigating with `NavigateDirection_{Previous/Next}Sibling`. An example:
``` +------------------------------------+-----------------------------------+ | 'Raw' (ConditionType_True) | UIA_IsControlElementPropertyId | | tree view | equals TRUE tree view | +------------------------------------+-----------------------------------+ | | | | +---+---+ | +---+---+ | | | | | | | | | | 1 + | | 1 + | | | | | | | | | +---+---+ | +---+---+ | | | | | | | +-----------+-----------+ | +-----------+-----------+ | | | | | | | | | | +---+---+ +---+---+ +---+---+ | +---+---+ +---+---+ | | | | | | | | | | | | | | | | 2 +---| 3 +---| 4 + | | 6 +---------------| 4 + | | | | | | | | | | | | | | | +---+---+ +---+---+ +---+---+ | +---+---+ +---+---+ | | | | | | +---+---+ | | | | | | | | | 5 | | | | | | | | | +---+---+ | | | | | | | +---+---+ | | | | | | | | | 6 | | | | | | | | | +-------+ | | | | | +------------------------------------+-----------------------------------+
```
If our view condition here is `UIA_IsControlElementPropertyId` being set to TRUE, and only nodes 6 and 4 return TRUE for that property, how do we navigate from node 6 to its sibling node 4 in the treeview?
First, we need to do what `get_sibling_node_for_tree` does: - Check if node 6 has a sibling. It doesn't. - Navigate to node 5 from node 6. - Check if node 5 matches our view condition, and is therefore a parent of 6 in this treeview. It doesn't. - Check if node 5 has any siblings. It doesn't. - Navigate to node 2 from node 5. - Check if node 2 matches our view condition, and is therefore a parent of 6 in this treeview. It doesn't. - Check if node 2 has any siblings. It does. Return its sibling, node 3 from `get_sibling_node_for_tree`.
Now, we're back to whatever function called `get_sibling_node_for_tree` (either `UiaNavigate` or `traverse_uia_node_tree`) and can continue doing whatever we need to do to get from node 3 to node 4.