| 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/css/invalidation/StyleInvalidationTreeWalk.h" |
| 37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 38 #include "core/dom/Element.h" | 39 #include "core/dom/Element.h" |
| 39 #include "core/dom/ElementTraversal.h" | 40 #include "core/dom/ElementTraversal.h" |
| 40 #include "core/dom/Node.h" | 41 #include "core/dom/Node.h" |
| 41 #include "core/dom/NodeRenderStyle.h" | 42 #include "core/dom/NodeRenderStyle.h" |
| 42 #include "core/dom/shadow/ElementShadow.h" | 43 #include "core/dom/shadow/ElementShadow.h" |
| 43 #include "core/dom/shadow/ShadowRoot.h" | 44 #include "core/dom/shadow/ShadowRoot.h" |
| 44 #include "core/rendering/RenderObject.h" | 45 #include "core/rendering/RenderObject.h" |
| 45 #include "wtf/BitVector.h" | 46 #include "wtf/BitVector.h" |
| 46 | 47 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 RuleFeatureSet::InvalidationList& RuleFeatureSet::ensurePendingInvalidationList(
Element* element) | 364 RuleFeatureSet::InvalidationList& RuleFeatureSet::ensurePendingInvalidationList(
Element* element) |
| 364 { | 365 { |
| 365 PendingInvalidationMap::AddResult addResult = m_pendingInvalidationMap.add(e
lement, nullptr); | 366 PendingInvalidationMap::AddResult addResult = m_pendingInvalidationMap.add(e
lement, nullptr); |
| 366 if (addResult.isNewEntry) | 367 if (addResult.isNewEntry) |
| 367 addResult.storedValue->value = adoptPtr(new InvalidationList); | 368 addResult.storedValue->value = adoptPtr(new InvalidationList); |
| 368 return *addResult.storedValue->value; | 369 return *addResult.storedValue->value; |
| 369 } | 370 } |
| 370 | 371 |
| 371 void RuleFeatureSet::computeStyleInvalidation(Document& document) | 372 void RuleFeatureSet::computeStyleInvalidation(Document& document) |
| 372 { | 373 { |
| 373 Vector<AtomicString> invalidationClasses; | 374 StyleInvalidationTreeWalk::computeStyleInvalidation(document, this); |
| 374 if (Element* documentElement = document.documentElement()) { | |
| 375 if (documentElement->childNeedsStyleInvalidation()) | |
| 376 invalidateStyleForClassChange(documentElement, invalidationClasses,
false); | |
| 377 } | |
| 378 document.clearChildNeedsStyleInvalidation(); | |
| 379 document.clearNeedsStyleInvalidation(); | |
| 380 m_pendingInvalidationMap.clear(); | |
| 381 } | 375 } |
| 382 | 376 |
| 383 void RuleFeatureSet::clearStyleInvalidation(Node* node) | 377 void RuleFeatureSet::clearStyleInvalidation(Node* node) |
| 384 { | 378 { |
| 385 node->clearChildNeedsStyleInvalidation(); | 379 node->clearChildNeedsStyleInvalidation(); |
| 386 node->clearNeedsStyleInvalidation(); | 380 node->clearNeedsStyleInvalidation(); |
| 387 if (node->isElementNode()) | 381 if (node->isElementNode()) |
| 388 m_pendingInvalidationMap.remove(toElement(node)); | 382 m_pendingInvalidationMap.remove(toElement(node)); |
| 389 } | 383 } |
| 390 | 384 |
| 391 bool RuleFeatureSet::invalidateStyleForClassChangeOnChildren(Element* element, V
ector<AtomicString>& invalidationClasses, bool foundInvalidationSet) | |
| 392 { | |
| 393 bool someChildrenNeedStyleRecalc = false; | |
| 394 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root->ol
derShadowRoot()) { | |
| 395 for (Element* child = ElementTraversal::firstWithin(*root); child; child
= ElementTraversal::nextSibling(*child)) { | |
| 396 bool childRecalced = invalidateStyleForClassChange(child, invalidati
onClasses, foundInvalidationSet); | |
| 397 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRe
calced; | |
| 398 } | |
| 399 root->clearChildNeedsStyleInvalidation(); | |
| 400 root->clearNeedsStyleInvalidation(); | |
| 401 } | |
| 402 for (Element* child = ElementTraversal::firstWithin(*element); child; child
= ElementTraversal::nextSibling(*child)) { | |
| 403 bool childRecalced = invalidateStyleForClassChange(child, invalidationCl
asses, foundInvalidationSet); | |
| 404 someChildrenNeedStyleRecalc = someChildrenNeedStyleRecalc || childRecalc
ed; | |
| 405 } | |
| 406 return someChildrenNeedStyleRecalc; | |
| 407 } | |
| 408 | |
| 409 bool RuleFeatureSet::invalidateStyleForClassChange(Element* element, Vector<Atom
icString>& invalidationClasses, bool foundInvalidationSet) | |
| 410 { | |
| 411 bool thisElementNeedsStyleRecalc = false; | |
| 412 int oldSize = invalidationClasses.size(); | |
| 413 if (element->needsStyleInvalidation()) { | |
| 414 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(el
ement)) { | |
| 415 // FIXME: it's really only necessary to clone the render style for t
his element, not full style recalc. | |
| 416 thisElementNeedsStyleRecalc = true; | |
| 417 foundInvalidationSet = true; | |
| 418 for (InvalidationList::const_iterator it = invalidationList->begin()
; it != invalidationList->end(); ++it) { | |
| 419 if ((*it)->wholeSubtreeInvalid()) { | |
| 420 element->setNeedsStyleRecalc(SubtreeStyleChange); | |
| 421 // Even though we have set needsStyleRecalc on the whole sub
tree, we need to keep walking over the subtree | |
| 422 // in order to clear the invalidation dirty bits on all elem
ents. | |
| 423 // FIXME: we can optimize this by having a dedicated functio
n that just traverses the tree and removes the dirty bits, | |
| 424 // without checking classes etc. | |
| 425 break; | |
| 426 } | |
| 427 (*it)->getClasses(invalidationClasses); | |
| 428 } | |
| 429 } | |
| 430 } | |
| 431 | |
| 432 if (element->hasClass()) { | |
| 433 const SpaceSplitString& classNames = element->classNames(); | |
| 434 for (Vector<AtomicString>::const_iterator it = invalidationClasses.begin
(); it != invalidationClasses.end(); ++it) { | |
| 435 if (classNames.contains(*it)) { | |
| 436 thisElementNeedsStyleRecalc = true; | |
| 437 break; | |
| 438 } | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 bool someChildrenNeedStyleRecalc = false; | |
| 443 // foundInvalidationSet will be true if we are in a subtree of a node with a
DescendantInvalidationSet on it. | |
| 444 // We need to check all nodes in the subtree of such a node. | |
| 445 if (foundInvalidationSet || element->childNeedsStyleInvalidation()) { | |
| 446 someChildrenNeedStyleRecalc = invalidateStyleForClassChangeOnChildren(el
ement, invalidationClasses, foundInvalidationSet); | |
| 447 } | |
| 448 | |
| 449 if (thisElementNeedsStyleRecalc) { | |
| 450 element->setNeedsStyleRecalc(LocalStyleChange); | |
| 451 } else if (foundInvalidationSet && someChildrenNeedStyleRecalc) { | |
| 452 // Clone the RenderStyle in order to preserve correct style sharing, if
possible. Otherwise recalc style. | |
| 453 if (RenderObject* renderer = element->renderer()) { | |
| 454 ASSERT(renderer->style()); | |
| 455 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); | |
| 456 } else { | |
| 457 element->setNeedsStyleRecalc(LocalStyleChange); | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 invalidationClasses.remove(oldSize, invalidationClasses.size() - oldSize); | |
| 462 element->clearChildNeedsStyleInvalidation(); | |
| 463 element->clearNeedsStyleInvalidation(); | |
| 464 | |
| 465 return thisElementNeedsStyleRecalc; | |
| 466 } | |
| 467 | |
| 468 } // namespace WebCore | 385 } // namespace WebCore |
| OLD | NEW |