Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_SEARCH_H_ | |
| 6 #define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_SEARCH_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "content/common/content_export.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 class BrowserAccessibility; | |
| 17 class BrowserAccessibilityManager; | |
| 18 | |
| 19 // A function that returns whether or not a given node matches, given the | |
| 20 // start element of the search as an optional comparator. | |
| 21 typedef bool (*AccessibilityMatchPredicate)(BrowserAccessibility* start_element, | |
| 22 BrowserAccessibility* this_element); | |
| 23 | |
| 24 // This class provides an interface for searching the accessibility tree from | |
| 25 // a given starting node, with a few built-in options and allowing an arbitrary | |
| 26 // number of predicates that can be used to restrict the search. | |
| 27 // | |
| 28 // This class is meant to perform one search. Initialize it, then iterate | |
| 29 // over the matches, and then delete it. | |
|
David Tseng
2015/05/08 21:58:25
Rename to *OneShot?
dmazzoni
2015/05/13 04:22:20
Done.
| |
| 30 // | |
| 31 // This class stores raw pointers to the matches in the tree! Don't keep this | |
| 32 // object around if the tree is mutating. | |
| 33 class CONTENT_EXPORT AccessibilityTreeSearch { | |
| 34 public: | |
| 35 enum Direction { FORWARDS, BACKWARDS }; | |
| 36 | |
| 37 AccessibilityTreeSearch(BrowserAccessibilityManager* tree); | |
| 38 virtual ~AccessibilityTreeSearch(); | |
| 39 | |
| 40 // | |
| 41 // Search parameters. All of these are optional. | |
| 42 // | |
| 43 | |
| 44 // Sets the node where the search starts. The first potential match will | |
| 45 // be the one immediately following this one. This node will be used as | |
| 46 // the first arguement to any predicates. | |
| 47 void SetStartNode(BrowserAccessibility* start_node); | |
| 48 | |
| 49 // Search forwards or backwards in an in-order traversal of the tree. | |
| 50 void SetDirection(Direction direction); | |
| 51 | |
| 52 // Set the maximum number of results, or -1 for no limit (default). | |
|
David Tseng
2015/05/08 21:58:25
Name -1; also, does it even make sense to allow 0
dmazzoni
2015/05/13 04:22:20
Done.
| |
| 53 void SetResultLimit(int result_limit); | |
| 54 | |
| 55 // If true, only searches descendants of |start_node|. | |
| 56 void SetImmediateDescendantsOnly(bool immediate_descendants_only); | |
|
David Tseng
2015/05/08 21:58:25
Is there a difference between immediate and non-im
dmazzoni
2015/05/13 04:22:20
Turns out I was wrong about the implementation. I
| |
| 57 | |
| 58 // If true, only considers nodes that aren't invisible or offscreen. | |
| 59 void SetVisibleOnly(bool visible_only); | |
| 60 | |
| 61 // Restricts the matches to only nodes where |text| is found as a | |
| 62 // substring of any of that node's accessible text, including its | |
| 63 // name, description, or value. Case-insensitive. | |
| 64 void SetSearchText(const std::string& text); | |
| 65 | |
| 66 // Restricts the matches to only those that satisfy all predicates. | |
| 67 void AddPredicate(AccessibilityMatchPredicate predicate); | |
| 68 | |
| 69 // | |
| 70 // Calling either of these executes the search. | |
| 71 // | |
| 72 | |
| 73 size_t CountMatches(); | |
| 74 BrowserAccessibility* GetMatchAtIndex(size_t index); | |
| 75 | |
| 76 private: | |
| 77 void DoSearch(); | |
| 78 | |
| 79 BrowserAccessibilityManager* tree_; | |
| 80 BrowserAccessibility* start_node_; | |
| 81 Direction direction_; | |
| 82 int result_limit_; | |
| 83 bool immediate_descendants_only_; | |
| 84 bool visible_only_; | |
| 85 std::string search_text_; | |
| 86 | |
| 87 std::vector<AccessibilityMatchPredicate> predicates_; | |
| 88 std::vector<BrowserAccessibility*> matches_; | |
| 89 | |
| 90 bool did_search_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeSearch); | |
| 93 }; | |
| 94 | |
| 95 } // namespace content | |
| 96 | |
| 97 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_SEARCH_H_ | |
| OLD | NEW |