Source/WebCore/ChangeLog

 12011-06-07 Roland Steiner <rolandsteiner@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Bug 49142 - Implement HTML5 style scoped attribute
 6 https://bugs.webkit.org/show_bug.cgi?id=49142
 7
 8 Add a new map to RuleSet that contains rules from <style scoped> elements.
 9 Add plumbing to register and unregister <style scoped> elements from their parents.
 10 Extend rule matching for scoped style rules.
 11
 12 No new tests. (OOPS!)
 13
 14 * WebCore.xcodeproj/project.pbxproj:
 15 * css/CSSStyleSelector.cpp:
 16 (WebCore::RuleSet::getIDRules):
 17 (WebCore::RuleSet::getClassRules):
 18 (WebCore::RuleSet::getTagRules):
 19 (WebCore::RuleSet::getPseudoRules):
 20 (WebCore::RuleSet::getUniversalRules):
 21 (WebCore::RuleSet::getPageRules):
 22 (WebCore::RuleSet::scopedRules):
 23 (WebCore::CSSStyleSelector::pushParentStackFrame):
 24 (WebCore::CSSStyleSelector::matchRules):
 25 (WebCore::CSSStyleSelector::fastStyleSheetScopeIsAnAncestor):
 26 (WebCore::CSSStyleSelector::slowStyleSheetScopeIsAnAncestor):
 27 (WebCore::matchesInTreeScope):
 28 (WebCore::CSSStyleSelector::matchRulesForList):
 29 (WebCore::RuleData::RuleData):
 30 (WebCore::RuleSet::addToRuleSet):
 31 (WebCore::RuleSet::addRule):
 32 (WebCore::RuleSet::determineRulesScope):
 33 (WebCore::RuleSet::addRulesFromSheet):
 34 (WebCore::RuleSet::addStyleRule):
 35 (WebCore::collectFeaturesFromList):
 36 (WebCore::RuleSet::collectFeatures):
 37 (WebCore::CSSStyleSelector::matchPageRulesForList):
 38 * css/CSSStyleSelector.h:
 39 (WebCore::CSSStyleSelector::ParentStackFrame::ParentStackFrame):
 40 * css/CSSStyleSheet.cpp:
 41 (WebCore::CSSStyleSheet::findOwnerNode):
 42 (WebCore::CSSStyleSheet::document):
 43 * css/CSSStyleSheet.h:
 44 * dom/ContainerNode.h:
 45 (WebCore::ContainerNode::registerScopedHTMLStyleChild):
 46 (WebCore::ContainerNode::unregisterScopedHTMLStyleChild):
 47 (WebCore::ContainerNode::hasScopedHTMLStyleChild):
 48 * dom/Element.cpp:
 49 (WebCore::Element::registerScopedHTMLStyleChild):
 50 (WebCore::Element::unregisterScopedHTMLStyleChild):
 51 (WebCore::Element::hasScopedHTMLStyleChild):
 52 * dom/Element.h:
 53 * dom/ElementRareData.h:
 54 (WebCore::ElementRareData::ElementRareData):
 55 (WebCore::ElementRareData::registerScopedHTMLStyleChild):
 56 (WebCore::ElementRareData::unregisterScopedHTMLStyleChild):
 57 (WebCore::ElementRareData::hasScopedHTMLStyleChild):
 58 * dom/ShadowRoot.h:
 59 (WebCore::ShadowRoot::registerScopedHTMLStyleChild):
 60 (WebCore::ShadowRoot::unregisterScopedHTMLStyleChild):
 61 (WebCore::ShadowRoot::hasScopedHTMLStyleChild):
 62 * html/HTMLAttributeNames.in:
 63 * html/HTMLStyleElement.cpp:
 64 (WebCore::HTMLStyleElement::insertedIntoDocument):
 65 (WebCore::HTMLStyleElement::willRemove):
 66 (WebCore::HTMLStyleElement::scoped):
 67 * html/HTMLStyleElement.h:
 68
