1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PDF_ACCESSIBILITY_STRUCTS_H_
6 #define PDF_ACCESSIBILITY_STRUCTS_H_
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/rect_f.h"
18 namespace chrome_pdf {
20 struct AccessibilityDocInfo {
21 bool operator==(const AccessibilityDocInfo& other) const;
22 bool operator!=(const AccessibilityDocInfo& other) const;
24 uint32_t page_count = 0;
25 bool text_accessible = false;
26 bool text_copyable = false;
29 struct AccessibilityPageInfo {
30 uint32_t page_index = 0;
32 uint32_t text_run_count = 0;
33 uint32_t char_count = 0;
36 // See PDF Reference 1.7, page 402, table 5.3.
37 enum class AccessibilityTextRenderMode {
50 struct AccessibilityTextStyleInfo {
51 AccessibilityTextStyleInfo();
52 AccessibilityTextStyleInfo(const std::string& font_name,
54 AccessibilityTextRenderMode render_mode,
57 uint32_t stroke_color,
60 AccessibilityTextStyleInfo(const AccessibilityTextStyleInfo& other);
61 ~AccessibilityTextStyleInfo();
63 std::string font_name;
65 AccessibilityTextRenderMode render_mode =
66 AccessibilityTextRenderMode::kUnknown;
67 float font_size = 0.0f;
69 uint32_t fill_color = 0;
70 uint32_t stroke_color = 0;
71 bool is_italic = false;
75 enum class AccessibilityTextDirection {
81 kMaxValue = kBottomToTop,
84 struct AccessibilityTextRunInfo {
85 AccessibilityTextRunInfo();
86 AccessibilityTextRunInfo(uint32_t len,
87 const gfx::RectF& bounds,
88 AccessibilityTextDirection direction,
89 const AccessibilityTextStyleInfo& style);
90 AccessibilityTextRunInfo(const AccessibilityTextRunInfo& other);
91 ~AccessibilityTextRunInfo();
95 AccessibilityTextDirection direction = AccessibilityTextDirection::kNone;
96 AccessibilityTextStyleInfo style;
99 struct AccessibilityCharInfo {
100 uint32_t unicode_character = 0;
101 double char_width = 0.0;
104 struct AccessibilityTextRunRangeInfo {
105 // Index of the starting text run of the annotation in the collection of all
106 // text runs in the page.
108 // Count of the text runs spanning the annotation.
112 struct AccessibilityLinkInfo {
113 AccessibilityLinkInfo();
114 AccessibilityLinkInfo(const std::string& url,
115 uint32_t index_in_page,
116 const gfx::RectF& bounds,
117 const AccessibilityTextRunRangeInfo& text_range);
118 AccessibilityLinkInfo(const AccessibilityLinkInfo& other);
119 ~AccessibilityLinkInfo();
123 // Index of this link in the collection of links in the page.
124 uint32_t index_in_page = 0;
125 // Bounding box of the link.
127 AccessibilityTextRunRangeInfo text_range;
130 struct AccessibilityImageInfo {
131 AccessibilityImageInfo();
132 AccessibilityImageInfo(const std::string& alt_text,
133 uint32_t text_run_index,
134 const gfx::RectF& bounds,
135 int32_t page_object_index);
136 AccessibilityImageInfo(const AccessibilityImageInfo& other);
137 ~AccessibilityImageInfo();
139 // Alternate text for the image provided by PDF.
140 std::string alt_text;
142 // We anchor the image to a char index, this denotes the text run before
143 // which the image should be inserted in the accessibility tree. The text run
144 // at this index should contain the anchor char index.
145 uint32_t text_run_index = 0;
147 // Bounding box of the image.
150 // Index of the image object in its page.
151 int32_t page_object_index;
154 struct AccessibilityHighlightInfo {
155 AccessibilityHighlightInfo();
156 AccessibilityHighlightInfo(const std::string& note_text,
157 uint32_t index_in_page,
159 const gfx::RectF& bounds,
160 const AccessibilityTextRunRangeInfo& text_range);
161 AccessibilityHighlightInfo(const AccessibilityHighlightInfo& other);
162 ~AccessibilityHighlightInfo();
164 // Represents the text of the associated popup note, if present.
165 std::string note_text;
166 // Index of this highlight in the collection of highlights in the page.
167 uint32_t index_in_page = 0;
168 // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB
169 // follows after it with each using 8 bytes.
171 // Bounding box of the highlight.
173 AccessibilityTextRunRangeInfo text_range;
176 struct AccessibilityTextFieldInfo {
177 AccessibilityTextFieldInfo();
178 AccessibilityTextFieldInfo(const std::string& name,
179 const std::string& value,
183 uint32_t index_in_page,
184 uint32_t text_run_index,
185 const gfx::RectF& bounds);
186 AccessibilityTextFieldInfo(const AccessibilityTextFieldInfo& other);
187 ~AccessibilityTextFieldInfo();
189 // Represents the name property of text field, if present.
191 // Represents the value property of text field, if present.
193 // Represents if the text field is non-editable.
194 bool is_read_only = false;
195 // Represents if the field should have value at the time it is exported by a
196 // submit form action.
197 bool is_required = false;
198 // Represents if the text field is a password text field type.
199 bool is_password = false;
200 // Index of this text field in the collection of text fields in the page.
201 uint32_t index_in_page = 0;
202 // We anchor the text field to a text run index, this denotes the text run
203 // before which the text field should be inserted in the accessibility tree.
204 uint32_t text_run_index = 0;
205 // Bounding box of the text field.
209 struct AccessibilityChoiceFieldOptionInfo {
210 // Represents the name property of choice field option.
212 // Represents if a choice field option is selected or not.
213 bool is_selected = false;
214 // Bounding box of the choice field option.
218 enum class ChoiceFieldType {
221 kMinValue = kListBox,
222 kMaxValue = kComboBox,
225 struct AccessibilityChoiceFieldInfo {
226 AccessibilityChoiceFieldInfo();
227 AccessibilityChoiceFieldInfo(
228 const std::string& name,
229 const std::vector<AccessibilityChoiceFieldOptionInfo>& options,
230 ChoiceFieldType type,
232 bool is_multi_select,
233 bool has_editable_text_box,
234 uint32_t index_in_page,
235 uint32_t text_run_index,
236 const gfx::RectF& bounds);
237 AccessibilityChoiceFieldInfo(const AccessibilityChoiceFieldInfo& other);
238 ~AccessibilityChoiceFieldInfo();
240 // Represents the name property of choice field, if present.
242 // Represents list of options in choice field, if present.
243 std::vector<AccessibilityChoiceFieldOptionInfo> options;
244 // Represents type of choice field.
245 ChoiceFieldType type;
246 // Represents if the choice field is non-editable.
247 bool is_read_only = false;
248 // Represents if the choice field is multi-selectable.
249 bool is_multi_select = false;
250 // Represents if the choice field includes an editable text box.
251 bool has_editable_text_box = false;
252 // Index of this choice field in the collection of choice fields in the
254 uint32_t index_in_page = 0;
255 // We anchor the choice field to a text run index, this denotes the text run
256 // before which the choice field should be inserted in the accessibility
258 uint32_t text_run_index = 0;
259 // Bounding box of the choice field.
263 enum class ButtonType {
267 kMinValue = kPushButton,
268 kMaxValue = kRadioButton,
271 struct AccessibilityButtonInfo {
272 AccessibilityButtonInfo();
273 AccessibilityButtonInfo(const std::string& name,
274 const std::string& value,
278 uint32_t control_count,
279 uint32_t control_index,
280 uint32_t index_in_page,
281 uint32_t text_run_index,
282 const gfx::RectF& bounds);
283 AccessibilityButtonInfo(const AccessibilityButtonInfo& other);
284 ~AccessibilityButtonInfo();
286 // Represents the name property of button, if present.
288 // Represents the value property of button, if present.
290 // Represents the button type.
292 // Represents if the button is non-editable.
293 bool is_read_only = false;
294 // Represents if the radio button or check box is checked or not.
295 bool is_checked = false;
296 // Represents count of controls in the control group. A group of interactive
297 // form annotations is collectively called a form control group. Here, an
298 // interactive form annotation, should be either a radio button or a
299 // checkbox. Value of `control_count` is >= 1.
300 uint32_t control_count = 0;
301 // Represents index of the control in the control group. A group of
302 // interactive form annotations is collectively called a form control group.
303 // Here, an interactive form annotation, should be either a radio button or
304 // a checkbox. Value of `control_index` should always be less than
306 uint32_t control_index = 0;
307 // Index of this button in the collection of buttons in the page.
308 uint32_t index_in_page = 0;
309 // We anchor the button to a text run index, this denotes the text run
310 // before which the button should be inserted in the accessibility tree.
311 uint32_t text_run_index = 0;
312 // Bounding box of the button.
316 struct AccessibilityFormFieldInfo {
317 AccessibilityFormFieldInfo();
318 AccessibilityFormFieldInfo(
319 const std::vector<AccessibilityTextFieldInfo>& text_fields,
320 const std::vector<AccessibilityChoiceFieldInfo>& choice_fields,
321 const std::vector<AccessibilityButtonInfo>& buttons);
322 AccessibilityFormFieldInfo(const AccessibilityFormFieldInfo& other);
323 ~AccessibilityFormFieldInfo();
325 std::vector<AccessibilityTextFieldInfo> text_fields;
326 std::vector<AccessibilityChoiceFieldInfo> choice_fields;
327 std::vector<AccessibilityButtonInfo> buttons;
330 struct AccessibilityPageObjects {
331 AccessibilityPageObjects();
332 AccessibilityPageObjects(
333 const std::vector<AccessibilityLinkInfo>& links,
334 const std::vector<AccessibilityImageInfo>& images,
335 const std::vector<AccessibilityHighlightInfo>& highlights,
336 const AccessibilityFormFieldInfo& form_fields);
337 AccessibilityPageObjects(const AccessibilityPageObjects& other);
338 ~AccessibilityPageObjects();
340 std::vector<AccessibilityLinkInfo> links;
341 std::vector<AccessibilityImageInfo> images;
342 std::vector<AccessibilityHighlightInfo> highlights;
343 AccessibilityFormFieldInfo form_fields;
346 enum class FocusObjectType {
352 kMaxValue = kTextField,
355 struct AccessibilityFocusInfo {
356 FocusObjectType focused_object_type = FocusObjectType::kNone;
357 uint32_t focused_object_page_index = 0;
358 uint32_t focused_annotation_index_in_page = 0;
361 struct AccessibilityViewportInfo {
366 uint32_t selection_start_page_index = 0;
367 uint32_t selection_start_char_index = 0;
368 uint32_t selection_end_page_index = 0;
369 uint32_t selection_end_char_index = 0;
370 AccessibilityFocusInfo focus_info;
373 enum class AccessibilityAction {
374 // No action specified.
376 // Invoke the rect to scroll into the viewport.
377 kScrollToMakeVisible = 1,
378 // Invoke the default action on a node.
379 kDoDefaultAction = 2,
380 // Invoke the global point to scroll into the viewport.
381 kScrollToGlobalPoint = 3,
382 // Set the text selection.
384 // Last enum value marker.
385 kMaxValue = kSetSelection,
388 enum class AccessibilityAnnotationType {
389 // No annotation type defined.
393 // Last enum value marker.
397 enum class AccessibilityScrollAlignment {
398 // No scroll alignment specified.
400 // Scroll the point to the center of the viewport.
402 // Scroll the point to the top of the viewport.
404 // Scroll the point to the bottom of the viewport.
406 // Scroll the point to the left of the viewport.
408 // Scroll the point to the right of the viewport.
410 // Scroll the point to the closest edge of the viewport.
412 // Last enum value marker.
413 kMaxValue = kClosestToEdge,
416 struct PageCharacterIndex {
417 // Index of PDF page.
418 uint32_t page_index = 0;
419 // Index of character within the PDF page.
420 uint32_t char_index = 0;
423 struct AccessibilityActionData {
424 AccessibilityActionData();
425 AccessibilityActionData(
426 AccessibilityAction action,
427 AccessibilityAnnotationType annotation_type,
428 const gfx::Point& target_point,
429 const gfx::Rect& target_rect,
430 uint32_t annotation_index,
432 AccessibilityScrollAlignment horizontal_scroll_alignment,
433 AccessibilityScrollAlignment vertical_scroll_alignment,
434 const PageCharacterIndex& selection_start_index,
435 const PageCharacterIndex& selection_end_index);
436 AccessibilityActionData(const AccessibilityActionData& other);
437 ~AccessibilityActionData();
439 // Accessibility action type.
440 AccessibilityAction action = AccessibilityAction::kNone;
441 // Annotation type on which the action is to be performed.
442 AccessibilityAnnotationType annotation_type =
443 AccessibilityAnnotationType::kNone;
444 // Target point on which the action is to be performed.
445 gfx::Point target_point;
446 // Target rect on which the action is to be performed.
447 gfx::Rect target_rect;
448 // Index of annotation in page.
449 uint32_t annotation_index = 0;
450 // Page index on which the link is present.
451 uint32_t page_index = 0;
452 // Horizontal scroll alignment with respect to the viewport
453 AccessibilityScrollAlignment horizontal_scroll_alignment =
454 AccessibilityScrollAlignment::kNone;
455 // Vertical scroll alignment with respect to the viewport
456 AccessibilityScrollAlignment vertical_scroll_alignment =
457 AccessibilityScrollAlignment::kNone;
458 // Page and character index of start of selection.
459 PageCharacterIndex selection_start_index;
460 // Page and character index of exclusive end of selection.
461 PageCharacterIndex selection_end_index;
464 } // namespace chrome_pdf
466 #endif // PDF_ACCESSIBILITY_STRUCTS_H_