ax_mode.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Copyright 2017 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_MODE_H_
  5. #define UI_ACCESSIBILITY_AX_MODE_H_
  6. #include <stdint.h>
  7. #include <ostream>
  8. #include <string>
  9. #include "ui/accessibility/ax_base_export.h"
  10. namespace ui {
  11. class AX_BASE_EXPORT AXMode {
  12. public:
  13. static constexpr uint32_t kFirstModeFlag = 1 << 0;
  14. // Native accessibility APIs, specific to each platform, are enabled.
  15. // When this mode is set that indicates the presence of a third-party
  16. // client accessing Chrome via accessibility APIs. However, unless one
  17. // of the modes below is set, the contents of web pages will not be
  18. // accessible.
  19. static constexpr uint32_t kNativeAPIs = 1 << 0;
  20. // The renderer process will generate an accessibility tree containing
  21. // basic information about all nodes, including role, name, value,
  22. // state, and location. This is the minimum mode required in order for
  23. // web contents to be accessible, and the remaining modes are meaningless
  24. // unless this one is set.
  25. //
  26. // Note that sometimes this mode will be set when kNativeAPI is not, when the
  27. // content layer embedder is providing accessibility support via some other
  28. // mechanism other than what's implemented in content/browser.
  29. static constexpr uint32_t kWebContents = 1 << 1;
  30. // The accessibility tree will contain inline text boxes, which are
  31. // necessary to expose information about line breaks and word boundaries.
  32. // Without this mode, you can retrieve the plaintext value of a text field
  33. // but not the information about how it's broken down into lines.
  34. //
  35. // Note that when this mode is off it's still possible to request inline
  36. // text boxes for a specific node on-demand, asynchronously.
  37. static constexpr uint32_t kInlineTextBoxes = 1 << 2;
  38. // The accessibility tree will contain extra accessibility
  39. // attributes typically only needed by screen readers and other
  40. // assistive technology for blind users. Examples include text style
  41. // attributes, table cell information, live region properties, range
  42. // values, and relationship attributes.
  43. static constexpr uint32_t kScreenReader = 1 << 3;
  44. // The accessibility tree will contain the HTML tag name and HTML attributes
  45. // for all accessibility nodes that come from web content.
  46. static constexpr uint32_t kHTML = 1 << 4;
  47. // The accessibility tree will contain some metadata from the
  48. // HTML HEAD, such as <meta> tags, in AXTreeData. Only supported
  49. // when doing a tree snapshot, there's no support for keeping these
  50. // in sync if a page changes them dynamically.
  51. static constexpr uint32_t kHTMLMetadata = 1 << 5;
  52. // The accessibility tree will contain automatic image annotations.
  53. static constexpr uint32_t kLabelImages = 1 << 6;
  54. // The accessibility tree will contain enough information to export
  55. // an accessible PDF.
  56. static constexpr uint32_t kPDF = 1 << 7;
  57. // Update this to include the last supported mode flag. If you add
  58. // another, be sure to update the stream insertion operator for
  59. // logging and debugging, as well as AccessibilityModeFlagEnum (and
  60. // related metrics callsites, see: |ModeFlagHistogramValue|).
  61. static constexpr uint32_t kLastModeFlag = 1 << 7;
  62. constexpr AXMode() : flags_(0) {}
  63. constexpr AXMode(uint32_t flags) : flags_(flags) {}
  64. bool has_mode(uint32_t flag) const { return (flags_ & flag) == flag; }
  65. void set_mode(uint32_t flag, bool value) {
  66. flags_ = value ? (flags_ | flag) : (flags_ & ~flag);
  67. }
  68. uint32_t mode() const { return flags_; }
  69. bool operator==(AXMode rhs) const { return flags_ == rhs.flags_; }
  70. bool is_mode_off() const { return flags_ == 0; }
  71. bool operator!=(AXMode rhs) const { return !(*this == rhs); }
  72. AXMode& operator|=(const AXMode& rhs) {
  73. flags_ |= rhs.flags_;
  74. return *this;
  75. }
  76. std::string ToString() const;
  77. // IMPORTANT!
  78. // These values are written to logs. Do not renumber or delete
  79. // existing items; add new entries to the end of the list.
  80. enum class ModeFlagHistogramValue {
  81. UMA_AX_MODE_NATIVE_APIS = 0,
  82. UMA_AX_MODE_WEB_CONTENTS = 1,
  83. UMA_AX_MODE_INLINE_TEXT_BOXES = 2,
  84. UMA_AX_MODE_SCREEN_READER = 3,
  85. UMA_AX_MODE_HTML = 4,
  86. UMA_AX_MODE_HTML_METADATA = 5,
  87. UMA_AX_MODE_LABEL_IMAGES = 6,
  88. UMA_AX_MODE_PDF = 7,
  89. // This must always be the last enum. It's okay for its value to
  90. // increase, but none of the other enum values may change.
  91. UMA_AX_MODE_MAX
  92. };
  93. private:
  94. uint32_t flags_;
  95. };
  96. // Used when an AT that only require basic accessibility information, such as
  97. // a dictation tool, is present.
  98. static constexpr AXMode kAXModeBasic(AXMode::kNativeAPIs |
  99. AXMode::kWebContents);
  100. // Used when complete accessibility access is desired but a third-party AT is
  101. // not present.
  102. static constexpr AXMode kAXModeWebContentsOnly(AXMode::kWebContents |
  103. AXMode::kInlineTextBoxes |
  104. AXMode::kScreenReader |
  105. AXMode::kHTML);
  106. // Used when an AT that requires full accessibility access, such as a screen
  107. // reader, is present.
  108. static constexpr AXMode kAXModeComplete(AXMode::kNativeAPIs |
  109. AXMode::kWebContents |
  110. AXMode::kInlineTextBoxes |
  111. AXMode::kScreenReader | AXMode::kHTML);
  112. // Similar to kAXModeComplete, used when an AT that requires full accessibility
  113. // access, but does not need all HTML properties or attributes.
  114. static constexpr AXMode kAXModeCompleteNoHTML(AXMode::kNativeAPIs |
  115. AXMode::kWebContents |
  116. AXMode::kInlineTextBoxes |
  117. AXMode::kScreenReader);
  118. // For debugging, test assertions, etc.
  119. AX_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
  120. const AXMode& mode);
  121. } // namespace ui
  122. #endif // UI_ACCESSIBILITY_AX_MODE_H_