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

Side by Side Diff: Source/core/css/RuleFeature.cpp

Issue 204873003: Factor the style invalidation tree walk out of RuleFeatureSet, and make it generic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added explicit. Created 6 years, 9 months 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 | « Source/core/css/RuleFeature.h ('k') | Source/core/css/invalidation/StyleInvalidator.h » ('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) 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
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/StyleInvalidator.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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 362 }
362 363
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 {
373 Vector<AtomicString> invalidationClasses;
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 }
382
383 void RuleFeatureSet::clearStyleInvalidation(Node* node) 372 void RuleFeatureSet::clearStyleInvalidation(Node* node)
384 { 373 {
385 node->clearChildNeedsStyleInvalidation(); 374 node->clearChildNeedsStyleInvalidation();
386 node->clearNeedsStyleInvalidation(); 375 node->clearNeedsStyleInvalidation();
387 if (node->isElementNode()) 376 if (node->isElementNode())
388 m_pendingInvalidationMap.remove(toElement(node)); 377 m_pendingInvalidationMap.remove(toElement(node));
389 } 378 }
390 379
391 bool RuleFeatureSet::invalidateStyleForClassChangeOnChildren(Element* element, V ector<AtomicString>& invalidationClasses, bool foundInvalidationSet) 380 RuleFeatureSet::PendingInvalidationMap& RuleFeatureSet::pendingInvalidationMap()
392 { 381 {
393 bool someChildrenNeedStyleRecalc = false; 382 return m_pendingInvalidationMap;
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 } 383 }
467 384
468 } // namespace WebCore 385 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/RuleFeature.h ('k') | Source/core/css/invalidation/StyleInvalidator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698