Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 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 UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_ |
| 6 | #define UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "ui/accessibility/ax_enums.mojom.h" |
| 11 | #include "ui/accessibility/ax_export.h" |
Ahmed Elwasefi | ab8ae77 | 2024-03-23 01:13:07 | [diff] [blame] | 12 | #include "ui/accessibility/ax_tree_data.h" |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 13 | #include "ui/accessibility/ax_tree_source.h" |
Nektarios Paisios | 700dd6f | 2021-09-21 16:09:05 | [diff] [blame] | 14 | #include "ui/accessibility/ax_tree_source_observer.h" |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 15 | |
| 16 | namespace ui { |
| 17 | |
| 18 | // This is an interface for a class that could be used by any `AXTreeSource` to |
| 19 | // provide automatically generated accessible names, such as automatically |
| 20 | // generated alt text for unlabeled images. A specific annotator may be able to |
| 21 | // work on multiple `AXNodeSource`s, e.g. `AXNode*` and `WebAXObject`. |
| 22 | template <typename AXNodeSource> |
Nektarios Paisios | 700dd6f | 2021-09-21 16:09:05 | [diff] [blame] | 23 | class AX_EXPORT AXTreeSourceAnnotator |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame^] | 24 | : public AXTreeSourceObserver<AXNodeSource, AXTreeData*, AXNodeData> { |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 25 | public: |
| 26 | virtual ~AXTreeSourceAnnotator() = default; |
| 27 | |
| 28 | // Returns the automatically generated accessible name for the given |
| 29 | // `AXNodeSource`, if any. For example, in the case of an unlabeled image, |
| 30 | // this would return automatically generated alt text for the image. |
| 31 | virtual std::string GetAnnotation( |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame^] | 32 | const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source, |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 33 | const AXNodeSource& node_source) const = 0; |
| 34 | |
| 35 | // Returns a value indicating the status of the automatically generated |
| 36 | // accessible name, such as whether it is currently being computed, if it has |
| 37 | // been computed successfully, if the operation is still pending, etc. |
| 38 | // |
| 39 | // TODO(nektar): Rename `ImageAnnotationStatus` to `AnnotationStatus`. |
| 40 | virtual ax::mojom::ImageAnnotationStatus GetAnnotationStatus( |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame^] | 41 | const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source, |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 42 | const AXNodeSource& node_source) const = 0; |
| 43 | |
| 44 | // Returns true if an accessible name for the given `AXNodeSource` has already |
| 45 | // been automatically generated. |
| 46 | virtual bool HasAnnotationInCache( |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame^] | 47 | const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source, |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 48 | const AXNodeSource& node_source) const = 0; |
| 49 | |
| 50 | // Returns true if an accessible name for the given `AXNodeSource` has already |
| 51 | // been automatically generated, is in the process of being generated, or has |
| 52 | // encountered an error. |
Ahmed Elwasefi | ab8ae77 | 2024-03-23 01:13:07 | [diff] [blame] | 53 | virtual bool HasNodeInCache( |
Jacques Newman | a4149e85 | 2024-08-28 23:35:42 | [diff] [blame^] | 54 | const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source, |
Ahmed Elwasefi | ab8ae77 | 2024-03-23 01:13:07 | [diff] [blame] | 55 | const AXNodeSource& node_source) const = 0; |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 56 | |
Nektarios Paisios | 66000104 | 2021-09-20 16:43:23 | [diff] [blame] | 57 | // Returns true if the existing accessible name for a node consists of mostly |
| 58 | // stopwords, such as "the" and "of". This would be a strong indication that |
| 59 | // the accessible name is not informative and should be replaced by an |
| 60 | // automatically generated one. |
| 61 | virtual bool AccessibleNameHasMostlyStopwords( |
| 62 | const std::string& accessible_name) = 0; |
| 63 | }; |
| 64 | |
| 65 | } // namespace ui |
| 66 | |
| 67 | #endif // UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_ |