| 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/common/accessibility_node_data.h" | 5 #include "content/common/accessibility_node_data.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 AccessibilityNodeData::AccessibilityNodeData() | 35 AccessibilityNodeData::AccessibilityNodeData() |
| 36 : id(-1), | 36 : id(-1), |
| 37 role(ROLE_UNKNOWN), | 37 role(ROLE_UNKNOWN), |
| 38 state(-1) { | 38 state(-1) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 AccessibilityNodeData::~AccessibilityNodeData() { | 41 AccessibilityNodeData::~AccessibilityNodeData() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 void AccessibilityNodeData::AddStringAttribute( |
| 45 StringAttribute attribute, const std::string& value) { |
| 46 string_attributes.push_back(std::make_pair(attribute, value)); |
| 47 } |
| 48 |
| 49 void AccessibilityNodeData::AddIntAttribute( |
| 50 IntAttribute attribute, int value) { |
| 51 int_attributes.push_back(std::make_pair(attribute, value)); |
| 52 } |
| 53 |
| 54 void AccessibilityNodeData::AddFloatAttribute( |
| 55 FloatAttribute attribute, float value) { |
| 56 float_attributes.push_back(std::make_pair(attribute, value)); |
| 57 } |
| 58 |
| 59 void AccessibilityNodeData::AddBoolAttribute( |
| 60 BoolAttribute attribute, bool value) { |
| 61 bool_attributes.push_back(std::make_pair(attribute, value)); |
| 62 } |
| 63 |
| 64 void AccessibilityNodeData::AddIntListAttribute( |
| 65 IntListAttribute attribute, const std::vector<int32>& value) { |
| 66 intlist_attributes.push_back(std::make_pair(attribute, value)); |
| 67 } |
| 68 |
| 69 void AccessibilityNodeData::SetName(std::string name) { |
| 70 string_attributes.push_back(std::make_pair(ATTR_NAME, name)); |
| 71 } |
| 72 |
| 44 AccessibilityNodeDataTreeNode::AccessibilityNodeDataTreeNode() | 73 AccessibilityNodeDataTreeNode::AccessibilityNodeDataTreeNode() |
| 45 : AccessibilityNodeData() { | 74 : AccessibilityNodeData() { |
| 46 } | 75 } |
| 47 | 76 |
| 48 AccessibilityNodeDataTreeNode::~AccessibilityNodeDataTreeNode() { | 77 AccessibilityNodeDataTreeNode::~AccessibilityNodeDataTreeNode() { |
| 49 } | 78 } |
| 50 | 79 |
| 51 AccessibilityNodeDataTreeNode& AccessibilityNodeDataTreeNode::operator=( | 80 AccessibilityNodeDataTreeNode& AccessibilityNodeDataTreeNode::operator=( |
| 52 const AccessibilityNodeData& src) { | 81 const AccessibilityNodeData& src) { |
| 53 AccessibilityNodeData::operator=(src); | 82 AccessibilityNodeData::operator=(src); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 result += " SELECTED"; | 292 result += " SELECTED"; |
| 264 if (state & (1 << STATE_TRAVERSED)) | 293 if (state & (1 << STATE_TRAVERSED)) |
| 265 result += " TRAVERSED"; | 294 result += " TRAVERSED"; |
| 266 if (state & (1 << STATE_UNAVAILABLE)) | 295 if (state & (1 << STATE_UNAVAILABLE)) |
| 267 result += " UNAVAILABLE"; | 296 result += " UNAVAILABLE"; |
| 268 if (state & (1 << STATE_VERTICAL)) | 297 if (state & (1 << STATE_VERTICAL)) |
| 269 result += " VERTICAL"; | 298 result += " VERTICAL"; |
| 270 if (state & (1 << STATE_VISITED)) | 299 if (state & (1 << STATE_VISITED)) |
| 271 result += " VISITED"; | 300 result += " VISITED"; |
| 272 | 301 |
| 273 std::string tmp = UTF16ToUTF8(name); | |
| 274 RemoveChars(tmp, "\n", &tmp); | |
| 275 if (!tmp.empty()) | |
| 276 result += " name=" + tmp; | |
| 277 | |
| 278 tmp = UTF16ToUTF8(value); | |
| 279 RemoveChars(tmp, "\n", &tmp); | |
| 280 if (!tmp.empty()) | |
| 281 result += " value=" + tmp; | |
| 282 | |
| 283 result += " (" + IntToString(location.x()) + ", " + | 302 result += " (" + IntToString(location.x()) + ", " + |
| 284 IntToString(location.y()) + ")-(" + | 303 IntToString(location.y()) + ")-(" + |
| 285 IntToString(location.width()) + ", " + | 304 IntToString(location.width()) + ", " + |
| 286 IntToString(location.height()) + ")"; | 305 IntToString(location.height()) + ")"; |
| 287 | 306 |
| 288 for (std::map<IntAttribute, int32>::const_iterator iter = | 307 for (size_t i = 0; i < int_attributes.size(); ++i) { |
| 289 int_attributes.begin(); | 308 std::string value = IntToString(int_attributes[i].second); |
| 290 iter != int_attributes.end(); | 309 switch (int_attributes[i].first) { |
| 291 ++iter) { | |
| 292 std::string value = IntToString(iter->second); | |
| 293 switch (iter->first) { | |
| 294 case ATTR_SCROLL_X: | 310 case ATTR_SCROLL_X: |
| 295 result += " scroll_x=" + value; | 311 result += " scroll_x=" + value; |
| 296 break; | 312 break; |
| 297 case ATTR_SCROLL_X_MIN: | 313 case ATTR_SCROLL_X_MIN: |
| 298 result += " scroll_x_min=" + value; | 314 result += " scroll_x_min=" + value; |
| 299 break; | 315 break; |
| 300 case ATTR_SCROLL_X_MAX: | 316 case ATTR_SCROLL_X_MAX: |
| 301 result += " scroll_x_max=" + value; | 317 result += " scroll_x_max=" + value; |
| 302 break; | 318 break; |
| 303 case ATTR_SCROLL_Y: | 319 case ATTR_SCROLL_Y: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 break; | 375 break; |
| 360 case ATTR_COLOR_VALUE_GREEN: | 376 case ATTR_COLOR_VALUE_GREEN: |
| 361 result += " color_value_green=" + value; | 377 result += " color_value_green=" + value; |
| 362 break; | 378 break; |
| 363 case ATTR_COLOR_VALUE_BLUE: | 379 case ATTR_COLOR_VALUE_BLUE: |
| 364 result += " color_value_blue=" + value; | 380 result += " color_value_blue=" + value; |
| 365 break; | 381 break; |
| 366 } | 382 } |
| 367 } | 383 } |
| 368 | 384 |
| 369 for (std::map<StringAttribute, string16>::const_iterator iter = | 385 for (size_t i = 0; i < string_attributes.size(); ++i) { |
| 370 string_attributes.begin(); | 386 std::string value = string_attributes[i].second; |
| 371 iter != string_attributes.end(); | 387 switch (string_attributes[i].first) { |
| 372 ++iter) { | |
| 373 std::string value = UTF16ToUTF8(iter->second); | |
| 374 switch (iter->first) { | |
| 375 case ATTR_DOC_URL: | 388 case ATTR_DOC_URL: |
| 376 result += " doc_url=" + value; | 389 result += " doc_url=" + value; |
| 377 break; | 390 break; |
| 378 case ATTR_DOC_TITLE: | 391 case ATTR_DOC_TITLE: |
| 379 result += " doc_title=" + value; | 392 result += " doc_title=" + value; |
| 380 break; | 393 break; |
| 381 case ATTR_DOC_MIMETYPE: | 394 case ATTR_DOC_MIMETYPE: |
| 382 result += " doc_mimetype=" + value; | 395 result += " doc_mimetype=" + value; |
| 383 break; | 396 break; |
| 384 case ATTR_DOC_DOCTYPE: | 397 case ATTR_DOC_DOCTYPE: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 break; | 429 break; |
| 417 case ATTR_ROLE: | 430 case ATTR_ROLE: |
| 418 result += " role=" + value; | 431 result += " role=" + value; |
| 419 break; | 432 break; |
| 420 case ATTR_SHORTCUT: | 433 case ATTR_SHORTCUT: |
| 421 result += " shortcut=" + value; | 434 result += " shortcut=" + value; |
| 422 break; | 435 break; |
| 423 case ATTR_URL: | 436 case ATTR_URL: |
| 424 result += " url=" + value; | 437 result += " url=" + value; |
| 425 break; | 438 break; |
| 439 case ATTR_NAME: |
| 440 result += " name=" + value; |
| 441 break; |
| 442 case ATTR_VALUE: |
| 443 result += " value=" + value; |
| 444 break; |
| 426 } | 445 } |
| 427 } | 446 } |
| 428 | 447 |
| 429 for (std::map<FloatAttribute, float>::const_iterator iter = | 448 for (size_t i = 0; i < float_attributes.size(); ++i) { |
| 430 float_attributes.begin(); | 449 std::string value = DoubleToString(float_attributes[i].second); |
| 431 iter != float_attributes.end(); | 450 switch (float_attributes[i].first) { |
| 432 ++iter) { | |
| 433 std::string value = DoubleToString(iter->second); | |
| 434 switch (iter->first) { | |
| 435 case ATTR_DOC_LOADING_PROGRESS: | 451 case ATTR_DOC_LOADING_PROGRESS: |
| 436 result += " doc_progress=" + value; | 452 result += " doc_progress=" + value; |
| 437 break; | 453 break; |
| 438 case ATTR_VALUE_FOR_RANGE: | 454 case ATTR_VALUE_FOR_RANGE: |
| 439 result += " value_for_range=" + value; | 455 result += " value_for_range=" + value; |
| 440 break; | 456 break; |
| 441 case ATTR_MAX_VALUE_FOR_RANGE: | 457 case ATTR_MAX_VALUE_FOR_RANGE: |
| 442 result += " max_value=" + value; | 458 result += " max_value=" + value; |
| 443 break; | 459 break; |
| 444 case ATTR_MIN_VALUE_FOR_RANGE: | 460 case ATTR_MIN_VALUE_FOR_RANGE: |
| 445 result += " min_value=" + value; | 461 result += " min_value=" + value; |
| 446 break; | 462 break; |
| 447 } | 463 } |
| 448 } | 464 } |
| 449 | 465 |
| 450 for (std::map<BoolAttribute, bool>::const_iterator iter = | 466 for (size_t i = 0; i < bool_attributes.size(); ++i) { |
| 451 bool_attributes.begin(); | 467 std::string value = bool_attributes[i].second ? "true" : "false"; |
| 452 iter != bool_attributes.end(); | 468 switch (bool_attributes[i].first) { |
| 453 ++iter) { | |
| 454 std::string value = iter->second ? "true" : "false"; | |
| 455 switch (iter->first) { | |
| 456 case ATTR_DOC_LOADED: | 469 case ATTR_DOC_LOADED: |
| 457 result += " doc_loaded=" + value; | 470 result += " doc_loaded=" + value; |
| 458 break; | 471 break; |
| 459 case ATTR_BUTTON_MIXED: | 472 case ATTR_BUTTON_MIXED: |
| 460 result += " mixed=" + value; | 473 result += " mixed=" + value; |
| 461 break; | 474 break; |
| 462 case ATTR_LIVE_ATOMIC: | 475 case ATTR_LIVE_ATOMIC: |
| 463 result += " atomic=" + value; | 476 result += " atomic=" + value; |
| 464 break; | 477 break; |
| 465 case ATTR_LIVE_BUSY: | 478 case ATTR_LIVE_BUSY: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 476 break; | 489 break; |
| 477 case ATTR_CAN_SET_VALUE: | 490 case ATTR_CAN_SET_VALUE: |
| 478 result += " can_set_value=" + value; | 491 result += " can_set_value=" + value; |
| 479 break; | 492 break; |
| 480 case ATTR_UPDATE_LOCATION_ONLY: | 493 case ATTR_UPDATE_LOCATION_ONLY: |
| 481 result += " update_location_only=" + value; | 494 result += " update_location_only=" + value; |
| 482 break; | 495 break; |
| 483 } | 496 } |
| 484 } | 497 } |
| 485 | 498 |
| 499 for (size_t i = 0; i < intlist_attributes.size(); ++i) { |
| 500 const std::vector<int32>& values = intlist_attributes[i].second; |
| 501 switch (intlist_attributes[i].first) { |
| 502 case ATTR_INDIRECT_CHILD_IDS: |
| 503 result += " indirect_child_ids=" + IntVectorToString(values); |
| 504 break; |
| 505 case ATTR_LINE_BREAKS: |
| 506 result += " line_breaks=" + IntVectorToString(values); |
| 507 break; |
| 508 case ATTR_CELL_IDS: |
| 509 result += " cell_ids=" + IntVectorToString(values); |
| 510 break; |
| 511 case ATTR_UNIQUE_CELL_IDS: |
| 512 result += " unique_cell_ids=" + IntVectorToString(values); |
| 513 break; |
| 514 } |
| 515 } |
| 516 |
| 486 if (!child_ids.empty()) | 517 if (!child_ids.empty()) |
| 487 result += " child_ids=" + IntVectorToString(child_ids); | 518 result += " child_ids=" + IntVectorToString(child_ids); |
| 488 | 519 |
| 489 if (!indirect_child_ids.empty()) | |
| 490 result += " indirect_child_ids=" + IntVectorToString(indirect_child_ids); | |
| 491 | |
| 492 if (!line_breaks.empty()) | |
| 493 result += " line_breaks=" + IntVectorToString(line_breaks); | |
| 494 | |
| 495 if (!cell_ids.empty()) | |
| 496 result += " cell_ids=" + IntVectorToString(cell_ids); | |
| 497 | |
| 498 return result; | 520 return result; |
| 499 } | 521 } |
| 500 | 522 |
| 501 std::string AccessibilityNodeDataTreeNode::DebugString(bool recursive) const { | 523 std::string AccessibilityNodeDataTreeNode::DebugString(bool recursive) const { |
| 502 std::string result; | 524 std::string result; |
| 503 | 525 |
| 504 static int indent = 0; | 526 static int indent = 0; |
| 505 result += "\n"; | 527 result += "\n"; |
| 506 for (int i = 0; i < indent; ++i) | 528 for (int i = 0; i < indent; ++i) |
| 507 result += " "; | 529 result += " "; |
| 508 | 530 |
| 509 result += AccessibilityNodeData::DebugString(recursive); | 531 result += AccessibilityNodeData::DebugString(recursive); |
| 510 | 532 |
| 511 if (recursive) { | 533 if (recursive) { |
| 512 result += "\n"; | 534 result += "\n"; |
| 513 ++indent; | 535 ++indent; |
| 514 for (size_t i = 0; i < children.size(); ++i) | 536 for (size_t i = 0; i < children.size(); ++i) |
| 515 result += children[i].DebugString(true); | 537 result += children[i].DebugString(true); |
| 516 --indent; | 538 --indent; |
| 517 } | 539 } |
| 518 | 540 |
| 519 return result; | 541 return result; |
| 520 } | 542 } |
| 521 | 543 |
| 522 #endif // ifndef NDEBUG | 544 #endif // ifndef NDEBUG |
| 523 | 545 |
| 524 } // namespace content | 546 } // namespace content |
| OLD | NEW |