accessibility_structs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. // Copyright 2020 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 PDF_ACCESSIBILITY_STRUCTS_H_
  5. #define PDF_ACCESSIBILITY_STRUCTS_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "third_party/skia/include/core/SkBitmap.h"
  10. #include "ui/gfx/geometry/point.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. #include "ui/gfx/geometry/rect_f.h"
  13. namespace chrome_pdf {
  14. struct AccessibilityDocInfo {
  15. bool operator==(const AccessibilityDocInfo& other) const;
  16. bool operator!=(const AccessibilityDocInfo& other) const;
  17. uint32_t page_count = 0;
  18. bool text_accessible = false;
  19. bool text_copyable = false;
  20. };
  21. struct AccessibilityPageInfo {
  22. uint32_t page_index = 0;
  23. gfx::Rect bounds;
  24. uint32_t text_run_count = 0;
  25. uint32_t char_count = 0;
  26. };
  27. // See PDF Reference 1.7, page 402, table 5.3.
  28. enum class AccessibilityTextRenderMode {
  29. kUnknown = -1,
  30. kFill = 0,
  31. kStroke = 1,
  32. kFillStroke = 2,
  33. kInvisible = 3,
  34. kFillClip = 4,
  35. kStrokeClip = 5,
  36. kFillStrokeClip = 6,
  37. kClip = 7,
  38. kMaxValue = kClip,
  39. };
  40. struct AccessibilityTextStyleInfo {
  41. AccessibilityTextStyleInfo();
  42. AccessibilityTextStyleInfo(const std::string& font_name,
  43. int font_weight,
  44. AccessibilityTextRenderMode render_mode,
  45. float font_size,
  46. uint32_t fill_color,
  47. uint32_t stroke_color,
  48. bool is_italic,
  49. bool is_bold);
  50. AccessibilityTextStyleInfo(const AccessibilityTextStyleInfo& other);
  51. ~AccessibilityTextStyleInfo();
  52. std::string font_name;
  53. int font_weight = 0;
  54. AccessibilityTextRenderMode render_mode =
  55. AccessibilityTextRenderMode::kUnknown;
  56. float font_size = 0.0f;
  57. // Colors are ARGB.
  58. uint32_t fill_color = 0;
  59. uint32_t stroke_color = 0;
  60. bool is_italic = false;
  61. bool is_bold = false;
  62. };
  63. enum class AccessibilityTextDirection {
  64. kNone = 0,
  65. kLeftToRight = 1,
  66. kRightToLeft = 2,
  67. kTopToBottom = 3,
  68. kBottomToTop = 4,
  69. kMaxValue = kBottomToTop,
  70. };
  71. struct AccessibilityTextRunInfo {
  72. AccessibilityTextRunInfo();
  73. AccessibilityTextRunInfo(uint32_t len,
  74. const gfx::RectF& bounds,
  75. AccessibilityTextDirection direction,
  76. const AccessibilityTextStyleInfo& style);
  77. AccessibilityTextRunInfo(const AccessibilityTextRunInfo& other);
  78. ~AccessibilityTextRunInfo();
  79. uint32_t len = 0;
  80. gfx::RectF bounds;
  81. AccessibilityTextDirection direction = AccessibilityTextDirection::kNone;
  82. AccessibilityTextStyleInfo style;
  83. };
  84. struct AccessibilityCharInfo {
  85. uint32_t unicode_character = 0;
  86. double char_width = 0.0;
  87. };
  88. struct AccessibilityTextRunRangeInfo {
  89. // Index of the starting text run of the annotation in the collection of all
  90. // text runs in the page.
  91. size_t index = 0;
  92. // Count of the text runs spanning the annotation.
  93. uint32_t count = 0;
  94. };
  95. struct AccessibilityLinkInfo {
  96. AccessibilityLinkInfo();
  97. AccessibilityLinkInfo(const std::string& url,
  98. uint32_t index_in_page,
  99. const gfx::RectF& bounds,
  100. const AccessibilityTextRunRangeInfo& text_range);
  101. AccessibilityLinkInfo(const AccessibilityLinkInfo& other);
  102. ~AccessibilityLinkInfo();
  103. // URL of the link.
  104. std::string url;
  105. // Index of this link in the collection of links in the page.
  106. uint32_t index_in_page = 0;
  107. // Bounding box of the link.
  108. gfx::RectF bounds;
  109. AccessibilityTextRunRangeInfo text_range;
  110. };
  111. struct AccessibilityImageInfo {
  112. AccessibilityImageInfo();
  113. AccessibilityImageInfo(const std::string& alt_text,
  114. uint32_t text_run_index,
  115. const gfx::RectF& bounds,
  116. const SkBitmap& image_data);
  117. AccessibilityImageInfo(const AccessibilityImageInfo& other);
  118. ~AccessibilityImageInfo();
  119. // Alternate text for the image provided by PDF.
  120. std::string alt_text;
  121. // We anchor the image to a char index, this denotes the text run before
  122. // which the image should be inserted in the accessibility tree. The text run
  123. // at this index should contain the anchor char index.
  124. uint32_t text_run_index = 0;
  125. // Bounding box of the image.
  126. gfx::RectF bounds;
  127. // Only populated if `alt_text` is empty or unavailable, and if the user has
  128. // requested that the OCR service tag the PDF so that it is made accessible.
  129. SkBitmap image_data;
  130. };
  131. struct AccessibilityHighlightInfo {
  132. AccessibilityHighlightInfo();
  133. AccessibilityHighlightInfo(const std::string& note_text,
  134. uint32_t index_in_page,
  135. uint32_t color,
  136. const gfx::RectF& bounds,
  137. const AccessibilityTextRunRangeInfo& text_range);
  138. AccessibilityHighlightInfo(const AccessibilityHighlightInfo& other);
  139. ~AccessibilityHighlightInfo();
  140. // Represents the text of the associated popup note, if present.
  141. std::string note_text;
  142. // Index of this highlight in the collection of highlights in the page.
  143. uint32_t index_in_page = 0;
  144. // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
  145. // follows after it with each using 8 bytes.
  146. uint32_t color = 0;
  147. // Bounding box of the highlight.
  148. gfx::RectF bounds;
  149. AccessibilityTextRunRangeInfo text_range;
  150. };
  151. struct AccessibilityTextFieldInfo {
  152. AccessibilityTextFieldInfo();
  153. AccessibilityTextFieldInfo(const std::string& name,
  154. const std::string& value,
  155. bool is_read_only,
  156. bool is_required,
  157. bool is_password,
  158. uint32_t index_in_page,
  159. uint32_t text_run_index,
  160. const gfx::RectF& bounds);
  161. AccessibilityTextFieldInfo(const AccessibilityTextFieldInfo& other);
  162. ~AccessibilityTextFieldInfo();
  163. // Represents the name property of text field, if present.
  164. std::string name;
  165. // Represents the value property of text field, if present.
  166. std::string value;
  167. // Represents if the text field is non-editable.
  168. bool is_read_only = false;
  169. // Represents if the field should have value at the time it is exported by a
  170. // submit form action.
  171. bool is_required = false;
  172. // Represents if the text field is a password text field type.
  173. bool is_password = false;
  174. // Index of this text field in the collection of text fields in the page.
  175. uint32_t index_in_page = 0;
  176. // We anchor the text field to a text run index, this denotes the text run
  177. // before which the text field should be inserted in the accessibility tree.
  178. uint32_t text_run_index = 0;
  179. // Bounding box of the text field.
  180. gfx::RectF bounds;
  181. };
  182. struct AccessibilityChoiceFieldOptionInfo {
  183. // Represents the name property of choice field option.
  184. std::string name;
  185. // Represents if a choice field option is selected or not.
  186. bool is_selected = false;
  187. // Bounding box of the choice field option.
  188. gfx::RectF bounds;
  189. };
  190. enum class ChoiceFieldType {
  191. kListBox = 0,
  192. kComboBox = 1,
  193. kMinValue = kListBox,
  194. kMaxValue = kComboBox,
  195. };
  196. struct AccessibilityChoiceFieldInfo {
  197. AccessibilityChoiceFieldInfo();
  198. AccessibilityChoiceFieldInfo(
  199. const std::string& name,
  200. const std::vector<AccessibilityChoiceFieldOptionInfo>& options,
  201. ChoiceFieldType type,
  202. bool is_read_only,
  203. bool is_multi_select,
  204. bool has_editable_text_box,
  205. uint32_t index_in_page,
  206. uint32_t text_run_index,
  207. const gfx::RectF& bounds);
  208. AccessibilityChoiceFieldInfo(const AccessibilityChoiceFieldInfo& other);
  209. ~AccessibilityChoiceFieldInfo();
  210. // Represents the name property of choice field, if present.
  211. std::string name;
  212. // Represents list of options in choice field, if present.
  213. std::vector<AccessibilityChoiceFieldOptionInfo> options;
  214. // Represents type of choice field.
  215. ChoiceFieldType type;
  216. // Represents if the choice field is non-editable.
  217. bool is_read_only = false;
  218. // Represents if the choice field is multi-selectable.
  219. bool is_multi_select = false;
  220. // Represents if the choice field includes an editable text box.
  221. bool has_editable_text_box = false;
  222. // Index of this choice field in the collection of choice fields in the
  223. // page.
  224. uint32_t index_in_page = 0;
  225. // We anchor the choice field to a text run index, this denotes the text run
  226. // before which the choice field should be inserted in the accessibility
  227. // tree.
  228. uint32_t text_run_index = 0;
  229. // Bounding box of the choice field.
  230. gfx::RectF bounds;
  231. };
  232. enum class ButtonType {
  233. kPushButton = 1,
  234. kCheckBox = 2,
  235. kRadioButton = 3,
  236. kMinValue = kPushButton,
  237. kMaxValue = kRadioButton,
  238. };
  239. struct AccessibilityButtonInfo {
  240. AccessibilityButtonInfo();
  241. AccessibilityButtonInfo(const std::string& name,
  242. const std::string& value,
  243. ButtonType type,
  244. bool is_read_only,
  245. bool is_checked,
  246. uint32_t control_count,
  247. uint32_t control_index,
  248. uint32_t index_in_page,
  249. uint32_t text_run_index,
  250. const gfx::RectF& bounds);
  251. AccessibilityButtonInfo(const AccessibilityButtonInfo& other);
  252. ~AccessibilityButtonInfo();
  253. // Represents the name property of button, if present.
  254. std::string name;
  255. // Represents the value property of button, if present.
  256. std::string value;
  257. // Represents the button type.
  258. ButtonType type;
  259. // Represents if the button is non-editable.
  260. bool is_read_only = false;
  261. // Represents if the radio button or check box is checked or not.
  262. bool is_checked = false;
  263. // Represents count of controls in the control group. A group of interactive
  264. // form annotations is collectively called a form control group. Here, an
  265. // interactive form annotation, should be either a radio button or a
  266. // checkbox. Value of `control_count` is >= 1.
  267. uint32_t control_count = 0;
  268. // Represents index of the control in the control group. A group of
  269. // interactive form annotations is collectively called a form control group.
  270. // Here, an interactive form annotation, should be either a radio button or
  271. // a checkbox. Value of `control_index` should always be less than
  272. // `control_count`.
  273. uint32_t control_index = 0;
  274. // Index of this button in the collection of buttons in the page.
  275. uint32_t index_in_page = 0;
  276. // We anchor the button to a text run index, this denotes the text run
  277. // before which the button should be inserted in the accessibility tree.
  278. uint32_t text_run_index = 0;
  279. // Bounding box of the button.
  280. gfx::RectF bounds;
  281. };
  282. struct AccessibilityFormFieldInfo {
  283. AccessibilityFormFieldInfo();
  284. AccessibilityFormFieldInfo(
  285. const std::vector<AccessibilityTextFieldInfo>& text_fields,
  286. const std::vector<AccessibilityChoiceFieldInfo>& choice_fields,
  287. const std::vector<AccessibilityButtonInfo>& buttons);
  288. AccessibilityFormFieldInfo(const AccessibilityFormFieldInfo& other);
  289. ~AccessibilityFormFieldInfo();
  290. std::vector<AccessibilityTextFieldInfo> text_fields;
  291. std::vector<AccessibilityChoiceFieldInfo> choice_fields;
  292. std::vector<AccessibilityButtonInfo> buttons;
  293. };
  294. struct AccessibilityPageObjects {
  295. AccessibilityPageObjects();
  296. AccessibilityPageObjects(
  297. const std::vector<AccessibilityLinkInfo>& links,
  298. const std::vector<AccessibilityImageInfo>& images,
  299. const std::vector<AccessibilityHighlightInfo>& highlights,
  300. const AccessibilityFormFieldInfo& form_fields);
  301. AccessibilityPageObjects(const AccessibilityPageObjects& other);
  302. ~AccessibilityPageObjects();
  303. std::vector<AccessibilityLinkInfo> links;
  304. std::vector<AccessibilityImageInfo> images;
  305. std::vector<AccessibilityHighlightInfo> highlights;
  306. AccessibilityFormFieldInfo form_fields;
  307. };
  308. enum class FocusObjectType {
  309. kNone = 0,
  310. kDocument = 1,
  311. kLink = 2,
  312. kHighlight = 3,
  313. kTextField = 4,
  314. kMaxValue = kTextField,
  315. };
  316. struct AccessibilityFocusInfo {
  317. FocusObjectType focused_object_type = FocusObjectType::kNone;
  318. uint32_t focused_object_page_index = 0;
  319. uint32_t focused_annotation_index_in_page = 0;
  320. };
  321. struct AccessibilityViewportInfo {
  322. double zoom = 0.0;
  323. double scale = 0.0;
  324. gfx::Point scroll;
  325. gfx::Point offset;
  326. uint32_t selection_start_page_index = 0;
  327. uint32_t selection_start_char_index = 0;
  328. uint32_t selection_end_page_index = 0;
  329. uint32_t selection_end_char_index = 0;
  330. AccessibilityFocusInfo focus_info;
  331. };
  332. enum class AccessibilityAction {
  333. // No action specified.
  334. kNone = 0,
  335. // Invoke the rect to scroll into the viewport.
  336. kScrollToMakeVisible = 1,
  337. // Invoke the default action on a node.
  338. kDoDefaultAction = 2,
  339. // Invoke the global point to scroll into the viewport.
  340. kScrollToGlobalPoint = 3,
  341. // Set the text selection.
  342. kSetSelection = 4,
  343. // Last enum value marker.
  344. kMaxValue = kSetSelection,
  345. };
  346. enum class AccessibilityAnnotationType {
  347. // No annotation type defined.
  348. kNone = 0,
  349. // Link annotation.
  350. kLink = 1,
  351. // Last enum value marker.
  352. kMaxValue = kLink,
  353. };
  354. enum class AccessibilityScrollAlignment {
  355. // No scroll alignment specified.
  356. kNone = 0,
  357. // Scroll the point to the center of the viewport.
  358. kCenter,
  359. // Scroll the point to the top of the viewport.
  360. kTop,
  361. // Scroll the point to the bottom of the viewport.
  362. kBottom,
  363. // Scroll the point to the left of the viewport.
  364. kLeft,
  365. // Scroll the point to the right of the viewport.
  366. kRight,
  367. // Scroll the point to the closest edge of the viewport.
  368. kClosestToEdge,
  369. // Last enum value marker.
  370. kMaxValue = kClosestToEdge,
  371. };
  372. struct PageCharacterIndex {
  373. // Index of PDF page.
  374. uint32_t page_index = 0;
  375. // Index of character within the PDF page.
  376. uint32_t char_index = 0;
  377. };
  378. struct AccessibilityActionData {
  379. AccessibilityActionData();
  380. AccessibilityActionData(
  381. AccessibilityAction action,
  382. AccessibilityAnnotationType annotation_type,
  383. const gfx::Point& target_point,
  384. const gfx::Rect& target_rect,
  385. uint32_t annotation_index,
  386. uint32_t page_index,
  387. AccessibilityScrollAlignment horizontal_scroll_alignment,
  388. AccessibilityScrollAlignment vertical_scroll_alignment,
  389. const PageCharacterIndex& selection_start_index,
  390. const PageCharacterIndex& selection_end_index);
  391. AccessibilityActionData(const AccessibilityActionData& other);
  392. ~AccessibilityActionData();
  393. // Accessibility action type.
  394. AccessibilityAction action = AccessibilityAction::kNone;
  395. // Annotation type on which the action is to be performed.
  396. AccessibilityAnnotationType annotation_type =
  397. AccessibilityAnnotationType::kNone;
  398. // Target point on which the action is to be performed.
  399. gfx::Point target_point;
  400. // Target rect on which the action is to be performed.
  401. gfx::Rect target_rect;
  402. // Index of annotation in page.
  403. uint32_t annotation_index = 0;
  404. // Page index on which the link is present.
  405. uint32_t page_index = 0;
  406. // Horizontal scroll alignment with respect to the viewport
  407. AccessibilityScrollAlignment horizontal_scroll_alignment =
  408. AccessibilityScrollAlignment::kNone;
  409. // Vertical scroll alignment with respect to the viewport
  410. AccessibilityScrollAlignment vertical_scroll_alignment =
  411. AccessibilityScrollAlignment::kNone;
  412. // Page and character index of start of selection.
  413. PageCharacterIndex selection_start_index;
  414. // Page and character index of exclusive end of selection.
  415. PageCharacterIndex selection_end_index;
  416. };
  417. } // namespace chrome_pdf
  418. #endif // PDF_ACCESSIBILITY_STRUCTS_H_