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 "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 BrowserAccessibility* title_elem = | 473 BrowserAccessibility* title_elem = |
474 manager()->GetFromRendererID(title_elem_id); | 474 manager()->GetFromRendererID(title_elem_id); |
475 if (title_elem) | 475 if (title_elem) |
476 name_str = title_elem->GetTextRecursive(); | 476 name_str = title_elem->GetTextRecursive(); |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 if (name_str.empty()) | 480 if (name_str.empty()) |
481 return S_FALSE; | 481 return S_FALSE; |
482 | 482 |
483 *name = SysAllocString(UTF8ToUTF16(name_str).c_str()); | 483 *name = SysAllocString(base::UTF8ToUTF16(name_str).c_str()); |
484 | 484 |
485 DCHECK(*name); | 485 DCHECK(*name); |
486 return S_OK; | 486 return S_OK; |
487 } | 487 } |
488 | 488 |
489 STDMETHODIMP BrowserAccessibilityWin::get_accParent(IDispatch** disp_parent) { | 489 STDMETHODIMP BrowserAccessibilityWin::get_accParent(IDispatch** disp_parent) { |
490 if (!instance_active()) | 490 if (!instance_active()) |
491 return E_FAIL; | 491 return E_FAIL; |
492 | 492 |
493 if (!disp_parent) | 493 if (!disp_parent) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 AccessibilityNodeData::ATTR_COLOR_VALUE_BLUE); | 584 AccessibilityNodeData::ATTR_COLOR_VALUE_BLUE); |
585 base::string16 value_text; | 585 base::string16 value_text; |
586 value_text = base::IntToString16((r * 100) / 255) + L"% red " + | 586 value_text = base::IntToString16((r * 100) / 255) + L"% red " + |
587 base::IntToString16((g * 100) / 255) + L"% green " + | 587 base::IntToString16((g * 100) / 255) + L"% green " + |
588 base::IntToString16((b * 100) / 255) + L"% blue"; | 588 base::IntToString16((b * 100) / 255) + L"% blue"; |
589 *value = SysAllocString(value_text.c_str()); | 589 *value = SysAllocString(value_text.c_str()); |
590 DCHECK(*value); | 590 DCHECK(*value); |
591 return S_OK; | 591 return S_OK; |
592 } | 592 } |
593 | 593 |
594 *value = SysAllocString(UTF8ToUTF16(target->value()).c_str()); | 594 *value = SysAllocString(base::UTF8ToUTF16(target->value()).c_str()); |
595 DCHECK(*value); | 595 DCHECK(*value); |
596 return S_OK; | 596 return S_OK; |
597 } | 597 } |
598 | 598 |
599 STDMETHODIMP BrowserAccessibilityWin::get_accHelpTopic(BSTR* help_file, | 599 STDMETHODIMP BrowserAccessibilityWin::get_accHelpTopic(BSTR* help_file, |
600 VARIANT var_id, | 600 VARIANT var_id, |
601 LONG* topic_id) { | 601 LONG* topic_id) { |
602 return E_NOTIMPL; | 602 return E_NOTIMPL; |
603 } | 603 } |
604 | 604 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 if (!app_name) | 898 if (!app_name) |
899 return E_INVALIDARG; | 899 return E_INVALIDARG; |
900 | 900 |
901 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out | 901 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out |
902 // the part before the "/". | 902 // the part before the "/". |
903 std::vector<std::string> product_components; | 903 std::vector<std::string> product_components; |
904 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components); | 904 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components); |
905 DCHECK_EQ(2U, product_components.size()); | 905 DCHECK_EQ(2U, product_components.size()); |
906 if (product_components.size() != 2) | 906 if (product_components.size() != 2) |
907 return E_FAIL; | 907 return E_FAIL; |
908 *app_name = SysAllocString(UTF8ToUTF16(product_components[0]).c_str()); | 908 *app_name = SysAllocString(base::UTF8ToUTF16(product_components[0]).c_str()); |
909 DCHECK(*app_name); | 909 DCHECK(*app_name); |
910 return *app_name ? S_OK : E_FAIL; | 910 return *app_name ? S_OK : E_FAIL; |
911 } | 911 } |
912 | 912 |
913 STDMETHODIMP BrowserAccessibilityWin::get_appVersion(BSTR* app_version) { | 913 STDMETHODIMP BrowserAccessibilityWin::get_appVersion(BSTR* app_version) { |
914 // No need to check |instance_active()| because this interface is | 914 // No need to check |instance_active()| because this interface is |
915 // global, and doesn't depend on any local state. | 915 // global, and doesn't depend on any local state. |
916 | 916 |
917 if (!app_version) | 917 if (!app_version) |
918 return E_INVALIDARG; | 918 return E_INVALIDARG; |
919 | 919 |
920 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out | 920 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out |
921 // the part after the "/". | 921 // the part after the "/". |
922 std::vector<std::string> product_components; | 922 std::vector<std::string> product_components; |
923 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components); | 923 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components); |
924 DCHECK_EQ(2U, product_components.size()); | 924 DCHECK_EQ(2U, product_components.size()); |
925 if (product_components.size() != 2) | 925 if (product_components.size() != 2) |
926 return E_FAIL; | 926 return E_FAIL; |
927 *app_version = SysAllocString(UTF8ToUTF16(product_components[1]).c_str()); | 927 *app_version = |
| 928 SysAllocString(base::UTF8ToUTF16(product_components[1]).c_str()); |
928 DCHECK(*app_version); | 929 DCHECK(*app_version); |
929 return *app_version ? S_OK : E_FAIL; | 930 return *app_version ? S_OK : E_FAIL; |
930 } | 931 } |
931 | 932 |
932 STDMETHODIMP BrowserAccessibilityWin::get_toolkitName(BSTR* toolkit_name) { | 933 STDMETHODIMP BrowserAccessibilityWin::get_toolkitName(BSTR* toolkit_name) { |
933 // No need to check |instance_active()| because this interface is | 934 // No need to check |instance_active()| because this interface is |
934 // global, and doesn't depend on any local state. | 935 // global, and doesn't depend on any local state. |
935 | 936 |
936 if (!toolkit_name) | 937 if (!toolkit_name) |
937 return E_INVALIDARG; | 938 return E_INVALIDARG; |
938 | 939 |
939 // This is hard-coded; all products based on the Chromium engine | 940 // This is hard-coded; all products based on the Chromium engine |
940 // will have the same toolkit name, so that assistive technology can | 941 // will have the same toolkit name, so that assistive technology can |
941 // detect any Chrome-based product. | 942 // detect any Chrome-based product. |
942 *toolkit_name = SysAllocString(L"Chrome"); | 943 *toolkit_name = SysAllocString(L"Chrome"); |
943 DCHECK(*toolkit_name); | 944 DCHECK(*toolkit_name); |
944 return *toolkit_name ? S_OK : E_FAIL; | 945 return *toolkit_name ? S_OK : E_FAIL; |
945 } | 946 } |
946 | 947 |
947 STDMETHODIMP BrowserAccessibilityWin::get_toolkitVersion( | 948 STDMETHODIMP BrowserAccessibilityWin::get_toolkitVersion( |
948 BSTR* toolkit_version) { | 949 BSTR* toolkit_version) { |
949 // No need to check |instance_active()| because this interface is | 950 // No need to check |instance_active()| because this interface is |
950 // global, and doesn't depend on any local state. | 951 // global, and doesn't depend on any local state. |
951 | 952 |
952 if (!toolkit_version) | 953 if (!toolkit_version) |
953 return E_INVALIDARG; | 954 return E_INVALIDARG; |
954 | 955 |
955 std::string user_agent = GetContentClient()->GetUserAgent(); | 956 std::string user_agent = GetContentClient()->GetUserAgent(); |
956 *toolkit_version = SysAllocString(UTF8ToUTF16(user_agent).c_str()); | 957 *toolkit_version = SysAllocString(base::UTF8ToUTF16(user_agent).c_str()); |
957 DCHECK(*toolkit_version); | 958 DCHECK(*toolkit_version); |
958 return *toolkit_version ? S_OK : E_FAIL; | 959 return *toolkit_version ? S_OK : E_FAIL; |
959 } | 960 } |
960 | 961 |
961 // | 962 // |
962 // IAccessibleImage methods. | 963 // IAccessibleImage methods. |
963 // | 964 // |
964 | 965 |
965 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { | 966 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { |
966 if (!instance_active()) | 967 if (!instance_active()) |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2428 return E_INVALIDARG; | 2429 return E_INVALIDARG; |
2429 } | 2430 } |
2430 | 2431 |
2431 base::string16 tag; | 2432 base::string16 tag; |
2432 if (GetString16Attribute(AccessibilityNodeData::ATTR_HTML_TAG, &tag)) | 2433 if (GetString16Attribute(AccessibilityNodeData::ATTR_HTML_TAG, &tag)) |
2433 *node_name = SysAllocString(tag.c_str()); | 2434 *node_name = SysAllocString(tag.c_str()); |
2434 else | 2435 else |
2435 *node_name = NULL; | 2436 *node_name = NULL; |
2436 | 2437 |
2437 *name_space_id = 0; | 2438 *name_space_id = 0; |
2438 *node_value = SysAllocString(UTF8ToUTF16(value()).c_str()); | 2439 *node_value = SysAllocString(base::UTF8ToUTF16(value()).c_str()); |
2439 *num_children = PlatformChildCount(); | 2440 *num_children = PlatformChildCount(); |
2440 *unique_id = unique_id_win_; | 2441 *unique_id = unique_id_win_; |
2441 | 2442 |
2442 if (ia_role_ == ROLE_SYSTEM_DOCUMENT) { | 2443 if (ia_role_ == ROLE_SYSTEM_DOCUMENT) { |
2443 *node_type = NODETYPE_DOCUMENT; | 2444 *node_type = NODETYPE_DOCUMENT; |
2444 } else if (ia_role_ == ROLE_SYSTEM_TEXT && | 2445 } else if (ia_role_ == ROLE_SYSTEM_TEXT && |
2445 ((ia2_state_ & IA2_STATE_EDITABLE) == 0)) { | 2446 ((ia2_state_ & IA2_STATE_EDITABLE) == 0)) { |
2446 *node_type = NODETYPE_TEXT; | 2447 *node_type = NODETYPE_TEXT; |
2447 } else { | 2448 } else { |
2448 *node_type = NODETYPE_ELEMENT; | 2449 *node_type = NODETYPE_ELEMENT; |
(...skipping 13 matching lines...) Expand all Loading... |
2462 | 2463 |
2463 if (!attrib_names || !name_space_id || !attrib_values || !num_attribs) | 2464 if (!attrib_names || !name_space_id || !attrib_values || !num_attribs) |
2464 return E_INVALIDARG; | 2465 return E_INVALIDARG; |
2465 | 2466 |
2466 *num_attribs = max_attribs; | 2467 *num_attribs = max_attribs; |
2467 if (*num_attribs > html_attributes().size()) | 2468 if (*num_attribs > html_attributes().size()) |
2468 *num_attribs = html_attributes().size(); | 2469 *num_attribs = html_attributes().size(); |
2469 | 2470 |
2470 for (unsigned short i = 0; i < *num_attribs; ++i) { | 2471 for (unsigned short i = 0; i < *num_attribs; ++i) { |
2471 attrib_names[i] = SysAllocString( | 2472 attrib_names[i] = SysAllocString( |
2472 UTF8ToUTF16(html_attributes()[i].first).c_str()); | 2473 base::UTF8ToUTF16(html_attributes()[i].first).c_str()); |
2473 name_space_id[i] = 0; | 2474 name_space_id[i] = 0; |
2474 attrib_values[i] = SysAllocString( | 2475 attrib_values[i] = SysAllocString( |
2475 UTF8ToUTF16(html_attributes()[i].second).c_str()); | 2476 base::UTF8ToUTF16(html_attributes()[i].second).c_str()); |
2476 } | 2477 } |
2477 return S_OK; | 2478 return S_OK; |
2478 } | 2479 } |
2479 | 2480 |
2480 STDMETHODIMP BrowserAccessibilityWin::get_attributesForNames( | 2481 STDMETHODIMP BrowserAccessibilityWin::get_attributesForNames( |
2481 unsigned short num_attribs, | 2482 unsigned short num_attribs, |
2482 BSTR* attrib_names, | 2483 BSTR* attrib_names, |
2483 short* name_space_id, | 2484 short* name_space_id, |
2484 BSTR* attrib_values) { | 2485 BSTR* attrib_values) { |
2485 if (!instance_active()) | 2486 if (!instance_active()) |
2486 return E_FAIL; | 2487 return E_FAIL; |
2487 | 2488 |
2488 if (!attrib_names || !name_space_id || !attrib_values) | 2489 if (!attrib_names || !name_space_id || !attrib_values) |
2489 return E_INVALIDARG; | 2490 return E_INVALIDARG; |
2490 | 2491 |
2491 for (unsigned short i = 0; i < num_attribs; ++i) { | 2492 for (unsigned short i = 0; i < num_attribs; ++i) { |
2492 name_space_id[i] = 0; | 2493 name_space_id[i] = 0; |
2493 bool found = false; | 2494 bool found = false; |
2494 std::string name = UTF16ToUTF8((LPCWSTR)attrib_names[i]); | 2495 std::string name = base::UTF16ToUTF8((LPCWSTR)attrib_names[i]); |
2495 for (unsigned int j = 0; j < html_attributes().size(); ++j) { | 2496 for (unsigned int j = 0; j < html_attributes().size(); ++j) { |
2496 if (html_attributes()[j].first == name) { | 2497 if (html_attributes()[j].first == name) { |
2497 attrib_values[i] = SysAllocString( | 2498 attrib_values[i] = SysAllocString( |
2498 UTF8ToUTF16(html_attributes()[j].second).c_str()); | 2499 base::UTF8ToUTF16(html_attributes()[j].second).c_str()); |
2499 found = true; | 2500 found = true; |
2500 break; | 2501 break; |
2501 } | 2502 } |
2502 } | 2503 } |
2503 if (!found) { | 2504 if (!found) { |
2504 attrib_values[i] = NULL; | 2505 attrib_values[i] = NULL; |
2505 } | 2506 } |
2506 } | 2507 } |
2507 return S_OK; | 2508 return S_OK; |
2508 } | 2509 } |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 void BrowserAccessibilityWin::PostInitialize() { | 3075 void BrowserAccessibilityWin::PostInitialize() { |
3075 BrowserAccessibility::PostInitialize(); | 3076 BrowserAccessibility::PostInitialize(); |
3076 | 3077 |
3077 // Construct the hypertext for this node. | 3078 // Construct the hypertext for this node. |
3078 hyperlink_offset_to_index_.clear(); | 3079 hyperlink_offset_to_index_.clear(); |
3079 hyperlinks_.clear(); | 3080 hyperlinks_.clear(); |
3080 hypertext_.clear(); | 3081 hypertext_.clear(); |
3081 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { | 3082 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { |
3082 BrowserAccessibility* child = PlatformGetChild(i); | 3083 BrowserAccessibility* child = PlatformGetChild(i); |
3083 if (child->role() == blink::WebAXRoleStaticText) { | 3084 if (child->role() == blink::WebAXRoleStaticText) { |
3084 hypertext_ += UTF8ToUTF16(child->name()); | 3085 hypertext_ += base::UTF8ToUTF16(child->name()); |
3085 } else { | 3086 } else { |
3086 hyperlink_offset_to_index_[hypertext_.size()] = hyperlinks_.size(); | 3087 hyperlink_offset_to_index_[hypertext_.size()] = hyperlinks_.size(); |
3087 hypertext_ += kEmbeddedCharacter; | 3088 hypertext_ += kEmbeddedCharacter; |
3088 hyperlinks_.push_back(i); | 3089 hyperlinks_.push_back(i); |
3089 } | 3090 } |
3090 } | 3091 } |
3091 DCHECK_EQ(hyperlink_offset_to_index_.size(), hyperlinks_.size()); | 3092 DCHECK_EQ(hyperlink_offset_to_index_.size(), hyperlinks_.size()); |
3092 | 3093 |
3093 // Fire an event when an alert first appears. | 3094 // Fire an event when an alert first appears. |
3094 if (blink_role() == blink::WebAXRoleAlert && first_time_) | 3095 if (blink_role() == blink::WebAXRoleAlert && first_time_) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3209 DCHECK(*value_bstr); | 3210 DCHECK(*value_bstr); |
3210 | 3211 |
3211 return S_OK; | 3212 return S_OK; |
3212 } | 3213 } |
3213 | 3214 |
3214 void BrowserAccessibilityWin::StringAttributeToIA2( | 3215 void BrowserAccessibilityWin::StringAttributeToIA2( |
3215 AccessibilityNodeData::StringAttribute attribute, | 3216 AccessibilityNodeData::StringAttribute attribute, |
3216 const char* ia2_attr) { | 3217 const char* ia2_attr) { |
3217 base::string16 value; | 3218 base::string16 value; |
3218 if (GetString16Attribute(attribute, &value)) | 3219 if (GetString16Attribute(attribute, &value)) |
3219 ia2_attributes_.push_back(ASCIIToUTF16(ia2_attr) + L":" + value); | 3220 ia2_attributes_.push_back(base::ASCIIToUTF16(ia2_attr) + L":" + value); |
3220 } | 3221 } |
3221 | 3222 |
3222 void BrowserAccessibilityWin::BoolAttributeToIA2( | 3223 void BrowserAccessibilityWin::BoolAttributeToIA2( |
3223 AccessibilityNodeData::BoolAttribute attribute, | 3224 AccessibilityNodeData::BoolAttribute attribute, |
3224 const char* ia2_attr) { | 3225 const char* ia2_attr) { |
3225 bool value; | 3226 bool value; |
3226 if (GetBoolAttribute(attribute, &value)) { | 3227 if (GetBoolAttribute(attribute, &value)) { |
3227 ia2_attributes_.push_back((ASCIIToUTF16(ia2_attr) + L":") + | 3228 ia2_attributes_.push_back((base::ASCIIToUTF16(ia2_attr) + L":") + |
3228 (value ? L"true" : L"false")); | 3229 (value ? L"true" : L"false")); |
3229 } | 3230 } |
3230 } | 3231 } |
3231 | 3232 |
3232 void BrowserAccessibilityWin::IntAttributeToIA2( | 3233 void BrowserAccessibilityWin::IntAttributeToIA2( |
3233 AccessibilityNodeData::IntAttribute attribute, | 3234 AccessibilityNodeData::IntAttribute attribute, |
3234 const char* ia2_attr) { | 3235 const char* ia2_attr) { |
3235 int value; | 3236 int value; |
3236 if (GetIntAttribute(attribute, &value)) { | 3237 if (GetIntAttribute(attribute, &value)) { |
3237 ia2_attributes_.push_back(ASCIIToUTF16(ia2_attr) + L":" + | 3238 ia2_attributes_.push_back(base::ASCIIToUTF16(ia2_attr) + L":" + |
3238 base::IntToString16(value)); | 3239 base::IntToString16(value)); |
3239 } | 3240 } |
3240 } | 3241 } |
3241 | 3242 |
3242 base::string16 BrowserAccessibilityWin::GetValueText() { | 3243 base::string16 BrowserAccessibilityWin::GetValueText() { |
3243 float fval; | 3244 float fval; |
3244 base::string16 value = UTF8ToUTF16(this->value()); | 3245 base::string16 value = base::UTF8ToUTF16(this->value()); |
3245 | 3246 |
3246 if (value.empty() && | 3247 if (value.empty() && |
3247 GetFloatAttribute(AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &fval)) { | 3248 GetFloatAttribute(AccessibilityNodeData::ATTR_VALUE_FOR_RANGE, &fval)) { |
3248 value = UTF8ToUTF16(base::DoubleToString(fval)); | 3249 value = base::UTF8ToUTF16(base::DoubleToString(fval)); |
3249 } | 3250 } |
3250 return value; | 3251 return value; |
3251 } | 3252 } |
3252 | 3253 |
3253 base::string16 BrowserAccessibilityWin::TextForIAccessibleText() { | 3254 base::string16 BrowserAccessibilityWin::TextForIAccessibleText() { |
3254 if (IsEditableText()) | 3255 if (IsEditableText()) |
3255 return UTF8ToUTF16(value()); | 3256 return base::UTF8ToUTF16(value()); |
3256 return (blink_role() == blink::WebAXRoleStaticText) ? | 3257 return (blink_role() == blink::WebAXRoleStaticText) ? |
3257 UTF8ToUTF16(name()) : hypertext_; | 3258 base::UTF8ToUTF16(name()) : hypertext_; |
3258 } | 3259 } |
3259 | 3260 |
3260 void BrowserAccessibilityWin::HandleSpecialTextOffset( | 3261 void BrowserAccessibilityWin::HandleSpecialTextOffset( |
3261 const base::string16& text, | 3262 const base::string16& text, |
3262 LONG* offset) { | 3263 LONG* offset) { |
3263 if (*offset == IA2_TEXT_OFFSET_LENGTH) | 3264 if (*offset == IA2_TEXT_OFFSET_LENGTH) |
3264 *offset = static_cast<LONG>(text.size()); | 3265 *offset = static_cast<LONG>(text.size()); |
3265 else if (*offset == IA2_TEXT_OFFSET_CARET) | 3266 else if (*offset == IA2_TEXT_OFFSET_CARET) |
3266 get_caretOffset(offset); | 3267 get_caretOffset(offset); |
3267 } | 3268 } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3785 // The role should always be set. | 3786 // The role should always be set. |
3786 DCHECK(!role_name_.empty() || ia_role_); | 3787 DCHECK(!role_name_.empty() || ia_role_); |
3787 | 3788 |
3788 // If we didn't explicitly set the IAccessible2 role, make it the same | 3789 // If we didn't explicitly set the IAccessible2 role, make it the same |
3789 // as the MSAA role. | 3790 // as the MSAA role. |
3790 if (!ia2_role_) | 3791 if (!ia2_role_) |
3791 ia2_role_ = ia_role_; | 3792 ia2_role_ = ia_role_; |
3792 } | 3793 } |
3793 | 3794 |
3794 } // namespace content | 3795 } // namespace content |
OLD | NEW |