Chromium Code Reviews| 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_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 6 | 6 |
| 7 #include <UIAutomationClient.h> | 7 #include <UIAutomationClient.h> |
| 8 #include <UIAutomationCoreApi.h> | 8 #include <UIAutomationCoreApi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2404 if (!instance_active()) | 2404 if (!instance_active()) |
| 2405 return E_FAIL; | 2405 return E_FAIL; |
| 2406 | 2406 |
| 2407 if (!hyperlink || | 2407 if (!hyperlink || |
| 2408 index < 0 || | 2408 index < 0 || |
| 2409 index >= static_cast<long>(hyperlinks().size())) { | 2409 index >= static_cast<long>(hyperlinks().size())) { |
| 2410 return E_INVALIDARG; | 2410 return E_INVALIDARG; |
| 2411 } | 2411 } |
| 2412 | 2412 |
| 2413 int32_t id = hyperlinks()[index]; | 2413 int32_t id = hyperlinks()[index]; |
| 2414 BrowserAccessibilityWin* link = GetFromID(id); | 2414 BrowserAccessibilityWin* link = nullptr; |
| 2415 if (id < 0) { | |
| 2416 // We are at a tree boundary. | |
| 2417 link = ToBrowserAccessibilityWin(PlatformGetChild(0)); | |
| 2418 } else { | |
| 2419 link = GetFromID(id); | |
| 2420 } | |
| 2415 if (!link) | 2421 if (!link) |
| 2416 return E_FAIL; | 2422 return E_FAIL; |
| 2417 | 2423 |
| 2418 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference()); | 2424 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference()); |
| 2419 return S_OK; | 2425 return S_OK; |
| 2420 } | 2426 } |
| 2421 | 2427 |
| 2422 STDMETHODIMP BrowserAccessibilityWin::get_hyperlinkIndex( | 2428 STDMETHODIMP BrowserAccessibilityWin::get_hyperlinkIndex( |
| 2423 long char_index, | 2429 long char_index, |
| 2424 long* hyperlink_index) { | 2430 long* hyperlink_index) { |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3502 case ui::AX_SORT_DIRECTION_OTHER: | 3508 case ui::AX_SORT_DIRECTION_OTHER: |
| 3503 win_attributes_->ia2_attributes.push_back(L"sort:other"); | 3509 win_attributes_->ia2_attributes.push_back(L"sort:other"); |
| 3504 break; | 3510 break; |
| 3505 } | 3511 } |
| 3506 } | 3512 } |
| 3507 | 3513 |
| 3508 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME); | 3514 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME); |
| 3509 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); | 3515 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); |
| 3510 | 3516 |
| 3511 base::string16 value = GetValue(); | 3517 base::string16 value = GetValue(); |
| 3512 | |
| 3513 // On Windows, the value of a document should be its url. | 3518 // On Windows, the value of a document should be its url. |
| 3514 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || | 3519 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || |
| 3515 GetRole() == ui::AX_ROLE_WEB_AREA) { | 3520 GetRole() == ui::AX_ROLE_WEB_AREA) { |
| 3516 value = base::UTF8ToUTF16(manager()->GetTreeData().url); | 3521 value = base::UTF8ToUTF16(manager()->GetTreeData().url); |
| 3517 } | 3522 } |
| 3518 | |
| 3519 // If this doesn't have a value and is linked then set its value to the url | 3523 // If this doesn't have a value and is linked then set its value to the url |
| 3520 // attribute. This allows screen readers to read an empty link's destination. | 3524 // attribute. This allows screen readers to read an empty link's destination. |
| 3521 if (value.empty() && (ia_state() & STATE_SYSTEM_LINKED)) | 3525 if (value.empty() && (ia_state() & STATE_SYSTEM_LINKED)) |
| 3522 value = GetString16Attribute(ui::AX_ATTR_URL); | 3526 value = GetString16Attribute(ui::AX_ATTR_URL); |
| 3523 | |
| 3524 win_attributes_->value = value; | 3527 win_attributes_->value = value; |
| 3525 | 3528 |
| 3526 // Clear any old relationships between this node and other nodes. | 3529 // Clear any old relationships between this node and other nodes. |
| 3527 for (size_t i = 0; i < relations_.size(); ++i) | 3530 for (size_t i = 0; i < relations_.size(); ++i) |
| 3528 relations_[i]->Release(); | 3531 relations_[i]->Release(); |
| 3529 relations_.clear(); | 3532 relations_.clear(); |
| 3530 | 3533 |
| 3531 // Handle title UI element. | 3534 // Handle title UI element. |
| 3532 AddRelations(ui::AX_ATTR_CONTROLS_IDS, IA2_RELATION_CONTROLLER_FOR); | 3535 AddRelations(ui::AX_ATTR_CONTROLS_IDS, IA2_RELATION_CONTROLLER_FOR); |
| 3533 AddRelations(ui::AX_ATTR_DESCRIBEDBY_IDS, IA2_RELATION_DESCRIBED_BY); | 3536 AddRelations(ui::AX_ATTR_DESCRIBEDBY_IDS, IA2_RELATION_DESCRIBED_BY); |
| 3534 AddRelations(ui::AX_ATTR_FLOWTO_IDS, IA2_RELATION_FLOWS_TO); | 3537 AddRelations(ui::AX_ATTR_FLOWTO_IDS, IA2_RELATION_FLOWS_TO); |
| 3535 AddRelations(ui::AX_ATTR_LABELLEDBY_IDS, IA2_RELATION_LABELLED_BY); | 3538 AddRelations(ui::AX_ATTR_LABELLEDBY_IDS, IA2_RELATION_LABELLED_BY); |
| 3536 | 3539 |
| 3537 UpdateRequiredAttributes(); | 3540 UpdateRequiredAttributes(); |
| 3538 // If this is a web area for a presentational iframe, give it a role of | 3541 // If this is a web area for a presentational iframe, give it a role of |
| 3539 // something other than DOCUMENT so that the fact that it's a separate doc | 3542 // something other than DOCUMENT so that the fact that it's a separate doc |
| 3540 // is not exposed to AT. | 3543 // is not exposed to AT. |
| 3541 if (IsWebAreaForPresentationalIframe()) { | 3544 if (IsWebAreaForPresentationalIframe()) { |
| 3542 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING; | 3545 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING; |
| 3543 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING; | 3546 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING; |
| 3544 } | 3547 } |
| 3545 } | 3548 } |
| 3546 | 3549 |
| 3547 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() { | 3550 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() { |
| 3548 if (PlatformIsLeaf()) { | 3551 if (!PlatformChildCount()) { |
| 3549 if (IsSimpleTextControl()) | 3552 if (IsSimpleTextControl()) { |
| 3550 win_attributes_->hypertext = value(); | 3553 win_attributes_->hypertext = value(); |
| 3551 else { | 3554 } else if (IsRichTextControl()) { |
| 3555 // We don't want to expose any associated label in IA2 Hypertext. | |
| 3556 return; | |
| 3557 } else { | |
| 3552 win_attributes_->hypertext = name(); | 3558 win_attributes_->hypertext = name(); |
| 3553 } | 3559 } |
| 3554 | 3560 |
| 3555 return; | 3561 return; |
| 3556 } | 3562 } |
| 3557 | 3563 |
| 3558 // Construct the hypertext for this node, which contains the concatenation | 3564 // Construct the hypertext for this node, which contains the concatenation |
| 3559 // of all of the static text and widespace of this node's children and an | 3565 // of all of the static text and widespace of this node's children and an |
| 3560 // embedded object character for all the other children. Build up a map from | 3566 // embedded object character for all the other children. Build up a map from |
| 3561 // the character index of each embedded object character to the id of the | 3567 // the character index of each embedded object character to the id of the |
| 3562 // child object it points to. | 3568 // child object it points to. |
| 3563 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { | 3569 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { |
| 3564 const auto child = ToBrowserAccessibilityWin(PlatformGetChild(i)); | 3570 const auto child = ToBrowserAccessibilityWin(PlatformGetChild(i)); |
| 3565 DCHECK(child); | 3571 DCHECK(child); |
| 3566 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. | 3572 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. |
| 3567 if (child->IsTextOnlyObject()) { | 3573 if (child->IsTextOnlyObject()) { |
| 3568 win_attributes_->hypertext += child->name(); | 3574 win_attributes_->hypertext += child->name(); |
| 3569 } else { | 3575 } else { |
| 3570 int32_t char_offset = static_cast<int32_t>(GetText().size()); | 3576 int32_t char_offset = static_cast<int32_t>(GetText().size()); |
| 3571 int32_t child_id = child->GetId(); | 3577 int32_t child_id = child->GetId(); |
| 3578 if (i == 0 && HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { | |
| 3579 // Cannot store IDs from another tree into this node. Store an invalid | |
| 3580 // ID to signal that we are in this situation. | |
| 3581 child_id = -1; | |
|
dmazzoni
2016/06/06 22:24:34
Use a unique id instead. Every BrowserAccessibilit
| |
| 3582 } | |
| 3572 int32_t index = hyperlinks().size(); | 3583 int32_t index = hyperlinks().size(); |
| 3573 win_attributes_->hyperlink_offset_to_index[char_offset] = index; | 3584 win_attributes_->hyperlink_offset_to_index[char_offset] = index; |
| 3574 win_attributes_->hyperlinks.push_back(child_id); | 3585 win_attributes_->hyperlinks.push_back(child_id); |
| 3575 win_attributes_->hypertext += kEmbeddedCharacter; | 3586 win_attributes_->hypertext += kEmbeddedCharacter; |
| 3576 } | 3587 } |
| 3577 } | 3588 } |
| 3578 } | 3589 } |
| 3579 | 3590 |
| 3580 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation) { | 3591 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation) { |
| 3581 // Fire an event when an alert first appears. | 3592 // Fire an event when an alert first appears. |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4025 BrowserAccessibilityWin::GetHyperlinkFromHypertextOffset(int offset) const { | 4036 BrowserAccessibilityWin::GetHyperlinkFromHypertextOffset(int offset) const { |
| 4026 std::map<int32_t, int32_t>::iterator iterator = | 4037 std::map<int32_t, int32_t>::iterator iterator = |
| 4027 hyperlink_offset_to_index().find(offset); | 4038 hyperlink_offset_to_index().find(offset); |
| 4028 if (iterator == hyperlink_offset_to_index().end()) | 4039 if (iterator == hyperlink_offset_to_index().end()) |
| 4029 return nullptr; | 4040 return nullptr; |
| 4030 | 4041 |
| 4031 int32_t index = iterator->second; | 4042 int32_t index = iterator->second; |
| 4032 DCHECK_GE(index, 0); | 4043 DCHECK_GE(index, 0); |
| 4033 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size())); | 4044 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size())); |
| 4034 int32_t id = hyperlinks()[index]; | 4045 int32_t id = hyperlinks()[index]; |
| 4035 BrowserAccessibilityWin* hyperlink = GetFromID(id); | 4046 BrowserAccessibilityWin* hyperlink = nullptr; |
| 4047 if (id < 0) { | |
| 4048 hyperlink = ToBrowserAccessibilityWin(PlatformGetChild(0)); | |
| 4049 } else { | |
| 4050 hyperlink = GetFromID(id); | |
| 4051 } | |
| 4052 | |
| 4036 if (!hyperlink) | 4053 if (!hyperlink) |
| 4037 return nullptr; | 4054 return nullptr; |
| 4038 return hyperlink; | 4055 return hyperlink; |
| 4039 } | 4056 } |
| 4040 | 4057 |
| 4041 int32_t BrowserAccessibilityWin::GetHyperlinkIndexFromChild( | 4058 int32_t BrowserAccessibilityWin::GetHyperlinkIndexFromChild( |
| 4042 const BrowserAccessibilityWin& child) const { | 4059 const BrowserAccessibilityWin& child) const { |
| 4043 if (hyperlinks().empty()) | 4060 if (hyperlinks().empty()) |
| 4044 return -1; | 4061 return -1; |
| 4045 | 4062 |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5086 return static_cast<BrowserAccessibilityWin*>(obj); | 5103 return static_cast<BrowserAccessibilityWin*>(obj); |
| 5087 } | 5104 } |
| 5088 | 5105 |
| 5089 const BrowserAccessibilityWin* | 5106 const BrowserAccessibilityWin* |
| 5090 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { | 5107 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { |
| 5091 DCHECK(!obj || obj->IsNative()); | 5108 DCHECK(!obj || obj->IsNative()); |
| 5092 return static_cast<const BrowserAccessibilityWin*>(obj); | 5109 return static_cast<const BrowserAccessibilityWin*>(obj); |
| 5093 } | 5110 } |
| 5094 | 5111 |
| 5095 } // namespace content | 5112 } // namespace content |
| OLD | NEW |