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

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: Add a test for watching dynamic attribute changes Created 7 years, 4 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/dom/ElementRareData.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 25 matching lines...) Expand all
36 #include "core/accessibility/AXObjectCache.h" 36 #include "core/accessibility/AXObjectCache.h"
37 #include "core/animation/DocumentTimeline.h" 37 #include "core/animation/DocumentTimeline.h"
38 #include "core/css/CSSParser.h" 38 #include "core/css/CSSParser.h"
39 #include "core/css/CSSStyleSheet.h" 39 #include "core/css/CSSStyleSheet.h"
40 #include "core/css/CSSValuePool.h" 40 #include "core/css/CSSValuePool.h"
41 #include "core/css/PropertySetCSSStyleDeclaration.h" 41 #include "core/css/PropertySetCSSStyleDeclaration.h"
42 #include "core/css/StylePropertySet.h" 42 #include "core/css/StylePropertySet.h"
43 #include "core/css/resolver/StyleResolver.h" 43 #include "core/css/resolver/StyleResolver.h"
44 #include "core/dom/Attr.h" 44 #include "core/dom/Attr.h"
45 #include "core/dom/Attribute.h" 45 #include "core/dom/Attribute.h"
46 #include "core/dom/CSSSelectorWatch.h"
46 #include "core/dom/ClientRect.h" 47 #include "core/dom/ClientRect.h"
47 #include "core/dom/ClientRectList.h" 48 #include "core/dom/ClientRectList.h"
48 #include "core/dom/CustomElement.h" 49 #include "core/dom/CustomElement.h"
49 #include "core/dom/CustomElementRegistrationContext.h" 50 #include "core/dom/CustomElementRegistrationContext.h"
50 #include "core/dom/DatasetDOMStringMap.h" 51 #include "core/dom/DatasetDOMStringMap.h"
51 #include "core/dom/Document.h" 52 #include "core/dom/Document.h"
52 #include "core/dom/DocumentSharedObjectPool.h" 53 #include "core/dom/DocumentSharedObjectPool.h"
53 #include "core/dom/ElementRareData.h" 54 #include "core/dom/ElementRareData.h"
54 #include "core/dom/EventDispatcher.h" 55 #include "core/dom/EventDispatcher.h"
55 #include "core/dom/ExceptionCode.h" 56 #include "core/dom/ExceptionCode.h"
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 } 1331 }
1331 1332
1332 void Element::attach(const AttachContext& context) 1333 void Element::attach(const AttachContext& context)
1333 { 1334 {
1334 PostAttachCallbackDisabler callbackDisabler(this); 1335 PostAttachCallbackDisabler callbackDisabler(this);
1335 StyleResolverParentPusher parentPusher(this); 1336 StyleResolverParentPusher parentPusher(this);
1336 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; 1337 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
1337 1338
1338 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed(); 1339 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed();
1339 1340
1341 updateCallbackSelectors(Add);
1342
1340 createPseudoElementIfNeeded(BEFORE); 1343 createPseudoElementIfNeeded(BEFORE);
1341 1344
1342 // When a shadow root exists, it does the work of attaching the children. 1345 // When a shadow root exists, it does the work of attaching the children.
1343 if (ElementShadow* shadow = this->shadow()) { 1346 if (ElementShadow* shadow = this->shadow()) {
1344 parentPusher.push(); 1347 parentPusher.push();
1345 shadow->attach(context); 1348 shadow->attach(context);
1346 } else if (firstChild()) 1349 } else if (firstChild())
1347 parentPusher.push(); 1350 parentPusher.push();
1348 1351
1349 ContainerNode::attach(context); 1352 ContainerNode::attach(context);
(...skipping 21 matching lines...) Expand all
1371 { 1374 {
1372 if (RuntimeEnabledFeatures::cssRegionsEnabled() && inNamedFlow() && document ()->renderView()) 1375 if (RuntimeEnabledFeatures::cssRegionsEnabled() && inNamedFlow() && document ()->renderView())
1373 document()->renderView()->flowThreadController()->unregisterNamedFlowCon tentNode(this); 1376 document()->renderView()->flowThreadController()->unregisterNamedFlowCon tentNode(this);
1374 } 1377 }
1375 1378
1376 void Element::detach(const AttachContext& context) 1379 void Element::detach(const AttachContext& context)
1377 { 1380 {
1378 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; 1381 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
1379 unregisterNamedFlowContentNode(); 1382 unregisterNamedFlowContentNode();
1380 cancelFocusAppearanceUpdate(); 1383 cancelFocusAppearanceUpdate();
1384 updateCallbackSelectors(Remove);
1381 if (hasRareData()) { 1385 if (hasRareData()) {
1382 ElementRareData* data = elementRareData(); 1386 ElementRareData* data = elementRareData();
1383 data->setPseudoElement(BEFORE, 0); 1387 data->setPseudoElement(BEFORE, 0);
1384 data->setPseudoElement(AFTER, 0); 1388 data->setPseudoElement(AFTER, 0);
1385 data->setPseudoElement(BACKDROP, 0); 1389 data->setPseudoElement(BACKDROP, 0);
1386 data->clearComputedStyle(); 1390 data->clearComputedStyle();
1387 data->resetDynamicRestyleObservations(); 1391 data->resetDynamicRestyleObservations();
1388 data->setIsInsideRegion(false); 1392 data->setIsInsideRegion(false);
1389 1393
1390 // Only clear the style state if we're not going to reuse the style from recalcStyle. 1394 // Only clear the style state if we're not going to reuse the style from recalcStyle.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 return document()->styleResolver()->styleForElement(this); 1458 return document()->styleResolver()->styleForElement(this);
1455 } 1459 }
1456 1460
1457 bool Element::recalcStyle(StyleChange change) 1461 bool Element::recalcStyle(StyleChange change)
1458 { 1462 {
1459 ASSERT(document()->inStyleRecalc()); 1463 ASSERT(document()->inStyleRecalc());
1460 1464
1461 if (hasCustomStyleCallbacks()) 1465 if (hasCustomStyleCallbacks())
1462 willRecalcStyle(change); 1466 willRecalcStyle(change);
1463 1467
1468 class SelectorWatchUpdater {
1469 public:
1470 SelectorWatchUpdater(Element* element)
1471 : m_element(element)
1472 {
1473 m_element->updateCallbackSelectors(Remove);
1474 }
1475
1476 ~SelectorWatchUpdater()
1477 {
1478 m_element->updateCallbackSelectors(Add);
1479 }
1480
1481 private:
1482 Element* const m_element;
1483 };
1484 SelectorWatchUpdater watchUpdater(this);
1485
1464 // Ref currentStyle in case it would otherwise be deleted when setting the n ew style in the renderer. 1486 // Ref currentStyle in case it would otherwise be deleted when setting the n ew style in the renderer.
1465 RefPtr<RenderStyle> currentStyle = renderStyle(); 1487 RefPtr<RenderStyle> currentStyle = renderStyle();
1466 bool hasParentStyle = static_cast<bool>(parentRenderStyle()); 1488 bool hasParentStyle = static_cast<bool>(parentRenderStyle());
1467 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); 1489 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
1468 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); 1490 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules();
1469 1491
1470 if (hasRareData() && (change > NoChange || needsStyleRecalc())) { 1492 if (hasRareData() && (change > NoChange || needsStyleRecalc())) {
1471 ElementRareData* data = elementRareData(); 1493 ElementRareData* data = elementRareData();
1472 data->resetStyleState(); 1494 data->resetStyleState();
1473 data->clearComputedStyle(); 1495 data->clearComputedStyle();
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 } 2461 }
2440 2462
2441 void Element::cancelFocusAppearanceUpdate() 2463 void Element::cancelFocusAppearanceUpdate()
2442 { 2464 {
2443 if (hasRareData()) 2465 if (hasRareData())
2444 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false); 2466 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
2445 if (document()->focusedElement() == this) 2467 if (document()->focusedElement() == this)
2446 document()->cancelFocusAppearanceUpdate(); 2468 document()->cancelFocusAppearanceUpdate();
2447 } 2469 }
2448 2470
2471 void Element::updateCallbackSelectors(AddOrRemove addOrRemove)
2472 {
2473 if (!renderStyle())
2474 return;
2475 const Vector<String>& callbackSelectors = renderStyle()->callbackSelectors() ;
2476 if (callbackSelectors.isEmpty())
2477 return;
2478
2479 CSSSelectorWatch* selectorWatch = CSSSelectorWatch::from(document());
2480 switch (addOrRemove) {
2481 case Add: {
2482 ElementRareData* rareData = ensureElementRareData();
2483 if (!rareData->renderStyleWatchedSelectorsRepresentedInSelectorWatch()) {
2484 selectorWatch->addSelectorMatches(callbackSelectors);
2485 rareData->setRenderStyleWatchedSelectorsRepresentedInSelectorWatch(t rue);
2486 }
2487 break;
2488 }
2489 case Remove:
2490 if (hasRareData() && elementRareData()->renderStyleWatchedSelectorsRepre sentedInSelectorWatch()) {
2491 selectorWatch->removeSelectorMatches(callbackSelectors);
2492 elementRareData()->setRenderStyleWatchedSelectorsRepresentedInSelect orWatch(false);
2493 }
2494 break;
2495 }
2496 }
2497
2449 void Element::normalizeAttributes() 2498 void Element::normalizeAttributes()
2450 { 2499 {
2451 if (!hasAttributes()) 2500 if (!hasAttributes())
2452 return; 2501 return;
2453 for (unsigned i = 0; i < attributeCount(); ++i) { 2502 for (unsigned i = 0; i < attributeCount(); ++i) {
2454 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) 2503 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
2455 attr->normalize(); 2504 attr->normalize();
2456 } 2505 }
2457 } 2506 }
2458 2507
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
3693 return 0; 3742 return 0;
3694 } 3743 }
3695 3744
3696 Attribute* UniqueElementData::attributeItem(unsigned index) 3745 Attribute* UniqueElementData::attributeItem(unsigned index)
3697 { 3746 {
3698 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 3747 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
3699 return &m_attributeVector.at(index); 3748 return &m_attributeVector.at(index);
3700 } 3749 }
3701 3750
3702 } // namespace WebCore 3751 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementRareData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698