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

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

Issue 848653002: Re-land: Send Windows accessibility events based on tree updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implicit_1_tests
Patch Set: Remove logging Created 5 years, 11 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 20 matching lines...) Expand all
31 31
32 BrowserAccessibility::~BrowserAccessibility() { 32 BrowserAccessibility::~BrowserAccessibility() {
33 } 33 }
34 34
35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, 35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager,
36 ui::AXNode* node) { 36 ui::AXNode* node) {
37 manager_ = manager; 37 manager_ = manager;
38 node_ = node; 38 node_ = node;
39 } 39 }
40 40
41 void BrowserAccessibility::OnDataChanged() {
42 GetStringAttribute(ui::AX_ATTR_NAME, &name_);
43 GetStringAttribute(ui::AX_ATTR_VALUE, &value_);
44 }
45
46 bool BrowserAccessibility::PlatformIsLeaf() const { 41 bool BrowserAccessibility::PlatformIsLeaf() const {
47 if (InternalChildCount() == 0) 42 if (InternalChildCount() == 0)
48 return true; 43 return true;
49 44
50 // All of these roles may have children that we use as internal 45 // All of these roles may have children that we use as internal
51 // implementation details, but we want to expose them as leaves 46 // implementation details, but we want to expose them as leaves
52 // to platform accessibility APIs. 47 // to platform accessibility APIs.
53 switch (GetRole()) { 48 switch (GetRole()) {
54 case ui::AX_ROLE_LINE_BREAK: 49 case ui::AX_ROLE_LINE_BREAK:
55 case ui::AX_ROLE_SLIDER: 50 case ui::AX_ROLE_SLIDER:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) { 84 if (result->HasBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST)) {
90 BrowserAccessibilityManager* child_manager = 85 BrowserAccessibilityManager* child_manager =
91 manager_->delegate()->AccessibilityGetChildFrame(result->GetId()); 86 manager_->delegate()->AccessibilityGetChildFrame(result->GetId());
92 if (child_manager) 87 if (child_manager)
93 result = child_manager->GetRoot(); 88 result = child_manager->GetRoot();
94 } 89 }
95 90
96 return result; 91 return result;
97 } 92 }
98 93
94 bool BrowserAccessibility::PlatformIsChildOfLeaf() const {
aboxhall 2015/01/22 21:22:09 Is this something we could or should reasonably ca
dmazzoni 2015/01/23 23:26:13 Worth considering! Right now our bottlenecks are m
95 BrowserAccessibility* ancestor = GetParent();
96 while (ancestor) {
97 if (ancestor->PlatformIsLeaf())
98 return true;
99 ancestor = ancestor->GetParent();
100 }
101
102 return false;
103 }
104
99 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { 105 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() {
100 if (GetParent() && GetIndexInParent() > 0) 106 if (GetParent() && GetIndexInParent() > 0)
101 return GetParent()->InternalGetChild(GetIndexInParent() - 1); 107 return GetParent()->InternalGetChild(GetIndexInParent() - 1);
102 108
103 return NULL; 109 return NULL;
104 } 110 }
105 111
106 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { 112 BrowserAccessibility* BrowserAccessibility::GetNextSibling() {
107 if (GetParent() && 113 if (GetParent() &&
108 GetIndexInParent() >= 0 && 114 GetIndexInParent() >= 0 &&
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (descendant_result) 383 if (descendant_result)
378 return descendant_result; 384 return descendant_result;
379 if (child_result) 385 if (child_result)
380 return child_result; 386 return child_result;
381 387
382 return this; 388 return this;
383 } 389 }
384 390
385 void BrowserAccessibility::Destroy() { 391 void BrowserAccessibility::Destroy() {
386 // Allow the object to fire a TextRemoved notification. 392 // Allow the object to fire a TextRemoved notification.
387 name_.clear();
388 value_.clear();
389
390 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); 393 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this);
391 node_ = NULL; 394 node_ = NULL;
392 manager_ = NULL; 395 manager_ = NULL;
393 396
394 NativeReleaseReference(); 397 NativeReleaseReference();
395 } 398 }
396 399
397 void BrowserAccessibility::NativeReleaseReference() { 400 void BrowserAccessibility::NativeReleaseReference() {
398 delete this; 401 delete this;
399 } 402 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 bool BrowserAccessibility::GetString16Attribute( 553 bool BrowserAccessibility::GetString16Attribute(
551 ui::AXStringAttribute attribute, 554 ui::AXStringAttribute attribute,
552 base::string16* value) const { 555 base::string16* value) const {
553 std::string value_utf8; 556 std::string value_utf8;
554 if (!GetStringAttribute(attribute, &value_utf8)) 557 if (!GetStringAttribute(attribute, &value_utf8))
555 return false; 558 return false;
556 *value = base::UTF8ToUTF16(value_utf8); 559 *value = base::UTF8ToUTF16(value_utf8);
557 return true; 560 return true;
558 } 561 }
559 562
560 void BrowserAccessibility::SetStringAttribute(
561 ui::AXStringAttribute attribute, const std::string& value) {
562 if (!node_)
563 return;
564 ui::AXNodeData data = GetData();
565 for (size_t i = 0; i < data.string_attributes.size(); ++i) {
566 if (data.string_attributes[i].first == attribute) {
567 data.string_attributes[i].second = value;
568 node_->SetData(data);
569 return;
570 }
571 }
572 if (!value.empty()) {
573 data.string_attributes.push_back(std::make_pair(attribute, value));
574 node_->SetData(data);
575 }
576 }
577
578 bool BrowserAccessibility::HasIntListAttribute( 563 bool BrowserAccessibility::HasIntListAttribute(
579 ui::AXIntListAttribute attribute) const { 564 ui::AXIntListAttribute attribute) const {
580 const ui::AXNodeData& data = GetData(); 565 const ui::AXNodeData& data = GetData();
581 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) { 566 for (size_t i = 0; i < data.intlist_attributes.size(); ++i) {
582 if (data.intlist_attributes[i].first == attribute) 567 if (data.intlist_attributes[i].first == attribute)
583 return true; 568 return true;
584 } 569 }
585 570
586 return false; 571 return false;
587 } 572 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 if (!parent) 680 if (!parent)
696 return false; 681 return false;
697 682
698 BrowserAccessibility* grandparent = parent->GetParent(); 683 BrowserAccessibility* grandparent = parent->GetParent();
699 if (!grandparent) 684 if (!grandparent)
700 return false; 685 return false;
701 686
702 return grandparent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL; 687 return grandparent->GetRole() == ui::AX_ROLE_IFRAME_PRESENTATIONAL;
703 } 688 }
704 689
705 std::string BrowserAccessibility::GetTextRecursive() const {
706 if (!name_.empty()) {
707 return name_;
708 }
709
710 std::string result;
711 for (uint32 i = 0; i < PlatformChildCount(); ++i)
712 result += PlatformGetChild(i)->GetTextRecursive();
713 return result;
714 }
715
716 int BrowserAccessibility::GetStaticTextLenRecursive() const { 690 int BrowserAccessibility::GetStaticTextLenRecursive() const {
717 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) 691 if (GetRole() == ui::AX_ROLE_STATIC_TEXT)
718 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); 692 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size());
719 693
720 int len = 0; 694 int len = 0;
721 for (size_t i = 0; i < InternalChildCount(); ++i) 695 for (size_t i = 0; i < InternalChildCount(); ++i)
722 len += InternalGetChild(i)->GetStaticTextLenRecursive(); 696 len += InternalGetChild(i)->GetStaticTextLenRecursive();
723 return len; 697 return len;
724 } 698 }
725 699
726 } // namespace content 700 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698