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

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

Issue 7461104: Fix a few lingering bugs in BrowserAccessibilityManager and BrowserAccessibilityCocoa. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix corner case with removal of renderer to child id mappings. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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_manager.h" 5 #include "content/browser/accessibility/browser_accessibility_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/accessibility/browser_accessibility.h" 8 #include "content/browser/accessibility/browser_accessibility.h"
9 #include "content/common/view_messages.h" 9 #include "content/common/view_messages.h"
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 renderer_id_to_child_id_map_.find(renderer_id); 92 renderer_id_to_child_id_map_.find(renderer_id);
93 if (iter == renderer_id_to_child_id_map_.end()) 93 if (iter == renderer_id_to_child_id_map_.end())
94 return NULL; 94 return NULL;
95 95
96 int32 child_id = iter->second; 96 int32 child_id = iter->second;
97 return GetFromChildID(child_id); 97 return GetFromChildID(child_id);
98 } 98 }
99 99
100 void BrowserAccessibilityManager::Remove(int32 child_id, int32 renderer_id) { 100 void BrowserAccessibilityManager::Remove(int32 child_id, int32 renderer_id) {
101 child_id_map_.erase(child_id); 101 child_id_map_.erase(child_id);
102 renderer_id_to_child_id_map_.erase(renderer_id); 102 // Make sure we don't overwrite a newer entry (see UpdateNode for a possible
dmazzoni 2011/08/02 06:19:35 Good catch - would it be possible to write a unit
David Tseng 2011/08/02 21:30:57 Done.
103 // corner case).
104 if (renderer_id_to_child_id_map_[renderer_id] == child_id)
105 renderer_id_to_child_id_map_.erase(renderer_id);
103 } 106 }
104 107
105 void BrowserAccessibilityManager::OnAccessibilityNotifications( 108 void BrowserAccessibilityManager::OnAccessibilityNotifications(
106 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { 109 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) {
107 for (uint32 index = 0; index < params.size(); index++) { 110 for (uint32 index = 0; index < params.size(); index++) {
108 const ViewHostMsg_AccessibilityNotification_Params& param = params[index]; 111 const ViewHostMsg_AccessibilityNotification_Params& param = params[index];
109 112
110 switch (param.notification_type) { 113 switch (param.notification_type) {
111 case ViewHostMsg_AccessibilityNotification_Type:: 114 case ViewHostMsg_AccessibilityNotification_Type::
112 NOTIFICATION_TYPE_CHECK_STATE_CHANGED: 115 NOTIFICATION_TYPE_CHECK_STATE_CHANGED:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 NotifyAccessibilityEvent( 180 NotifyAccessibilityEvent(
178 ViewHostMsg_AccessibilityNotification_Type:: 181 ViewHostMsg_AccessibilityNotification_Type::
179 NOTIFICATION_TYPE_FOCUS_CHANGED, 182 NOTIFICATION_TYPE_FOCUS_CHANGED,
180 focus_); 183 focus_);
181 } 184 }
182 } 185 }
183 186
184 void BrowserAccessibilityManager::OnAccessibilityObjectLoadComplete( 187 void BrowserAccessibilityManager::OnAccessibilityObjectLoadComplete(
185 const WebAccessibility& acc_obj) { 188 const WebAccessibility& acc_obj) {
186 SetFocus(NULL, false); 189 SetFocus(NULL, false);
187 root_->InternalReleaseReference(true);
188 190
189 root_ = CreateAccessibilityTree(NULL, acc_obj, 0); 191 root_ = UpdateNode(acc_obj, true);
190 if (!focus_) 192 if (!focus_)
191 SetFocus(root_, false); 193 SetFocus(root_, false);
192 194
193 NotifyAccessibilityEvent( 195 NotifyAccessibilityEvent(
194 ViewHostMsg_AccessibilityNotification_Type:: 196 ViewHostMsg_AccessibilityNotification_Type::
195 NOTIFICATION_TYPE_LOAD_COMPLETE, 197 NOTIFICATION_TYPE_LOAD_COMPLETE,
196 root_); 198 root_);
197 if (delegate_ && delegate_->HasFocus()) 199 if (delegate_ && delegate_->HasFocus())
198 GotFocus(); 200 GotFocus();
199 } 201 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 BrowserAccessibility* BrowserAccessibilityManager::GetFocus( 242 BrowserAccessibility* BrowserAccessibilityManager::GetFocus(
241 BrowserAccessibility* root) { 243 BrowserAccessibility* root) {
242 if (focus_ && (!root || focus_->IsDescendantOf(root))) 244 if (focus_ && (!root || focus_->IsDescendantOf(root)))
243 return focus_; 245 return focus_;
244 246
245 return NULL; 247 return NULL;
246 } 248 }
247 249
248 void BrowserAccessibilityManager::SetFocus( 250 void BrowserAccessibilityManager::SetFocus(
249 BrowserAccessibility* node, bool notify) { 251 BrowserAccessibility* node, bool notify) {
250 if (focus_) 252 if (focus_ != node) {
251 focus_->InternalReleaseReference(false); 253 if (focus_)
252 focus_ = node; 254 focus_->InternalReleaseReference(false);
253 if (focus_) 255 focus_ = node;
254 focus_->InternalAddReference(); 256 if (focus_)
257 focus_->InternalAddReference();
258 }
255 259
256 if (notify && node && delegate_) 260 if (notify && node && delegate_)
257 delegate_->SetAccessibilityFocus(node->renderer_id()); 261 delegate_->SetAccessibilityFocus(node->renderer_id());
258 } 262 }
259 263
260 void BrowserAccessibilityManager::DoDefaultAction( 264 void BrowserAccessibilityManager::DoDefaultAction(
261 const BrowserAccessibility& node) { 265 const BrowserAccessibility& node) {
262 if (delegate_) 266 if (delegate_)
263 delegate_->AccessibilityDoDefaultAction(node.renderer_id()); 267 delegate_->AccessibilityDoDefaultAction(node.renderer_id());
264 } 268 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Build a new tree, reusing old nodes if possible. Each node that's 308 // Build a new tree, reusing old nodes if possible. Each node that's
305 // reused will have its reference count incremented by one. 309 // reused will have its reference count incremented by one.
306 current = 310 current =
307 CreateAccessibilityTree(current_parent, src, current_index_in_parent); 311 CreateAccessibilityTree(current_parent, src, current_index_in_parent);
308 312
309 // Decrement the reference count of all nodes in the old tree, which will 313 // Decrement the reference count of all nodes in the old tree, which will
310 // delete any nodes no longer needed. 314 // delete any nodes no longer needed.
311 for (int i = 0; i < static_cast<int>(old_tree_nodes.size()); i++) 315 for (int i = 0; i < static_cast<int>(old_tree_nodes.size()); i++)
312 old_tree_nodes[i]->InternalReleaseReference(false); 316 old_tree_nodes[i]->InternalReleaseReference(false);
313 317
314 DCHECK(focus_); 318 if (!focus_ || !focus_->instance_active())
315 if (!focus_->instance_active())
316 SetFocus(root_, false); 319 SetFocus(root_, false);
317 320
318 return current; 321 return current;
319 } 322 }
320 323
321 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( 324 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree(
322 BrowserAccessibility* parent, 325 BrowserAccessibility* parent,
323 const WebAccessibility& src, 326 const WebAccessibility& src,
324 int index_in_parent) { 327 int index_in_parent) {
325 BrowserAccessibility* instance = NULL; 328 BrowserAccessibility* instance = NULL;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) 367 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1)
365 SetFocus(instance, false); 368 SetFocus(instance, false);
366 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { 369 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) {
367 BrowserAccessibility* child = CreateAccessibilityTree( 370 BrowserAccessibility* child = CreateAccessibilityTree(
368 instance, src.children[i], i); 371 instance, src.children[i], i);
369 instance->AddChild(child); 372 instance->AddChild(child);
370 } 373 }
371 374
372 return instance; 375 return instance;
373 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698