| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversion_utils.h" | 9 #include "base/strings/utf_string_conversion_utils.h" |
| 10 #include "components/pdf/renderer/pdf_accessibility_tree.h" | 10 #include "components/pdf/renderer/pdf_accessibility_tree.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 gfx::RectF ToGfxRectF(const PP_FloatRect& r) { | 38 gfx::RectF ToGfxRectF(const PP_FloatRect& r) { |
| 39 return gfx::RectF(r.point.x, r.point.y, r.size.width, r.size.height); | 39 return gfx::RectF(r.point.x, r.point.y, r.size.width, r.size.height); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } | 42 } |
| 43 | 43 |
| 44 PdfAccessibilityTree::PdfAccessibilityTree( | 44 PdfAccessibilityTree::PdfAccessibilityTree( |
| 45 content::RenderView* render_view) | 45 content::RenderView* render_view) |
| 46 : render_view_(render_view), | 46 : render_view_(render_view), |
| 47 render_accessibility_(nullptr), | |
| 48 zoom_(1.0) { | 47 zoom_(1.0) { |
| 49 content::RenderFrame* render_frame = render_view->GetMainRenderFrame(); | |
| 50 render_accessibility_ = render_frame->GetRenderAccessibility(); | |
| 51 } | 48 } |
| 52 | 49 |
| 53 PdfAccessibilityTree::~PdfAccessibilityTree() { | 50 PdfAccessibilityTree::~PdfAccessibilityTree() { |
| 54 } | 51 } |
| 55 | 52 |
| 56 void PdfAccessibilityTree::SetAccessibilityViewportInfo( | 53 void PdfAccessibilityTree::SetAccessibilityViewportInfo( |
| 57 const PP_PrivateAccessibilityViewportInfo& viewport_info) { | 54 const PP_PrivateAccessibilityViewportInfo& viewport_info) { |
| 58 zoom_ = viewport_info.zoom; | 55 zoom_ = viewport_info.zoom; |
| 59 CHECK_GT(zoom_, 0); | 56 CHECK_GT(zoom_, 0); |
| 60 scroll_ = ToVector2dF(viewport_info.scroll); | 57 scroll_ = ToVector2dF(viewport_info.scroll); |
| 61 scroll_.Scale(1.0 / zoom_); | 58 scroll_.Scale(1.0 / zoom_); |
| 62 offset_ = ToVector2dF(viewport_info.offset); | 59 offset_ = ToVector2dF(viewport_info.offset); |
| 63 offset_.Scale(1.0 / zoom_); | 60 offset_.Scale(1.0 / zoom_); |
| 64 } | 61 } |
| 65 | 62 |
| 66 void PdfAccessibilityTree::SetAccessibilityDocInfo( | 63 void PdfAccessibilityTree::SetAccessibilityDocInfo( |
| 67 const PP_PrivateAccessibilityDocInfo& doc_info) { | 64 const PP_PrivateAccessibilityDocInfo& doc_info) { |
| 68 doc_info_ = doc_info; | 65 doc_info_ = doc_info; |
| 69 doc_node_ = CreateNode(ui::AX_ROLE_GROUP); | 66 doc_node_ = CreateNode(ui::AX_ROLE_GROUP); |
| 70 } | 67 } |
| 71 | 68 |
| 72 void PdfAccessibilityTree::SetAccessibilityPageInfo( | 69 void PdfAccessibilityTree::SetAccessibilityPageInfo( |
| 73 const PP_PrivateAccessibilityPageInfo& page_info, | 70 const PP_PrivateAccessibilityPageInfo& page_info, |
| 74 const std::vector<PP_PrivateAccessibilityTextRunInfo>& text_runs, | 71 const std::vector<PP_PrivateAccessibilityTextRunInfo>& text_runs, |
| 75 const std::vector<PP_PrivateAccessibilityCharInfo>& chars) { | 72 const std::vector<PP_PrivateAccessibilityCharInfo>& chars) { |
| 73 content::RenderFrame* render_frame = render_view_->GetMainRenderFrame(); |
| 74 content::RenderAccessibility* render_accessibility = |
| 75 render_frame->GetRenderAccessibility(); |
| 76 if (!render_accessibility) |
| 77 return; |
| 78 |
| 76 uint32_t page_index = page_info.page_index; | 79 uint32_t page_index = page_info.page_index; |
| 77 CHECK_GE(page_index, 0U); | 80 CHECK_GE(page_index, 0U); |
| 78 CHECK_LT(page_index, doc_info_.page_count); | 81 CHECK_LT(page_index, doc_info_.page_count); |
| 79 | 82 |
| 80 ui::AXNodeData* page_node = CreateNode(ui::AX_ROLE_REGION); | 83 ui::AXNodeData* page_node = CreateNode(ui::AX_ROLE_REGION); |
| 81 page_node->AddStringAttribute( | 84 page_node->AddStringAttribute( |
| 82 ui::AX_ATTR_NAME, | 85 ui::AX_ATTR_NAME, |
| 83 l10n_util::GetPluralStringFUTF8( | 86 l10n_util::GetPluralStringFUTF8( |
| 84 IDS_PDF_PAGE_INDEX, page_index + 1)); | 87 IDS_PDF_PAGE_INDEX, page_index + 1)); |
| 85 | 88 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 Finish(); | 167 Finish(); |
| 165 } | 168 } |
| 166 | 169 |
| 167 void PdfAccessibilityTree::Finish() { | 170 void PdfAccessibilityTree::Finish() { |
| 168 ui::AXTreeUpdate update; | 171 ui::AXTreeUpdate update; |
| 169 update.root_id = doc_node_->id; | 172 update.root_id = doc_node_->id; |
| 170 for (const auto& node : nodes_) | 173 for (const auto& node : nodes_) |
| 171 update.nodes.push_back(*node); | 174 update.nodes.push_back(*node); |
| 172 | 175 |
| 173 CHECK(tree_.Unserialize(update)) << update.ToString() << tree_.error(); | 176 CHECK(tree_.Unserialize(update)) << update.ToString() << tree_.error(); |
| 174 render_accessibility_->SetPdfTreeSource(this); | 177 content::RenderFrame* render_frame = render_view_->GetMainRenderFrame(); |
| 178 content::RenderAccessibility* render_accessibility = |
| 179 render_frame->GetRenderAccessibility(); |
| 180 if (render_accessibility) |
| 181 render_accessibility->SetPdfTreeSource(this); |
| 175 } | 182 } |
| 176 | 183 |
| 177 void PdfAccessibilityTree::ComputeParagraphAndHeadingThresholds( | 184 void PdfAccessibilityTree::ComputeParagraphAndHeadingThresholds( |
| 178 const std::vector<PP_PrivateAccessibilityTextRunInfo>& text_runs, | 185 const std::vector<PP_PrivateAccessibilityTextRunInfo>& text_runs, |
| 179 double* out_heading_font_size_threshold, | 186 double* out_heading_font_size_threshold, |
| 180 double* out_line_spacing_threshold) { | 187 double* out_line_spacing_threshold) { |
| 181 // Scan over the font sizes and line spacing within this page and | 188 // Scan over the font sizes and line spacing within this page and |
| 182 // set heuristic thresholds so that text larger than the median font | 189 // set heuristic thresholds so that text larger than the median font |
| 183 // size can be marked as a heading, and spacing larger than the median | 190 // size can be marked as a heading, and spacing larger than the median |
| 184 // line spacing can be a paragraph break. | 191 // line spacing can be a paragraph break. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 245 |
| 239 gfx::Vector2dF PdfAccessibilityTree::ToVector2dF(const PP_Point& p) { | 246 gfx::Vector2dF PdfAccessibilityTree::ToVector2dF(const PP_Point& p) { |
| 240 return gfx::Vector2dF(p.x, p.y); | 247 return gfx::Vector2dF(p.x, p.y); |
| 241 } | 248 } |
| 242 | 249 |
| 243 gfx::RectF PdfAccessibilityTree::ToRectF(const PP_Rect& r) { | 250 gfx::RectF PdfAccessibilityTree::ToRectF(const PP_Rect& r) { |
| 244 return gfx::RectF(r.point.x, r.point.y, r.size.width, r.size.height); | 251 return gfx::RectF(r.point.x, r.point.y, r.size.width, r.size.height); |
| 245 } | 252 } |
| 246 | 253 |
| 247 ui::AXNodeData* PdfAccessibilityTree::CreateNode(ui::AXRole role) { | 254 ui::AXNodeData* PdfAccessibilityTree::CreateNode(ui::AXRole role) { |
| 255 content::RenderFrame* render_frame = render_view_->GetMainRenderFrame(); |
| 256 content::RenderAccessibility* render_accessibility = |
| 257 render_frame->GetRenderAccessibility(); |
| 258 |
| 248 ui::AXNodeData* node = new ui::AXNodeData(); | 259 ui::AXNodeData* node = new ui::AXNodeData(); |
| 249 node->id = render_accessibility_->GenerateAXID(); | 260 node->id = render_accessibility->GenerateAXID(); |
| 250 node->role = role; | 261 node->role = role; |
| 251 node->state = 1 << ui::AX_STATE_ENABLED | 1 << ui::AX_STATE_READ_ONLY; | 262 node->state = 1 << ui::AX_STATE_ENABLED | 1 << ui::AX_STATE_READ_ONLY; |
| 252 nodes_.push_back(base::WrapUnique(node)); | 263 nodes_.push_back(base::WrapUnique(node)); |
| 253 return node; | 264 return node; |
| 254 } | 265 } |
| 255 | 266 |
| 256 float PdfAccessibilityTree::GetDeviceScaleFactor() const { | 267 float PdfAccessibilityTree::GetDeviceScaleFactor() const { |
| 257 return render_view_->GetDeviceScaleFactor(); | 268 return render_view_->GetDeviceScaleFactor(); |
| 258 } | 269 } |
| 259 | 270 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 const ui::AXNode* PdfAccessibilityTree::GetNull() const { | 311 const ui::AXNode* PdfAccessibilityTree::GetNull() const { |
| 301 return nullptr; | 312 return nullptr; |
| 302 } | 313 } |
| 303 | 314 |
| 304 void PdfAccessibilityTree::SerializeNode( | 315 void PdfAccessibilityTree::SerializeNode( |
| 305 const ui::AXNode* node, ui::AXNodeData* out_data) const { | 316 const ui::AXNode* node, ui::AXNodeData* out_data) const { |
| 306 *out_data = node->data(); | 317 *out_data = node->data(); |
| 307 } | 318 } |
| 308 | 319 |
| 309 } // namespace pdf | 320 } // namespace pdf |
| OLD | NEW |