Shaka Player Embedded
attr.cc
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/dom/attr.h"
16 
17 #include "src/js/dom/document.h"
18 #include "src/js/dom/element.h"
19 
20 namespace shaka {
21 namespace js {
22 namespace dom {
23 
25  const std::string& local_name, optional<std::string> namespace_uri,
26  optional<std::string> namespace_prefix, const std::string& value)
27  : Node(ATTRIBUTE_NODE, document),
28  namespace_uri(namespace_uri),
29  namespace_prefix(namespace_prefix),
30  local_name(local_name),
31  value(value),
32  owner_element(owner) {
33  DCHECK(!owner || owner->document() == document);
34 }
35 
36 // \cond Doxygen_Skip
37 Attr::~Attr() {}
38 // \endcond Doxygen_Skip
39 
40 std::string Attr::attr_name() const {
42  return local_name;
43  return namespace_prefix.value() + ":" + local_name;
44 }
45 
46 void Attr::Trace(memory::HeapTracer* tracer) const {
47  Node::Trace(tracer);
48  tracer->Trace(&owner_element);
49 }
50 
51 std::string Attr::node_name() const {
52  return attr_name();
53 }
54 
56  return value;
57 }
58 
60  return value;
61 }
62 
63 
65  AddReadOnlyProperty("namespaceURI", &Attr::namespace_uri);
66  AddReadOnlyProperty("prefix", &Attr::namespace_prefix);
67  AddReadOnlyProperty("localName", &Attr::local_name);
68  AddReadOnlyProperty("value", &Attr::value);
69  AddReadOnlyProperty("specified", &Attr::specified);
70  AddReadOnlyProperty("ownerElement", &Attr::owner_element);
71 
72  AddGenericProperty("name", &Attr::attr_name);
73 }
74 
75 } // namespace dom
76 } // namespace js
77 } // namespace shaka
void Trace(memory::HeapTracer *tracer) const override
Definition: attr.cc:46
optional< std::string > NodeValue() const override
Definition: attr.cc:55
const optional< std::string > namespace_prefix
Definition: attr.h:43
const std::string local_name
Definition: attr.h:44
const T & value() const &
Definition: optional.h:147
RefPtr< Document > document() const
Definition: node.cc:47
void Trace(const Traceable *ptr)
Definition: heap_tracer.cc:43
std::string value
Definition: attr.h:46
optional< std::string > TextContent() const override
Definition: attr.cc:59
std::string node_name() const override
Definition: attr.cc:51
const bool specified
Definition: attr.h:45
std::string attr_name() const
Definition: attr.cc:40
const Member< Element > owner_element
Definition: attr.h:48
bool has_value() const
Definition: optional.h:143
const optional< std::string > namespace_uri
Definition: attr.h:42
Attr(RefPtr< Document > document, RefPtr< Element > owner, const std::string &local_name, optional< std::string > namespace_uri, optional< std::string > namespace_prefix, const std::string &value)
Definition: attr.cc:24
void Trace(memory::HeapTracer *tracer) const override
Definition: node.cc:35