| // Copyright 2020 The Chromium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef PDF_ACCESSIBILITY_STRUCTS_H_ | |
| #define PDF_ACCESSIBILITY_STRUCTS_H_ | |
| #include <stdint.h> | |
| #include <string> | |
| #include <vector> | |
| #include "base/memory/raw_ptr.h" | |
| #include "pdf/page_character_index.h" | |
| #include "pdf/pdf_accessibility_constants.h" | |
| #include "ui/gfx/geometry/point.h" | |
| #include "ui/gfx/geometry/point_f.h" | |
| #include "ui/gfx/geometry/rect.h" | |
| #include "ui/gfx/geometry/rect_f.h" | |
| namespace chrome_pdf { | |
| struct Selection { | |
| PageCharacterIndex start; | |
| PageCharacterIndex end; | |
| }; | |
| // See PDF Reference 1.7, page 402, table 5.3. | |
| enum class AccessibilityTextRenderMode { | |
| kUnknown = -1, | |
| kFill = 0, | |
| kStroke = 1, | |
| kFillStroke = 2, | |
| kInvisible = 3, | |
| kFillClip = 4, | |
| kStrokeClip = 5, | |
| kFillStrokeClip = 6, | |
| kClip = 7, | |
| kMaxValue = kClip, | |
| }; | |
| struct AccessibilityTextStyleInfo { | |
| AccessibilityTextStyleInfo(); | |
| AccessibilityTextStyleInfo(const std::string& font_name, | |
| int font_weight, | |
| AccessibilityTextRenderMode render_mode, | |
| float font_size, | |
| uint32_t fill_color, | |
| uint32_t stroke_color, | |
| bool is_italic); | |
| AccessibilityTextStyleInfo(const AccessibilityTextStyleInfo& other); | |
| ~AccessibilityTextStyleInfo(); | |
| std::string font_name; | |
| int font_weight = 0; | |
| AccessibilityTextRenderMode render_mode = | |
| AccessibilityTextRenderMode::kUnknown; | |
| float font_size = 0.0f; | |
| // Colors are ARGB. | |
| uint32_t fill_color = 0; | |
| uint32_t stroke_color = 0; | |
| bool is_italic = false; | |
| }; | |
| enum class AccessibilityTextDirection { | |
| kNone = 0, | |
| kLeftToRight = 1, | |
| kRightToLeft = 2, | |
| kTopToBottom = 3, | |
| kBottomToTop = 4, | |
| kMaxValue = kBottomToTop, | |
| }; | |
| // A consecutive range of text run indices not associated with any structure | |
| // element, inclusive of both `start` and `end`. | |
| struct UnassociatedTextRunRange { | |
| size_t start; | |
| size_t end; | |
| }; | |
| struct AccessibilityTextRunInfo { | |
| AccessibilityTextRunInfo(); | |
| AccessibilityTextRunInfo(uint32_t start_index, | |
| uint32_t len, | |
| const gfx::RectF& bounds, | |
| AccessibilityTextDirection direction, | |
| const AccessibilityTextStyleInfo& style); | |
| AccessibilityTextRunInfo(const AccessibilityTextRunInfo& other); | |
| ~AccessibilityTextRunInfo(); | |
| uint32_t start_index = 0; | |
| uint32_t len = 0; | |
| gfx::RectF bounds; | |
| AccessibilityTextDirection direction = AccessibilityTextDirection::kNone; | |
| AccessibilityTextStyleInfo style; | |
| bool is_searchified = false; | |
| std::string language; | |
| }; | |
| struct AccessibilityImageInfo { | |
| AccessibilityImageInfo(); | |
| AccessibilityImageInfo(const std::string& alt_text, | |
| uint32_t text_run_index, | |
| const gfx::RectF& bounds, | |
| int32_t page_object_index); | |
| AccessibilityImageInfo(const AccessibilityImageInfo& other); | |
| ~AccessibilityImageInfo(); | |
| // Alternate text for the image provided by PDF. | |
| // TODO(crbug.com/40707542): Remove in favor of AccessibilityStructureElement. | |
| std::string alt_text; | |
| // We anchor the image to a char index, this denotes the text run before | |
| // which the image should be inserted in the accessibility tree. The text run | |
| // at this index should contain the anchor char index. | |
| uint32_t text_run_index = 0; | |
| // Bounding box of the image. | |
| gfx::RectF bounds; | |
| // Index of the image object in its page. | |
| int32_t page_object_index = 0; | |
| }; | |
| // Represents a node in the PDF's structure tree. This tree represents the | |
| // logical organization of the text inside the PDF, e.g. when data is placed in | |
| // a table, or points are placed inside a bulleted list. This should result in | |
| // additional “structural nodes” to be added to the accessibility tree or | |
| // existing nodes to get new accessibility roles / attributes. | |
| struct AccessibilityStructureElement { | |
| AccessibilityStructureElement(); | |
| AccessibilityStructureElement(const AccessibilityStructureElement&) = delete; | |
| AccessibilityStructureElement& operator=( | |
| const AccessibilityStructureElement&) = delete; | |
| ~AccessibilityStructureElement(); | |
| // Trailing comments indicate corresponding PDF spec dictionary keys. | |
| PdfTagType type = PdfTagType::kNone; // /S | |
| std::string language; // /Lang | |
| std::string alt_text; // /Alt | |
| std::string abbreviation_expansion; // /E | |
| std::string actual_text; // /ActualText | |
| std::vector<raw_ptr<AccessibilityTextRunInfo, VectorExperimental>> | |
| associated_text_runs_if_available; | |
| std::unique_ptr<AccessibilityImageInfo> associated_image_if_available; | |
| // Only used on the node which is the root of a PDF page: ranges of text runs | |
| // within a page that are not associated with a structured element. These text | |
| // runs form "unstructured" text within a page that will need to be | |
| // interleaved with structured content. | |
| std::vector<UnassociatedTextRunRange> unassociated_text_run_ranges_for_page; | |
| std::vector<std::unique_ptr<AccessibilityStructureElement>> children; | |
| raw_ptr<AccessibilityStructureElement> parent = nullptr; | |
| }; | |
| struct AccessibilityDocInfo { | |
| AccessibilityDocInfo(); | |
| AccessibilityDocInfo(const AccessibilityDocInfo&) = delete; | |
| AccessibilityDocInfo& operator=(const AccessibilityDocInfo&) = delete; | |
| ~AccessibilityDocInfo(); | |
| friend bool operator==(const AccessibilityDocInfo&, | |
| const AccessibilityDocInfo&) = default; | |
| uint32_t page_count = 0; | |
| bool is_tagged = false; | |
| std::unique_ptr<AccessibilityStructureElement> structure_tree_root; | |
| bool text_accessible = false; | |
| bool text_copyable = false; | |
| std::string language; | |
| }; | |
| struct AccessibilityPageInfo { | |
| uint32_t page_index = 0; | |
| gfx::Rect bounds; | |
| uint32_t text_run_count = 0; | |
| uint32_t char_count = 0; | |
| bool is_searchified = false; | |
| }; | |
| struct AccessibilityCharInfo { | |
| uint32_t unicode_character = 0; | |
| double char_width = 0.0; | |
| }; | |
| struct AccessibilityTextRunRangeInfo { | |
| // Index of the starting text run of the annotation in the collection of all | |
| // text runs in the page. | |
| size_t index = 0; | |
| // Count of the text runs spanning the annotation. | |
| uint32_t count = 0; | |
| }; | |
| struct AccessibilityLinkInfo { | |
| AccessibilityLinkInfo(); | |
| AccessibilityLinkInfo(const std::string& url, | |
| uint32_t index_in_page, | |
| const gfx::RectF& bounds, | |
| const AccessibilityTextRunRangeInfo& text_range); | |
| AccessibilityLinkInfo(const AccessibilityLinkInfo& other); | |
| ~AccessibilityLinkInfo(); | |
| // URL of the link. | |
| std::string url; | |
| // Index of this link in the collection of links in the page. | |
| uint32_t index_in_page = 0; | |
| // Bounding box of the link. | |
| gfx::RectF bounds; | |
| AccessibilityTextRunRangeInfo text_range; | |
| }; | |
| struct AccessibilityHighlightInfo { | |
| AccessibilityHighlightInfo(); | |
| AccessibilityHighlightInfo(const std::string& note_text, | |
| uint32_t index_in_page, | |
| uint32_t color, | |
| const gfx::RectF& bounds, | |
| const AccessibilityTextRunRangeInfo& text_range); | |
| AccessibilityHighlightInfo(const AccessibilityHighlightInfo& other); | |
| ~AccessibilityHighlightInfo(); | |
| // Represents the text of the associated popup note, if present. | |
| std::string note_text; | |
| // Index of this highlight in the collection of highlights in the page. | |
| uint32_t index_in_page = 0; | |
| // Color of the highlight in ARGB. Alpha is stored in the first 8 MSBs. RGB | |
| // follows after it with each using 8 bytes. | |
| uint32_t color = 0; | |
| // Bounding box of the highlight. | |
| gfx::RectF bounds; | |
| AccessibilityTextRunRangeInfo text_range; | |
| }; | |
| // Represents a composite graphic (a PDF Form XObject, such as a chart or | |
| // diagram) that combines graphical primitives with embedded visible text, as | |
| // opposed to `AccessibilityImageInfo`, which represents a single bitmap image | |
| // object. | |
| struct AccessibilityFormGraphicInfo { | |
| // Bounding box of the graphic. | |
| gfx::RectF bounds; | |
| AccessibilityTextRunRangeInfo text_range; | |
| }; | |
| // A straight line segment stroked on a page, such as a table border, column | |
| // divider, or decorative separator, in the same pixel coordinates as | |
| // `AccessibilityTextRunInfo::bounds`. | |
| struct AccessibilityLineSegment { | |
| friend bool operator==(const AccessibilityLineSegment&, | |
| const AccessibilityLineSegment&) = default; | |
| gfx::PointF start; | |
| gfx::PointF end; | |
| }; | |
| struct AccessibilityPageObjects { | |
| AccessibilityPageObjects(); | |
| AccessibilityPageObjects(const AccessibilityPageObjects& other); | |
| ~AccessibilityPageObjects(); | |
| std::vector<AccessibilityLinkInfo> links; | |
| std::vector<AccessibilityImageInfo> images; | |
| std::vector<AccessibilityHighlightInfo> highlights; | |
| std::vector<AccessibilityFormGraphicInfo> graphics; | |
| std::vector<AccessibilityLineSegment> line_segments; | |
| // Filled axis-aligned rectangles, in the same pixel coordinates as | |
| // `AccessibilityTextRunInfo::bounds`. | |
| std::vector<gfx::RectF> filled_rects; | |
| }; | |
| struct AccessibilityViewportInfo { | |
| AccessibilityViewportInfo(); | |
| AccessibilityViewportInfo(const AccessibilityViewportInfo& other); | |
| ~AccessibilityViewportInfo(); | |
| double zoom = 0.0; | |
| double scale = 0.0; | |
| gfx::Point scroll; | |
| gfx::Point offset; | |
| Selection selection; | |
| }; | |
| enum class AccessibilityAction { | |
| // No action specified. | |
| kNone = 0, | |
| // Invoke the rect to scroll into the viewport. | |
| kScrollToMakeVisible = 1, | |
| // Invoke the default action on a node. | |
| kDoDefaultAction = 2, | |
| // Invoke the global point to scroll into the viewport. | |
| kScrollToGlobalPoint = 3, | |
| // Set the text selection. | |
| kSetSelection = 4, | |
| // Last enum value marker. | |
| kMaxValue = kSetSelection, | |
| }; | |
| enum class AccessibilityAnnotationType { | |
| // No annotation type defined. | |
| kNone = 0, | |
| // Link annotation. | |
| kLink = 1, | |
| // Last enum value marker. | |
| kMaxValue = kLink, | |
| }; | |
| enum class AccessibilityScrollAlignment { | |
| // No scroll alignment specified. | |
| kNone = 0, | |
| // Scroll the point to the center of the viewport. | |
| kCenter, | |
| // Scroll the point to the top of the viewport. | |
| kTop, | |
| // Scroll the point to the bottom of the viewport. | |
| kBottom, | |
| // Scroll the point to the left of the viewport. | |
| kLeft, | |
| // Scroll the point to the right of the viewport. | |
| kRight, | |
| // Scroll the point to the closest edge of the viewport. | |
| kClosestToEdge, | |
| // Last enum value marker. | |
| kMaxValue = kClosestToEdge, | |
| }; | |
| struct AccessibilityActionData { | |
| AccessibilityActionData(); | |
| AccessibilityActionData(const AccessibilityActionData& other); | |
| ~AccessibilityActionData(); | |
| // Accessibility action type. | |
| AccessibilityAction action = AccessibilityAction::kNone; | |
| // Annotation type on which the action is to be performed. | |
| AccessibilityAnnotationType annotation_type = | |
| AccessibilityAnnotationType::kNone; | |
| // Target point on which the action is to be performed. | |
| gfx::Point target_point; | |
| // Target rect on which the action is to be performed. | |
| gfx::Rect target_rect; | |
| // Index of annotation in page. | |
| uint32_t annotation_index = 0; | |
| // Page index on which the link is present. | |
| uint32_t page_index = 0; | |
| // Horizontal scroll alignment with respect to the viewport | |
| AccessibilityScrollAlignment horizontal_scroll_alignment = | |
| AccessibilityScrollAlignment::kNone; | |
| // Vertical scroll alignment with respect to the viewport | |
| AccessibilityScrollAlignment vertical_scroll_alignment = | |
| AccessibilityScrollAlignment::kNone; | |
| // Page and character index of start of selection. | |
| PageCharacterIndex selection_start_index; | |
| // Page and character index of exclusive end of selection. | |
| PageCharacterIndex selection_end_index; | |
| }; | |
| } // namespace chrome_pdf | |
| #endif // PDF_ACCESSIBILITY_STRUCTS_H_ |