Chromium Code Reviews| Index: content/browser/accessibility/browser_accessibility_manager.cc |
| diff --git a/content/browser/accessibility/browser_accessibility_manager.cc b/content/browser/accessibility/browser_accessibility_manager.cc |
| index 75c0b821589fd4c547be0fa412253e53f458b6b8..eb2d8972a43b128b9b49d4b097d9605a893273fe 100644 |
| --- a/content/browser/accessibility/browser_accessibility_manager.cc |
| +++ b/content/browser/accessibility/browser_accessibility_manager.cc |
| @@ -127,7 +127,6 @@ BrowserAccessibilityManager::BrowserAccessibilityManager( |
| : delegate_(delegate), |
| factory_(factory), |
| tree_(new ui::AXSerializableTree()), |
| - focus_(NULL), |
| user_is_navigating_away_(false), |
| osk_state_(OSK_ALLOWED), |
| ax_tree_id_(AXTreeIDRegistry::kNoAXTreeID), |
| @@ -142,7 +141,6 @@ BrowserAccessibilityManager::BrowserAccessibilityManager( |
| : delegate_(delegate), |
| factory_(factory), |
| tree_(new ui::AXSerializableTree()), |
| - focus_(NULL), |
| user_is_navigating_away_(false), |
| osk_state_(OSK_ALLOWED), |
| ax_tree_id_(AXTreeIDRegistry::kNoAXTreeID), |
| @@ -166,9 +164,6 @@ void BrowserAccessibilityManager::Initialize( |
| LOG(FATAL) << tree_->error(); |
| } |
| } |
| - |
| - if (!focus_) |
| - SetFocus(tree_->root(), false); |
| } |
| // static |
| @@ -247,13 +242,15 @@ const ui::AXTreeData& BrowserAccessibilityManager::GetTreeData() { |
| } |
| void BrowserAccessibilityManager::OnWindowFocused() { |
| - if (focus_) |
| - NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetFromAXNode(focus_)); |
| + BrowserAccessibility* focus = GetFocus(); |
| + if (focus) |
| + NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, focus); |
| } |
| void BrowserAccessibilityManager::OnWindowBlurred() { |
| - if (focus_) |
| - NotifyAccessibilityEvent(ui::AX_EVENT_BLUR, GetFromAXNode(focus_)); |
| + BrowserAccessibility* focus = GetFocus(); |
| + if (focus) |
| + NotifyAccessibilityEvent(ui::AX_EVENT_BLUR, focus); |
| } |
| void BrowserAccessibilityManager::UserIsNavigatingAway() { |
| @@ -273,11 +270,12 @@ void BrowserAccessibilityManager::NavigationFailed() { |
| } |
| void BrowserAccessibilityManager::GotMouseDown() { |
| - if (!focus_) |
| + BrowserAccessibility* focus = GetFocus(); |
| + if (!focus) |
| return; |
| osk_state_ = OSK_ALLOWED_WITHIN_FOCUSED_OBJECT; |
| - NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetFromAXNode(focus_)); |
| + NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, focus); |
| } |
| bool BrowserAccessibilityManager::UseRootScrollOffsetsWhenComputingBounds() { |
| @@ -286,8 +284,6 @@ bool BrowserAccessibilityManager::UseRootScrollOffsetsWhenComputingBounds() { |
| void BrowserAccessibilityManager::OnAccessibilityEvents( |
| const std::vector<AXEventNotificationDetails>& details) { |
| - bool should_send_initial_focus = false; |
| - |
| // Process all changes to the accessibility tree first. |
| for (uint32_t index = 0; index < details.size(); ++index) { |
| const AXEventNotificationDetails& detail = details[index]; |
| @@ -300,17 +296,8 @@ void BrowserAccessibilityManager::OnAccessibilityEvents( |
| } |
| return; |
| } |
|
David Tseng
2016/01/28 02:00:56
Are there clients on other platforms that may need
|
| - |
| - // Set focus to the root if it's not anywhere else. |
| - if (!focus_) { |
| - SetFocus(tree_->root(), false); |
| - should_send_initial_focus = true; |
| - } |
| } |
| - if (should_send_initial_focus && NativeViewHasFocus()) |
| - NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetFromAXNode(focus_)); |
| - |
| // Now iterate over the events again and fire the events. |
| for (uint32_t index = 0; index < details.size(); index++) { |
| const AXEventNotificationDetails& detail = details[index]; |
| @@ -324,8 +311,6 @@ void BrowserAccessibilityManager::OnAccessibilityEvents( |
| ui::AXEvent event_type = detail.event_type; |
| if (event_type == ui::AX_EVENT_FOCUS || |
| event_type == ui::AX_EVENT_BLUR) { |
| - SetFocus(node, false); |
| - |
| if (osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_HIDDEN && |
| osk_state_ != OSK_DISALLOWED_BECAUSE_TAB_JUST_APPEARED) |
| osk_state_ = OSK_ALLOWED; |
| @@ -390,21 +375,20 @@ void BrowserAccessibilityManager::ActivateFindInPageResult( |
| NotifyAccessibilityEvent(ui::AX_EVENT_SCROLLED_TO_ANCHOR, node); |
| } |
| -BrowserAccessibility* BrowserAccessibilityManager::GetActiveDescendantFocus( |
| - BrowserAccessibility* root) { |
| - BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(root); |
| - if (!node) |
| +BrowserAccessibility* BrowserAccessibilityManager::GetActiveDescendantFocus() { |
| + BrowserAccessibility* focus = GetFocus(); |
| + if (!focus) |
| return NULL; |
| int active_descendant_id; |
| - if (node->GetIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, |
| - &active_descendant_id)) { |
| + if (focus->GetIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, |
| + &active_descendant_id)) { |
| BrowserAccessibility* active_descendant = |
| - node->manager()->GetFromID(active_descendant_id); |
| + focus->manager()->GetFromID(active_descendant_id); |
| if (active_descendant) |
| return active_descendant; |
| } |
| - return node; |
| + return focus; |
| } |
| bool BrowserAccessibilityManager::NativeViewHasFocus() { |
| @@ -414,39 +398,26 @@ bool BrowserAccessibilityManager::NativeViewHasFocus() { |
| return false; |
| } |
| -BrowserAccessibility* BrowserAccessibilityManager::GetFocus( |
| - BrowserAccessibility* root) { |
| - if (!focus_) |
| - return nullptr; |
| +BrowserAccessibility* BrowserAccessibilityManager::GetFocus() { |
| + int32_t focus_id = GetTreeData().focus_id; |
| + BrowserAccessibility* obj = GetFromID(focus_id); |
| + if (!obj) |
| + return GetRoot(); |
| - if (root && !focus_->IsDescendantOf(root->node())) |
| - return nullptr; |
| - |
| - BrowserAccessibility* obj = GetFromAXNode(focus_); |
| - DCHECK(obj); |
| if (obj->HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { |
| BrowserAccessibilityManager* child_manager = |
| BrowserAccessibilityManager::FromID( |
| obj->GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); |
| if (child_manager) |
| - return child_manager->GetFocus(child_manager->GetRoot()); |
| + return child_manager->GetFocus(); |
| } |
| return obj; |
| } |
| -void BrowserAccessibilityManager::SetFocus(ui::AXNode* node, bool notify) { |
| - if (focus_ != node) |
| - focus_ = node; |
| - |
| - if (notify && node && delegate_) |
| - delegate_->AccessibilitySetFocus(node->id()); |
| -} |
| - |
| -void BrowserAccessibilityManager::SetFocus( |
| - BrowserAccessibility* obj, bool notify) { |
| - if (obj->node()) |
| - SetFocus(obj->node(), notify); |
| +void BrowserAccessibilityManager::SetFocus(const BrowserAccessibility& node) { |
| + if (delegate_) |
| + delegate_->AccessibilitySetFocus(node.GetId()); |
| } |
| void BrowserAccessibilityManager::DoDefaultAction( |
| @@ -558,12 +529,6 @@ void BrowserAccessibilityManager::OnTreeDataChanged(ui::AXTree* tree) { |
| void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXTree* tree, |
| ui::AXNode* node) { |
| DCHECK(node); |
| - if (node == focus_ && tree_) { |
| - if (node != tree_->root()) |
| - SetFocus(tree_->root(), false); |
| - else |
| - focus_ = NULL; |
| - } |
| if (id_wrapper_map_.find(node->id()) == id_wrapper_map_.end()) |
| return; |
| GetFromAXNode(node)->Destroy(); |