diff options
author | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 11:54:31 +0000 |
---|---|---|
committer | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 11:54:31 +0000 |
commit | 520cb7d74997ad71aa26cbb842dc7eec75be4f49 (patch) | |
tree | 01761cfd3fb461bd60d612138e77c8a1c4dfdb2b /chrome/browser/browser_accessibility_manager_win.cc | |
parent | 4a188ca7f4aeb5b84187029bc2b61dcbee1797a8 (diff) | |
download | chromium_src-520cb7d74997ad71aa26cbb842dc7eec75be4f49.zip chromium_src-520cb7d74997ad71aa26cbb842dc7eec75be4f49.tar.gz chromium_src-520cb7d74997ad71aa26cbb842dc7eec75be4f49.tar.bz2 |
Update browser cache of accessibility tree on renderer sub-tree changes.
WebKit sister patch: http://trac.webkit.org/changeset/66305
BUG=13291
TEST=interactive_ui_tests --gtest_filter=AccessibilityWinBrowserTest.TestDynamicAccessibilityTree
TEST=unit_tests --gtest_filter=BrowserAccessibilityTest.TestChildrenChange
TEST=unit_tests --gtest_filter=BrowserAccessibilityTest.TestChildrenChangeNoLeaks
Review URL: http://codereview.chromium.org/3117036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_accessibility_manager_win.cc')
-rw-r--r-- | chrome/browser/browser_accessibility_manager_win.cc | 77 |
1 files changed, 68 insertions, 9 deletions
diff --git a/chrome/browser/browser_accessibility_manager_win.cc b/chrome/browser/browser_accessibility_manager_win.cc index c1ce8a7..d17a0bd 100644 --- a/chrome/browser/browser_accessibility_manager_win.cc +++ b/chrome/browser/browser_accessibility_manager_win.cc @@ -39,7 +39,7 @@ BrowserAccessibilityManager::BrowserAccessibilityManager( parent_hwnd_, OBJID_WINDOW, IID_IAccessible, reinterpret_cast<void **>(&window_iaccessible_)); DCHECK(SUCCEEDED(hr)); - root_ = CreateAccessibilityTree(NULL, src, 0); + root_ = CreateAccessibilityTree(NULL, GetNextChildID(), src, 0); if (!focus_) focus_ = root_; } @@ -57,6 +57,10 @@ BrowserAccessibility* BrowserAccessibilityManager::GetRoot() { return root_; } +void BrowserAccessibilityManager::Remove(LONG child_id) { + child_id_map_.erase(child_id); +} + BrowserAccessibility* BrowserAccessibilityManager::GetFromChildID( LONG child_id) { base::hash_map<LONG, BrowserAccessibility*>::iterator iter = @@ -117,24 +121,79 @@ void BrowserAccessibilityManager::OnAccessibilityObjectStateChange( return; LONG child_id = iter->second; - ::NotifyWinEvent(EVENT_OBJECT_FOCUS, parent_hwnd_, OBJID_CLIENT, child_id); + ::NotifyWinEvent( + EVENT_OBJECT_STATECHANGE, + parent_hwnd_, + OBJID_CLIENT, + child_id); } -BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( - BrowserAccessibility* parent, - const webkit_glue::WebAccessibility& src, - int index_in_parent) { - BrowserAccessibility* instance = factory_->Create(); +void BrowserAccessibilityManager::OnAccessibilityObjectChildrenChange( + const std::vector<webkit_glue::WebAccessibility>& acc_changes) { + if (delegate_) + delegate_->AccessibilityObjectChildrenChangeAck(); + + // For each accessibility object child change. + for (unsigned int index = 0; index < acc_changes.size(); index++) { + const webkit_glue::WebAccessibility& acc_obj = acc_changes[index]; + base::hash_map<int, LONG>::iterator iter = + renderer_id_to_child_id_map_.find(acc_obj.id); + if (iter == renderer_id_to_child_id_map_.end()) + continue; + + LONG child_id = iter->second; + BrowserAccessibility* old_browser_acc = GetFromChildID(child_id); + + BrowserAccessibility* new_browser_acc = CreateAccessibilityTree( + old_browser_acc->GetParent(), + child_id, + acc_obj, + old_browser_acc->index_in_parent()); + + if (focus_->IsDescendantOf(old_browser_acc)) + focus_ = new_browser_acc; + + if (old_browser_acc->GetParent()) { + old_browser_acc->GetParent()->ReplaceChild( + old_browser_acc, + new_browser_acc); + } else { + DCHECK_EQ(old_browser_acc, root_); + root_ = new_browser_acc; + } + old_browser_acc->InactivateTree(); + old_browser_acc->Release(); + child_id_map_[child_id] = new_browser_acc; + + if (root_ != new_browser_acc) { + NotifyWinEvent( + EVENT_OBJECT_REORDER, parent_hwnd_, OBJID_CLIENT, child_id); + } else { + NotifyWinEvent( + EVENT_OBJECT_REORDER, parent_hwnd_, OBJID_CLIENT, CHILDID_SELF); + } + } +} +LONG BrowserAccessibilityManager::GetNextChildID() { // Get the next child ID, and wrap around when we get near the end // of a 32-bit integer range. It's okay to wrap around; we just want // to avoid it as long as possible because clients may cache the ID of // an object for a while to determine if they've seen it before. - LONG child_id = next_child_id_; next_child_id_--; if (next_child_id_ == -2000000000) next_child_id_ = -1; + return next_child_id_; +} + +BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( + BrowserAccessibility* parent, + int child_id, + const webkit_glue::WebAccessibility& src, + int index_in_parent) { + BrowserAccessibility* instance = factory_->Create(); + instance->Initialize(this, parent, child_id, index_in_parent, src); child_id_map_[child_id] = instance; renderer_id_to_child_id_map_[src.id] = child_id; @@ -142,7 +201,7 @@ BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( focus_ = instance; for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { BrowserAccessibility* child = CreateAccessibilityTree( - instance, src.children[i], i); + instance, GetNextChildID(), src.children[i], i); instance->AddChild(child); } |