Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: sky/engine/core/dom/ContainerNode.h

Issue 698123002: Remove more API from Node and ContainerNode. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/dom/CharacterData.cpp ('k') | sky/engine/core/dom/ContainerNode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2013 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2013 Apple Inc. All r ights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 class ContainerNode : public Node { 45 class ContainerNode : public Node {
46 public: 46 public:
47 virtual ~ContainerNode(); 47 virtual ~ContainerNode();
48 48
49 Node* firstChild() const { return m_firstChild; } 49 Node* firstChild() const { return m_firstChild; }
50 Node* lastChild() const { return m_lastChild; } 50 Node* lastChild() const { return m_lastChild; }
51 bool hasChildren() const { return m_firstChild; } 51 bool hasChildren() const { return m_firstChild; }
52 52
53 bool hasOneChild() const { return m_firstChild && !m_firstChild->nextSibling (); } 53 bool hasOneChild() const { return m_firstChild && !m_firstChild->nextSibling (); }
54 bool hasOneTextChild() const { return hasOneChild() && m_firstChild->isTextN ode(); } 54 bool hasOneTextChild() const { return hasOneChild() && m_firstChild->isTextN ode(); }
55 bool hasChildCount(unsigned) const;
56 55
57 unsigned countChildren() const; 56 unsigned countChildren() const;
58 57
59 PassRefPtr<Element> querySelector(const AtomicString& selectors, ExceptionSt ate&); 58 PassRefPtr<Element> querySelector(const AtomicString& selectors, ExceptionSt ate&);
60 PassRefPtr<StaticElementList> querySelectorAll(const AtomicString& selectors , ExceptionState&); 59 PassRefPtr<StaticElementList> querySelectorAll(const AtomicString& selectors , ExceptionState&);
61 60
62 PassRefPtr<Node> insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exc eptionState& = ASSERT_NO_EXCEPTION); 61 PassRefPtr<Node> insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exc eptionState& = ASSERT_NO_EXCEPTION);
63 PassRefPtr<Node> replaceChild(PassRefPtr<Node> newChild, PassRefPtr<Node> ol dChild, ExceptionState& = ASSERT_NO_EXCEPTION); 62 PassRefPtr<Node> replaceChild(PassRefPtr<Node> newChild, PassRefPtr<Node> ol dChild, ExceptionState& = ASSERT_NO_EXCEPTION);
64 PassRefPtr<Node> removeChild(PassRefPtr<Node> child, ExceptionState& = ASSER T_NO_EXCEPTION); 63 PassRefPtr<Node> removeChild(PassRefPtr<Node> child, ExceptionState& = ASSER T_NO_EXCEPTION);
65 PassRefPtr<Node> appendChild(PassRefPtr<Node> newChild, ExceptionState& = AS SERT_NO_EXCEPTION); 64 PassRefPtr<Node> appendChild(PassRefPtr<Node> newChild, ExceptionState& = AS SERT_NO_EXCEPTION);
66 65
67 Element* getElementById(const AtomicString& id) const; 66 Element* getElementById(const AtomicString& id) const;
68 67
69 // These methods are only used during parsing. 68 // These methods are only used during parsing.
70 // They don't send DOM mutation events or handle reparenting. 69 // They don't send DOM mutation events or handle reparenting.
71 void parserAppendChild(PassRefPtr<Node>); 70 void parserAppendChild(PassRefPtr<Node>);
72 void parserRemoveChild(Node&); 71 void parserRemoveChild(Node&);
73 void parserInsertBefore(PassRefPtr<Node> newChild, Node& refChild); 72 void parserInsertBefore(PassRefPtr<Node> newChild, Node& refChild);
74 void parserTakeAllChildrenFrom(ContainerNode&);
75 73
76 void removeChildren(); 74 void removeChildren();
77 75
78 void cloneChildNodes(ContainerNode* clone); 76 void cloneChildNodes(ContainerNode* clone);
79 77
80 virtual void attach(const AttachContext& = AttachContext()) override; 78 virtual void attach(const AttachContext& = AttachContext()) override;
81 virtual void detach(const AttachContext& = AttachContext()) override; 79 virtual void detach(const AttachContext& = AttachContext()) override;
82 virtual LayoutRect boundingBox() const override final; 80 virtual LayoutRect boundingBox() const override final;
83 virtual void setFocus(bool) override; 81 virtual void setFocus(bool) override;
84 void focusStateChanged(); 82 void focusStateChanged();
85 virtual void setActive(bool = true) override; 83 virtual void setActive(bool = true) override;
86 virtual void setHovered(bool = true) override; 84 virtual void setHovered(bool = true) override;
87 85
88 // ------------------------------------------------------------------------- ---- 86 // ------------------------------------------------------------------------- ----
89 // Notification of document structure changes (see core/dom/Node.h for more notification methods) 87 // Notification of document structure changes (see core/dom/Node.h for more notification methods)
90 88
91 enum ChildrenChangeType { ElementInserted, NonElementInserted, ElementRemove d, NonElementRemoved, AllChildrenRemoved, TextChanged }; 89 enum ChildrenChangeType { ElementInserted, NonElementInserted, ElementRemove d, NonElementRemoved, AllChildrenRemoved, TextChanged };
92 enum ChildrenChangeSource { ChildrenChangeSourceAPI, ChildrenChangeSourcePar ser }; 90 enum ChildrenChangeSource { ChildrenChangeSourceAPI, ChildrenChangeSourcePar ser };
93 struct ChildrenChange { 91 struct ChildrenChange {
94 STACK_ALLOCATED(); 92 STACK_ALLOCATED();
95 public: 93 public:
96 static ChildrenChange forInsertion(Node& node, ChildrenChangeSource byPa rser) 94 static ChildrenChange forInsertion(Node& node, ChildrenChangeSource byPa rser)
97 { 95 {
98 ChildrenChange change = { 96 ChildrenChange change = {
99 node.isElementNode() ? ElementInserted : NonElementInserted, 97 node.isElementNode() ? ElementInserted : NonElementInserted,
100 node.previousSibling(),
101 node.nextSibling(),
102 byParser 98 byParser
103 }; 99 };
104 return change; 100 return change;
105 } 101 }
106 102
107 static ChildrenChange forRemoval(Node& node, Node* previousSibling, Node * nextSibling, ChildrenChangeSource byParser) 103 static ChildrenChange forRemoval(Node& node, ChildrenChangeSource byPars er)
108 { 104 {
109 ChildrenChange change = { 105 ChildrenChange change = {
110 node.isElementNode() ? ElementRemoved : NonElementRemoved, 106 node.isElementNode() ? ElementRemoved : NonElementRemoved,
111 previousSibling,
112 nextSibling,
113 byParser 107 byParser
114 }; 108 };
115 return change; 109 return change;
116 } 110 }
117 111
118 bool isChildInsertion() const { return type == ElementInserted || type = = NonElementInserted; } 112 bool isChildInsertion() const { return type == ElementInserted || type = = NonElementInserted; }
119 bool isChildRemoval() const { return type == ElementRemoved || type == N onElementRemoved; }
120 bool isChildElementChange() const { return type == ElementInserted || ty pe == ElementRemoved; }
121 113
122 ChildrenChangeType type; 114 ChildrenChangeType type;
123 RawPtr<Node> siblingBeforeChange;
124 RawPtr<Node> siblingAfterChange;
125 ChildrenChangeSource byParser; 115 ChildrenChangeSource byParser;
126 }; 116 };
127 117
128 // Notifies the node that it's list of children have changed (either by addi ng or removing child nodes), or a child 118 // Notifies the node that it's list of children have changed (either by addi ng or removing child nodes), or a child
129 // node that is of the type TEXT_NODE has changed its value. 119 // node that is of the type TEXT_NODE has changed its value.
130 virtual void childrenChanged(const ChildrenChange&); 120 virtual void childrenChanged(const ChildrenChange&);
131 121
132 virtual void trace(Visitor*) override;
133
134 protected: 122 protected:
135 ContainerNode(TreeScope*, ConstructionType = CreateContainer); 123 ContainerNode(TreeScope*, ConstructionType = CreateContainer);
136 124
137 #if !ENABLE(OILPAN)
138 void removeDetachedChildren(); 125 void removeDetachedChildren();
139 #endif
140 126
141 void setFirstChild(Node* child) { m_firstChild = child; } 127 void setFirstChild(Node* child) { m_firstChild = child; }
142 void setLastChild(Node* child) { m_lastChild = child; } 128 void setLastChild(Node* child) { m_lastChild = child; }
143 129
144 private: 130 private:
145 bool isContainerNode() const = delete; // This will catch anyone doing an un necessary check. 131 bool isContainerNode() const = delete; // This will catch anyone doing an un necessary check.
146 bool isTextNode() const = delete; // This will catch anyone doing an unneces sary check. 132 bool isTextNode() const = delete; // This will catch anyone doing an unneces sary check.
147 133
148 void removeBetween(Node* previousChild, Node* nextChild, Node& oldChild); 134 void removeBetween(Node* previousChild, Node* nextChild, Node& oldChild);
149 void insertBeforeCommon(Node& nextChild, Node& oldChild); 135 void insertBeforeCommon(Node& nextChild, Node& oldChild);
(...skipping 22 matching lines...) Expand all
172 RawPtr<Node> m_firstChild; 158 RawPtr<Node> m_firstChild;
173 RawPtr<Node> m_lastChild; 159 RawPtr<Node> m_lastChild;
174 }; 160 };
175 161
176 #if ENABLE(ASSERT) 162 #if ENABLE(ASSERT)
177 bool childAttachedAllowedWhenAttachingChildren(ContainerNode*); 163 bool childAttachedAllowedWhenAttachingChildren(ContainerNode*);
178 #endif 164 #endif
179 165
180 DEFINE_NODE_TYPE_CASTS(ContainerNode, isContainerNode()); 166 DEFINE_NODE_TYPE_CASTS(ContainerNode, isContainerNode());
181 167
182 inline bool ContainerNode::hasChildCount(unsigned count) const
183 {
184 Node* child = m_firstChild;
185 while (count && child) {
186 child = child->nextSibling();
187 --count;
188 }
189 return !count && !child;
190 }
191
192 inline ContainerNode::ContainerNode(TreeScope* treeScope, ConstructionType type) 168 inline ContainerNode::ContainerNode(TreeScope* treeScope, ConstructionType type)
193 : Node(treeScope, type) 169 : Node(treeScope, type)
194 , m_firstChild(nullptr) 170 , m_firstChild(nullptr)
195 , m_lastChild(nullptr) 171 , m_lastChild(nullptr)
196 { 172 {
197 } 173 }
198 174
199 inline void ContainerNode::attachChildren(const AttachContext& context) 175 inline void ContainerNode::attachChildren(const AttachContext& context)
200 { 176 {
201 AttachContext childrenContext(context); 177 AttachContext childrenContext(context);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 inline void getChildNodes(ContainerNode& node, NodeVector& nodes) 234 inline void getChildNodes(ContainerNode& node, NodeVector& nodes)
259 { 235 {
260 ASSERT(!nodes.size()); 236 ASSERT(!nodes.size());
261 for (Node* child = node.firstChild(); child; child = child->nextSibling()) 237 for (Node* child = node.firstChild(); child; child = child->nextSibling())
262 nodes.append(child); 238 nodes.append(child);
263 } 239 }
264 240
265 } // namespace blink 241 } // namespace blink
266 242
267 #endif // ContainerNode_h 243 #endif // ContainerNode_h
OLDNEW
« no previous file with comments | « sky/engine/core/dom/CharacterData.cpp ('k') | sky/engine/core/dom/ContainerNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698