Fix: warnings in media/capture/filters
[platform/framework/web/chromium-efl.git] / pdf / accessibility_structs.h
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.
4
5 #ifndef PDF_ACCESSIBILITY_STRUCTS_H_
6 #define PDF_ACCESSIBILITY_STRUCTS_H_
7
8 #include <stdint.h>
9
10 #include <string>
11 #include <vector>
12
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"
17
18 namespace chrome_pdf {
19
20 struct AccessibilityDocInfo {
21   bool operator==(const AccessibilityDocInfo& other) const;
22   bool operator!=(const AccessibilityDocInfo& other) const;
23
24   uint32_t page_count = 0;
25   bool text_accessible = false;
26   bool text_copyable = false;
27 };
28
29 struct AccessibilityPageInfo {
30   uint32_t page_index = 0;
31   gfx::Rect bounds;
32   uint32_t text_run_count = 0;
33   uint32_t char_count = 0;
34 };
35
36 // See PDF Reference 1.7, page 402, table 5.3.
37 enum class AccessibilityTextRenderMode {
38   kUnknown = -1,
39   kFill = 0,
40   kStroke = 1,
41   kFillStroke = 2,
42   kInvisible = 3,
43   kFillClip = 4,
44   kStrokeClip = 5,
45   kFillStrokeClip = 6,
46   kClip = 7,
47   kMaxValue = kClip,
48 };
49
50 struct AccessibilityTextStyleInfo {
51   AccessibilityTextStyleInfo();
52   AccessibilityTextStyleInfo(const std::string& font_name,
53                              int font_weight,
54                              AccessibilityTextRenderMode render_mode,
55                              float font_size,
56                              uint32_t fill_color,
57                              uint32_t stroke_color,
58                              bool is_italic,
59                              bool is_bold);
60   AccessibilityTextStyleInfo(const AccessibilityTextStyleInfo& other);
61   ~AccessibilityTextStyleInfo();
62
63   std::string font_name;
64   int font_weight = 0;
65   AccessibilityTextRenderMode render_mode =
66       AccessibilityTextRenderMode::kUnknown;
67   float font_size = 0.0f;
68   // Colors are ARGB.
69   uint32_t fill_color = 0;
70   uint32_t stroke_color = 0;
71   bool is_italic = false;
72   bool is_bold = false;
73 };
74
75 enum class AccessibilityTextDirection {
76   kNone = 0,
77   kLeftToRight = 1,
78   kRightToLeft = 2,
79   kTopToBottom = 3,
80   kBottomToTop = 4,
81   kMaxValue = kBottomToTop,
82 };
83
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();
92
93   uint32_t len = 0;
94   gfx::RectF bounds;
95   AccessibilityTextDirection direction = AccessibilityTextDirection::kNone;
96   AccessibilityTextStyleInfo style;
97 };
98
99 struct AccessibilityCharInfo {
100   uint32_t unicode_character = 0;
101   double char_width = 0.0;
102 };
103
104 struct AccessibilityTextRunRangeInfo {
105   // Index of the starting text run of the annotation in the collection of all
106   // text runs in the page.
107   size_t index = 0;
108   // Count of the text runs spanning the annotation.
109   uint32_t count = 0;
110 };
111
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();
120
121   // URL of the link.
122   std::string url;
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.
126   gfx::RectF bounds;
127   AccessibilityTextRunRangeInfo text_range;
128 };
129
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();
138
139   // Alternate text for the image provided by PDF.
140   std::string alt_text;
141
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;
146
147   // Bounding box of the image.
148   gfx::RectF bounds;
149
150   // Index of the image object in its page.
151   int32_t page_object_index;
152 };
153
154 struct AccessibilityHighlightInfo {
155   AccessibilityHighlightInfo();
156   AccessibilityHighlightInfo(const std::string& note_text,
157                              uint32_t index_in_page,
158                              uint32_t color,
159                              const gfx::RectF& bounds,
160                              const AccessibilityTextRunRangeInfo& text_range);
161   AccessibilityHighlightInfo(const AccessibilityHighlightInfo& other);
162   ~AccessibilityHighlightInfo();
163
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.
170   uint32_t color = 0;
171   // Bounding box of the highlight.
172   gfx::RectF bounds;
173   AccessibilityTextRunRangeInfo text_range;
174 };
175
176 struct AccessibilityTextFieldInfo {
177   AccessibilityTextFieldInfo();
178   AccessibilityTextFieldInfo(const std::string& name,
179                              const std::string& value,
180                              bool is_read_only,
181                              bool is_required,
182                              bool is_password,
183                              uint32_t index_in_page,
184                              uint32_t text_run_index,
185                              const gfx::RectF& bounds);
186   AccessibilityTextFieldInfo(const AccessibilityTextFieldInfo& other);
187   ~AccessibilityTextFieldInfo();
188
189   // Represents the name property of text field, if present.
190   std::string name;
191   // Represents the value property of text field, if present.
192   std::string value;
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.
206   gfx::RectF bounds;
207 };
208
209 struct AccessibilityChoiceFieldOptionInfo {
210   // Represents the name property of choice field option.
211   std::string name;
212   // Represents if a choice field option is selected or not.
213   bool is_selected = false;
214   // Bounding box of the choice field option.
215   gfx::RectF bounds;
216 };
217
218 enum class ChoiceFieldType {
219   kListBox = 0,
220   kComboBox = 1,
221   kMinValue = kListBox,
222   kMaxValue = kComboBox,
223 };
224
225 struct AccessibilityChoiceFieldInfo {
226   AccessibilityChoiceFieldInfo();
227   AccessibilityChoiceFieldInfo(
228       const std::string& name,
229       const std::vector<AccessibilityChoiceFieldOptionInfo>& options,
230       ChoiceFieldType type,
231       bool is_read_only,
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();
239
240   // Represents the name property of choice field, if present.
241   std::string name;
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
253   // page.
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
257   // tree.
258   uint32_t text_run_index = 0;
259   // Bounding box of the choice field.
260   gfx::RectF bounds;
261 };
262
263 enum class ButtonType {
264   kPushButton = 1,
265   kCheckBox = 2,
266   kRadioButton = 3,
267   kMinValue = kPushButton,
268   kMaxValue = kRadioButton,
269 };
270
271 struct AccessibilityButtonInfo {
272   AccessibilityButtonInfo();
273   AccessibilityButtonInfo(const std::string& name,
274                           const std::string& value,
275                           ButtonType type,
276                           bool is_read_only,
277                           bool is_checked,
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();
285
286   // Represents the name property of button, if present.
287   std::string name;
288   // Represents the value property of button, if present.
289   std::string value;
290   // Represents the button type.
291   ButtonType 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
305   // `control_count`.
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.
313   gfx::RectF bounds;
314 };
315
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();
324
325   std::vector<AccessibilityTextFieldInfo> text_fields;
326   std::vector<AccessibilityChoiceFieldInfo> choice_fields;
327   std::vector<AccessibilityButtonInfo> buttons;
328 };
329
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();
339
340   std::vector<AccessibilityLinkInfo> links;
341   std::vector<AccessibilityImageInfo> images;
342   std::vector<AccessibilityHighlightInfo> highlights;
343   AccessibilityFormFieldInfo form_fields;
344 };
345
346 enum class FocusObjectType {
347   kNone = 0,
348   kDocument = 1,
349   kLink = 2,
350   kHighlight = 3,
351   kTextField = 4,
352   kMaxValue = kTextField,
353 };
354
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;
359 };
360
361 struct AccessibilityViewportInfo {
362   double zoom = 0.0;
363   double scale = 0.0;
364   gfx::Point scroll;
365   gfx::Point offset;
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;
371 };
372
373 enum class AccessibilityAction {
374   // No action specified.
375   kNone = 0,
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.
383   kSetSelection = 4,
384   // Last enum value marker.
385   kMaxValue = kSetSelection,
386 };
387
388 enum class AccessibilityAnnotationType {
389   // No annotation type defined.
390   kNone = 0,
391   // Link annotation.
392   kLink = 1,
393   // Last enum value marker.
394   kMaxValue = kLink,
395 };
396
397 enum class AccessibilityScrollAlignment {
398   // No scroll alignment specified.
399   kNone = 0,
400   // Scroll the point to the center of the viewport.
401   kCenter,
402   // Scroll the point to the top of the viewport.
403   kTop,
404   // Scroll the point to the bottom of the viewport.
405   kBottom,
406   // Scroll the point to the left of the viewport.
407   kLeft,
408   // Scroll the point to the right of the viewport.
409   kRight,
410   // Scroll the point to the closest edge of the viewport.
411   kClosestToEdge,
412   // Last enum value marker.
413   kMaxValue = kClosestToEdge,
414 };
415
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;
421 };
422
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,
431       uint32_t page_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();
438
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;
462 };
463
464 }  // namespace chrome_pdf
465
466 #endif  // PDF_ACCESSIBILITY_STRUCTS_H_