ax_tree_source_annotator.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2021 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. #ifndef UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_
  5. #define UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_
  6. #include <string>
  7. #include "ui/accessibility/ax_enums.mojom.h"
  8. #include "ui/accessibility/ax_export.h"
  9. #include "ui/accessibility/ax_tree_source.h"
  10. #include "ui/accessibility/ax_tree_source_observer.h"
  11. namespace ui {
  12. // This is an interface for a class that could be used by any `AXTreeSource` to
  13. // provide automatically generated accessible names, such as automatically
  14. // generated alt text for unlabeled images. A specific annotator may be able to
  15. // work on multiple `AXNodeSource`s, e.g. `AXNode*` and `WebAXObject`.
  16. template <typename AXNodeSource>
  17. class AX_EXPORT AXTreeSourceAnnotator
  18. : public AXTreeSourceObserver<AXNodeSource> {
  19. public:
  20. virtual ~AXTreeSourceAnnotator() = default;
  21. // Returns the automatically generated accessible name for the given
  22. // `AXNodeSource`, if any. For example, in the case of an unlabeled image,
  23. // this would return automatically generated alt text for the image.
  24. virtual std::string GetAnnotation(
  25. const AXTreeSource<AXNodeSource>& tree_source,
  26. const AXNodeSource& node_source) const = 0;
  27. // Returns a value indicating the status of the automatically generated
  28. // accessible name, such as whether it is currently being computed, if it has
  29. // been computed successfully, if the operation is still pending, etc.
  30. //
  31. // TODO(nektar): Rename `ImageAnnotationStatus` to `AnnotationStatus`.
  32. virtual ax::mojom::ImageAnnotationStatus GetAnnotationStatus(
  33. const AXTreeSource<AXNodeSource>& tree_source,
  34. const AXNodeSource& node_source) const = 0;
  35. // Returns true if an accessible name for the given `AXNodeSource` has already
  36. // been automatically generated.
  37. virtual bool HasAnnotationInCache(
  38. const AXTreeSource<AXNodeSource>& tree_source,
  39. const AXNodeSource& node_source) const = 0;
  40. // Returns true if an accessible name for the given `AXNodeSource` has already
  41. // been automatically generated, is in the process of being generated, or has
  42. // encountered an error.
  43. virtual bool HasNodeInCache(const AXTreeSource<AXNodeSource>& tree_source,
  44. const AXNodeSource& node_source) const = 0;
  45. // Returns true if the existing accessible name for a node consists of mostly
  46. // stopwords, such as "the" and "of". This would be a strong indication that
  47. // the accessible name is not informative and should be replaced by an
  48. // automatically generated one.
  49. virtual bool AccessibleNameHasMostlyStopwords(
  50. const std::string& accessible_name) = 0;
  51. };
  52. } // namespace ui
  53. #endif // UI_ACCESSIBILITY_AX_TREE_SOURCE_ANNOTATOR_H_