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 2571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 // ISimpleDOMDocument methods. | 2582 // ISimpleDOMDocument methods. |
2583 // | 2583 // |
2584 | 2584 |
2585 STDMETHODIMP BrowserAccessibilityWin::get_URL(BSTR* url) { | 2585 STDMETHODIMP BrowserAccessibilityWin::get_URL(BSTR* url) { |
2586 if (!instance_active()) | 2586 if (!instance_active()) |
2587 return E_FAIL; | 2587 return E_FAIL; |
2588 | 2588 |
2589 if (!url) | 2589 if (!url) |
2590 return E_INVALIDARG; | 2590 return E_INVALIDARG; |
2591 | 2591 |
2592 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_URL, url); | 2592 if (this != manager()->GetRoot()) |
| 2593 return E_FAIL; |
| 2594 |
| 2595 std::string str = manager()->GetTreeData().url; |
| 2596 if (str.empty()) |
| 2597 return S_FALSE; |
| 2598 |
| 2599 *url = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2600 DCHECK(*url); |
| 2601 |
| 2602 return S_OK; |
2593 } | 2603 } |
2594 | 2604 |
2595 STDMETHODIMP BrowserAccessibilityWin::get_title(BSTR* title) { | 2605 STDMETHODIMP BrowserAccessibilityWin::get_title(BSTR* title) { |
2596 if (!instance_active()) | 2606 if (!instance_active()) |
2597 return E_FAIL; | 2607 return E_FAIL; |
2598 | 2608 |
2599 if (!title) | 2609 if (!title) |
2600 return E_INVALIDARG; | 2610 return E_INVALIDARG; |
2601 | 2611 |
2602 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_TITLE, title); | 2612 std::string str = manager()->GetTreeData().title; |
| 2613 if (str.empty()) |
| 2614 return S_FALSE; |
| 2615 |
| 2616 *title = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2617 DCHECK(*title); |
| 2618 |
| 2619 return S_OK; |
2603 } | 2620 } |
2604 | 2621 |
2605 STDMETHODIMP BrowserAccessibilityWin::get_mimeType(BSTR* mime_type) { | 2622 STDMETHODIMP BrowserAccessibilityWin::get_mimeType(BSTR* mime_type) { |
2606 if (!instance_active()) | 2623 if (!instance_active()) |
2607 return E_FAIL; | 2624 return E_FAIL; |
2608 | 2625 |
2609 if (!mime_type) | 2626 if (!mime_type) |
2610 return E_INVALIDARG; | 2627 return E_INVALIDARG; |
2611 | 2628 |
2612 return GetStringAttributeAsBstr( | 2629 std::string str = manager()->GetTreeData().mimetype; |
2613 ui::AX_ATTR_DOC_MIMETYPE, mime_type); | 2630 if (str.empty()) |
| 2631 return S_FALSE; |
| 2632 |
| 2633 *mime_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2634 DCHECK(*mime_type); |
| 2635 |
| 2636 return S_OK; |
2614 } | 2637 } |
2615 | 2638 |
2616 STDMETHODIMP BrowserAccessibilityWin::get_docType(BSTR* doc_type) { | 2639 STDMETHODIMP BrowserAccessibilityWin::get_docType(BSTR* doc_type) { |
2617 if (!instance_active()) | 2640 if (!instance_active()) |
2618 return E_FAIL; | 2641 return E_FAIL; |
2619 | 2642 |
2620 if (!doc_type) | 2643 if (!doc_type) |
2621 return E_INVALIDARG; | 2644 return E_INVALIDARG; |
2622 | 2645 |
2623 return GetStringAttributeAsBstr( | 2646 std::string str = manager()->GetTreeData().doctype; |
2624 ui::AX_ATTR_DOC_DOCTYPE, doc_type); | 2647 if (str.empty()) |
| 2648 return S_FALSE; |
| 2649 |
| 2650 *doc_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2651 DCHECK(*doc_type); |
| 2652 |
| 2653 return S_OK; |
2625 } | 2654 } |
2626 | 2655 |
2627 STDMETHODIMP | 2656 STDMETHODIMP |
2628 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id, | 2657 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id, |
2629 BSTR* name_space_uri) { | 2658 BSTR* name_space_uri) { |
2630 return E_NOTIMPL; | 2659 return E_NOTIMPL; |
2631 } | 2660 } |
2632 STDMETHODIMP | 2661 STDMETHODIMP |
2633 BrowserAccessibilityWin::put_alternateViewMediaTypes( | 2662 BrowserAccessibilityWin::put_alternateViewMediaTypes( |
2634 BSTR* comma_separated_media_types) { | 2663 BSTR* comma_separated_media_types) { |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3355 if (name.empty() && !title_elem_id) { | 3384 if (name.empty() && !title_elem_id) { |
3356 name = placeholder; | 3385 name = placeholder; |
3357 } else if (description.empty()) { | 3386 } else if (description.empty()) { |
3358 description = placeholder; | 3387 description = placeholder; |
3359 } | 3388 } |
3360 } | 3389 } |
3361 | 3390 |
3362 // On Windows, the value of a document should be its url. | 3391 // On Windows, the value of a document should be its url. |
3363 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || | 3392 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || |
3364 GetRole() == ui::AX_ROLE_WEB_AREA) { | 3393 GetRole() == ui::AX_ROLE_WEB_AREA) { |
3365 value = GetString16Attribute(ui::AX_ATTR_DOC_URL); | 3394 value = base::UTF8ToUTF16(manager()->GetTreeData().url); |
3366 } | 3395 } |
3367 | 3396 |
3368 // For certain roles (listbox option, static text, and list marker) | 3397 // For certain roles (listbox option, static text, and list marker) |
3369 // WebKit stores the main accessible text in the "value" - swap it so | 3398 // WebKit stores the main accessible text in the "value" - swap it so |
3370 // that it's the "name". | 3399 // that it's the "name". |
3371 if (name.empty() && | 3400 if (name.empty() && |
3372 (GetRole() == ui::AX_ROLE_STATIC_TEXT || | 3401 (GetRole() == ui::AX_ROLE_STATIC_TEXT || |
3373 GetRole() == ui::AX_ROLE_LIST_MARKER || | 3402 GetRole() == ui::AX_ROLE_LIST_MARKER || |
3374 IsListBoxOptionOrMenuListOption())) { | 3403 IsListBoxOptionOrMenuListOption())) { |
3375 base::string16 tmp = value; | 3404 base::string16 tmp = value; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3784 return 0; | 3813 return 0; |
3785 if (endpoint_index_in_common_parent > index_in_common_parent) | 3814 if (endpoint_index_in_common_parent > index_in_common_parent) |
3786 return TextForIAccessibleText().length(); | 3815 return TextForIAccessibleText().length(); |
3787 | 3816 |
3788 NOTREACHED(); | 3817 NOTREACHED(); |
3789 return -1; | 3818 return -1; |
3790 } | 3819 } |
3791 | 3820 |
3792 int BrowserAccessibilityWin::GetSelectionAnchor() const { | 3821 int BrowserAccessibilityWin::GetSelectionAnchor() const { |
3793 BrowserAccessibility* root = manager()->GetRoot(); | 3822 BrowserAccessibility* root = manager()->GetRoot(); |
3794 int32 anchor_id; | 3823 if (!root) |
3795 if (!root || !root->GetIntAttribute(ui::AX_ATTR_ANCHOR_OBJECT_ID, &anchor_id)) | |
3796 return -1; | 3824 return -1; |
3797 | 3825 |
| 3826 int32 anchor_id = manager()->GetTreeData().sel_anchor_object_id; |
3798 BrowserAccessibilityWin* anchor_object = manager()->GetFromID( | 3827 BrowserAccessibilityWin* anchor_object = manager()->GetFromID( |
3799 anchor_id)->ToBrowserAccessibilityWin(); | 3828 anchor_id)->ToBrowserAccessibilityWin(); |
3800 if (!anchor_object) | 3829 if (!anchor_object) |
3801 return -1; | 3830 return -1; |
3802 | 3831 |
3803 int anchor_offset; | 3832 int32 anchor_offset = manager()->GetTreeData().sel_anchor_offset; |
3804 if (!root->GetIntAttribute(ui::AX_ATTR_ANCHOR_OFFSET, &anchor_offset)) | 3833 if (!anchor_offset) |
3805 return -1; | 3834 return -1; |
3806 | 3835 |
3807 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset); | 3836 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset); |
3808 } | 3837 } |
3809 | 3838 |
3810 int BrowserAccessibilityWin::GetSelectionFocus() const { | 3839 int BrowserAccessibilityWin::GetSelectionFocus() const { |
3811 BrowserAccessibility* root = manager()->GetRoot(); | 3840 BrowserAccessibility* root = manager()->GetRoot(); |
3812 int32 focus_id; | 3841 if (!root) |
3813 if (!root || !root->GetIntAttribute(ui::AX_ATTR_FOCUS_OBJECT_ID, &focus_id)) | |
3814 return -1; | 3842 return -1; |
3815 | 3843 |
| 3844 int32 focus_id = manager()->GetTreeData().sel_focus_object_id; |
3816 BrowserAccessibilityWin* focus_object = manager()->GetFromID( | 3845 BrowserAccessibilityWin* focus_object = manager()->GetFromID( |
3817 focus_id)->ToBrowserAccessibilityWin(); | 3846 focus_id)->ToBrowserAccessibilityWin(); |
3818 if (!focus_object) | 3847 if (!focus_object) |
3819 return -1; | 3848 return -1; |
3820 | 3849 |
3821 int focus_offset; | 3850 int focus_offset = manager()->GetTreeData().sel_focus_offset; |
3822 if (!root->GetIntAttribute(ui::AX_ATTR_FOCUS_OFFSET, &focus_offset)) | |
3823 return -1; | |
3824 | |
3825 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset); | 3851 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset); |
3826 } | 3852 } |
3827 | 3853 |
3828 void BrowserAccessibilityWin::GetSelectionOffsets( | 3854 void BrowserAccessibilityWin::GetSelectionOffsets( |
3829 int* selection_start, int* selection_end) const { | 3855 int* selection_start, int* selection_end) const { |
3830 DCHECK(selection_start && selection_end); | 3856 DCHECK(selection_start && selection_end); |
3831 | 3857 |
3832 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && | 3858 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && |
3833 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, selection_start) && | 3859 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, selection_start) && |
3834 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) { | 3860 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) { |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4674 ia2_role = ia_role; | 4700 ia2_role = ia_role; |
4675 | 4701 |
4676 win_attributes_->ia_role = ia_role; | 4702 win_attributes_->ia_role = ia_role; |
4677 win_attributes_->ia_state = ia_state; | 4703 win_attributes_->ia_state = ia_state; |
4678 win_attributes_->role_name = role_name; | 4704 win_attributes_->role_name = role_name; |
4679 win_attributes_->ia2_role = ia2_role; | 4705 win_attributes_->ia2_role = ia2_role; |
4680 win_attributes_->ia2_state = ia2_state; | 4706 win_attributes_->ia2_state = ia2_state; |
4681 } | 4707 } |
4682 | 4708 |
4683 } // namespace content | 4709 } // namespace content |
OLD | NEW |