blob: be7ababefa03ebcd41c8f22cb6bca6b700ab3dae [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2021 The Chromium Authors
Nektarios Paisios660001042021-09-20 16:43:232// 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 Elwasefiab8ae772024-03-23 01:13:0712#include "ui/accessibility/ax_tree_data.h"
Nektarios Paisios660001042021-09-20 16:43:2313#include "ui/accessibility/ax_tree_source.h"
Nektarios Paisios700dd6f2021-09-21 16:09:0514#include "ui/accessibility/ax_tree_source_observer.h"
Nektarios Paisios660001042021-09-20 16:43:2315
16namespace 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`.
22template <typename AXNodeSource>
Nektarios Paisios700dd6f2021-09-21 16:09:0523class AX_EXPORT AXTreeSourceAnnotator
Jacques Newmana4149e852024-08-28 23:35:4224 : public AXTreeSourceObserver<AXNodeSource, AXTreeData*, AXNodeData> {
Nektarios Paisios660001042021-09-20 16:43:2325 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 Newmana4149e852024-08-28 23:35:4232 const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source,
Nektarios Paisios660001042021-09-20 16:43:2333 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 Newmana4149e852024-08-28 23:35:4241 const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source,
Nektarios Paisios660001042021-09-20 16:43:2342 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 Newmana4149e852024-08-28 23:35:4247 const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source,
Nektarios Paisios660001042021-09-20 16:43:2348 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 Elwasefiab8ae772024-03-23 01:13:0753 virtual bool HasNodeInCache(
Jacques Newmana4149e852024-08-28 23:35:4254 const AXTreeSource<AXNodeSource, AXTreeData*, AXNodeData>& tree_source,
Ahmed Elwasefiab8ae772024-03-23 01:13:0755 const AXNodeSource& node_source) const = 0;
Nektarios Paisios660001042021-09-20 16:43:2356
Nektarios Paisios660001042021-09-20 16:43:2357 // 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_