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

Side by Side Diff: Source/core/dom/Element.cpp

Issue 18371008: Add a WebDocument::watchCssSelectors(selectors) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pinned
Patch Set: Sync Created 7 years, 2 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/dom/Element.h ('k') | Source/core/loader/EmptyClients.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) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 26 matching lines...) Expand all
37 #include "core/animation/DocumentTimeline.h" 37 #include "core/animation/DocumentTimeline.h"
38 #include "core/animation/css/CSSAnimations.h" 38 #include "core/animation/css/CSSAnimations.h"
39 #include "core/css/CSSParser.h" 39 #include "core/css/CSSParser.h"
40 #include "core/css/CSSStyleSheet.h" 40 #include "core/css/CSSStyleSheet.h"
41 #include "core/css/CSSValuePool.h" 41 #include "core/css/CSSValuePool.h"
42 #include "core/css/PropertySetCSSStyleDeclaration.h" 42 #include "core/css/PropertySetCSSStyleDeclaration.h"
43 #include "core/css/StylePropertySet.h" 43 #include "core/css/StylePropertySet.h"
44 #include "core/css/resolver/StyleResolver.h" 44 #include "core/css/resolver/StyleResolver.h"
45 #include "core/dom/Attr.h" 45 #include "core/dom/Attr.h"
46 #include "core/dom/Attribute.h" 46 #include "core/dom/Attribute.h"
47 #include "core/dom/CSSSelectorWatch.h"
47 #include "core/dom/ClientRect.h" 48 #include "core/dom/ClientRect.h"
48 #include "core/dom/ClientRectList.h" 49 #include "core/dom/ClientRectList.h"
49 #include "core/dom/CustomElement.h" 50 #include "core/dom/CustomElement.h"
50 #include "core/dom/CustomElementRegistrationContext.h" 51 #include "core/dom/CustomElementRegistrationContext.h"
51 #include "core/dom/DatasetDOMStringMap.h" 52 #include "core/dom/DatasetDOMStringMap.h"
52 #include "core/dom/Document.h" 53 #include "core/dom/Document.h"
53 #include "core/dom/DocumentSharedObjectPool.h" 54 #include "core/dom/DocumentSharedObjectPool.h"
54 #include "core/dom/ElementRareData.h" 55 #include "core/dom/ElementRareData.h"
55 #include "core/events/EventDispatcher.h" 56 #include "core/events/EventDispatcher.h"
56 #include "core/dom/ExceptionCode.h" 57 #include "core/dom/ExceptionCode.h"
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 if (hasRareData() && styleChangeType() == LazyAttachStyleChange) { 1323 if (hasRareData() && styleChangeType() == LazyAttachStyleChange) {
1323 ElementRareData* data = elementRareData(); 1324 ElementRareData* data = elementRareData();
1324 data->clearComputedStyle(); 1325 data->clearComputedStyle();
1325 data->resetDynamicRestyleObservations(); 1326 data->resetDynamicRestyleObservations();
1326 if (!context.resolvedStyle) 1327 if (!context.resolvedStyle)
1327 data->resetStyleState(); 1328 data->resetStyleState();
1328 } 1329 }
1329 1330
1330 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed(); 1331 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed();
1331 1332
1333 if (RenderStyle* style = renderStyle())
1334 updateCallbackSelectors(0, style);
1335
1332 createPseudoElementIfNeeded(BEFORE); 1336 createPseudoElementIfNeeded(BEFORE);
1333 1337
1334 // When a shadow root exists, it does the work of attaching the children. 1338 // When a shadow root exists, it does the work of attaching the children.
1335 if (ElementShadow* shadow = this->shadow()) { 1339 if (ElementShadow* shadow = this->shadow()) {
1336 parentPusher.push(); 1340 parentPusher.push();
1337 shadow->attach(context); 1341 shadow->attach(context);
1338 } else if (firstChild()) 1342 } else if (firstChild())
1339 parentPusher.push(); 1343 parentPusher.push();
1340 1344
1341 ContainerNode::attach(context); 1345 ContainerNode::attach(context);
(...skipping 17 matching lines...) Expand all
1359 { 1363 {
1360 if (RuntimeEnabledFeatures::cssRegionsEnabled() && inNamedFlow() && document ().renderView()) 1364 if (RuntimeEnabledFeatures::cssRegionsEnabled() && inNamedFlow() && document ().renderView())
1361 document().renderView()->flowThreadController()->unregisterNamedFlowCont entNode(this); 1365 document().renderView()->flowThreadController()->unregisterNamedFlowCont entNode(this);
1362 } 1366 }
1363 1367
1364 void Element::detach(const AttachContext& context) 1368 void Element::detach(const AttachContext& context)
1365 { 1369 {
1366 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; 1370 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
1367 unregisterNamedFlowContentNode(); 1371 unregisterNamedFlowContentNode();
1368 cancelFocusAppearanceUpdate(); 1372 cancelFocusAppearanceUpdate();
1373 if (RenderStyle* style = renderStyle()) {
1374 if (!style->callbackSelectors().isEmpty())
1375 updateCallbackSelectors(style, 0);
1376 }
1369 if (hasRareData()) { 1377 if (hasRareData()) {
1370 ElementRareData* data = elementRareData(); 1378 ElementRareData* data = elementRareData();
1371 data->setPseudoElement(BEFORE, 0); 1379 data->setPseudoElement(BEFORE, 0);
1372 data->setPseudoElement(AFTER, 0); 1380 data->setPseudoElement(AFTER, 0);
1373 data->setPseudoElement(BACKDROP, 0); 1381 data->setPseudoElement(BACKDROP, 0);
1374 data->clearComputedStyle(); 1382 data->clearComputedStyle();
1375 data->resetDynamicRestyleObservations(); 1383 data->resetDynamicRestyleObservations();
1376 data->setIsInsideRegion(false); 1384 data->setIsInsideRegion(false);
1377 1385
1378 // Only clear the style state if we're not going to reuse the style from recalcStyle. 1386 // Only clear the style state if we're not going to reuse the style from recalcStyle.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 1473
1466 clearNeedsStyleRecalc(); 1474 clearNeedsStyleRecalc();
1467 clearChildNeedsStyleRecalc(); 1475 clearChildNeedsStyleRecalc();
1468 1476
1469 if (hasCustomStyleCallbacks()) 1477 if (hasCustomStyleCallbacks())
1470 didRecalcStyle(change); 1478 didRecalcStyle(change);
1471 1479
1472 return change == Reattach; 1480 return change == Reattach;
1473 } 1481 }
1474 1482
1483 static bool callbackSelectorsDiffer(RenderStyle* style1, RenderStyle* style2)
1484 {
1485 const Vector<String> emptyVector;
1486 const Vector<String>& callbackSelectors1 = style1 ? style1->callbackSelector s() : emptyVector;
1487 const Vector<String>& callbackSelectors2 = style2 ? style2->callbackSelector s() : emptyVector;
1488 if (callbackSelectors1.isEmpty() && callbackSelectors2.isEmpty()) {
1489 // Help the inliner with this common case.
1490 return false;
1491 }
1492 return callbackSelectors1 != callbackSelectors2;
1493 }
1494
1475 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) 1495 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change)
1476 { 1496 {
1477 ASSERT(document().inStyleRecalc()); 1497 ASSERT(document().inStyleRecalc());
1478 1498
1479 CSSAnimationUpdateScope cssAnimationUpdateScope(this); 1499 CSSAnimationUpdateScope cssAnimationUpdateScope(this);
1480 RefPtr<RenderStyle> oldStyle = renderStyle(); 1500 RefPtr<RenderStyle> oldStyle = renderStyle();
1481 RefPtr<RenderStyle> newStyle = styleForRenderer(); 1501 RefPtr<RenderStyle> newStyle = styleForRenderer();
1482 StyleRecalcChange localChange = RenderStyle::compare(oldStyle.get(), newStyl e.get()); 1502 StyleRecalcChange localChange = RenderStyle::compare(oldStyle.get(), newStyl e.get());
1483 1503
1484 if (localChange == Reattach) { 1504 if (localChange == Reattach) {
1485 AttachContext reattachContext; 1505 AttachContext reattachContext;
1486 reattachContext.resolvedStyle = newStyle.get(); 1506 reattachContext.resolvedStyle = newStyle.get();
1487 reattach(reattachContext); 1507 reattach(reattachContext);
1488 return Reattach; 1508 return Reattach;
1489 } 1509 }
1490 1510
1491 InspectorInstrumentation::didRecalculateStyleForElement(this); 1511 InspectorInstrumentation::didRecalculateStyleForElement(this);
1492 1512
1513 if (localChange != NoChange && callbackSelectorsDiffer(oldStyle.get(), newSt yle.get()))
1514 updateCallbackSelectors(oldStyle.get(), newStyle.get());
1515
1493 if (RenderObject* renderer = this->renderer()) { 1516 if (RenderObject* renderer = this->renderer()) {
1494 if (localChange != NoChange || pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get()) || (change == Force && renderer->requiresForcedStyleRecalcPropa gation()) || shouldNotifyRendererWithIdenticalStyles()) { 1517 if (localChange != NoChange || pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get()) || (change == Force && renderer->requiresForcedStyleRecalcPropa gation()) || shouldNotifyRendererWithIdenticalStyles()) {
1495 renderer->setAnimatableStyle(newStyle.get()); 1518 renderer->setAnimatableStyle(newStyle.get());
1496 } else if (needsStyleRecalc()) { 1519 } else if (needsStyleRecalc()) {
1497 // Although no change occurred, we use the new style so that the cou sin style sharing code won't get 1520 // Although no change occurred, we use the new style so that the cou sin style sharing code won't get
1498 // fooled into believing this style is the same. 1521 // fooled into believing this style is the same.
1499 renderer->setStyleInternal(newStyle.get()); 1522 renderer->setStyleInternal(newStyle.get());
1500 } 1523 }
1501 } 1524 }
1502 1525
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 } 2450 }
2428 2451
2429 void Element::cancelFocusAppearanceUpdate() 2452 void Element::cancelFocusAppearanceUpdate()
2430 { 2453 {
2431 if (hasRareData()) 2454 if (hasRareData())
2432 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false); 2455 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
2433 if (document().focusedElement() == this) 2456 if (document().focusedElement() == this)
2434 document().cancelFocusAppearanceUpdate(); 2457 document().cancelFocusAppearanceUpdate();
2435 } 2458 }
2436 2459
2460 void Element::updateCallbackSelectors(RenderStyle* oldStyle, RenderStyle* newSty le)
2461 {
2462 const Vector<String> emptyVector;
2463 const Vector<String>& oldCallbackSelectors = oldStyle ? oldStyle->callbackSe lectors() : emptyVector;
2464 const Vector<String>& newCallbackSelectors = newStyle ? newStyle->callbackSe lectors() : emptyVector;
2465
2466 CSSSelectorWatch::from(document()).updateSelectorMatches(oldCallbackSelector s, newCallbackSelectors);
2467 }
2468
2437 void Element::normalizeAttributes() 2469 void Element::normalizeAttributes()
2438 { 2470 {
2439 if (!hasAttributes()) 2471 if (!hasAttributes())
2440 return; 2472 return;
2441 for (unsigned i = 0; i < attributeCount(); ++i) { 2473 for (unsigned i = 0; i < attributeCount(); ++i) {
2442 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) 2474 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
2443 attr->normalize(); 2475 attr->normalize();
2444 } 2476 }
2445 } 2477 }
2446 2478
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3642 return 0; 3674 return 0;
3643 } 3675 }
3644 3676
3645 Attribute* UniqueElementData::attributeItem(unsigned index) 3677 Attribute* UniqueElementData::attributeItem(unsigned index)
3646 { 3678 {
3647 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 3679 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
3648 return &m_attributeVector.at(index); 3680 return &m_attributeVector.at(index);
3649 } 3681 }
3650 3682
3651 } // namespace WebCore 3683 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/loader/EmptyClients.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698