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 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2658 // ISimpleDOMDocument methods. | 2658 // ISimpleDOMDocument methods. |
2659 // | 2659 // |
2660 | 2660 |
2661 STDMETHODIMP BrowserAccessibilityWin::get_URL(BSTR* url) { | 2661 STDMETHODIMP BrowserAccessibilityWin::get_URL(BSTR* url) { |
2662 if (!instance_active()) | 2662 if (!instance_active()) |
2663 return E_FAIL; | 2663 return E_FAIL; |
2664 | 2664 |
2665 if (!url) | 2665 if (!url) |
2666 return E_INVALIDARG; | 2666 return E_INVALIDARG; |
2667 | 2667 |
2668 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_URL, url); | 2668 if (this != manager()->GetRoot()) |
| 2669 return E_FAIL; |
| 2670 |
| 2671 std::string str = manager()->GetTreeData().url; |
| 2672 if (str.empty()) |
| 2673 return S_FALSE; |
| 2674 |
| 2675 *url = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2676 DCHECK(*url); |
| 2677 |
| 2678 return S_OK; |
2669 } | 2679 } |
2670 | 2680 |
2671 STDMETHODIMP BrowserAccessibilityWin::get_title(BSTR* title) { | 2681 STDMETHODIMP BrowserAccessibilityWin::get_title(BSTR* title) { |
2672 if (!instance_active()) | 2682 if (!instance_active()) |
2673 return E_FAIL; | 2683 return E_FAIL; |
2674 | 2684 |
2675 if (!title) | 2685 if (!title) |
2676 return E_INVALIDARG; | 2686 return E_INVALIDARG; |
2677 | 2687 |
2678 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_TITLE, title); | 2688 std::string str = manager()->GetTreeData().title; |
| 2689 if (str.empty()) |
| 2690 return S_FALSE; |
| 2691 |
| 2692 *title = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2693 DCHECK(*title); |
| 2694 |
| 2695 return S_OK; |
2679 } | 2696 } |
2680 | 2697 |
2681 STDMETHODIMP BrowserAccessibilityWin::get_mimeType(BSTR* mime_type) { | 2698 STDMETHODIMP BrowserAccessibilityWin::get_mimeType(BSTR* mime_type) { |
2682 if (!instance_active()) | 2699 if (!instance_active()) |
2683 return E_FAIL; | 2700 return E_FAIL; |
2684 | 2701 |
2685 if (!mime_type) | 2702 if (!mime_type) |
2686 return E_INVALIDARG; | 2703 return E_INVALIDARG; |
2687 | 2704 |
2688 return GetStringAttributeAsBstr( | 2705 std::string str = manager()->GetTreeData().mimetype; |
2689 ui::AX_ATTR_DOC_MIMETYPE, mime_type); | 2706 if (str.empty()) |
| 2707 return S_FALSE; |
| 2708 |
| 2709 *mime_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2710 DCHECK(*mime_type); |
| 2711 |
| 2712 return S_OK; |
2690 } | 2713 } |
2691 | 2714 |
2692 STDMETHODIMP BrowserAccessibilityWin::get_docType(BSTR* doc_type) { | 2715 STDMETHODIMP BrowserAccessibilityWin::get_docType(BSTR* doc_type) { |
2693 if (!instance_active()) | 2716 if (!instance_active()) |
2694 return E_FAIL; | 2717 return E_FAIL; |
2695 | 2718 |
2696 if (!doc_type) | 2719 if (!doc_type) |
2697 return E_INVALIDARG; | 2720 return E_INVALIDARG; |
2698 | 2721 |
2699 return GetStringAttributeAsBstr( | 2722 std::string str = manager()->GetTreeData().doctype; |
2700 ui::AX_ATTR_DOC_DOCTYPE, doc_type); | 2723 if (str.empty()) |
| 2724 return S_FALSE; |
| 2725 |
| 2726 *doc_type = SysAllocString(base::UTF8ToUTF16(str).c_str()); |
| 2727 DCHECK(*doc_type); |
| 2728 |
| 2729 return S_OK; |
2701 } | 2730 } |
2702 | 2731 |
2703 STDMETHODIMP | 2732 STDMETHODIMP |
2704 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id, | 2733 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id, |
2705 BSTR* name_space_uri) { | 2734 BSTR* name_space_uri) { |
2706 return E_NOTIMPL; | 2735 return E_NOTIMPL; |
2707 } | 2736 } |
2708 STDMETHODIMP | 2737 STDMETHODIMP |
2709 BrowserAccessibilityWin::put_alternateViewMediaTypes( | 2738 BrowserAccessibilityWin::put_alternateViewMediaTypes( |
2710 BSTR* comma_separated_media_types) { | 2739 BSTR* comma_separated_media_types) { |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3437 if (name.empty() && !title_elem_id) { | 3466 if (name.empty() && !title_elem_id) { |
3438 name = placeholder; | 3467 name = placeholder; |
3439 } else if (description.empty()) { | 3468 } else if (description.empty()) { |
3440 description = placeholder; | 3469 description = placeholder; |
3441 } | 3470 } |
3442 } | 3471 } |
3443 | 3472 |
3444 // On Windows, the value of a document should be its url. | 3473 // On Windows, the value of a document should be its url. |
3445 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || | 3474 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || |
3446 GetRole() == ui::AX_ROLE_WEB_AREA) { | 3475 GetRole() == ui::AX_ROLE_WEB_AREA) { |
3447 value = GetString16Attribute(ui::AX_ATTR_DOC_URL); | 3476 value = base::UTF8ToUTF16(manager()->GetTreeData().url); |
3448 } | 3477 } |
3449 | 3478 |
3450 // For certain roles (listbox option, static text, and list marker) | 3479 // For certain roles (listbox option, static text, and list marker) |
3451 // WebKit stores the main accessible text in the "value" - swap it so | 3480 // WebKit stores the main accessible text in the "value" - swap it so |
3452 // that it's the "name". | 3481 // that it's the "name". |
3453 if (name.empty() && | 3482 if (name.empty() && |
3454 (GetRole() == ui::AX_ROLE_STATIC_TEXT || | 3483 (GetRole() == ui::AX_ROLE_STATIC_TEXT || |
3455 GetRole() == ui::AX_ROLE_LIST_MARKER || | 3484 GetRole() == ui::AX_ROLE_LIST_MARKER || |
3456 IsListBoxOptionOrMenuListOption())) { | 3485 IsListBoxOptionOrMenuListOption())) { |
3457 base::string16 tmp = value; | 3486 base::string16 tmp = value; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3878 if (endpoint_index_in_common_parent < index_in_common_parent) | 3907 if (endpoint_index_in_common_parent < index_in_common_parent) |
3879 return 0; | 3908 return 0; |
3880 if (endpoint_index_in_common_parent > index_in_common_parent) | 3909 if (endpoint_index_in_common_parent > index_in_common_parent) |
3881 return TextForIAccessibleText().length(); | 3910 return TextForIAccessibleText().length(); |
3882 | 3911 |
3883 NOTREACHED(); | 3912 NOTREACHED(); |
3884 return -1; | 3913 return -1; |
3885 } | 3914 } |
3886 | 3915 |
3887 int BrowserAccessibilityWin::GetSelectionAnchor() const { | 3916 int BrowserAccessibilityWin::GetSelectionAnchor() const { |
3888 BrowserAccessibility* root = manager()->GetRoot(); | 3917 int32 anchor_id = manager()->GetTreeData().sel_anchor_object_id; |
3889 int32 anchor_id; | |
3890 if (!root || !root->GetIntAttribute(ui::AX_ATTR_ANCHOR_OBJECT_ID, &anchor_id)) | |
3891 return -1; | |
3892 | |
3893 BrowserAccessibilityWin* anchor_object = manager()->GetFromID( | 3918 BrowserAccessibilityWin* anchor_object = manager()->GetFromID( |
3894 anchor_id)->ToBrowserAccessibilityWin(); | 3919 anchor_id)->ToBrowserAccessibilityWin(); |
3895 if (!anchor_object) | 3920 if (!anchor_object) |
3896 return -1; | 3921 return -1; |
3897 | 3922 |
3898 int anchor_offset; | 3923 int32 anchor_offset = manager()->GetTreeData().sel_anchor_offset; |
3899 if (!root->GetIntAttribute(ui::AX_ATTR_ANCHOR_OFFSET, &anchor_offset)) | |
3900 return -1; | |
3901 | |
3902 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset); | 3924 return GetHypertextOffsetFromEndpoint(*anchor_object, anchor_offset); |
3903 } | 3925 } |
3904 | 3926 |
3905 int BrowserAccessibilityWin::GetSelectionFocus() const { | 3927 int BrowserAccessibilityWin::GetSelectionFocus() const { |
3906 BrowserAccessibility* root = manager()->GetRoot(); | 3928 int32 focus_id = manager()->GetTreeData().sel_focus_object_id; |
3907 int32 focus_id; | |
3908 if (!root || !root->GetIntAttribute(ui::AX_ATTR_FOCUS_OBJECT_ID, &focus_id)) | |
3909 return -1; | |
3910 | |
3911 BrowserAccessibilityWin* focus_object = manager()->GetFromID( | 3929 BrowserAccessibilityWin* focus_object = manager()->GetFromID( |
3912 focus_id)->ToBrowserAccessibilityWin(); | 3930 focus_id)->ToBrowserAccessibilityWin(); |
3913 if (!focus_object) | 3931 if (!focus_object) |
3914 return -1; | 3932 return -1; |
3915 | 3933 |
3916 int focus_offset; | 3934 int focus_offset = manager()->GetTreeData().sel_focus_offset; |
3917 if (!root->GetIntAttribute(ui::AX_ATTR_FOCUS_OFFSET, &focus_offset)) | |
3918 return -1; | |
3919 | |
3920 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset); | 3935 return GetHypertextOffsetFromEndpoint(*focus_object, focus_offset); |
3921 } | 3936 } |
3922 | 3937 |
3923 void BrowserAccessibilityWin::GetSelectionOffsets( | 3938 void BrowserAccessibilityWin::GetSelectionOffsets( |
3924 int* selection_start, int* selection_end) const { | 3939 int* selection_start, int* selection_end) const { |
3925 DCHECK(selection_start && selection_end); | 3940 DCHECK(selection_start && selection_end); |
3926 | 3941 |
3927 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && | 3942 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && |
3928 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, selection_start) && | 3943 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, selection_start) && |
3929 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) { | 3944 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, selection_end)) { |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4769 ia2_role = ia_role; | 4784 ia2_role = ia_role; |
4770 | 4785 |
4771 win_attributes_->ia_role = ia_role; | 4786 win_attributes_->ia_role = ia_role; |
4772 win_attributes_->ia_state = ia_state; | 4787 win_attributes_->ia_state = ia_state; |
4773 win_attributes_->role_name = role_name; | 4788 win_attributes_->role_name = role_name; |
4774 win_attributes_->ia2_role = ia2_role; | 4789 win_attributes_->ia2_role = ia2_role; |
4775 win_attributes_->ia2_state = ia2_state; | 4790 win_attributes_->ia2_state = ia2_state; |
4776 } | 4791 } |
4777 | 4792 |
4778 } // namespace content | 4793 } // namespace content |
OLD | NEW |