| 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_mac.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/logging.h" |
| 8 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" | 12 #import "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/location.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 16 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 17 #import "content/browser/accessibility/browser_accessibility_mac.h" | 17 #import "content/browser/accessibility/browser_accessibility_mac.h" |
| 18 #include "content/common/accessibility_messages.h" | 18 #include "content/common/accessibility_messages.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "ui/accessibility/ax_role_properties.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Use same value as in Safari's WebKit. | 24 // Use same value as in Safari's WebKit. |
| 24 const int kLiveRegionChangeIntervalMS = 20; | 25 const int kLiveRegionChangeIntervalMS = 20; |
| 25 | 26 |
| 26 // Declare undocumented accessibility constants and enums only present in | 27 // Declare undocumented accessibility constants and enums only present in |
| 27 // WebKit. | 28 // WebKit. |
| 28 | 29 |
| 29 enum AXTextStateChangeType { | 30 enum AXTextStateChangeType { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (IsRootTree()) { | 204 if (IsRootTree()) { |
| 204 mac_notification = NSAccessibilityLoadCompleteNotification; | 205 mac_notification = NSAccessibilityLoadCompleteNotification; |
| 205 } else { | 206 } else { |
| 206 mac_notification = NSAccessibilityLayoutCompleteNotification; | 207 mac_notification = NSAccessibilityLayoutCompleteNotification; |
| 207 } | 208 } |
| 208 break; | 209 break; |
| 209 case ui::AX_EVENT_INVALID_STATUS_CHANGED: | 210 case ui::AX_EVENT_INVALID_STATUS_CHANGED: |
| 210 mac_notification = NSAccessibilityInvalidStatusChangedNotification; | 211 mac_notification = NSAccessibilityInvalidStatusChangedNotification; |
| 211 break; | 212 break; |
| 212 case ui::AX_EVENT_SELECTED_CHILDREN_CHANGED: | 213 case ui::AX_EVENT_SELECTED_CHILDREN_CHANGED: |
| 213 if (node->IsTableLikeRole()) { | 214 if (ui::IsTableLikeRole(node->GetRole())) { |
| 214 mac_notification = NSAccessibilitySelectedRowsChangedNotification; | 215 mac_notification = NSAccessibilitySelectedRowsChangedNotification; |
| 215 } else { | 216 } else { |
| 216 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; | 217 mac_notification = NSAccessibilitySelectedChildrenChangedNotification; |
| 217 } | 218 } |
| 218 break; | 219 break; |
| 219 case ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED: { | 220 case ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED: { |
| 220 mac_notification = NSAccessibilitySelectedTextChangedNotification; | 221 mac_notification = NSAccessibilitySelectedTextChangedNotification; |
| 221 // WebKit fires a notification both on the focused object and the root. | 222 // WebKit fires a notification both on the focused object and the root. |
| 222 BrowserAccessibility* focus = GetFocus(); | 223 BrowserAccessibility* focus = GetFocus(); |
| 223 if (!focus) | 224 if (!focus) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 while (i < old_text.length() && i < new_text.length() && | 425 while (i < old_text.length() && i < new_text.length() && |
| 425 old_text[i] == new_text[i]) { | 426 old_text[i] == new_text[i]) { |
| 426 ++i; | 427 ++i; |
| 427 } | 428 } |
| 428 size_t length = (old_text.length() - i) - (new_text.length() - i); | 429 size_t length = (old_text.length() - i) - (new_text.length() - i); |
| 429 base::string16 deleted_text = old_text.substr(i, length); | 430 base::string16 deleted_text = old_text.substr(i, length); |
| 430 text_edits_[new_node_data.id] = deleted_text; | 431 text_edits_[new_node_data.id] = deleted_text; |
| 431 } | 432 } |
| 432 } | 433 } |
| 433 | 434 |
| 434 bool IsContainerWithSelectableChildrenRole(ui::AXRole role) { | |
| 435 switch (role) { | |
| 436 case ui::AX_ROLE_COMBO_BOX: | |
| 437 case ui::AX_ROLE_GRID: | |
| 438 case ui::AX_ROLE_LIST_BOX: | |
| 439 case ui::AX_ROLE_MENU: | |
| 440 case ui::AX_ROLE_MENU_BAR: | |
| 441 case ui::AX_ROLE_RADIO_GROUP: | |
| 442 case ui::AX_ROLE_TAB_LIST: | |
| 443 case ui::AX_ROLE_TOOLBAR: | |
| 444 case ui::AX_ROLE_TREE: | |
| 445 case ui::AX_ROLE_TREE_GRID: | |
| 446 return true; | |
| 447 default: | |
| 448 return false; | |
| 449 } | |
| 450 } | |
| 451 | |
| 452 bool IsRowContainer(ui::AXRole role) { | |
| 453 switch (role) { | |
| 454 case ui::AX_ROLE_TREE: | |
| 455 case ui::AX_ROLE_TREE_GRID: | |
| 456 case ui::AX_ROLE_GRID: | |
| 457 case ui::AX_ROLE_TABLE: | |
| 458 return true; | |
| 459 default: | |
| 460 return false; | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 void BrowserAccessibilityManagerMac::OnStateChanged(ui::AXTree* tree, | 435 void BrowserAccessibilityManagerMac::OnStateChanged(ui::AXTree* tree, |
| 465 ui::AXNode* node, | 436 ui::AXNode* node, |
| 466 ui::AXState state, | 437 ui::AXState state, |
| 467 bool new_value) { | 438 bool new_value) { |
| 468 BrowserAccessibilityManager::OnStateChanged(tree, node, state, new_value); | 439 BrowserAccessibilityManager::OnStateChanged(tree, node, state, new_value); |
| 469 if (state == ui::AX_STATE_EXPANDED) { | 440 if (state == ui::AX_STATE_EXPANDED) { |
| 470 if (node->data().role == ui::AX_ROLE_ROW || | 441 if (node->data().role == ui::AX_ROLE_ROW || |
| 471 node->data().role == ui::AX_ROLE_TREE_ITEM) { | 442 node->data().role == ui::AX_ROLE_TREE_ITEM) { |
| 472 if (new_value) | 443 if (new_value) |
| 473 tree_events_[node->id()].insert(ui::AX_EVENT_ROW_EXPANDED); | 444 tree_events_[node->id()].insert(ui::AX_EVENT_ROW_EXPANDED); |
| 474 else | 445 else |
| 475 tree_events_[node->id()].insert(ui::AX_EVENT_ROW_COLLAPSED); | 446 tree_events_[node->id()].insert(ui::AX_EVENT_ROW_COLLAPSED); |
| 476 ui::AXNode* container = node; | 447 ui::AXNode* container = node; |
| 477 while (container && !IsRowContainer(container->data().role)) | 448 while (container && !ui::IsRowContainer(container->data().role)) |
| 478 container = container->parent(); | 449 container = container->parent(); |
| 479 if (container) | 450 if (container) |
| 480 tree_events_[container->id()].insert(ui::AX_EVENT_ROW_COUNT_CHANGED); | 451 tree_events_[container->id()].insert(ui::AX_EVENT_ROW_COUNT_CHANGED); |
| 481 } else { | 452 } else { |
| 482 tree_events_[node->id()].insert(ui::AX_EVENT_EXPANDED_CHANGED); | 453 tree_events_[node->id()].insert(ui::AX_EVENT_EXPANDED_CHANGED); |
| 483 } | 454 } |
| 484 } | 455 } |
| 485 if (state == ui::AX_STATE_SELECTED) { | 456 if (state == ui::AX_STATE_SELECTED) { |
| 486 ui::AXNode* container = node; | 457 ui::AXNode* container = node; |
| 487 while (container && | 458 while (container && |
| 488 !IsContainerWithSelectableChildrenRole(container->data().role)) | 459 !ui::IsContainerWithSelectableChildrenRole(container->data().role)) |
| 489 container = container->parent(); | 460 container = container->parent(); |
| 490 if (container) | 461 if (container) |
| 491 tree_events_[container->id()].insert( | 462 tree_events_[container->id()].insert( |
| 492 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED); | 463 ui::AX_EVENT_SELECTED_CHILDREN_CHANGED); |
| 493 } | 464 } |
| 494 } | 465 } |
| 495 | 466 |
| 496 void BrowserAccessibilityManagerMac::OnStringAttributeChanged( | 467 void BrowserAccessibilityManagerMac::OnStringAttributeChanged( |
| 497 ui::AXTree* tree, | 468 ui::AXTree* tree, |
| 498 ui::AXNode* node, | 469 ui::AXNode* node, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 NSAccessibilityTextChangeValues : changes, | 613 NSAccessibilityTextChangeValues : changes, |
| 643 NSAccessibilityTextChangeElement : native_node | 614 NSAccessibilityTextChangeElement : native_node |
| 644 }; | 615 }; |
| 645 } | 616 } |
| 646 | 617 |
| 647 NSView* BrowserAccessibilityManagerMac::GetParentView() { | 618 NSView* BrowserAccessibilityManagerMac::GetParentView() { |
| 648 return delegate() ? delegate()->AccessibilityGetAcceleratedWidget() : nullptr; | 619 return delegate() ? delegate()->AccessibilityGetAcceleratedWidget() : nullptr; |
| 649 } | 620 } |
| 650 | 621 |
| 651 } // namespace content | 622 } // namespace content |
| OLD | NEW |