1692011-06-07 MORITA Hajime <morrita@google.com>
270
371 Unreviewed, rolling out r88212 and r88219.

Source/WebCore/css/CSSStyleSelector.cpp

6363#include "HTMLDocument.h"
6464#include "HTMLElement.h"
6565#include "HTMLFrameElementBase.h"
 66#include "HTMLHeadElement.h"
6667#include "HTMLInputElement.h"
6768#include "HTMLNames.h"
 69#include "HTMLStyleElement.h"
6870#include "HTMLTextAreaElement.h"
6971#include "KeyframeList.h"
7072#include "LinkHash.h"

@@if (id == propID) { \
286288 return; \
287289}
288290
 291typedef CSSStyleSelector::StyleSheetScope StyleSheetScope;
 292
289293class RuleData {
290294public:
291  RuleData(CSSStyleRule*, CSSSelector*, unsigned position);
 295 RuleData(CSSStyleRule*, CSSSelector*, unsigned position, StyleSheetScope);
292296
293297 unsigned position() const { return m_position; }
294298 CSSStyleRule* rule() const { return m_rule; }

@@private:
318322 unsigned m_descendantSelectorIdentifierHashes[maximumIdentifierCount];
319323};
320324
 325typedef Vector<RuleData> RulesVector;
 326
321327class RuleSet {
322328 WTF_MAKE_NONCOPYABLE(RuleSet);
323329public:
324330 RuleSet();
325331 ~RuleSet();
326 
327  typedef HashMap<AtomicStringImpl*, Vector<RuleData>*> AtomRuleMap;
328 
329  void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0);
330332
331  void addStyleRule(CSSStyleRule* item);
332  void addRule(CSSStyleRule* rule, CSSSelector* sel);
333  void addPageRule(CSSStyleRule* rule, CSSSelector* sel);
 333 typedef HashMap<AtomicStringImpl*, RulesVector*> AtomRuleMap;
 334 typedef HashMap<StyleSheetScope, RulesVector*> ScopedRuleMap;
 335
 336 StyleSheetScope determineRulesScope(CSSStyleSheet*) const;
 337
 338 void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0, StyleSheetScope = 0);
 339
 340 void addStyleRule(CSSStyleRule*, StyleSheetScope);
 341 void addRule(CSSStyleRule*, CSSSelector*, StyleSheetScope);
 342 void addPageRule(CSSStyleRule*, CSSSelector*);
334343 void addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
335344 CSSStyleRule* rule, CSSSelector* sel);
336345 void shrinkToFit();

@@public:
338347
339348 void collectFeatures(CSSStyleSelector::Features&) const;
340349
341  const Vector<RuleData>* getIDRules(AtomicStringImpl* key) const { return m_idRules.get(key); }
342  const Vector<RuleData>* getClassRules(AtomicStringImpl* key) const { return m_classRules.get(key); }
343  const Vector<RuleData>* getTagRules(AtomicStringImpl* key) const { return m_tagRules.get(key); }
344  const Vector<RuleData>* getPseudoRules(AtomicStringImpl* key) const { return m_pseudoRules.get(key); }
345  const Vector<RuleData>* getUniversalRules() const { return &m_universalRules; }
346  const Vector<RuleData>* getPageRules() const { return &m_pageRules; }
 350 const RulesVector* getIDRules(AtomicStringImpl* key) const { return m_idRules.get(key); }
 351 const RulesVector* getClassRules(AtomicStringImpl* key) const { return m_classRules.get(key); }
 352 const RulesVector* getTagRules(AtomicStringImpl* key) const { return m_tagRules.get(key); }
 353 const RulesVector* getPseudoRules(AtomicStringImpl* key) const { return m_pseudoRules.get(key); }
 354 const RulesVector* getUniversalRules() const { return &m_universalRules; }
 355 const RulesVector* getPageRules() const { return &m_pageRules; }
 356 const ScopedRuleMap& scopedRules() const { return m_scopedRules; }
347357
348358public:
349359 AtomRuleMap m_idRules;
350360 AtomRuleMap m_classRules;
351361 AtomRuleMap m_tagRules;
352362 AtomRuleMap m_pseudoRules;
353  Vector<RuleData> m_universalRules;
354  Vector<RuleData> m_pageRules;
 363 RulesVector m_universalRules;
 364 RulesVector m_pageRules;
 365 ScopedRuleMap m_scopedRules;
355366 unsigned m_ruleCount;
356367 bool m_autoShrinkToFitEnabled;
357368};

@@void CSSStyleSelector::pushParentStackFrame(Element* parent)
633644 size_t count = parentFrame.identifierHashes.size();
634645 for (size_t i = 0; i < count; ++i)
635646 m_ancestorIdentifierFilter->add(parentFrame.identifierHashes[i]);
 647 // Point to frame containing the closest style scope (or leave at 0 if none).
 648 if (parent->hasScopedHTMLStyleChild())
 649 parentFrame.closestStyleScopeFrame = &parentFrame;
 650 else if (m_parentStack.size() >= 2)
 651 parentFrame.closestStyleScopeFrame = m_parentStack[m_parentStack.size() - 2].closestStyleScopeFrame;
636652}
637653
638654void CSSStyleSelector::popParentStackFrame()

@@void CSSStyleSelector::matchRules(RuleSet* rules, int& firstRuleIndex, int& last
718734 }
719735 matchRulesForList(rules->getTagRules(m_element->localName().impl()), firstRuleIndex, lastRuleIndex, includeEmptyRules);
720736 matchRulesForList(rules->getUniversalRules(), firstRuleIndex, lastRuleIndex, includeEmptyRules);
721 
 737 // Add applicable scoped rules.
 738 bool canUseFastScoping = !m_parentStack.isEmpty() && m_parentStack.last().element == m_parentNode;
 739 if (canUseFastScoping) {
 740 for (RuleSet::ScopedRuleMap::const_iterator it = rules->scopedRules().begin(), itEnd = rules->scopedRules().end(); it != itEnd; ++it) {
 741 ASSERT(it->first);
 742 ASSERT(it->first->hasScopedHTMLStyleChild());
 743 if (it->first == m_element || fastStyleSheetScopeIsAnAncestor(it->first))
 744 matchRulesForList(it->second, firstRuleIndex, lastRuleIndex, includeEmptyRules, it->first);
 745 }
 746 } else {
 747 for (RuleSet::ScopedRuleMap::const_iterator it = rules->scopedRules().begin(), itEnd = rules->scopedRules().end(); it != itEnd; ++it) {
 748 ASSERT(it->first);
 749 ASSERT(it->first->hasScopedHTMLStyleChild());
 750 if (slowStyleSheetScopeIsAnAncestor(it->first))
 751 matchRulesForList(it->second, firstRuleIndex, lastRuleIndex, includeEmptyRules, it->first);
 752 }
 753 }
 754
722755 // If we didn't match any rules, we're done.
723756 if (m_matchedRules.isEmpty())
724757 return;

@@void CSSStyleSelector::matchRules(RuleSet* rules, int& firstRuleIndex, int& last
739772 }
740773}
741774
 775bool CSSStyleSelector::fastStyleSheetScopeIsAnAncestor(StyleSheetScope scope) const
 776{
 777 ASSERT(!m_parentStack.isEmpty());
 778 ParentStackFrame* closestScopeFrame = m_parentStack.last().closestStyleScopeFrame;
 779 while (closestScopeFrame) {
 780 if (closestScopeFrame->element == scope)
 781 return true;
 782 if (closestScopeFrame == &m_parentStack.first())
 783 return false;
 784 --closestScopeFrame;
 785 closestScopeFrame = closestScopeFrame->closestStyleScopeFrame;
 786 }
 787 return false;
 788}
 789
 790bool CSSStyleSelector::slowStyleSheetScopeIsAnAncestor(StyleSheetScope scope) const
 791{
 792 for (const ContainerNode* node = m_element; node; node = node->parentOrHostNode()) {
 793 if (scope == node)
 794 return true;
 795 }
 796 return false;
 797}
 798
742799inline bool CSSStyleSelector::fastRejectSelector(const RuleData& ruleData) const
743800{
744801 ASSERT(m_ancestorIdentifierFilter);

@@inline bool MatchingUARulesScope::isMatchingUARules()
779836
780837bool MatchingUARulesScope::m_matchingUARules = false;
781838
782 inline static bool matchesInTreeScope(TreeScope* treeScope, bool ruleReachesIntoShadowDOM)
 839inline static bool matchesInTreeScope(TreeScope* treeScope, StyleSheetScope styleScope, bool ruleReachesIntoShadowDOM)
783840{
784  return MatchingUARulesScope::isMatchingUARules() || treeScope->applyAuthorSheets() || ruleReachesIntoShadowDOM;
 841 return MatchingUARulesScope::isMatchingUARules()
 842 || treeScope->applyAuthorSheets()
 843 || (styleScope && styleScope->treeScope() == treeScope)
 844 || ruleReachesIntoShadowDOM;
785845}
786846
787 void CSSStyleSelector::matchRulesForList(const Vector<RuleData>* rules, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules)
 847void CSSStyleSelector::matchRulesForList(const RulesVector* rules, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules, StyleSheetScope styleScope)
788848{
789849 if (!rules)
790850 return;

@@void CSSStyleSelector::matchRulesForList(const Vector<RuleData>* rules, int& fir
798858 if (canUseFastReject && fastRejectSelector(ruleData))
799859 continue;
800860 if (checkSelector(ruleData)) {
801  if (!matchesInTreeScope(m_element->treeScope(), m_checker.m_hasUnknownPseudoElements))
 861 if (!matchesInTreeScope(m_element->treeScope(), styleScope, m_checker.m_hasUnknownPseudoElements))
802862 continue;
803863 // If the rule has no properties to apply, then ignore it in the non-debug mode.
804864 CSSStyleRule* rule = ruleData.rule();

@@static inline bool isSelectorMatchingHTMLBasedOnRuleHash(const CSSSelector* sele
30493109 return selector->tag() == starAtom;
30503110}
30513111
3052 RuleData::RuleData(CSSStyleRule* rule, CSSSelector* selector, unsigned position)
 3112RuleData::RuleData(CSSStyleRule* rule, CSSSelector* selector, unsigned position, StyleSheetScope scope = 0)
30533113 : m_rule(rule)
30543114 , m_selector(selector)
30553115 , m_specificity(selector->specificity())
30563116 , m_position(position)
30573117 , m_hasFastCheckableSelector(isFastCheckableSelector(selector))
30583118 , m_hasMultipartSelector(selector->tagHistory())
3059  , m_hasTopSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector))
 3119 , m_hasTopSelectorMatchingHTMLBasedOnRuleHash(!scope && isSelectorMatchingHTMLBasedOnRuleHash(selector))
30603120{
30613121 collectDescendantSelectorIdentifierHashes();
30623122}

@@void RuleSet::addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
31233183 CSSStyleRule* rule, CSSSelector* sel)
31243184{
31253185 if (!key) return;
3126  Vector<RuleData>* rules = map.get(key);
 3186 RulesVector* rules = map.get(key);
31273187 if (!rules) {
3128  rules = new Vector<RuleData>;
 3188 rules = new RulesVector;
31293189 map.set(key, rules);
31303190 }
31313191 rules->append(RuleData(rule, sel, m_ruleCount++));
31323192}
31333193
3134 void RuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel)
 3194void RuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel, StyleSheetScope scope)
31353195{
 3196 if (scope) {
 3197 RulesVector* rules = m_scopedRules.get(scope);
 3198 if (!rules) {
 3199 rules = new RulesVector;
 3200 m_scopedRules.set(scope, rules);
 3201 }
 3202 rules->append(RuleData(rule, sel, m_ruleCount++, scope));
 3203 return;
 3204 }
31363205 if (sel->m_match == CSSSelector::Id) {
31373206 addToRuleSet(sel->value().impl(), m_idRules, rule, sel);
31383207 return;

@@void RuleSet::addPageRule(CSSStyleRule* rule, CSSSelector* sel)
31613230 m_pageRules.append(RuleData(rule, sel, m_pageRules.size()));
31623231}
31633232
3164 void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector)
 3233StyleSheetScope RuleSet::determineRulesScope(CSSStyleSheet* sheet) const
 3234{
 3235 if (!sheet)
 3236 return 0;
 3237
 3238 Node* ownerNode = sheet->findOwnerNode();
 3239 if (!ownerNode || !ownerNode->isHTMLElement() || !ownerNode->hasTagName(HTMLNames::styleTag))
 3240 return 0;
 3241
 3242 HTMLStyleElement* styleElement = static_cast<HTMLStyleElement*>(ownerNode);
 3243 if (!styleElement->scoped())
 3244 return 0;
 3245
 3246 Document* document = styleElement->document();
 3247 if (!document)
 3248 return 0;
 3249
 3250 // Ignore 'scoped' attribute for <style scoped> elements within <head>.
 3251 HTMLHeadElement* head = document->head();
 3252 if (head && head->contains(styleElement))
 3253 return 0;
 3254
 3255 StyleSheetScope scope = styleElement->parentNode();
 3256
 3257 return scope;
 3258}
 3259
 3260void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector, StyleSheetScope scope)
31653261{
31663262 if (!sheet)
31673263 return;

@@void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
31763272 for (int i = 0; i < len; i++) {
31773273 StyleBase* item = sheet->item(i);
31783274 if (item->isStyleRule())
3179  addStyleRule(static_cast<CSSStyleRule*>(item));
 3275 addStyleRule(static_cast<CSSStyleRule*>(item), scope);
31803276 else if (item->isImportRule()) {
31813277 CSSImportRule* import = static_cast<CSSImportRule*>(item);
31823278 if (!import->media() || medium.eval(import->media(), styleSelector))

@@void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
31923288 CSSRule *childItem = rules->item(j);
31933289 if (childItem->isStyleRule()) {
31943290 // It is a StyleRule, so append it to our list
3195  addStyleRule(static_cast<CSSStyleRule*>(childItem));
 3291 addStyleRule(static_cast<CSSStyleRule*>(childItem), scope);
31963292 } else if (childItem->isFontFaceRule() && styleSelector) {
31973293 // Add this font face to our set.
31983294 const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(childItem);

@@void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
32143310 shrinkToFit();
32153311}
32163312
3217 void RuleSet::addStyleRule(CSSStyleRule* rule)
 3313void RuleSet::addStyleRule(CSSStyleRule* rule, StyleSheetScope scope)
32183314{
32193315 if (rule->isPageRule()) {
 3316 // Ignore @page rules if the style sheet is scoped
 3317 if (scope)
 3318 return;
32203319 CSSPageRule* pageRule = static_cast<CSSPageRule*>(rule);
32213320 addPageRule(pageRule, pageRule->selectorList().first());
32223321 } else {
32233322 for (CSSSelector* s = rule->selectorList().first(); s; s = CSSSelectorList::next(s))
3224  addRule(rule, s);
 3323 addRule(rule, s, scope);
32253324 }
32263325}
32273326

@@static inline void collectFeaturesFromSelector(CSSStyleSelector::Features& featu
32613360 }
32623361}
32633362
3264 static void collectFeaturesFromList(CSSStyleSelector::Features& features, const Vector<RuleData>& rules)
 3363static void collectFeaturesFromList(CSSStyleSelector::Features& features, const RulesVector& rules, StyleSheetScope scope = 0)
32653364{
32663365 unsigned size = rules.size();
32673366 for (unsigned i = 0; i < size; ++i) {

@@static void collectFeaturesFromList(CSSStyleSelector::Features& features, const
32823381 if (foundSiblingSelector) {
32833382 if (!features.siblingRules)
32843383 features.siblingRules = adoptPtr(new RuleSet);
3285  features.siblingRules->addRule(ruleData.rule(), ruleData.selector());
 3384 features.siblingRules->addRule(ruleData.rule(), ruleData.selector(), scope);
32863385 }
32873386 }
32883387}
32893388
32903389void RuleSet::collectFeatures(CSSStyleSelector::Features& features) const
32913390{
 3391 for (ScopedRuleMap::const_iterator it = m_scopedRules.begin(), itEnd = m_scopedRules.end(); it != itEnd; ++it)
 3392 collectFeaturesFromList(features, *it->second, it->first);
32923393 AtomRuleMap::const_iterator end = m_idRules.end();
32933394 for (AtomRuleMap::const_iterator it = m_idRules.begin(); it != end; ++it)
32943395 collectFeaturesFromList(features, *it->second);

@@void CSSStyleSelector::matchPageRules(RuleSet* rules, bool isLeftPage, bool isFi
34223523 addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
34233524}
34243525
3425 void CSSStyleSelector::matchPageRulesForList(const Vector<RuleData>* rules, bool isLeftPage, bool isFirstPage, const String& pageName)
 3526void CSSStyleSelector::matchPageRulesForList(const RulesVector* rules, bool isLeftPage, bool isFirstPage, const String& pageName)
34263527{
34273528 if (!rules)
34283529 return;

Source/WebCore/css/CSSStyleSelector.h

@@public:
8787 friend class CSSStyleApplyProperty;
8888 WTF_MAKE_NONCOPYABLE(CSSStyleSelector); WTF_MAKE_FAST_ALLOCATED;
8989 public:
 90 typedef const ContainerNode* StyleSheetScope;
 91
9092 CSSStyleSelector(Document*, StyleSheetList* authorSheets, CSSStyleSheet* mappedElementSheet,
9193 CSSStyleSheet* pageUserSheet, const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets,
9294 bool strictParsing, bool matchAuthorAndUserStyles);

@@public:
215217 void addMatchedDeclaration(CSSMutableStyleDeclaration* decl);
216218
217219 void matchRules(RuleSet*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
218  void matchRulesForList(const Vector<RuleData>*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules);
 220 void matchRulesForList(const Vector<RuleData>*, int& firstRuleIndex, int& lastRuleIndex, bool includeEmptyRules, StyleSheetScope styleScope = 0);
219221 bool fastRejectSelector(const RuleData&) const;
 222 bool fastStyleSheetScopeIsAnAncestor(StyleSheetScope) const;
 223 bool slowStyleSheetScopeIsAnAncestor(StyleSheetScope) const;
220224 void sortMatchedRules();
221225
222226 bool checkSelector(const RuleData&);

@@public:
238242
239243 struct ParentStackFrame {
240244 ParentStackFrame() {}
241  ParentStackFrame(Element* element) : element(element) {}
 245 ParentStackFrame(Element* element) : element(element), closestStyleScopeFrame(0) { }
242246 Element* element;
243247 Vector<unsigned, 4> identifierHashes;
 248 ParentStackFrame* closestStyleScopeFrame;
 249
244250 };
245251 Vector<ParentStackFrame> m_parentStack;
246252

Source/WebCore/css/CSSStyleSheet.cpp

@@void CSSStyleSheet::startLoadingDynamicSheet()
236236 owner->startLoadingDynamicSheet();
237237}
238238
239 Document* CSSStyleSheet::document()
 239Node* CSSStyleSheet::findOwnerNode() const
240240{
241  StyleBase* styleObject = this;
242  while (styleObject) {
 241 for (const StyleBase* styleObject = this; styleObject; styleObject = styleObject->parent()) {
243242 if (styleObject->isCSSStyleSheet()) {
244  Node* ownerNode = static_cast<CSSStyleSheet*>(styleObject)->ownerNode();
 243 Node* ownerNode = static_cast<const CSSStyleSheet*>(styleObject)->ownerNode();
245244 if (ownerNode)
246  return ownerNode->document();
 245 return ownerNode;
247246 }
248  if (styleObject->isRule())
249  styleObject = static_cast<CSSRule*>(styleObject)->parentStyleSheet();
250  else
251  styleObject = styleObject->parent();
252247 }
253 
254248 return 0;
255249}
256250
 251Document* CSSStyleSheet::document()
 252{
 253 Node* ownerNode = findOwnerNode();
 254
 255 return ownerNode ? ownerNode->document() : 0;
 256}
 257
 258
257259void CSSStyleSheet::styleSheetChanged()
258260{
259261 StyleBase* root = this;

Source/WebCore/css/CSSStyleSheet.h

@@public:
8888 virtual void checkLoaded();
8989 void startLoadingDynamicSheet();
9090
 91 Node* findOwnerNode() const;
9192 Document* document();
9293
9394 const String& charset() const { return m_charset; }

Source/WebCore/dom/ContainerNode.h

@@public:
8080 void takeAllChildrenFrom(ContainerNode*);
8181
8282 void cloneChildNodes(ContainerNode* clone);
83 
 83
 84 // This is virtual on ContainerNode with a default no-op implementation for convenience.
 85 // If we should convert ShadowRoot to become a regular element, we can move these methods
 86 // to Element and make them non-virtual.
 87 virtual void registerScopedHTMLStyleChild() { }
 88 virtual void unregisterScopedHTMLStyleChild() { }
 89 virtual bool hasScopedHTMLStyleChild() const { return false; }
 90
8491 bool dispatchBeforeLoadEvent(const String& sourceURL);
8592
8693 static void queuePostAttachCallback(NodeCallback, Node*);

Source/WebCore/dom/Element.cpp

@@void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* af
13491349 checkForSiblingStyleChanges(this, renderStyle(), false, beforeChange, afterChange, childCountDelta);
13501350}
13511351
 1352void Element::registerScopedHTMLStyleChild()
 1353{
 1354 ensureRareData()->registerScopedHTMLStyleChild();
 1355}
 1356
 1357void Element::unregisterScopedHTMLStyleChild()
 1358{
 1359 ASSERT(hasRareData());
 1360 if (hasRareData())
 1361 rareData()->unregisterScopedHTMLStyleChild();
 1362}
 1363
 1364bool Element::hasScopedHTMLStyleChild() const
 1365{
 1366 return hasRareData() && rareData()->hasScopedHTMLStyleChild();
 1367}
 1368
13521369void Element::beginParsingChildren()
13531370{
13541371 clearIsParsingChildrenFinished();

Source/WebCore/dom/Element.h

@@public:
236236
237237 virtual const AtomicString& shadowPseudoId() const;
238238
 239 virtual void registerScopedHTMLStyleChild();
 240 virtual void unregisterScopedHTMLStyleChild();
 241 virtual bool hasScopedHTMLStyleChild() const;
 242
239243 RenderStyle* computedStyle(PseudoId = NOPSEUDO);
240244
241245 AtomicString computeInheritedLanguage() const;

Source/WebCore/dom/ElementRareData.h

@@public:
3939
4040 void resetComputedStyle();
4141
 42 void registerScopedHTMLStyleChild();
 43 void unregisterScopedHTMLStyleChild();
 44 bool hasScopedHTMLStyleChild() const;
 45
4246 using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
4347 using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
4448

@@public:
4953 OwnPtr<DatasetDOMStringMap> m_datasetDOMStringMap;
5054 OwnPtr<ClassList> m_classList;
5155
 56 unsigned m_numberOfScopedHTMLStyleChildren;
 57
5258#if ENABLE(FULLSCREEN_API)
5359 bool m_containsFullScreenElement;
5460#endif

@@inline IntSize defaultMinimumSizeForResizing()
6268inline ElementRareData::ElementRareData()
6369 : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
6470 , m_shadowRoot(0)
 71 , m_numberOfScopedHTMLStyleChildren(0)
6572#if ENABLE(FULLSCREEN_API)
6673 , m_containsFullScreenElement(false)
6774#endif

@@inline void ElementRareData::resetComputedStyle()
7885 m_computedStyle.clear();
7986}
8087
 88inline void ElementRareData::registerScopedHTMLStyleChild()
 89{
 90 ++m_numberOfScopedHTMLStyleChildren;
 91}
 92
 93inline void ElementRareData::unregisterScopedHTMLStyleChild()
 94{
 95 ASSERT(m_numberOfScopedHTMLStyleChildren > 0);
 96 --m_numberOfScopedHTMLStyleChildren;
 97}
 98
 99inline bool ElementRareData::hasScopedHTMLStyleChild() const
 100{
 101 return m_numberOfScopedHTMLStyleChildren;
 102}
 103
81104}
82105#endif // ElementRareData_h

Source/WebCore/dom/ShadowRoot.h

@@public:
4444 ContainerNode* activeContentContainer();
4545 void hostChildrenChanged();
4646
 47 virtual void registerScopedHTMLStyleChild();
 48 virtual void unregisterScopedHTMLStyleChild();
 49 virtual bool hasScopedHTMLStyleChild() const;
 50
4751private:
4852 ShadowRoot(Document*);
4953 virtual ~ShadowRoot();

@@private:
5660 virtual void attach();
5761
5862 bool hasContentElement() const;
 63
 64 unsigned m_numberOfScopedHTMLStyleChildren;
5965};
6066
6167inline PassRefPtr<ShadowRoot> ShadowRoot::create(Document* document)

@@inline PassRefPtr<ShadowRoot> ShadowRoot::create(Document* document)
6369 return adoptRef(new ShadowRoot(document));
6470}
6571
 72inline void ShadowRoot::registerScopedHTMLStyleChild()
 73{
 74 ++m_numberOfScopedHTMLStyleChildren;
 75}
 76
 77inline void ShadowRoot::unregisterScopedHTMLStyleChild()
 78{
 79 ASSERT(m_numberOfScopedHTMLStyleChildren > 0);
 80 --m_numberOfScopedHTMLStyleChildren;
 81}
 82
 83inline bool ShadowRoot::hasScopedHTMLStyleChild() const
 84{
 85 return m_numberOfScopedHTMLStyleChildren;
 86}
 87
6688} // namespace
6789
6890#endif

Source/WebCore/html/HTMLAttributeNames.in

@@rules
265265sandbox
266266scheme
267267scope
 268scoped
268269scrollamount
269270scrolldelay
270271scrolling

Source/WebCore/html/HTMLStyleElement.cpp

@@void HTMLStyleElement::insertedIntoDocument()
7373{
7474 HTMLElement::insertedIntoDocument();
7575 StyleElement::insertedIntoDocument(document(), this);
 76 if (scoped()) {
 77 ContainerNode* parent = parentNode();
 78 if (parent)
 79 parent->registerScopedHTMLStyleChild();
 80 }
 81}
 82
 83void HTMLStyleElement::willRemove()
 84{
 85 if (scoped()) {
 86 ContainerNode* parent = parentNode();
 87 if (parent)
 88 parent->unregisterScopedHTMLStyleChild();
 89 }
7690}
7791
7892void HTMLStyleElement::removedFromDocument()

@@void HTMLStyleElement::setDisabled(bool setDisabled)
120134 styleSheet->setDisabled(setDisabled);
121135}
122136
 137bool HTMLStyleElement::scoped() const
 138{
 139 return fastHasAttribute(scopedAttr);
 140}
 141
123142}

Source/WebCore/html/HTMLStyleElement.h

@@public:
4242 bool disabled() const;
4343 void setDisabled(bool);
4444
 45 bool scoped() const;
 46
4547private:
4648 HTMLStyleElement(const QualifiedName&, Document*, bool createdByParser);
4749
4850 // overload from HTMLElement
4951 virtual void parseMappedAttribute(Attribute*);
5052 virtual void insertedIntoDocument();
 53 virtual void willRemove();
5154 virtual void removedFromDocument();
5255 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
5356