OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_util.h" |
9 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 11 #include "content/common/view_messages.h" |
10 | 12 |
| 13 typedef WebAccessibility::BoolAttribute BoolAttribute; |
| 14 typedef WebAccessibility::FloatAttribute FloatAttribute; |
11 typedef WebAccessibility::IntAttribute IntAttribute; | 15 typedef WebAccessibility::IntAttribute IntAttribute; |
12 typedef WebAccessibility::StringAttribute StringAttribute; | 16 typedef WebAccessibility::StringAttribute StringAttribute; |
13 | 17 |
14 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 18 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
15 // There's no OS-specific implementation of BrowserAccessibilityManager | 19 // There's no OS-specific implementation of BrowserAccessibilityManager |
16 // on Unix, so just instantiate the base class. | 20 // on Unix, so just instantiate the base class. |
17 // static | 21 // static |
18 BrowserAccessibility* BrowserAccessibility::Create() { | 22 BrowserAccessibility* BrowserAccessibility::Create() { |
19 return new BrowserAccessibility(); | 23 return new BrowserAccessibility(); |
20 } | 24 } |
(...skipping 27 matching lines...) Expand all Loading... |
48 BrowserAccessibilityManager* manager, | 52 BrowserAccessibilityManager* manager, |
49 BrowserAccessibility* parent, | 53 BrowserAccessibility* parent, |
50 int32 child_id, | 54 int32 child_id, |
51 int32 index_in_parent, | 55 int32 index_in_parent, |
52 const webkit_glue::WebAccessibility& src) { | 56 const webkit_glue::WebAccessibility& src) { |
53 manager_ = manager; | 57 manager_ = manager; |
54 parent_ = parent; | 58 parent_ = parent; |
55 child_id_ = child_id; | 59 child_id_ = child_id; |
56 index_in_parent_ = index_in_parent; | 60 index_in_parent_ = index_in_parent; |
57 | 61 |
58 renderer_id_ = src.id; | 62 // Update all of the rest of the attributes. |
59 name_ = src.name; | 63 name_ = src.name; |
60 value_ = src.value; | 64 value_ = src.value; |
| 65 role_ = src.role; |
| 66 state_ = src.state; |
| 67 renderer_id_ = src.id; |
61 string_attributes_ = src.string_attributes; | 68 string_attributes_ = src.string_attributes; |
62 int_attributes_ = src.int_attributes; | 69 int_attributes_ = src.int_attributes; |
| 70 float_attributes_ = src.float_attributes; |
| 71 bool_attributes_ = src.bool_attributes; |
63 html_attributes_ = src.html_attributes; | 72 html_attributes_ = src.html_attributes; |
64 location_ = src.location; | 73 location_ = src.location; |
65 role_ = src.role; | |
66 state_ = src.state; | |
67 indirect_child_ids_ = src.indirect_child_ids; | 74 indirect_child_ids_ = src.indirect_child_ids; |
68 line_breaks_ = src.line_breaks; | 75 line_breaks_ = src.line_breaks; |
69 cell_ids_ = src.cell_ids; | 76 cell_ids_ = src.cell_ids; |
| 77 unique_cell_ids_ = src.unique_cell_ids; |
70 | 78 |
71 Initialize(); | 79 Initialize(); |
72 } | 80 } |
73 | 81 |
74 void BrowserAccessibility::Initialize() { | 82 void BrowserAccessibility::Initialize() { |
75 instance_active_ = true; | 83 instance_active_ = true; |
76 } | 84 } |
77 | 85 |
78 void BrowserAccessibility::AddChild(BrowserAccessibility* child) { | 86 void BrowserAccessibility::AddChild(BrowserAccessibility* child) { |
79 children_.push_back(child); | 87 children_.push_back(child); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (recursive || ref_count_ == 1) { | 167 if (recursive || ref_count_ == 1) { |
160 for (std::vector<BrowserAccessibility*>::iterator iter = children_.begin(); | 168 for (std::vector<BrowserAccessibility*>::iterator iter = children_.begin(); |
161 iter != children_.end(); | 169 iter != children_.end(); |
162 ++iter) { | 170 ++iter) { |
163 (*iter)->InternalReleaseReference(true); | 171 (*iter)->InternalReleaseReference(true); |
164 } | 172 } |
165 } | 173 } |
166 | 174 |
167 ref_count_--; | 175 ref_count_--; |
168 if (ref_count_ == 0) { | 176 if (ref_count_ == 0) { |
| 177 // Allow the object to fire a TEXT_REMOVED notification. |
| 178 name_.clear(); |
| 179 value_.clear(); |
| 180 SendNodeUpdateEvents(); |
| 181 |
| 182 manager_->NotifyAccessibilityEvent( |
| 183 ViewHostMsg_AccEvent::OBJECT_HIDE, this); |
| 184 |
169 instance_active_ = false; | 185 instance_active_ = false; |
170 children_.clear(); | 186 children_.clear(); |
171 manager_->Remove(child_id_, renderer_id_); | 187 manager_->Remove(child_id_, renderer_id_); |
172 NativeReleaseReference(); | 188 NativeReleaseReference(); |
173 } | 189 } |
174 } | 190 } |
175 | 191 |
176 void BrowserAccessibility::NativeReleaseReference() { | 192 void BrowserAccessibility::NativeReleaseReference() { |
177 delete this; | 193 delete this; |
178 } | 194 } |
179 | 195 |
180 bool BrowserAccessibility::GetStringAttribute( | 196 bool BrowserAccessibility::GetBoolAttribute( |
181 StringAttribute attribute, | 197 BoolAttribute attribute, bool* value) const { |
182 string16* value) { | 198 BoolAttrMap::const_iterator iter = bool_attributes_.find(attribute); |
183 std::map<StringAttribute, string16>::iterator iter = | 199 if (iter != bool_attributes_.end()) { |
184 string_attributes_.find(attribute); | |
185 if (iter != string_attributes_.end()) { | |
186 *value = iter->second; | 200 *value = iter->second; |
187 return true; | 201 return true; |
188 } | 202 } |
189 | 203 |
190 return false; | 204 return false; |
191 } | 205 } |
192 | 206 |
| 207 bool BrowserAccessibility::GetFloatAttribute( |
| 208 FloatAttribute attribute, float* value) const { |
| 209 FloatAttrMap::const_iterator iter = float_attributes_.find(attribute); |
| 210 if (iter != float_attributes_.end()) { |
| 211 *value = iter->second; |
| 212 return true; |
| 213 } |
| 214 |
| 215 return false; |
| 216 } |
| 217 |
193 bool BrowserAccessibility::GetIntAttribute( | 218 bool BrowserAccessibility::GetIntAttribute( |
194 IntAttribute attribute, int* value) { | 219 IntAttribute attribute, int* value) const { |
195 std::map<IntAttribute, int32>::iterator iter = | 220 IntAttrMap::const_iterator iter = int_attributes_.find(attribute); |
196 int_attributes_.find(attribute); | |
197 if (iter != int_attributes_.end()) { | 221 if (iter != int_attributes_.end()) { |
198 *value = iter->second; | 222 *value = iter->second; |
199 return true; | 223 return true; |
200 } | 224 } |
201 | 225 |
202 return false; | 226 return false; |
203 } | 227 } |
| 228 |
| 229 bool BrowserAccessibility::GetStringAttribute( |
| 230 StringAttribute attribute, |
| 231 string16* value) const { |
| 232 StringAttrMap::const_iterator iter = string_attributes_.find(attribute); |
| 233 if (iter != string_attributes_.end()) { |
| 234 *value = iter->second; |
| 235 return true; |
| 236 } |
| 237 |
| 238 return false; |
| 239 } |
| 240 |
| 241 bool BrowserAccessibility::GetHtmlAttribute( |
| 242 const char* html_attr, string16* value) const { |
| 243 for (size_t i = 0; i < html_attributes_.size(); i++) { |
| 244 const string16& attr = html_attributes_[i].first; |
| 245 if (LowerCaseEqualsASCII(attr, html_attr)) { |
| 246 *value = html_attributes_[i].second; |
| 247 return true; |
| 248 } |
| 249 } |
| 250 |
| 251 return false; |
| 252 } |
| 253 |
| 254 bool BrowserAccessibility::IsEditableText() const { |
| 255 return (role_ == WebAccessibility::ROLE_TEXT_FIELD || |
| 256 role_ == WebAccessibility::ROLE_TEXTAREA); |
| 257 } |
OLD | NEW |