OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 16 matching lines...) Expand all Loading... | |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/css/RuleFeature.h" | 30 #include "core/css/RuleFeature.h" |
31 | 31 |
32 #include "HTMLNames.h" | 32 #include "HTMLNames.h" |
33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
34 #include "core/css/CSSSelector.h" | 34 #include "core/css/CSSSelector.h" |
35 #include "core/css/CSSSelectorList.h" | 35 #include "core/css/CSSSelectorList.h" |
36 #include "core/css/RuleSet.h" | 36 #include "core/css/RuleSet.h" |
37 #include "core/dom/Document.h" | |
38 #include "core/dom/Element.h" | |
39 #include "core/dom/Node.h" | |
40 #include "core/dom/shadow/ElementShadow.h" | |
41 #include "core/dom/shadow/ShadowRoot.h" | |
42 #include "wtf/BitVector.h" | |
37 | 43 |
38 namespace WebCore { | 44 namespace WebCore { |
39 | 45 |
40 static bool isSkippableComponentForInvalidation(const CSSSelector* selector) | 46 static bool isSkippableComponentForInvalidation(const CSSSelector* selector) |
41 { | 47 { |
42 if (selector->matchesPseudoElement() || selector->pseudoType() == CSSSelecto r::PseudoHost) | 48 if (selector->matchesPseudoElement() || selector->pseudoType() == CSSSelecto r::PseudoHost) |
43 return false; | 49 return false; |
44 return true; | 50 return true; |
45 } | 51 } |
46 | 52 |
47 // This method is somewhat conservative in what it acceptss. | 53 // This method is somewhat conservative in what it acceptss. |
48 static bool supportsClassDescendantInvalidation(const CSSSelector* selector) | 54 static bool supportsClassDescendantInvalidation(const CSSSelector* selector) |
49 { | 55 { |
50 bool foundDescendantRelation = false; | 56 bool foundDescendantRelation = false; |
51 bool foundAncestorIdent = false; | 57 bool foundAncestorIdent = false; |
52 bool foundIdent = false; | 58 bool foundIdent = false; |
53 for (const CSSSelector* component = selector; component; component = compone nt->tagHistory()) { | 59 for (const CSSSelector* component = selector; component; component = compone nt->tagHistory()) { |
54 | 60 |
55 // FIXME: We should allow pseudo elements, but we need to change how the y hook | 61 // FIXME: We should allow pseudo elements, but we need to change how the y hook |
56 // into recalcStyle by moving them to recalcOwnStyle instead of recalcCh ildStyle. | 62 // into recalcStyle by moving them to recalcOwnStyle instead of recalcCh ildStyle. |
57 | 63 |
58 if (component->m_match == CSSSelector::Tag | 64 // FIXME: next up: Tag and Id. |
59 || component->m_match == CSSSelector::Id | 65 if (component->m_match == CSSSelector::Class) { |
60 || component->m_match == CSSSelector::Class) { | |
61 if (!foundDescendantRelation) | 66 if (!foundDescendantRelation) |
62 foundIdent = true; | 67 foundIdent = true; |
63 else | 68 else |
64 foundAncestorIdent = true; | 69 foundAncestorIdent = true; |
65 } else if (!isSkippableComponentForInvalidation(component)) { | 70 } else if (!isSkippableComponentForInvalidation(component)) { |
66 return false; | 71 return false; |
67 } | 72 } |
68 // FIXME: We can probably support ChildTree and DescendantTree. | 73 // FIXME: We can probably support ChildTree and DescendantTree. |
69 switch (component->relation()) { | 74 switch (component->relation()) { |
70 case CSSSelector::Descendant: | 75 case CSSSelector::Descendant: |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 uncommonAttributeRules.append(other.uncommonAttributeRules); | 238 uncommonAttributeRules.append(other.uncommonAttributeRules); |
234 } | 239 } |
235 | 240 |
236 void RuleFeatureSet::clear() | 241 void RuleFeatureSet::clear() |
237 { | 242 { |
238 m_metadata.clear(); | 243 m_metadata.clear(); |
239 siblingRules.clear(); | 244 siblingRules.clear(); |
240 uncommonAttributeRules.clear(); | 245 uncommonAttributeRules.clear(); |
241 } | 246 } |
242 | 247 |
248 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& changedClasses, Element* element) | |
249 { | |
250 if (scheduleStyleInvalidationForClassChangeInternal(changedClasses, element) | |
251 && !RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) | |
esprehn
2014/01/28 00:11:34
Your flag checks need to always be first, otherwis
chrishtr
2014/01/28 01:11:55
The situation here is a little subtle. The code in
| |
252 element->setNeedsStyleRecalc(); | |
253 } | |
254 | |
255 void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitStr ing& oldClasses, const SpaceSplitString& newClasses, Element* element) | |
256 { | |
257 if (scheduleStyleInvalidationForClassChangeInternal(oldClasses, newClasses, element) | |
258 && !RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) | |
259 element->setNeedsStyleRecalc(); | |
esprehn
2014/01/28 00:11:34
Ditto.
chrishtr
2014/01/28 01:11:55
Same.
| |
260 } | |
261 | |
262 bool RuleFeatureSet::scheduleStyleInvalidationForClassChangeInternal(const Space SplitString& changedClasses, Element* element) | |
263 { | |
264 unsigned changedSize = changedClasses.size(); | |
265 for (unsigned i = 0; i < changedSize; ++i) { | |
266 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) | |
267 scheduleStyleInvalidationForOneClass(changedClasses[i], element); | |
268 else if (m_metadata.classesInRules.contains(changedClasses[i])) | |
269 return true; | |
270 } | |
271 return false; | |
272 } | |
273 | |
274 bool RuleFeatureSet::scheduleStyleInvalidationForClassChangeInternal(const Space SplitString& oldClasses, const SpaceSplitString& newClasses, Element* element) | |
275 { | |
276 if (!oldClasses.size()) | |
277 return scheduleStyleInvalidationForClassChangeInternal(newClasses, eleme nt); | |
278 | |
279 // Class vectors tend to be very short. This is faster than using a hash tab le. | |
280 BitVector remainingClassBits; | |
281 remainingClassBits.ensureSize(oldClasses.size()); | |
282 | |
283 for (unsigned i = 0; i < newClasses.size(); ++i) { | |
284 bool found = false; | |
285 for (unsigned j = 0; j < oldClasses.size(); ++j) { | |
286 if (newClasses[i] == oldClasses[j]) { | |
287 // Mark each class that is still in the newClasses so we can ski p doing | |
288 // an n^2 search below when looking for removals. We can't break from | |
289 // this loop early since a class can appear more than once. | |
290 remainingClassBits.quickSet(j); | |
291 found = true; | |
292 } | |
293 } | |
294 // Class was added. | |
295 if (!found) { | |
296 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) | |
297 scheduleStyleInvalidationForOneClass(newClasses[i], element); | |
298 else if (m_metadata.classesInRules.contains(newClasses[i])) | |
299 return true; | |
300 } | |
301 } | |
302 | |
303 for (unsigned i = 0; i < oldClasses.size(); ++i) { | |
304 if (remainingClassBits.quickGet(i)) | |
305 continue; | |
306 | |
307 // Class was removed. | |
308 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) | |
309 scheduleStyleInvalidationForOneClass(oldClasses[i], element); | |
310 else if (m_metadata.classesInRules.contains(oldClasses[i])) | |
311 return true; | |
312 } | |
313 return false; | |
314 } | |
315 | |
316 void RuleFeatureSet::scheduleStyleInvalidationForOneClass(const AtomicString& cl assName, Element* element) | |
esprehn
2014/01/28 00:11:34
ForClass(), no need for the "OneClass". Multiple c
chrishtr
2014/01/28 01:11:55
Made name more clear, it's really about adding a d
| |
317 { | |
318 if (DescendantInvalidationSet* invalidationSet = m_classInvalidationSets.get (className)) { | |
319 ensurePendingInvalidationVector(element)->append(invalidationSet); | |
320 element->markAncestorsWithChildNeedsStyleInvalidation(); | |
321 } | |
322 } | |
323 | |
324 RuleFeatureSet::InvalidationVec* RuleFeatureSet::ensurePendingInvalidationVector (Element* element) | |
esprehn
2014/01/28 00:11:34
Returns a ref.
chrishtr
2014/01/28 01:11:55
Done.
| |
325 { | |
326 PendingInvalidationMap::AddResult addResult = m_pendingInvalidationMap.add(e lement, 0); | |
327 if (addResult.isNewEntry) | |
328 addResult.iterator->value = new InvalidationVec; | |
329 return addResult.iterator->value; | |
esprehn
2014/01/28 00:11:34
*addResult->value
chrishtr
2014/01/28 01:11:55
Done.
| |
330 } | |
331 | |
332 void RuleFeatureSet::computeStyleInvalidation(Document* document) | |
333 { | |
334 Vector<AtomicString> invalidationClasses; | |
335 for (Node* child = document->firstChild(); child; child = child->nextSibling ()) { | |
336 if (child->isElementNode() && child->childNeedsStyleInvalidation()) { | |
337 Element* childElement = toElement(child); | |
338 computeStyleInvalidationInternal(childElement, invalidationClasses, false); | |
339 } | |
340 } | |
341 document->clearChildNeedsStyleInvalidation(); | |
342 m_pendingInvalidationMap.clear(); | |
343 } | |
344 | |
345 bool RuleFeatureSet::computeStyleInvalidationForChildren(Element* element, Vecto r<AtomicString>& invalidationClasses, bool foundInvalidationSet) | |
346 { | |
347 bool someChildrenNeedStyleRecalc = false; | |
348 for (Node* child = element->firstChild(); child; child = child->nextSibling( )) { | |
349 if (child->isElementNode()) { | |
350 Element* childElement = toElement(child); | |
351 bool childRecalced = computeStyleInvalidationInternal(childElement, invalidationClasses, foundInvalidationSet); | |
352 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe calced; | |
353 } | |
354 } | |
355 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root->ol derShadowRoot()) { | |
356 for (Node* child = root->firstChild(); child; child = child->nextSibling ()) { | |
357 if (child->isElementNode()) { | |
358 Element* childElement = toElement(child); | |
359 bool childRecalced = computeStyleInvalidationInternal(childEleme nt, invalidationClasses, foundInvalidationSet); | |
360 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || chi ldRecalced; | |
esprehn
2014/01/28 00:11:34
Remove this boolean stuff.
chrishtr
2014/01/28 01:11:55
See below.
| |
361 } | |
362 } | |
363 } | |
364 return someChildrenNeedStyleRecalc; | |
365 } | |
366 | |
367 bool RuleFeatureSet::computeStyleInvalidationInternal(Element* element, Vector<A tomicString>& invalidationClasses, bool foundInvalidationSet) | |
368 { | |
369 int oldSize = invalidationClasses.size(); | |
370 if (InvalidationVec* invalidationVec = m_pendingInvalidationMap.get(element) ) { | |
esprehn
2014/01/28 00:11:34
You want two bits, you're doing tons of hash map l
chrishtr
2014/01/28 01:11:55
Done.
| |
371 foundInvalidationSet = true; | |
372 bool recalcWholeSubtree = false; | |
373 for (InvalidationVec::const_iterator it = invalidationVec->begin(); it ! = invalidationVec->end(); ++it) { | |
374 if ((*it)->wholeSubtreeInvalid()) { | |
375 recalcWholeSubtree = true; | |
376 break; | |
377 } | |
378 (*it)->getClasses(invalidationClasses); | |
379 } | |
380 if (recalcWholeSubtree) { | |
381 element->setNeedsStyleRecalc(SubtreeStyleChange); | |
382 invalidationClasses.remove(oldSize, invalidationClasses.size() - old Size); | |
383 element->clearChildNeedsStyleInvalidation(); | |
384 return true; | |
385 } | |
386 } | |
387 bool thisElementNeedsStyleRecalc = false; | |
388 | |
389 if (element->hasClass()) { | |
390 const SpaceSplitString& classNames = element->classNames(); | |
391 for (Vector<AtomicString>::const_iterator it = invalidationClasses.begin (); it != invalidationClasses.end(); ++it) { | |
392 if (classNames.contains(*it)) { | |
393 thisElementNeedsStyleRecalc = true; | |
394 break; | |
395 } | |
396 } | |
397 } | |
398 | |
399 // foundInvalidationSet will be true if we are in a subtree of a node with a DescendantInvalidationSet on it. | |
400 // We need to check all nodes in the subtree of such a node. | |
401 if (foundInvalidationSet || element->childNeedsStyleInvalidation()) { | |
402 bool someChildrenNeedStyleRecalc = computeStyleInvalidationForChildren(e lement, invalidationClasses, foundInvalidationSet); | |
403 // We only need to possibly recalc style if this node is in the subtree of a node with a DescendantInvalidationSet on it. | |
404 if (foundInvalidationSet) | |
405 thisElementNeedsStyleRecalc = thisElementNeedsStyleRecalc || someChi ldrenNeedStyleRecalc; | |
esprehn
2014/01/28 00:11:34
Instead of returning this bool, just walk the ance
chrishtr
2014/01/28 01:11:55
See below.
| |
406 } | |
407 | |
408 if (thisElementNeedsStyleRecalc) | |
409 element->setNeedsStyleRecalc(LocalStyleChange); | |
esprehn
2014/01/28 00:11:34
This should just walk ancestors:
for (Element* an
chrishtr
2014/01/28 01:11:55
That'll do a bunch of of extra tree walking. Ineff
| |
410 | |
411 invalidationClasses.remove(oldSize, invalidationClasses.size() - oldSize); | |
412 element->clearChildNeedsStyleInvalidation(); | |
413 return thisElementNeedsStyleRecalc; | |
414 } | |
415 | |
243 } // namespace WebCore | 416 } // namespace WebCore |
OLD | NEW |