| Index: trunk/src/content/browser/accessibility/accessibility_tree_formatter_win.cc
|
| ===================================================================
|
| --- trunk/src/content/browser/accessibility/accessibility_tree_formatter_win.cc (revision 194894)
|
| +++ trunk/src/content/browser/accessibility/accessibility_tree_formatter_win.cc (working copy)
|
| @@ -19,63 +19,52 @@
|
| #include "third_party/iaccessible2/ia2_api_all.h"
|
| #include "ui/base/win/atl_module.h"
|
|
|
| -using base::StringPrintf;
|
| -
|
| namespace content {
|
|
|
| -const char* ALL_ATTRIBUTES[] = {
|
| - "name",
|
| - "value",
|
| - "states",
|
| - "attributes",
|
| - "role_name",
|
| - "currentValue",
|
| - "minimumValue",
|
| - "maximumValue",
|
| - "description",
|
| - "default_action",
|
| - "keyboard_shortcut",
|
| - "location",
|
| - "size",
|
| - "index_in_parent",
|
| - "n_relations",
|
| - "group_level",
|
| - "similar_items_in_group",
|
| - "position_in_group",
|
| - "table_rows",
|
| - "table_columns",
|
| - "row_index",
|
| - "column_index",
|
| - "n_characters",
|
| - "caret_offset",
|
| - "n_selections",
|
| - "selection_start",
|
| - "selection_end"
|
| -};
|
| -
|
| void AccessibilityTreeFormatter::Initialize() {
|
| ui::win::CreateATLModuleIfNeeded();
|
| }
|
|
|
| -void AccessibilityTreeFormatter::AddProperties(
|
| - const BrowserAccessibility& node, DictionaryValue* dict) {
|
| - BrowserAccessibilityWin* acc_obj =
|
| - const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityWin();
|
| +string16 AccessibilityTreeFormatter::ToString(
|
| + BrowserAccessibility* node, char* prefix) {
|
| + BrowserAccessibilityWin* acc_obj = node->ToBrowserAccessibilityWin();
|
|
|
| + // Get the computed name.
|
| VARIANT variant_self;
|
| variant_self.vt = VT_I4;
|
| variant_self.lVal = CHILDID_SELF;
|
| -
|
| - dict->SetString("role", IAccessible2RoleToString(acc_obj->ia2_role()));
|
| -
|
| CComBSTR msaa_variant;
|
| HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_variant);
|
| - if (hresult == S_OK)
|
| - dict->SetString("name", msaa_variant.m_str);
|
| + string16 name;
|
| + if (S_OK == hresult)
|
| + name = msaa_variant.m_str;
|
| +
|
| hresult = acc_obj->get_accValue(variant_self, &msaa_variant);
|
| - if (hresult == S_OK)
|
| - dict->SetString("value", msaa_variant.m_str);
|
| + string16 value;
|
| + if (S_OK == hresult)
|
| + value = msaa_variant.m_str;
|
| +
|
| + hresult = acc_obj->get_accDescription(variant_self, &msaa_variant);
|
| + string16 description;
|
| + if (S_OK == hresult)
|
| + description = msaa_variant.m_str;
|
| +
|
| + hresult = acc_obj->get_accHelp(variant_self, &msaa_variant);
|
| + string16 help;
|
| + if (S_OK == hresult)
|
| + help = msaa_variant.m_str;
|
|
|
| + hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant);
|
| + string16 default_action;
|
| + if (S_OK == hresult)
|
| + default_action = msaa_variant.m_str;
|
| +
|
| + hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant);
|
| + string16 keyboard_shortcut;
|
| + if (S_OK == hresult)
|
| + keyboard_shortcut = msaa_variant.m_str;
|
| +
|
| + // Get state strings.
|
| std::vector<string16> state_strings;
|
| int32 ia_state = acc_obj->ia_state();
|
|
|
| @@ -86,207 +75,95 @@
|
|
|
| IAccessibleStateToStringVector(ia_state, &state_strings);
|
| IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings);
|
| - ListValue* states = new ListValue;
|
| +
|
| + // Get the attributes.
|
| + const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes();
|
| +
|
| + // Build the line.
|
| + StartLine();
|
| + Add(true, IAccessible2RoleToString(acc_obj->ia2_role()));
|
| + Add(true, L"name='" + name + L"'");
|
| + Add(false, L"value='" + value + L"'");
|
| for (std::vector<string16>::const_iterator it = state_strings.begin();
|
| it != state_strings.end();
|
| ++it) {
|
| - states->AppendString(UTF16ToUTF8(*it));
|
| + Add(false, *it);
|
| }
|
| - dict->Set("states", states);
|
| -
|
| - const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes();
|
| - ListValue* attributes = new ListValue;
|
| for (std::vector<string16>::const_iterator it = ia2_attributes.begin();
|
| it != ia2_attributes.end();
|
| ++it) {
|
| - attributes->AppendString(UTF16ToUTF8(*it));
|
| + Add(false, *it);
|
| }
|
| - dict->Set("attributes", attributes);
|
| -
|
| - dict->SetString("role_name", acc_obj->role_name());
|
| -
|
| + Add(false, L"role_name='" + acc_obj->role_name() + L"'");
|
| VARIANT currentValue;
|
| if (acc_obj->get_currentValue(¤tValue) == S_OK)
|
| - dict->SetDouble("currentValue", V_R8(¤tValue));
|
| -
|
| + Add(false, base::StringPrintf(L"currentValue=%.2f", V_R8(¤tValue)));
|
| VARIANT minimumValue;
|
| if (acc_obj->get_minimumValue(&minimumValue) == S_OK)
|
| - dict->SetDouble("minimumValue", V_R8(&minimumValue));
|
| -
|
| + Add(false, base::StringPrintf(L"minimumValue=%.2f", V_R8(&minimumValue)));
|
| VARIANT maximumValue;
|
| if (acc_obj->get_maximumValue(&maximumValue) == S_OK)
|
| - dict->SetDouble("maximumValue", V_R8(&maximumValue));
|
| -
|
| - hresult = acc_obj->get_accDescription(variant_self, &msaa_variant);
|
| - if (hresult == S_OK)
|
| - dict->SetString("description", msaa_variant.m_str);
|
| -
|
| - hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant);
|
| - if (hresult == S_OK)
|
| - dict->SetString("default_action", msaa_variant.m_str);
|
| -
|
| - hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant);
|
| - if (hresult == S_OK)
|
| - dict->SetString("keyboard_shortcut", msaa_variant.m_str);
|
| -
|
| - hresult = acc_obj->get_accHelp(variant_self, &msaa_variant);
|
| - if (S_OK == hresult)
|
| - dict->SetString("help", msaa_variant.m_str);
|
| -
|
| - BrowserAccessibility* root = node.manager()->GetRoot();
|
| + Add(false, base::StringPrintf(L"maximumValue=%.2f", V_R8(&maximumValue)));
|
| + Add(false, L"description='" + description + L"'");
|
| + Add(false, L"default_action='" + default_action + L"'");
|
| + Add(false, L"keyboard_shortcut='" + keyboard_shortcut + L"'");
|
| + BrowserAccessibility* root = node->manager()->GetRoot();
|
| LONG left, top, width, height;
|
| LONG root_left, root_top, root_width, root_height;
|
| - if (acc_obj->accLocation(&left, &top, &width, &height, variant_self)
|
| - != S_FALSE
|
| - && root->ToBrowserAccessibilityWin()->accLocation(
|
| - &root_left, &root_top, &root_width, &root_height, variant_self)
|
| - != S_FALSE) {
|
| - DictionaryValue* location = new DictionaryValue;
|
| - location->SetInteger("x", left - root_left);
|
| - location->SetInteger("y", top - root_top);
|
| - dict->Set("location", location);
|
| -
|
| - DictionaryValue* size = new DictionaryValue;
|
| - size->SetInteger("width", width);
|
| - size->SetInteger("height", height);
|
| - dict->Set("size", size);
|
| + if (S_FALSE != acc_obj->accLocation(
|
| + &left, &top, &width, &height, variant_self) &&
|
| + S_FALSE != root->ToBrowserAccessibilityWin()->accLocation(
|
| + &root_left, &root_top, &root_width, &root_height, variant_self)) {
|
| + Add(false, base::StringPrintf(L"location=(%d, %d)",
|
| + left - root_left, top - root_top));
|
| + Add(false, base::StringPrintf(L"size=(%d, %d)", width, height));
|
| }
|
| -
|
| LONG index_in_parent;
|
| if (acc_obj->get_indexInParent(&index_in_parent) == S_OK)
|
| - dict->SetInteger("index_in_parent", index_in_parent);
|
| -
|
| + Add(false, base::StringPrintf(L"index_in_parent=%d", index_in_parent));
|
| LONG n_relations;
|
| if (acc_obj->get_nRelations(&n_relations) == S_OK)
|
| - dict->SetInteger("n_relations", n_relations);
|
| -
|
| + Add(false, base::StringPrintf(L"n_relations=%d", n_relations));
|
| LONG group_level, similar_items_in_group, position_in_group;
|
| if (acc_obj->get_groupPosition(&group_level,
|
| &similar_items_in_group,
|
| &position_in_group) == S_OK) {
|
| - dict->SetInteger("group_level", group_level);
|
| - dict->SetInteger("similar_items_in_group", similar_items_in_group);
|
| - dict->SetInteger("position_in_group", position_in_group);
|
| + Add(false, base::StringPrintf(L"group_level=%d", group_level));
|
| + Add(false, base::StringPrintf(L"similar_items_in_group=%d",
|
| + similar_items_in_group));
|
| + Add(false, base::StringPrintf(L"position_in_group=%d", position_in_group));
|
| }
|
| LONG table_rows;
|
| if (acc_obj->get_nRows(&table_rows) == S_OK)
|
| - dict->SetInteger("table_rows", table_rows);
|
| + Add(false, base::StringPrintf(L"table_rows=%d", table_rows));
|
| LONG table_columns;
|
| if (acc_obj->get_nRows(&table_columns) == S_OK)
|
| - dict->SetInteger("table_columns", table_columns);
|
| + Add(false, base::StringPrintf(L"table_columns=%d", table_columns));
|
| LONG row_index;
|
| if (acc_obj->get_rowIndex(&row_index) == S_OK)
|
| - dict->SetInteger("row_index", row_index);
|
| + Add(false, base::StringPrintf(L"row_index=%d", row_index));
|
| LONG column_index;
|
| if (acc_obj->get_columnIndex(&column_index) == S_OK)
|
| - dict->SetInteger("column_index", column_index);
|
| + Add(false, base::StringPrintf(L"column_index=%d", column_index));
|
| LONG n_characters;
|
| if (acc_obj->get_nCharacters(&n_characters) == S_OK)
|
| - dict->SetInteger("n_characters", n_characters);
|
| + Add(false, base::StringPrintf(L"n_characters=%d", n_characters));
|
| LONG caret_offset;
|
| if (acc_obj->get_caretOffset(&caret_offset) == S_OK)
|
| - dict->SetInteger("caret_offset", caret_offset);
|
| + Add(false, base::StringPrintf(L"caret_offset=%d", caret_offset));
|
| LONG n_selections;
|
| if (acc_obj->get_nSelections(&n_selections) == S_OK) {
|
| - dict->SetInteger("n_selections", n_selections);
|
| + Add(false, base::StringPrintf(L"n_selections=%d", n_selections));
|
| if (n_selections > 0) {
|
| LONG start, end;
|
| if (acc_obj->get_selection(0, &start, &end) == S_OK) {
|
| - dict->SetInteger("selection_start", start);
|
| - dict->SetInteger("selection_end", end);
|
| - }
|
| - }
|
| - }
|
| -}
|
| -
|
| -string16 AccessibilityTreeFormatter::ToString(const DictionaryValue& dict,
|
| - const string16& indent) {
|
| - string16 line;
|
| -
|
| - string16 role_value;
|
| - dict.GetString("role", &role_value);
|
| - WriteAttribute(true, UTF16ToUTF8(role_value), &line);
|
| -
|
| - string16 name_value;
|
| - dict.GetString("name", &name_value);
|
| - WriteAttribute(true, base::StringPrintf(L"name='%ls'", name_value.c_str()),
|
| - &line);
|
| -
|
| - for (int i = 0; i < arraysize(ALL_ATTRIBUTES); i++) {
|
| - const char* attribute_name = ALL_ATTRIBUTES[i];
|
| - const Value* value;
|
| - if (!dict.Get(attribute_name, &value))
|
| - continue;
|
| -
|
| - switch (value->GetType()) {
|
| - case Value::TYPE_STRING: {
|
| - string16 string_value;
|
| - value->GetAsString(&string_value);
|
| - WriteAttribute(false,
|
| - StringPrintf(L"%ls='%ls'",
|
| - UTF8ToUTF16(attribute_name).c_str(),
|
| - string_value.c_str()),
|
| - &line);
|
| - break;
|
| - }
|
| - case Value::TYPE_INTEGER: {
|
| - int int_value;
|
| - value->GetAsInteger(&int_value);
|
| - WriteAttribute(false,
|
| - base::StringPrintf(L"%ls=%d",
|
| - UTF8ToUTF16(attribute_name).c_str(),
|
| - int_value),
|
| - &line);
|
| - break;
|
| - }
|
| - case Value::TYPE_DOUBLE: {
|
| - double double_value;
|
| - value->GetAsDouble(&double_value);
|
| - WriteAttribute(false,
|
| - base::StringPrintf(L"%ls=%.2f",
|
| - UTF8ToUTF16(attribute_name).c_str(),
|
| - double_value),
|
| - &line);
|
| - break;
|
| - }
|
| - case Value::TYPE_LIST: {
|
| - // Currently all list values are string and are written without
|
| - // attribute names.
|
| - const ListValue* list_value;
|
| - value->GetAsList(&list_value);
|
| - for (ListValue::const_iterator it = list_value->begin();
|
| - it != list_value->end();
|
| - ++it) {
|
| - string16 string_value;
|
| - if ((*it)->GetAsString(&string_value))
|
| - WriteAttribute(false, string_value, &line);
|
| - }
|
| - break;
|
| - }
|
| - case Value::TYPE_DICTIONARY: {
|
| - // Currently all dictionary values are coordinates.
|
| - // Revisit this if that changes.
|
| - const DictionaryValue* dict_value;
|
| - value->GetAsDictionary(&dict_value);
|
| - if (strcmp(attribute_name, "size") == 0) {
|
| - WriteAttribute(false,
|
| - FormatCoordinates("size", "width", "height",
|
| - *dict_value),
|
| - &line);
|
| - } else if (strcmp(attribute_name, "location") == 0) {
|
| - WriteAttribute(false,
|
| - FormatCoordinates("location", "x", "y", *dict_value),
|
| - &line);
|
| - }
|
| - break;
|
| + Add(false, base::StringPrintf(L"selection_start=%d", start));
|
| + Add(false, base::StringPrintf(L"selection_end=%d", end));
|
| }
|
| - default:
|
| - NOTREACHED();
|
| - break;
|
| }
|
| }
|
|
|
| - return indent + line + ASCIIToUTF16("\n");
|
| + return UTF8ToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n");
|
| }
|
|
|
| // static
|
|
|