Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "content/browser/accessibility/browser_accessibility_manager.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 12 #include "content/browser/accessibility/frame_tree_accessibility.h" | |
| 12 #include "content/common/accessibility_messages.h" | 13 #include "content/common/accessibility_messages.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 #if !defined(OS_MACOSX) && \ | 17 #if !defined(OS_MACOSX) && \ |
| 17 !defined(OS_WIN) && \ | 18 !defined(OS_WIN) && \ |
| 18 !defined(OS_ANDROID) | 19 !defined(OS_ANDROID) |
| 19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other | 20 // We have subclassess of BrowserAccessibility on Mac and Win. For any other |
| 20 // platform, instantiate the base class. | 21 // platform, instantiate the base class. |
| 21 // static | 22 // static |
| 22 BrowserAccessibility* BrowserAccessibility::Create() { | 23 BrowserAccessibility* BrowserAccessibility::Create() { |
| 23 return new BrowserAccessibility(); | 24 return new BrowserAccessibility(); |
| 24 } | 25 } |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 BrowserAccessibility::BrowserAccessibility() | 28 BrowserAccessibility::BrowserAccessibility() |
| 28 : manager_(NULL), | 29 : manager_(NULL), |
| 29 node_(NULL) { | 30 node_(NULL), |
| 31 child_frame_id_(0) { | |
|
David Tseng
2014/05/01 18:07:54
Maybe the id should be a uint32?
dmazzoni
2014/05/05 07:17:57
Done.
| |
| 30 } | 32 } |
| 31 | 33 |
| 32 BrowserAccessibility::~BrowserAccessibility() { | 34 BrowserAccessibility::~BrowserAccessibility() { |
| 33 } | 35 } |
| 34 | 36 |
| 35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 37 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
| 36 ui::AXNode* node) { | 38 ui::AXNode* node) { |
| 37 manager_ = manager; | 39 manager_ = manager; |
| 38 node_ = node; | 40 node_ = node; |
| 39 } | 41 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 56 case ui::AX_ROLE_STATIC_TEXT: | 58 case ui::AX_ROLE_STATIC_TEXT: |
| 57 case ui::AX_ROLE_TEXT_AREA: | 59 case ui::AX_ROLE_TEXT_AREA: |
| 58 case ui::AX_ROLE_TEXT_FIELD: | 60 case ui::AX_ROLE_TEXT_FIELD: |
| 59 return true; | 61 return true; |
| 60 default: | 62 default: |
| 61 return false; | 63 return false; |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 | 66 |
| 65 uint32 BrowserAccessibility::PlatformChildCount() const { | 67 uint32 BrowserAccessibility::PlatformChildCount() const { |
| 66 return PlatformIsLeaf() ? 0 : InternalChildCount(); | 68 if (!child_frame_id_) |
|
David Tseng
2014/05/01 18:07:54
So, 0 means no iframe? Would it make sense to defi
dmazzoni
2014/05/05 07:17:57
Done.
| |
| 69 return PlatformIsLeaf() ? 0 : InternalChildCount(); | |
| 70 FrameTreeAccessibility* frames = FrameTreeAccessibility::GetInstance(); | |
| 71 BrowserAccessibilityManager* child_manager = | |
| 72 frames->FindAccessibilityManagerById(child_frame_id_); | |
| 73 return child_manager ? 1 : 0; | |
| 67 } | 74 } |
| 68 | 75 |
| 69 bool BrowserAccessibility::IsNative() const { | 76 bool BrowserAccessibility::IsNative() const { |
| 70 return false; | 77 return false; |
| 71 } | 78 } |
| 72 | 79 |
| 73 bool BrowserAccessibility::IsDescendantOf( | 80 bool BrowserAccessibility::IsDescendantOf( |
| 74 BrowserAccessibility* ancestor) { | 81 BrowserAccessibility* ancestor) { |
| 75 if (this == ancestor) { | 82 if (this == ancestor) { |
| 76 return true; | 83 return true; |
| 77 } else if (GetParent()) { | 84 } else if (GetParent()) { |
| 78 return GetParent()->IsDescendantOf(ancestor); | 85 return GetParent()->IsDescendantOf(ancestor); |
| 79 } | 86 } |
| 80 | 87 |
| 81 return false; | 88 return false; |
| 82 } | 89 } |
| 83 | 90 |
| 84 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( | 91 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( |
| 85 uint32 child_index) const { | 92 uint32 child_index) const { |
| 93 if (child_index == 0 && child_frame_id_ != 0) { | |
|
David Tseng
2014/05/01 18:07:54
A named constant would help the readability of thi
David Tseng
2014/05/01 18:07:54
Crazy question...but can an iframe element have ch
dmazzoni
2014/05/05 07:17:57
Done.
dmazzoni
2014/05/05 07:17:57
No - but even if that were the case that shouldn't
| |
| 94 FrameTreeAccessibility* frames = FrameTreeAccessibility::GetInstance(); | |
| 95 BrowserAccessibilityManager* child_manager = | |
| 96 frames->FindAccessibilityManagerById(child_frame_id_); | |
| 97 return child_manager ? child_manager->GetRoot() : NULL; | |
| 98 } | |
| 99 | |
| 86 DCHECK(child_index < InternalChildCount()); | 100 DCHECK(child_index < InternalChildCount()); |
| 87 return InternalGetChild(child_index); | 101 return InternalGetChild(child_index); |
| 88 } | 102 } |
| 89 | 103 |
| 90 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 104 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
| 91 if (GetParent() && GetIndexInParent() > 0) | 105 if (GetParent() && GetIndexInParent() > 0) |
| 92 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 106 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
| 93 | 107 |
| 94 return NULL; | 108 return NULL; |
| 95 } | 109 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 115 uint32 child_index) const { | 129 uint32 child_index) const { |
| 116 if (!node_ || !manager_) | 130 if (!node_ || !manager_) |
| 117 return NULL; | 131 return NULL; |
| 118 return manager_->GetFromAXNode(node_->children()[child_index]); | 132 return manager_->GetFromAXNode(node_->children()[child_index]); |
| 119 } | 133 } |
| 120 | 134 |
| 121 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 135 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
| 122 if (!node_ || !manager_) | 136 if (!node_ || !manager_) |
| 123 return NULL; | 137 return NULL; |
| 124 ui::AXNode* parent = node_->parent(); | 138 ui::AXNode* parent = node_->parent(); |
| 125 return parent ? manager_->GetFromAXNode(parent) : NULL; | 139 if (parent) |
| 140 return manager_->GetFromAXNode(parent); | |
| 141 return manager_->GetCrossFrameParent(); | |
| 126 } | 142 } |
| 127 | 143 |
| 128 int32 BrowserAccessibility::GetIndexInParent() const { | 144 int32 BrowserAccessibility::GetIndexInParent() const { |
| 129 return node_ ? node_->index_in_parent() : -1; | 145 return node_ ? node_->index_in_parent() : -1; |
| 130 } | 146 } |
| 131 | 147 |
| 132 int32 BrowserAccessibility::GetId() const { | 148 int32 BrowserAccessibility::GetId() const { |
| 133 return node_ ? node_->id() : -1; | 149 return node_ ? node_->id() : -1; |
| 134 } | 150 } |
| 135 | 151 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 689 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
| 674 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 690 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
| 675 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 691 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
| 676 | 692 |
| 677 int len = 0; | 693 int len = 0; |
| 678 for (size_t i = 0; i < InternalChildCount(); ++i) | 694 for (size_t i = 0; i < InternalChildCount(); ++i) |
| 679 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 695 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
| 680 return len; | 696 return len; |
| 681 } | 697 } |
| 682 | 698 |
| 699 void BrowserAccessibility::SetChildFrameId(int child_frame_id) { | |
| 700 child_frame_id_ = child_frame_id; | |
| 701 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, this); | |
| 702 } | |
| 703 | |
| 683 } // namespace content | 704 } // namespace content |
| OLD | NEW |