1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/string_number_conversions.h"
6 #include "content/common/ax_content_node_data.h"
8 using base::IntToString
;
14 // Helper function that finds a key in a vector of pairs by matching on the
15 // first value, and returns an iterator.
16 template<typename FirstType
, typename SecondType
>
17 typename
std::vector
<std::pair
<FirstType
, SecondType
>>::const_iterator
20 const std::vector
<std::pair
<FirstType
, SecondType
>>& vector
) {
21 return std::find_if(vector
.begin(),
23 [first
](std::pair
<FirstType
, SecondType
> const& p
) {
24 return p
.first
== first
;
30 AXContentNodeData::AXContentNodeData() {
33 AXContentNodeData::~AXContentNodeData() {
36 bool AXContentNodeData::HasContentIntAttribute(
37 AXContentIntAttribute attribute
) const {
38 auto iter
= FindInVectorOfPairs(attribute
, content_int_attributes
);
39 return iter
!= content_int_attributes
.end();
42 int AXContentNodeData::GetContentIntAttribute(
43 AXContentIntAttribute attribute
) const {
45 if (GetContentIntAttribute(attribute
, &result
))
50 bool AXContentNodeData::GetContentIntAttribute(
51 AXContentIntAttribute attribute
, int* value
) const {
52 auto iter
= FindInVectorOfPairs(attribute
, content_int_attributes
);
53 if (iter
!= content_int_attributes
.end()) {
54 *value
= iter
->second
;
61 void AXContentNodeData::AddContentIntAttribute(
62 AXContentIntAttribute attribute
, int32 value
) {
63 content_int_attributes
.push_back(std::make_pair(attribute
, value
));
66 std::string
AXContentNodeData::ToString() const {
67 std::string result
= AXNodeData::ToString();
69 for (auto iter
: content_int_attributes
) {
70 std::string value
= IntToString(iter
.second
);
72 case AX_CONTENT_ATTR_ROUTING_ID
:
73 result
+= " routing_id=" + value
;
75 case AX_CONTENT_ATTR_PARENT_ROUTING_ID
:
76 result
+= " parent_routing_id=" + value
;
78 case AX_CONTENT_ATTR_CHILD_ROUTING_ID
:
79 result
+= " child_routing_id=" + value
;
81 case AX_CONTENT_ATTR_CHILD_BROWSER_PLUGIN_INSTANCE_ID
:
82 result
+= " child_browser_plugin_instance_id=" + value
;
84 case AX_CONTENT_INT_ATTRIBUTE_LAST
: