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

Side by Side Diff: third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp

Issue 2166213002: Fire attributeChangedCallback on style changes for Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dominicc review Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 16 matching lines...) Expand all
27 #include "core/css/CSSCustomPropertyDeclaration.h" 27 #include "core/css/CSSCustomPropertyDeclaration.h"
28 #include "core/css/CSSKeyframesRule.h" 28 #include "core/css/CSSKeyframesRule.h"
29 #include "core/css/CSSStyleSheet.h" 29 #include "core/css/CSSStyleSheet.h"
30 #include "core/css/StylePropertySet.h" 30 #include "core/css/StylePropertySet.h"
31 #include "core/css/parser/CSSVariableParser.h" 31 #include "core/css/parser/CSSVariableParser.h"
32 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
33 #include "core/dom/MutationObserverInterestGroup.h" 33 #include "core/dom/MutationObserverInterestGroup.h"
34 #include "core/dom/MutationRecord.h" 34 #include "core/dom/MutationRecord.h"
35 #include "core/dom/StyleChangeReason.h" 35 #include "core/dom/StyleChangeReason.h"
36 #include "core/dom/StyleEngine.h" 36 #include "core/dom/StyleEngine.h"
37 #include "core/dom/custom/CustomElement.h"
38 #include "core/dom/custom/CustomElementDefinition.h"
37 #include "core/inspector/InspectorInstrumentation.h" 39 #include "core/inspector/InspectorInstrumentation.h"
38 #include "platform/RuntimeEnabledFeatures.h" 40 #include "platform/RuntimeEnabledFeatures.h"
39 41
40 namespace blink { 42 namespace blink {
41 43
42 namespace { 44 namespace {
43 45
46 static CustomElementDefinition* definitionIfStyleChangedCallback(Element* elemen t)
47 {
48 CustomElementDefinition* definition = CustomElement::definitionForElement(el ement);
49 return definition && definition->hasStyleAttributeChangedCallback()
50 ? definition : nullptr;
51 }
52
44 class StyleAttributeMutationScope { 53 class StyleAttributeMutationScope {
45 WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope); 54 WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
46 STACK_ALLOCATED(); 55 STACK_ALLOCATED();
47 public: 56 public:
48 StyleAttributeMutationScope(AbstractPropertySetCSSStyleDeclaration* decl) 57 StyleAttributeMutationScope(AbstractPropertySetCSSStyleDeclaration* decl)
49 { 58 {
50 ++s_scopeCount; 59 ++s_scopeCount;
51 60
52 if (s_scopeCount != 1) { 61 if (s_scopeCount != 1) {
53 ASSERT(s_currentDecl == decl); 62 ASSERT(s_currentDecl == decl);
54 return; 63 return;
55 } 64 }
56 65
57 ASSERT(!s_currentDecl); 66 ASSERT(!s_currentDecl);
58 s_currentDecl = decl; 67 s_currentDecl = decl;
59 68
60 if (!s_currentDecl->parentElement()) 69 if (!s_currentDecl->parentElement())
61 return; 70 return;
62 71
63 bool shouldReadOldValue = false; 72 m_mutationRecipients = MutationObserverInterestGroup::createForAttribute sMutation(*s_currentDecl->parentElement(), HTMLNames::styleAttr);
73 bool shouldReadOldValue =
74 (m_mutationRecipients && m_mutationRecipients->isOldValueRequested() )
75 || definitionIfStyleChangedCallback(s_currentDecl->parentElement());
64 76
65 m_mutationRecipients = MutationObserverInterestGroup::createForAttribute sMutation(*s_currentDecl->parentElement(), HTMLNames::styleAttr);
66 if (m_mutationRecipients && m_mutationRecipients->isOldValueRequested())
67 shouldReadOldValue = true;
68
69 AtomicString oldValue;
70 if (shouldReadOldValue) 77 if (shouldReadOldValue)
71 oldValue = s_currentDecl->parentElement()->getAttribute(HTMLNames::s tyleAttr); 78 m_oldValue = s_currentDecl->parentElement()->getAttribute(HTMLNames: :styleAttr);
72 79
73 if (m_mutationRecipients) { 80 if (m_mutationRecipients) {
74 AtomicString requestedOldValue = m_mutationRecipients->isOldValueReq uested() ? oldValue : nullAtom; 81 AtomicString requestedOldValue = m_mutationRecipients->isOldValueReq uested() ? m_oldValue : nullAtom;
75 m_mutation = MutationRecord::createAttributes(s_currentDecl->parentE lement(), HTMLNames::styleAttr, requestedOldValue); 82 m_mutation = MutationRecord::createAttributes(s_currentDecl->parentE lement(), HTMLNames::styleAttr, requestedOldValue);
76 } 83 }
77 } 84 }
78 85
79 ~StyleAttributeMutationScope() 86 ~StyleAttributeMutationScope()
80 { 87 {
81 --s_scopeCount; 88 --s_scopeCount;
82 if (s_scopeCount) 89 if (s_scopeCount)
83 return; 90 return;
84 91
85 if (m_mutation && s_shouldDeliver) 92 if (s_shouldDeliver) {
86 m_mutationRecipients->enqueueMutationRecord(m_mutation); 93 if (m_mutation)
94 m_mutationRecipients->enqueueMutationRecord(m_mutation);
87 95
88 s_shouldDeliver = false; 96 Element* element = s_currentDecl->parentElement();
97 if (CustomElementDefinition* definition = definitionIfStyleChangedCa llback(element)) {
98 definition->enqueueAttributeChangedCallback(element,
99 HTMLNames::styleAttr, m_oldValue,
100 element->getAttribute(HTMLNames::styleAttr));
101 }
102
103 s_shouldDeliver = false;
104 }
89 105
90 // We have to clear internal state before calling Inspector's code. 106 // We have to clear internal state before calling Inspector's code.
91 AbstractPropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDe cl; 107 AbstractPropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDe cl;
92 s_currentDecl = 0; 108 s_currentDecl = 0;
93 109
94 if (!s_shouldNotifyInspector) 110 if (!s_shouldNotifyInspector)
95 return; 111 return;
96 112
97 s_shouldNotifyInspector = false; 113 s_shouldNotifyInspector = false;
98 if (localCopyStyleDecl->parentElement()) 114 if (localCopyStyleDecl->parentElement())
(...skipping 11 matching lines...) Expand all
110 } 126 }
111 127
112 private: 128 private:
113 static unsigned s_scopeCount; 129 static unsigned s_scopeCount;
114 static AbstractPropertySetCSSStyleDeclaration* s_currentDecl; 130 static AbstractPropertySetCSSStyleDeclaration* s_currentDecl;
115 static bool s_shouldNotifyInspector; 131 static bool s_shouldNotifyInspector;
116 static bool s_shouldDeliver; 132 static bool s_shouldDeliver;
117 133
118 Member<MutationObserverInterestGroup> m_mutationRecipients; 134 Member<MutationObserverInterestGroup> m_mutationRecipients;
119 Member<MutationRecord> m_mutation; 135 Member<MutationRecord> m_mutation;
136 AtomicString m_oldValue;
120 }; 137 };
121 138
122 unsigned StyleAttributeMutationScope::s_scopeCount = 0; 139 unsigned StyleAttributeMutationScope::s_scopeCount = 0;
123 AbstractPropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDe cl = 0; 140 AbstractPropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDe cl = 0;
124 bool StyleAttributeMutationScope::s_shouldNotifyInspector = false; 141 bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
125 bool StyleAttributeMutationScope::s_shouldDeliver = false; 142 bool StyleAttributeMutationScope::s_shouldDeliver = false;
126 143
127 } // namespace 144 } // namespace
128 145
129 DEFINE_TRACE(PropertySetCSSStyleDeclaration) 146 DEFINE_TRACE(PropertySetCSSStyleDeclaration)
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return m_parentElement ? &m_parentElement->document().elementSheet() : nullp tr; 391 return m_parentElement ? &m_parentElement->document().elementSheet() : nullp tr;
375 } 392 }
376 393
377 DEFINE_TRACE(InlineCSSStyleDeclaration) 394 DEFINE_TRACE(InlineCSSStyleDeclaration)
378 { 395 {
379 visitor->trace(m_parentElement); 396 visitor->trace(m_parentElement);
380 AbstractPropertySetCSSStyleDeclaration::trace(visitor); 397 AbstractPropertySetCSSStyleDeclaration::trace(visitor);
381 } 398 }
382 399
383 } // namespace blink 400 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSStyleDeclaration.idl ('k') | third_party/WebKit/Source/core/dom/custom/CustomElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698