-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathelement.h
More file actions
209 lines (170 loc) · 8.17 KB
/
element.h
File metadata and controls
209 lines (170 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (C) 2019-2022 The Kraken authors. All rights reserved.
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/
#ifndef BRIDGE_ELEMENT_H
#define BRIDGE_ELEMENT_H
#include "bindings/qjs/cppgc/garbage_collected.h"
#include "bindings/qjs/script_promise.h"
#include "container_node.h"
#include "core/css/inline_css_style_declaration.h"
#include "element_data.h"
#include "legacy/bounding_client_rect.h"
#include "legacy/element_attributes.h"
#include "parent_node.h"
#include "qjs_scroll_to_options.h"
namespace webf {
class Element : public ContainerNode {
DEFINE_WRAPPERTYPEINFO();
public:
using ImplType = Element*;
enum class AttributeModificationReason {
kDirectly,
kByParser,
kByCloning,
kByMoveToNewDocument,
kBySynchronizationOfLazyAttribute
};
struct AttributeModificationParams {
WEBF_STACK_ALLOCATED();
public:
AttributeModificationParams(const AtomicString& qname,
const AtomicString& old_value,
const AtomicString& new_value,
AttributeModificationReason reason)
: name(qname), old_value(old_value), new_value(new_value), reason(reason) {}
const AtomicString& name;
const AtomicString& old_value;
const AtomicString& new_value;
const AttributeModificationReason reason;
};
Element(const AtomicString& namespace_uri,
const AtomicString& local_name,
const AtomicString& prefix,
Document* document,
ConstructionType = kCreateElement);
ElementAttributes* attributes() const { return &EnsureElementAttributes(); }
ElementAttributes& EnsureElementAttributes() const;
bool hasAttribute(const AtomicString&, ExceptionState& exception_state);
AtomicString getAttribute(const AtomicString&, ExceptionState& exception_state) const;
// Passing null as the second parameter removes the attribute when
// calling either of these set methods.
void setAttribute(const AtomicString&, const AtomicString& value);
void setAttribute(const AtomicString&, const AtomicString& value, ExceptionState&);
void removeAttribute(const AtomicString&, ExceptionState& exception_state);
BoundingClientRect* getBoundingClientRect(ExceptionState& exception_state);
std::vector<BoundingClientRect*> getClientRects(ExceptionState& exception_state);
void click(ExceptionState& exception_state);
void scroll(ExceptionState& exception_state);
void scroll(const std::shared_ptr<ScrollToOptions>& options, ExceptionState& exception_state);
void scroll(double x, double y, ExceptionState& exception_state);
void scrollTo(ExceptionState& exception_state);
void scrollTo(const std::shared_ptr<ScrollToOptions>& options, ExceptionState& exception_state);
void scrollTo(double x, double y, ExceptionState& exception_state);
void scrollBy(ExceptionState& exception_state);
void scrollBy(double x, double y, ExceptionState& exception_state);
void scrollBy(const std::shared_ptr<ScrollToOptions>& options, ExceptionState& exception_state);
ScriptPromise toBlob(double device_pixel_ratio, ExceptionState& exception_state);
ScriptPromise toBlob(ExceptionState& exception_state);
void DidAddAttribute(const AtomicString&, const AtomicString&);
void WillModifyAttribute(const AtomicString&, const AtomicString& old_value, const AtomicString& new_value);
void DidModifyAttribute(const AtomicString&,
const AtomicString& old_value,
const AtomicString& new_value,
AttributeModificationReason reason);
void DidRemoveAttribute(const AtomicString&, const AtomicString& old_value);
void SynchronizeStyleAttributeInternal();
void SynchronizeAttribute(const AtomicString& name);
void InvalidateStyleAttribute();
void AttributeChanged(const AttributeModificationParams& params);
void StyleAttributeChanged(const AtomicString& new_style_string, AttributeModificationReason modification_reason);
void SetInlineStyleFromString(const AtomicString&);
std::string outerHTML();
std::string innerHTML();
void setInnerHTML(const AtomicString& value, ExceptionState& exception_state);
bool HasTagName(const AtomicString&) const;
AtomicString nodeValue() const override;
AtomicString tagName() const { return getUppercasedQualifiedName(); }
AtomicString prefix() const { return prefix_; }
AtomicString localName() const { return local_name_; }
AtomicString namespaceURI() const { return namespace_uri_; }
std::string nodeName() const override;
AtomicString className() const;
void setClassName(const AtomicString& value, ExceptionState& exception_state);
AtomicString id() const;
void setId(const AtomicString& value, ExceptionState& exception_state);
std::vector<Element*> getElementsByClassName(const AtomicString& class_name, ExceptionState& exception_state);
std::vector<Element*> getElementsByTagName(const AtomicString& tag_name, ExceptionState& exception_state);
Element* querySelector(const AtomicString& selectors, ExceptionState& exception_state);
std::vector<Element*> querySelectorAll(const AtomicString& selectors, ExceptionState& exception_state);
bool matches(const AtomicString& selectors, ExceptionState& exception_state);
Element* closest(const AtomicString& selectors, ExceptionState& exception_state);
InlineCssStyleDeclaration* style();
InlineCssStyleDeclaration& EnsureCSSStyleDeclaration();
DOMTokenList* classList();
DOMStringMap* dataset();
Element& CloneWithChildren(CloneChildrenFlag flag, Document* = nullptr) const;
Element& CloneWithoutChildren(Document* = nullptr) const;
NodeType nodeType() const override;
bool ChildTypeAllowed(NodeType) const override;
// Clones attributes only.
void CloneAttributesFrom(const Element&);
bool HasEquivalentAttributes(const Element& other) const;
// Step 5 of https://dom.spec.whatwg.org/#concept-node-clone
virtual void CloneNonAttributePropertiesFrom(const Element&, CloneChildrenFlag) {}
virtual bool IsWidgetElement() const;
void Trace(GCVisitor* visitor) const override;
protected:
void SetAttributeInternal(const AtomicString&,
const AtomicString& value,
AttributeModificationReason reason,
ExceptionState& exception_state);
const ElementData* GetElementData() const { return element_data_.get(); }
bool HasElementData() const { return element_data_ != nullptr; }
const AtomicString& getQualifiedName() const { return local_name_; }
const AtomicString getUppercasedQualifiedName() const;
ElementData& EnsureElementData();
AtomicString namespace_uri_ = AtomicString::Null();
AtomicString prefix_ = AtomicString::Null();
AtomicString local_name_ = AtomicString::Empty();
private:
// Clone is private so that non-virtual CloneElementWithChildren and
// CloneElementWithoutChildren are used inst
Node* Clone(Document&, CloneChildrenFlag) const override;
virtual Element& CloneWithoutAttributesAndChildren(Document& factory) const;
void _notifyNodeRemoved(Node* node);
void _notifyChildRemoved();
void _notifyNodeInsert(Node* insertNode);
void _notifyChildInsert();
void _beforeUpdateId(JSValue oldIdValue, JSValue newIdValue);
mutable std::unique_ptr<ElementData> element_data_;
mutable Member<ElementAttributes> attributes_;
Member<InlineCssStyleDeclaration> cssom_wrapper_;
};
template <typename T>
bool IsElementOfType(const Node&);
template <>
inline bool IsElementOfType<const Element>(const Node& node) {
return node.IsElementNode();
}
template <typename T>
inline bool IsElementOfType(const Element& element) {
return IsElementOfType<T>(static_cast<const Node&>(element));
}
template <>
inline bool IsElementOfType<const Element>(const Element&) {
return true;
}
template <>
struct DowncastTraits<Element> {
static bool AllowFrom(const Node& node) { return node.IsElementNode(); }
static bool AllowFrom(const BindingObject& binding_object) {
return binding_object.IsEventTarget() && To<EventTarget>(binding_object).IsNode() &&
To<Node>(binding_object).IsElementNode();
}
};
inline Element* Node::parentElement() const {
return DynamicTo<Element>(parentNode());
}
} // namespace webf
#endif // BRIDGE_ELEMENT_H