Shaka Player Embedded
document.h
Go to the documentation of this file.
1 // Copyright 2016 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 #ifndef SHAKA_EMBEDDED_JS_DOM_DOCUMENT_H_
16 #define SHAKA_EMBEDDED_JS_DOM_DOCUMENT_H_
17 
18 #include <atomic>
19 #include <string>
20 #include <vector>
21 
22 #include "shaka/optional.h"
24 
25 namespace shaka {
26 namespace js {
27 namespace dom {
28 
29 class Attr;
30 class Comment;
31 class Element;
32 class Text;
33 
38 class Document : public ContainerNode {
39  DECLARE_TYPE_INFO(Document);
40 
41  public:
42  Document();
43 
44  static Document* Create() {
45  return new Document();
46  }
48 
53  uint64_t created_at() const { return created_at_; }
54 
55  std::string node_name() const override;
56  optional<std::string> NodeValue() const override;
57  optional<std::string> TextContent() const override;
58 
60 
61  std::vector<RefPtr<Element>> GetElementsByTagName(
62  const std::string& name) const override;
63 
64  RefPtr<Element> CreateElement(const std::string& name);
65  RefPtr<Comment> CreateComment(const std::string& data);
66  RefPtr<Text> CreateTextNode(const std::string& data);
67 
68  ExceptionOr<RefPtr<Attr>> CreateAttribute(const std::string& name);
70  const std::string& namespace_uri, const std::string& qualified_name);
71 
72  private:
73  static std::atomic<Document*> instance_;
74  const uint64_t created_at_;
75 };
76 
77 class DocumentFactory : public BackingObjectFactory<Document, ContainerNode> {
78  public:
80 };
81 
82 } // namespace dom
83 } // namespace js
84 } // namespace shaka
85 
86 #endif // SHAKA_EMBEDDED_JS_DOM_DOCUMENT_H_
std::vector< RefPtr< Element > > GetElementsByTagName(const std::string &name) const override
Definition: document.cc:85
static Document * Create()
Definition: document.h:44
RefPtr< Element > CreateElement(const std::string &name)
Definition: document.cc:95
uint64_t created_at() const
Definition: document.h:53
RefPtr< Comment > CreateComment(const std::string &data)
Definition: document.cc:103
optional< std::string > TextContent() const override
Definition: document.cc:73
RefPtr< Text > CreateTextNode(const std::string &data)
Definition: document.cc:107
static RefPtr< Document > EnsureGlobalDocument()
Definition: document.cc:51
optional< std::string > NodeValue() const override
Definition: document.cc:69
RefPtr< Element > DocumentElement() const
Definition: document.cc:77
std::string node_name() const override
Definition: document.cc:65
ExceptionOr< RefPtr< Attr > > CreateAttribute(const std::string &name)
Definition: document.cc:111
ExceptionOr< RefPtr< Attr > > CreateAttributeNS(const std::string &namespace_uri, const std::string &qualified_name)
Definition: document.cc:120
std::string name() const