Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: content/browser/accessibility/browser_accessibility.cc

Issue 1768753003: Implemented the reporting of text style and language information on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated to using HashTable from base and GetInheritedStringAttribute instead of specialized methods… Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility.h" 5 #include "content/browser/accessibility/browser_accessibility.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 uint32_t child_index) const { 223 uint32_t child_index) const {
224 if (!node_ || !manager_ || child_index >= InternalChildCount()) 224 if (!node_ || !manager_ || child_index >= InternalChildCount())
225 return nullptr; 225 return nullptr;
226 226
227 const auto child_node = node_->ChildAtIndex(child_index); 227 const auto child_node = node_->ChildAtIndex(child_index);
228 DCHECK(child_node); 228 DCHECK(child_node);
229 return manager_->GetFromAXNode(child_node); 229 return manager_->GetFromAXNode(child_node);
230 } 230 }
231 231
232 BrowserAccessibility* BrowserAccessibility::GetParent() const { 232 BrowserAccessibility* BrowserAccessibility::GetParent() const {
233 if (!node_ || !manager_) 233 if (!instance_active())
234 return NULL; 234 return nullptr;
235
235 ui::AXNode* parent = node_->parent(); 236 ui::AXNode* parent = node_->parent();
236 if (parent) 237 if (parent)
237 return manager_->GetFromAXNode(parent); 238 return manager_->GetFromAXNode(parent);
238 239
239 return manager_->GetParentNodeFromParentTree(); 240 return manager_->GetParentNodeFromParentTree();
240 } 241 }
241 242
242 BrowserAccessibility* BrowserAccessibility::InternalGetParent() const { 243 BrowserAccessibility* BrowserAccessibility::InternalGetParent() const {
243 if (!node_ || !manager_) 244 if (!node_ || !manager_)
244 return nullptr; 245 return nullptr;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (child_end < start) 356 if (child_end < start)
356 continue; 357 continue;
357 358
358 int overlap_start = std::max(start, child_start); 359 int overlap_start = std::max(start, child_start);
359 int overlap_end = std::min(end, child_end); 360 int overlap_end = std::min(end, child_end);
360 361
361 int local_start = overlap_start - child_start; 362 int local_start = overlap_start - child_start;
362 int local_end = overlap_end - child_start; 363 int local_end = overlap_end - child_start;
363 364
364 gfx::Rect child_rect = child->GetLocation(); 365 gfx::Rect child_rect = child->GetLocation();
365 int text_direction = child->GetIntAttribute( 366 auto text_direction = static_cast<ui::AXTextDirection>(
366 ui::AX_ATTR_TEXT_DIRECTION); 367 child->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION));
367 const std::vector<int32_t>& character_offsets = 368 const std::vector<int32_t>& character_offsets =
368 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); 369 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS);
369 int start_pixel_offset = 370 int start_pixel_offset =
370 local_start > 0 ? character_offsets[local_start - 1] : 0; 371 local_start > 0 ? character_offsets[local_start - 1] : 0;
371 int end_pixel_offset = 372 int end_pixel_offset =
372 local_end > 0 ? character_offsets[local_end - 1] : 0; 373 local_end > 0 ? character_offsets[local_end - 1] : 0;
373 374
374 gfx::Rect child_overlap_rect; 375 gfx::Rect child_overlap_rect;
375 switch (text_direction) { 376 switch (text_direction) {
376 case ui::AX_TEXT_DIRECTION_NONE: 377 case ui::AX_TEXT_DIRECTION_NONE:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 float BrowserAccessibility::GetFloatAttribute( 625 float BrowserAccessibility::GetFloatAttribute(
625 ui::AXFloatAttribute attribute) const { 626 ui::AXFloatAttribute attribute) const {
626 return GetData().GetFloatAttribute(attribute); 627 return GetData().GetFloatAttribute(attribute);
627 } 628 }
628 629
629 bool BrowserAccessibility::GetFloatAttribute( 630 bool BrowserAccessibility::GetFloatAttribute(
630 ui::AXFloatAttribute attribute, float* value) const { 631 ui::AXFloatAttribute attribute, float* value) const {
631 return GetData().GetFloatAttribute(attribute, value); 632 return GetData().GetFloatAttribute(attribute, value);
632 } 633 }
633 634
635 bool BrowserAccessibility::HasInheritedStringAttribute(
636 ui::AXStringAttribute attribute) const {
637 if (!instance_active())
638 return false;
639
640 if (GetData().HasStringAttribute(attribute))
641 return true;
642 return GetParent() && GetParent()->HasInheritedStringAttribute(attribute);
643 }
644
645 std::string BrowserAccessibility::GetInheritedStringAttribute(
646 ui::AXStringAttribute attribute) const {
647 if (!instance_active())
648 return std::string();
649
650 std::string value;
651 if (GetInheritedStringAttribute(attribute, &value))
652 return value;
653 return std::string();
654 }
655
656 bool BrowserAccessibility::GetInheritedStringAttribute(
657 ui::AXStringAttribute attribute,
658 std::string* value) const {
659 if (!instance_active()) {
660 *value = std::string();
661 return false;
662 }
663
664 if (GetData().GetStringAttribute(attribute, value))
665 return true;
666 return GetParent() &&
667 GetParent()->GetData().GetStringAttribute(attribute, value);
668 }
669
670 base::string16 BrowserAccessibility::GetInheritedString16Attribute(
671 ui::AXStringAttribute attribute) const {
672 if (!instance_active())
673 return base::string16();
674
675 base::string16 value;
676 if (GetInheritedString16Attribute(attribute, &value))
677 return value;
678 return base::string16();
679 }
680
681 bool BrowserAccessibility::GetInheritedString16Attribute(
682 ui::AXStringAttribute attribute,
683 base::string16* value) const {
684 if (!instance_active()) {
685 *value = base::string16();
686 return false;
687 }
688
689 if (GetData().GetString16Attribute(attribute, value))
690 return true;
691 return GetParent() &&
692 GetParent()->GetData().GetString16Attribute(attribute, value);
693 }
694
634 bool BrowserAccessibility::HasIntAttribute( 695 bool BrowserAccessibility::HasIntAttribute(
635 ui::AXIntAttribute attribute) const { 696 ui::AXIntAttribute attribute) const {
636 return GetData().HasIntAttribute(attribute); 697 return GetData().HasIntAttribute(attribute);
637 } 698 }
638 699
639 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const { 700 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const {
640 return GetData().GetIntAttribute(attribute); 701 return GetData().GetIntAttribute(attribute);
641 } 702 }
642 703
643 bool BrowserAccessibility::GetIntAttribute( 704 bool BrowserAccessibility::GetIntAttribute(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 base::string16 BrowserAccessibility::GetInnerText() const { 903 base::string16 BrowserAccessibility::GetInnerText() const {
843 if (IsTextOnlyObject()) 904 if (IsTextOnlyObject())
844 return GetString16Attribute(ui::AX_ATTR_NAME); 905 return GetString16Attribute(ui::AX_ATTR_NAME);
845 906
846 base::string16 text; 907 base::string16 text;
847 for (size_t i = 0; i < InternalChildCount(); ++i) 908 for (size_t i = 0; i < InternalChildCount(); ++i)
848 text += InternalGetChild(i)->GetInnerText(); 909 text += InternalGetChild(i)->GetInnerText();
849 return text; 910 return text;
850 } 911 }
851 912
913 // static
914 // TODO(nektar): Figure out if there is an existing Skia function to use
dmazzoni 2016/03/07 23:38:10 You can use SkColorGetR, etc. from SkColor.h
915 // instead.
916 void BrowserAccessibility::RGBAToColorValues(unsigned int color,
917 unsigned int* red,
918 unsigned int* green,
919 unsigned int* blue,
920 unsigned int* alpha) {
921 DCHECK(red && green && blue && alpha);
922 *alpha = (color >> 24) & 0xFF;
923 *red = (color >> 16) & 0xFF;
924 *green = (color >> 8) & 0xFF;
925 *blue = color & 0xFF;
926 }
927
852 void BrowserAccessibility::FixEmptyBounds(gfx::Rect* bounds) const 928 void BrowserAccessibility::FixEmptyBounds(gfx::Rect* bounds) const
853 { 929 {
854 if (bounds->width() > 0 && bounds->height() > 0) 930 if (bounds->width() > 0 && bounds->height() > 0)
855 return; 931 return;
856 932
857 for (size_t i = 0; i < InternalChildCount(); ++i) { 933 for (size_t i = 0; i < InternalChildCount(); ++i) {
858 // Compute the bounds of each child - this calls FixEmptyBounds 934 // Compute the bounds of each child - this calls FixEmptyBounds
859 // recursively if necessary. 935 // recursively if necessary.
860 BrowserAccessibility* child = InternalGetChild(i); 936 BrowserAccessibility* child = InternalGetChild(i);
861 gfx::Rect child_bounds = child->GetLocalBoundsRect(); 937 gfx::Rect child_bounds = child->GetLocalBoundsRect();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 } 985 }
910 need_to_offset_web_area = true; 986 need_to_offset_web_area = true;
911 } 987 }
912 parent = parent->GetParent(); 988 parent = parent->GetParent();
913 } 989 }
914 990
915 return bounds; 991 return bounds;
916 } 992 }
917 993
918 } // namespace content 994 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698