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/common/accessibility_messages.h" | 12 #include "content/common/accessibility_messages.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 #if !defined(OS_MACOSX) && \ | 16 #if !defined(OS_MACOSX) && \ |
17 !defined(OS_WIN) && \ | 17 !defined(OS_WIN) && \ |
18 !defined(OS_ANDROID) | 18 !defined(OS_ANDROID) |
19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other | 19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other |
20 // platform, instantiate the base class. | 20 // platform, instantiate the base class. |
21 // static | 21 // static |
22 BrowserAccessibility* BrowserAccessibility::Create() { | 22 BrowserAccessibility* BrowserAccessibility::Create() { |
23 return new BrowserAccessibility(); | 23 return new BrowserAccessibility(); |
24 } | 24 } |
25 #endif | 25 #endif |
26 | 26 |
27 BrowserAccessibility::BrowserAccessibility() | 27 BrowserAccessibility::BrowserAccessibility() |
28 : manager_(NULL), | 28 : manager_(NULL), |
29 node_(NULL) { | 29 node_(NULL), |
30 child_frame_id_(kNoFrameId) { | |
30 } | 31 } |
31 | 32 |
32 BrowserAccessibility::~BrowserAccessibility() { | 33 BrowserAccessibility::~BrowserAccessibility() { |
33 } | 34 } |
34 | 35 |
35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 36 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
36 ui::AXNode* node) { | 37 ui::AXNode* node) { |
37 manager_ = manager; | 38 manager_ = manager; |
38 node_ = node; | 39 node_ = node; |
39 } | 40 } |
(...skipping 16 matching lines...) Expand all Loading... | |
56 case ui::AX_ROLE_STATIC_TEXT: | 57 case ui::AX_ROLE_STATIC_TEXT: |
57 case ui::AX_ROLE_TEXT_AREA: | 58 case ui::AX_ROLE_TEXT_AREA: |
58 case ui::AX_ROLE_TEXT_FIELD: | 59 case ui::AX_ROLE_TEXT_FIELD: |
59 return true; | 60 return true; |
60 default: | 61 default: |
61 return false; | 62 return false; |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 uint32 BrowserAccessibility::PlatformChildCount() const { | 66 uint32 BrowserAccessibility::PlatformChildCount() const { |
66 return PlatformIsLeaf() ? 0 : InternalChildCount(); | 67 if (child_frame_id_ == kNoFrameId || !manager_ || !manager_->delegate()) |
68 return PlatformIsLeaf() ? 0 : InternalChildCount(); | |
69 BrowserAccessibilityManager* child_manager = | |
70 manager_->delegate()->AccessibilityGetChildFrame(child_frame_id_); | |
71 return child_manager ? 1 : 0; | |
67 } | 72 } |
68 | 73 |
69 bool BrowserAccessibility::IsNative() const { | 74 bool BrowserAccessibility::IsNative() const { |
70 return false; | 75 return false; |
71 } | 76 } |
72 | 77 |
73 bool BrowserAccessibility::IsDescendantOf( | 78 bool BrowserAccessibility::IsDescendantOf( |
74 BrowserAccessibility* ancestor) { | 79 BrowserAccessibility* ancestor) { |
75 if (this == ancestor) { | 80 if (this == ancestor) { |
76 return true; | 81 return true; |
77 } else if (GetParent()) { | 82 } else if (GetParent()) { |
78 return GetParent()->IsDescendantOf(ancestor); | 83 return GetParent()->IsDescendantOf(ancestor); |
79 } | 84 } |
80 | 85 |
81 return false; | 86 return false; |
82 } | 87 } |
83 | 88 |
84 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( | 89 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( |
85 uint32 child_index) const { | 90 uint32 child_index) const { |
91 if (child_index == 0 && child_frame_id_ != kNoFrameId && manager_ && | |
92 manager_->delegate()) { | |
93 BrowserAccessibilityManager* child_manager = | |
94 manager_->delegate()->AccessibilityGetChildFrame(child_frame_id_); | |
95 if (!child_manager) | |
96 return NULL; | |
97 | |
98 child_manager->SetNodeIdInParentFrame(GetId()); | |
Charlie Reis
2014/08/21 19:23:27
Seems odd to be doing a modification to the child_
dmazzoni
2014/08/25 06:49:36
I agree this is ugly.
Maybe this is premature opt
| |
99 return child_manager->GetRoot(); | |
100 } | |
101 | |
86 DCHECK(child_index < InternalChildCount()); | 102 DCHECK(child_index < InternalChildCount()); |
87 return InternalGetChild(child_index); | 103 return InternalGetChild(child_index); |
88 } | 104 } |
89 | 105 |
90 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 106 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
91 if (GetParent() && GetIndexInParent() > 0) | 107 if (GetParent() && GetIndexInParent() > 0) |
92 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 108 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
93 | 109 |
94 return NULL; | 110 return NULL; |
95 } | 111 } |
(...skipping 19 matching lines...) Expand all Loading... | |
115 uint32 child_index) const { | 131 uint32 child_index) const { |
116 if (!node_ || !manager_) | 132 if (!node_ || !manager_) |
117 return NULL; | 133 return NULL; |
118 return manager_->GetFromAXNode(node_->children()[child_index]); | 134 return manager_->GetFromAXNode(node_->children()[child_index]); |
119 } | 135 } |
120 | 136 |
121 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 137 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
122 if (!node_ || !manager_) | 138 if (!node_ || !manager_) |
123 return NULL; | 139 return NULL; |
124 ui::AXNode* parent = node_->parent(); | 140 ui::AXNode* parent = node_->parent(); |
125 return parent ? manager_->GetFromAXNode(parent) : NULL; | 141 if (parent) |
142 return manager_->GetFromAXNode(parent); | |
143 return manager_->GetCrossFrameParent(); | |
126 } | 144 } |
127 | 145 |
128 int32 BrowserAccessibility::GetIndexInParent() const { | 146 int32 BrowserAccessibility::GetIndexInParent() const { |
129 return node_ ? node_->index_in_parent() : -1; | 147 return node_ ? node_->index_in_parent() : -1; |
130 } | 148 } |
131 | 149 |
132 int32 BrowserAccessibility::GetId() const { | 150 int32 BrowserAccessibility::GetId() const { |
133 return node_ ? node_->id() : -1; | 151 return node_ ? node_->id() : -1; |
134 } | 152 } |
135 | 153 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 691 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
674 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 692 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
675 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 693 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
676 | 694 |
677 int len = 0; | 695 int len = 0; |
678 for (size_t i = 0; i < InternalChildCount(); ++i) | 696 for (size_t i = 0; i < InternalChildCount(); ++i) |
679 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 697 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
680 return len; | 698 return len; |
681 } | 699 } |
682 | 700 |
701 void BrowserAccessibility::SetChildFrameId(int64 child_frame_id) { | |
702 child_frame_id_ = child_frame_id; | |
703 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, this); | |
704 } | |
705 | |
683 } // namespace content | 706 } // namespace content |
OLD | NEW |