30 namespace_uri(namespace_uri),
31 namespace_prefix(namespace_prefix),
32 local_name(local_name) {}
35 Element::~Element() {}
40 tracer->
Trace(&attributes_);
61 ret.append(static_cast<Text*>(child.get())->data());
62 }
else if (child->is_element()) {
63 auto temp = child->TextContent();
64 DCHECK(temp.has_value());
65 ret.append(temp.value());
72 auto it = FindAttribute(name);
73 if (it == attributes_.end())
79 const std::string&
name)
const {
80 auto it = FindAttributeNS(ns, name);
81 if (it == attributes_.end())
87 return FindAttribute(name) != attributes_.end();
91 const std::string&
name)
const {
92 return FindAttributeNS(ns, name) != attributes_.end();
96 auto it = FindAttribute(key);
97 if (it != attributes_.end()) {
100 attributes_.emplace_back(
106 const std::string& value) {
109 auto split_at = key.find(
':');
110 CHECK_NE(split_at, std::string::npos);
111 const std::string
local_name = key.substr(split_at + 1);
112 const std::string prefix = key.substr(0, split_at);
114 auto it = FindAttributeNS(ns, local_name);
115 if (it != attributes_.end()) {
116 (*it)->value = value;
118 attributes_.push_back(
119 new Attr(
document(),
this, local_name, ns, prefix, value));
124 auto it = FindAttribute(attr);
125 if (it != attributes_.end())
126 attributes_.erase(it);
130 const std::string& attr) {
131 auto it = FindAttributeNS(ns, attr);
132 if (it != attributes_.end())
133 attributes_.erase(it);
136 Element::attr_iter Element::FindAttribute(
const std::string&
name) {
137 auto it = attributes_.begin();
138 for (; it != attributes_.end(); it++) {
139 if ((*it)->attr_name() ==
name)
145 Element::attr_iter Element::FindAttributeNS(
const std::string& ns,
146 const std::string& name) {
147 auto it = attributes_.begin();
148 for (; it != attributes_.end(); it++) {
149 if ((*it)->namespace_uri == ns && (*it)->local_name == name)
156 return std::vector<RefPtr<Attr>>(attributes_.begin(), attributes_.end());
179 NotImplemented(
"className");
180 NotImplemented(
"classList");
181 NotImplemented(
"slot");
183 NotImplemented(
"getAttributeNames");
185 NotImplemented(
"getAttributeNode");
186 NotImplemented(
"getAttributeNodeNS");
187 NotImplemented(
"setAttributeNode");
188 NotImplemented(
"setAttributeNodeNS");
189 NotImplemented(
"removeAttributeNode");
191 NotImplemented(
"attachShadow");
192 NotImplemented(
"shadowRoot");
194 NotImplemented(
"closest");
195 NotImplemented(
"matches");
196 NotImplemented(
"webkitMatchesSelector");
198 NotImplemented(
"insertAdjacentElement");
199 NotImplemented(
"insertAdjacentText");
bool HasAttribute(const std::string &name) const
void RemoveAttributeNS(const std::string &ns, const std::string &attr)
std::vector< RefPtr< Attr > > attributes() const
bool has_attributes() const
optional< std::string > NodeValue() const override
const optional< std::string > namespace_uri
bool HasAttributeNS(const std::string &ns, const std::string &name) const
const T & value() const &
virtual void RemoveAttribute(const std::string &attr)
optional< std::string > TextContent() const override
Element(RefPtr< Document > document, const std::string &local_name, optional< std::string > namespace_uri, optional< std::string > namespace_prefix)
void Trace(memory::HeapTracer *tracer) const override
RefPtr< Document > document() const
optional< std::string > GetAttribute(const std::string &name) const
std::string node_name() const override
void Trace(const Traceable *ptr)
void SetAttributeNS(const std::string &ns, const std::string &key, const std::string &value)
void SetAttribute(const std::string &key, const std::string &value)
const std::string local_name
std::vector< RefPtr< Node > > child_nodes() const
optional< std::string > GetAttributeNS(const std::string &ns, const std::string &name) const
std::string tag_name() const
const optional< std::string > namespace_prefix
void Trace(memory::HeapTracer *tracer) const override