| 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_manager_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 10 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 11 #include "content/browser/accessibility/browser_accessibility_win.h" | 11 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 12 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" | 12 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" |
| 13 #include "content/common/accessibility_messages.h" | 13 #include "content/common/accessibility_messages.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( | 18 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( |
| 19 const ui::AXTreeUpdate& initial_tree, | 19 const ui::AXTreeUpdate& initial_tree, |
| 20 BrowserAccessibilityDelegate* delegate, | 20 BrowserAccessibilityDelegate* delegate, |
| 21 BrowserAccessibilityFactory* factory) { | 21 BrowserAccessibilityFactory* factory) { |
| 22 return new BrowserAccessibilityManagerWin( | 22 return new BrowserAccessibilityManagerWin(initial_tree, delegate, factory); |
| 23 content::LegacyRenderWidgetHostHWND::Create(GetDesktopWindow()).get(), | |
| 24 NULL, initial_tree, delegate, factory); | |
| 25 } | 23 } |
| 26 | 24 |
| 27 BrowserAccessibilityManagerWin* | 25 BrowserAccessibilityManagerWin* |
| 28 BrowserAccessibilityManager::ToBrowserAccessibilityManagerWin() { | 26 BrowserAccessibilityManager::ToBrowserAccessibilityManagerWin() { |
| 29 return static_cast<BrowserAccessibilityManagerWin*>(this); | 27 return static_cast<BrowserAccessibilityManagerWin*>(this); |
| 30 } | 28 } |
| 31 | 29 |
| 32 BrowserAccessibilityManagerWin::BrowserAccessibilityManagerWin( | 30 BrowserAccessibilityManagerWin::BrowserAccessibilityManagerWin( |
| 33 LegacyRenderWidgetHostHWND* accessible_hwnd, | |
| 34 IAccessible* parent_iaccessible, | |
| 35 const ui::AXTreeUpdate& initial_tree, | 31 const ui::AXTreeUpdate& initial_tree, |
| 36 BrowserAccessibilityDelegate* delegate, | 32 BrowserAccessibilityDelegate* delegate, |
| 37 BrowserAccessibilityFactory* factory) | 33 BrowserAccessibilityFactory* factory) |
| 38 : BrowserAccessibilityManager(initial_tree, delegate, factory), | 34 : BrowserAccessibilityManager(initial_tree, delegate, factory), |
| 39 parent_hwnd_(accessible_hwnd->GetParent()), | 35 tracked_scroll_object_(NULL) { |
| 40 parent_iaccessible_(parent_iaccessible), | |
| 41 tracked_scroll_object_(NULL), | |
| 42 accessible_hwnd_(accessible_hwnd) { | |
| 43 accessible_hwnd_->set_browser_accessibility_manager(this); | |
| 44 } | 36 } |
| 45 | 37 |
| 46 BrowserAccessibilityManagerWin::~BrowserAccessibilityManagerWin() { | 38 BrowserAccessibilityManagerWin::~BrowserAccessibilityManagerWin() { |
| 47 if (tracked_scroll_object_) { | 39 if (tracked_scroll_object_) { |
| 48 tracked_scroll_object_->Release(); | 40 tracked_scroll_object_->Release(); |
| 49 tracked_scroll_object_ = NULL; | 41 tracked_scroll_object_ = NULL; |
| 50 } | 42 } |
| 51 if (accessible_hwnd_) | |
| 52 accessible_hwnd_->OnManagerDeleted(); | |
| 53 } | 43 } |
| 54 | 44 |
| 55 // static | 45 // static |
| 56 ui::AXTreeUpdate BrowserAccessibilityManagerWin::GetEmptyDocument() { | 46 ui::AXTreeUpdate BrowserAccessibilityManagerWin::GetEmptyDocument() { |
| 57 ui::AXNodeData empty_document; | 47 ui::AXNodeData empty_document; |
| 58 empty_document.id = 0; | 48 empty_document.id = 0; |
| 59 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; | 49 empty_document.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 60 empty_document.state = | 50 empty_document.state = |
| 61 (1 << ui::AX_STATE_ENABLED) | | 51 (1 << ui::AX_STATE_ENABLED) | |
| 62 (1 << ui::AX_STATE_READ_ONLY) | | 52 (1 << ui::AX_STATE_READ_ONLY) | |
| 63 (1 << ui::AX_STATE_BUSY); | 53 (1 << ui::AX_STATE_BUSY); |
| 64 | 54 |
| 65 ui::AXTreeUpdate update; | 55 ui::AXTreeUpdate update; |
| 66 update.nodes.push_back(empty_document); | 56 update.nodes.push_back(empty_document); |
| 67 return update; | 57 return update; |
| 68 } | 58 } |
| 69 | 59 |
| 70 void BrowserAccessibilityManagerWin::MaybeCallNotifyWinEvent(DWORD event, | 60 void BrowserAccessibilityManagerWin::MaybeCallNotifyWinEvent(DWORD event, |
| 71 LONG child_id) { | 61 LONG child_id) { |
| 72 // Don't fire events if this view isn't hooked up to its parent. | 62 if (!delegate()) |
| 73 if (!parent_iaccessible()) | |
| 74 return; | 63 return; |
| 75 | 64 |
| 76 // If on Win 7 and complete accessibility is enabled, use the fake child HWND | 65 HWND parent_hwnd = delegate()->GetAccessibleParentHWND(); |
| 77 // to use as the root of the accessibility tree. See comments above | 66 if (!parent_hwnd) |
| 78 // LegacyRenderWidgetHostHWND for details. | 67 return; |
| 79 if (BrowserAccessibilityStateImpl::GetInstance()->IsAccessibleBrowser()) { | 68 |
| 80 DCHECK(accessible_hwnd_); | 69 ::NotifyWinEvent(event, parent_hwnd, OBJID_CLIENT, child_id); |
| 81 parent_hwnd_ = accessible_hwnd_->hwnd(); | |
| 82 parent_iaccessible_ = accessible_hwnd_->window_accessible(); | |
| 83 } | |
| 84 ::NotifyWinEvent(event, parent_hwnd(), OBJID_CLIENT, child_id); | |
| 85 } | 70 } |
| 86 | 71 |
| 87 | 72 |
| 88 void BrowserAccessibilityManagerWin::OnNodeCreated(ui::AXNode* node) { | 73 void BrowserAccessibilityManagerWin::OnNodeCreated(ui::AXNode* node) { |
| 89 BrowserAccessibilityManager::OnNodeCreated(node); | 74 BrowserAccessibilityManager::OnNodeCreated(node); |
| 90 BrowserAccessibility* obj = GetFromAXNode(node); | 75 BrowserAccessibility* obj = GetFromAXNode(node); |
| 91 LONG unique_id_win = obj->ToBrowserAccessibilityWin()->unique_id_win(); | 76 LONG unique_id_win = obj->ToBrowserAccessibilityWin()->unique_id_win(); |
| 92 unique_id_to_ax_id_map_[unique_id_win] = obj->GetId(); | 77 unique_id_to_ax_id_map_[unique_id_win] = obj->GetId(); |
| 93 } | 78 } |
| 94 | 79 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 base::hash_map<LONG, int32>::iterator iter = | 232 base::hash_map<LONG, int32>::iterator iter = |
| 248 unique_id_to_ax_id_map_.find(unique_id_win); | 233 unique_id_to_ax_id_map_.find(unique_id_win); |
| 249 if (iter != unique_id_to_ax_id_map_.end()) { | 234 if (iter != unique_id_to_ax_id_map_.end()) { |
| 250 BrowserAccessibility* result = GetFromID(iter->second); | 235 BrowserAccessibility* result = GetFromID(iter->second); |
| 251 if (result) | 236 if (result) |
| 252 return result->ToBrowserAccessibilityWin(); | 237 return result->ToBrowserAccessibilityWin(); |
| 253 } | 238 } |
| 254 return NULL; | 239 return NULL; |
| 255 } | 240 } |
| 256 | 241 |
| 257 void BrowserAccessibilityManagerWin::OnAccessibleHwndDeleted() { | |
| 258 // If the AccessibleHWND is deleted, |parent_hwnd_| and | |
| 259 // |parent_iaccessible_| are no longer valid either, since they were | |
| 260 // derived from AccessibleHWND. We don't have to restore them to | |
| 261 // previous values, though, because this should only happen | |
| 262 // during the destruct sequence for this window. | |
| 263 accessible_hwnd_ = NULL; | |
| 264 parent_hwnd_ = NULL; | |
| 265 parent_iaccessible_ = NULL; | |
| 266 } | |
| 267 | |
| 268 } // namespace content | 242 } // namespace content |
| OLD | NEW |