blob: 903983e9309463e8da6821d0987df70b2f602ebd [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
Ahmed Elwasefiab8ae772024-03-23 01:13:0724 : public AXTreeSourceObserver<AXNodeSource,
25 ui::AXTreeData*,
26 ui::AXNodeData> {
Nektarios Paisios660001042021-09-20 16:43:2327 public:
28 virtual ~AXTreeSourceAnnotator() = default;
29
30 // Returns the automatically generated accessible name for the given
31 // `AXNodeSource`, if any. For example, in the case of an unlabeled image,
32 // this would return automatically generated alt text for the image.
33 virtual std::string GetAnnotation(
Ahmed Elwasefiab8ae772024-03-23 01:13:0734 const AXTreeSource<AXNodeSource, ui::AXTreeData*, ui::AXNodeData>&
35 tree_source,
Nektarios Paisios660001042021-09-20 16:43:2336 const AXNodeSource& node_source) const = 0;
37
38 // Returns a value indicating the status of the automatically generated
39 // accessible name, such as whether it is currently being computed, if it has
40 // been computed successfully, if the operation is still pending, etc.
41 //
42 // TODO(nektar): Rename `ImageAnnotationStatus` to `AnnotationStatus`.
43 virtual ax::mojom::ImageAnnotationStatus GetAnnotationStatus(
Ahmed Elwasefiab8ae772024-03-23 01:13:0744 const AXTreeSource<AXNodeSource, ui::AXTreeData*, ui::AXNodeData>&
45 tree_source,
Nektarios Paisios660001042021-09-20 16:43:2346 const AXNodeSource& node_source) const = 0;
47
48 // Returns true if an accessible name for the given `AXNodeSource` has already
49 // been automatically generated.
50 virtual bool HasAnnotationInCache(
Ahmed Elwasefiab8ae772024-03-23 01:13:0751 const AXTreeSource<AXNodeSource, ui::AXTreeData*, ui::AXNodeData>&
52 tree_source,
Nektarios Paisios660001042021-09-20 16:43:2353 const AXNodeSource& node_source) const = 0;
54
55 // Returns true if an accessible name for the given `AXNodeSource` has already
56 // been automatically generated, is in the process of being generated, or has
57 // encountered an error.
Ahmed Elwasefiab8ae772024-03-23 01:13:0758 virtual bool HasNodeInCache(
59 const AXTreeSource<AXNodeSource, ui::AXTreeData*, ui::AXNodeData>&
60 tree_source,
61 const AXNodeSource& node_source) const = 0;
Nektarios Paisios660001042021-09-20 16:43:2362
Nektarios Paisios660001042021-09-20 16:43:2363 // Returns true if the existing accessible name for a node consists of mostly
64 // stopwords, such as "the" and "of". This would be a strong indication that
65 // the accessible name is not informative and should be replaced by an
66 // automatically generated one.
67 virtual bool AccessibleNameHasMostlyStopwords(
68 const std::string& accessible_name) = 0;
69};
70
71} // namespace ui
72
73#endif // UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_