Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 m_nodes[i]->lazyReattachIfAttached(); | 122 m_nodes[i]->lazyReattachIfAttached(); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 PassOwnPtr<ElementShadow> ElementShadow::create() | 126 PassOwnPtr<ElementShadow> ElementShadow::create() |
| 127 { | 127 { |
| 128 return adoptPtr(new ElementShadow()); | 128 return adoptPtr(new ElementShadow()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 ElementShadow::ElementShadow() | 131 ElementShadow::ElementShadow() |
| 132 : m_needsDistributionRecalc(false) | 132 : m_shadowRoot(0) |
| 133 , m_needsDistributionRecalc(false) | |
| 133 , m_needsSelectFeatureSet(false) | 134 , m_needsSelectFeatureSet(false) |
| 134 { | 135 { |
| 135 } | 136 } |
| 136 | 137 |
| 137 ElementShadow::~ElementShadow() | 138 ElementShadow::~ElementShadow() |
| 138 { | 139 { |
| 139 #if !ENABLE(OILPAN) | 140 #if !ENABLE(OILPAN) |
| 140 removeDetachedShadowRoots(); | 141 removeDetachedShadowRoots(); |
| 141 #endif | 142 #endif |
| 142 } | 143 } |
| 143 | 144 |
| 144 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost) | 145 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost) |
| 145 { | 146 { |
| 146 EventDispatchForbiddenScope assertNoEventDispatch; | 147 EventDispatchForbiddenScope assertNoEventDispatch; |
| 147 ScriptForbiddenScope forbidScript; | 148 ScriptForbiddenScope forbidScript; |
| 148 | 149 |
| 149 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | 150 ASSERT(!m_shadowRoot); |
| 150 root->lazyReattachIfAttached(); | |
| 151 | 151 |
| 152 RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.document()); | 152 RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.document()); |
| 153 shadowRoot->setParentOrShadowHostNode(&shadowHost); | 153 shadowRoot->setParentOrShadowHostNode(&shadowHost); |
| 154 shadowRoot->setParentTreeScope(shadowHost.treeScope()); | 154 shadowRoot->setParentTreeScope(shadowHost.treeScope()); |
| 155 m_shadowRoots.push(shadowRoot.get()); | 155 m_shadowRoot = shadowRoot.get(); |
| 156 | |
| 156 setNeedsDistributionRecalc(); | 157 setNeedsDistributionRecalc(); |
| 157 | 158 |
| 158 shadowRoot->insertedInto(&shadowHost); | 159 shadowRoot->insertedInto(&shadowHost); |
| 159 | 160 |
| 160 return *shadowRoot; | 161 return *shadowRoot; |
| 161 } | 162 } |
| 162 | 163 |
| 163 #if !ENABLE(OILPAN) | |
| 164 void ElementShadow::removeDetachedShadowRoots() | 164 void ElementShadow::removeDetachedShadowRoots() |
|
ojan
2014/11/26 18:43:17
removedDetachedShadowRoot ?
esprehn
2014/11/26 18:54:23
done.
| |
| 165 { | 165 { |
| 166 // Dont protect this ref count. | 166 // Dont protect this ref count. |
| 167 Element* shadowHost = host(); | 167 Element* shadowHost = host(); |
| 168 ASSERT(shadowHost); | 168 ASSERT(shadowHost); |
| 169 | 169 |
| 170 while (RefPtr<ShadowRoot> oldRoot = m_shadowRoots.head()) { | 170 if (RefPtr<ShadowRoot> oldRoot = m_shadowRoot) { |
| 171 shadowHost->document().removeFocusedElementOfSubtree(oldRoot.get()); | 171 shadowHost->document().removeFocusedElementOfSubtree(oldRoot.get()); |
| 172 m_shadowRoots.removeHead(); | 172 m_shadowRoot = 0; |
| 173 oldRoot->setParentOrShadowHostNode(0); | 173 oldRoot->setParentOrShadowHostNode(0); |
| 174 oldRoot->setParentTreeScope(shadowHost->document()); | 174 oldRoot->setParentTreeScope(shadowHost->document()); |
| 175 oldRoot->setPrev(0); | |
| 176 oldRoot->setNext(0); | |
| 177 } | 175 } |
| 178 } | 176 } |
| 179 #endif | |
| 180 | 177 |
| 181 void ElementShadow::attach(const Node::AttachContext& context) | 178 void ElementShadow::attach(const Node::AttachContext& context) |
| 182 { | 179 { |
| 180 if (!m_shadowRoot) | |
| 181 return; | |
| 182 | |
| 183 ASSERT(m_shadowRoot->needsAttach()); | |
| 184 | |
| 183 Node::AttachContext childrenContext(context); | 185 Node::AttachContext childrenContext(context); |
| 184 childrenContext.resolvedStyle = 0; | 186 childrenContext.resolvedStyle = 0; |
| 185 | 187 m_shadowRoot->attach(childrenContext); |
| 186 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | |
| 187 if (root->needsAttach()) | |
| 188 root->attach(childrenContext); | |
| 189 } | |
| 190 } | 188 } |
| 191 | 189 |
| 192 void ElementShadow::detach(const Node::AttachContext& context) | 190 void ElementShadow::detach(const Node::AttachContext& context) |
| 193 { | 191 { |
| 192 if (!m_shadowRoot) | |
| 193 return; | |
| 194 | |
| 194 Node::AttachContext childrenContext(context); | 195 Node::AttachContext childrenContext(context); |
| 195 childrenContext.resolvedStyle = 0; | 196 childrenContext.resolvedStyle = 0; |
| 196 | 197 m_shadowRoot->detach(childrenContext); |
| 197 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) | |
| 198 root->detach(childrenContext); | |
| 199 } | 198 } |
| 200 | 199 |
| 201 void ElementShadow::setNeedsDistributionRecalc() | 200 void ElementShadow::setNeedsDistributionRecalc() |
| 202 { | 201 { |
| 203 if (m_needsDistributionRecalc) | 202 if (m_needsDistributionRecalc) |
| 204 return; | 203 return; |
| 205 m_needsDistributionRecalc = true; | 204 m_needsDistributionRecalc = true; |
| 206 host()->markAncestorsWithChildNeedsDistributionRecalc(); | 205 host()->markAncestorsWithChildNeedsDistributionRecalc(); |
| 207 clearDistribution(); | 206 clearDistribution(); |
| 208 } | 207 } |
| 209 | 208 |
| 210 bool ElementShadow::hasSameStyles(const ElementShadow* other) const | 209 bool ElementShadow::hasSameStyles(const ElementShadow* other) const |
| 211 { | 210 { |
| 212 ShadowRoot* root = youngestShadowRoot(); | 211 ShadowRoot* root = m_shadowRoot; |
| 213 ShadowRoot* otherRoot = other->youngestShadowRoot(); | 212 ShadowRoot* otherRoot = other->shadowRoot(); |
| 214 while (root || otherRoot) { | 213 if (root || otherRoot) { |
| 215 if (!root || !otherRoot) | 214 if (!root || !otherRoot) |
| 216 return false; | 215 return false; |
| 217 | 216 |
| 218 StyleSheetList* list = root->styleSheets(); | 217 StyleSheetList* list = root->styleSheets(); |
| 219 StyleSheetList* otherList = otherRoot->styleSheets(); | 218 StyleSheetList* otherList = otherRoot->styleSheets(); |
| 220 | 219 |
| 221 if (list->length() != otherList->length()) | 220 if (list->length() != otherList->length()) |
| 222 return false; | 221 return false; |
| 223 | 222 |
| 224 for (size_t i = 0; i < list->length(); i++) { | 223 for (size_t i = 0; i < list->length(); i++) { |
| 225 if (toCSSStyleSheet(list->item(i))->contents() != toCSSStyleSheet(ot herList->item(i))->contents()) | 224 if (toCSSStyleSheet(list->item(i))->contents() != toCSSStyleSheet(ot herList->item(i))->contents()) |
| 226 return false; | 225 return false; |
| 227 } | 226 } |
| 228 root = root->olderShadowRoot(); | |
| 229 otherRoot = otherRoot->olderShadowRoot(); | |
| 230 } | 227 } |
| 231 | 228 |
| 232 return true; | 229 return true; |
| 233 } | 230 } |
| 234 | 231 |
| 235 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const | 232 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const |
| 236 { | 233 { |
| 237 ASSERT(key && !key->document().childNeedsDistributionRecalc()); | 234 ASSERT(key && !key->document().childNeedsDistributionRecalc()); |
| 238 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); | 235 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); |
| 239 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get(); | 236 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get(); |
| 240 } | 237 } |
| 241 | 238 |
| 242 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const | 239 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const |
| 243 { | 240 { |
| 244 ASSERT(key && !key->document().childNeedsDistributionRecalc()); | 241 ASSERT(key && !key->document().childNeedsDistributionRecalc()); |
| 245 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); | 242 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); |
| 246 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; | 243 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; |
| 247 } | 244 } |
| 248 | 245 |
| 249 void ElementShadow::distribute() | 246 void ElementShadow::distribute() |
| 250 { | 247 { |
| 251 host()->setNeedsStyleRecalc(SubtreeStyleChange); | 248 host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 252 DistributionPool pool(*host()); | 249 DistributionPool pool(*host()); |
| 253 | 250 |
| 254 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 251 if (ShadowRoot* root = shadowRoot()) { |
| 255 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints(); | 252 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints(); |
| 256 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 253 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
| 257 InsertionPoint* point = insertionPoints[i].get(); | 254 InsertionPoint* point = insertionPoints[i].get(); |
| 258 if (!point->isActive()) | 255 if (!point->isActive()) |
| 259 continue; | 256 continue; |
| 260 pool.distributeTo(point, this); | 257 pool.distributeTo(point, this); |
| 261 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*point)) | 258 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*point)) |
| 262 shadow->setNeedsDistributionRecalc(); | 259 shadow->setNeedsDistributionRecalc(); |
| 263 } | 260 } |
| 264 } | 261 } |
| 265 } | 262 } |
| 266 | 263 |
| 267 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) | 264 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) |
| 268 { | 265 { |
| 269 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints()); | 266 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints()); |
| 270 result.storedValue->value.append(insertionPoint); | 267 result.storedValue->value.append(insertionPoint); |
| 271 } | 268 } |
| 272 | 269 |
| 273 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() | 270 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() |
| 274 { | 271 { |
| 275 if (!m_needsSelectFeatureSet) | 272 if (!m_needsSelectFeatureSet) |
| 276 return m_selectFeatures; | 273 return m_selectFeatures; |
| 277 | 274 |
| 278 m_selectFeatures.clear(); | 275 m_selectFeatures.clear(); |
| 279 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root()) | 276 if (ShadowRoot* root = shadowRoot()) |
| 280 collectSelectFeatureSetFrom(*root); | 277 collectSelectFeatureSetFrom(*root); |
| 281 m_needsSelectFeatureSet = false; | 278 m_needsSelectFeatureSet = false; |
| 282 return m_selectFeatures; | 279 return m_selectFeatures; |
| 283 } | 280 } |
| 284 | 281 |
| 285 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root) | 282 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root) |
| 286 { | 283 { |
| 287 if (!root.containsShadowRoots() && !root.containsContentElements()) | 284 if (!root.containsShadowRoots() && !root.containsContentElements()) |
| 288 return; | 285 return; |
| 289 | 286 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 309 } | 306 } |
| 310 setNeedsDistributionRecalc(); | 307 setNeedsDistributionRecalc(); |
| 311 } | 308 } |
| 312 | 309 |
| 313 void ElementShadow::clearDistribution() | 310 void ElementShadow::clearDistribution() |
| 314 { | 311 { |
| 315 m_nodeToInsertionPoints.clear(); | 312 m_nodeToInsertionPoints.clear(); |
| 316 } | 313 } |
| 317 | 314 |
| 318 } // namespace | 315 } // namespace |
| OLD | NEW |