diff options
Diffstat (limited to 'Source/WebCore/html/HTMLStyleElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLStyleElement.cpp | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/Source/WebCore/html/HTMLStyleElement.cpp b/Source/WebCore/html/HTMLStyleElement.cpp index b0b667286..f7e9d5e8a 100644 --- a/Source/WebCore/html/HTMLStyleElement.cpp +++ b/Source/WebCore/html/HTMLStyleElement.cpp @@ -24,15 +24,17 @@ #include "config.h" #include "HTMLStyleElement.h" -#include "Attribute.h" +#include "CachedResource.h" #include "Document.h" #include "Event.h" +#include "EventNames.h" #include "EventSender.h" #include "HTMLNames.h" #include "MediaList.h" #include "RuntimeEnabledFeatures.h" #include "ScriptableDocumentParser.h" #include "ShadowRoot.h" +#include "StyleScope.h" #include "StyleSheetContents.h" namespace WebCore { @@ -41,31 +43,32 @@ using namespace HTMLNames; static StyleEventSender& styleLoadEventSender() { - DEFINE_STATIC_LOCAL(StyleEventSender, sharedLoadEventSender, (eventNames().loadEvent)); + static NeverDestroyed<StyleEventSender> sharedLoadEventSender(eventNames().loadEvent); return sharedLoadEventSender; } inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document& document, bool createdByParser) : HTMLElement(tagName, document) , m_styleSheetOwner(document, createdByParser) - , m_firedLoad(false) - , m_loadedSheet(false) { ASSERT(hasTagName(styleTag)); } HTMLStyleElement::~HTMLStyleElement() { - // During tear-down, willRemove isn't called, so m_scopedStyleRegistrationState may still be RegisteredAsScoped or RegisteredInShadowRoot here. - // Therefore we can't ASSERT(m_scopedStyleRegistrationState == NotRegistered). - m_styleSheetOwner.clearDocumentData(document(), *this); + m_styleSheetOwner.clearDocumentData(*this); - styleLoadEventSender().cancelEvent(this); + styleLoadEventSender().cancelEvent(*this); } -PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) +Ref<HTMLStyleElement> HTMLStyleElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) { - return adoptRef(new HTMLStyleElement(tagName, document, createdByParser)); + return adoptRef(*new HTMLStyleElement(tagName, document, createdByParser)); +} + +Ref<HTMLStyleElement> HTMLStyleElement::create(Document& document) +{ + return adoptRef(*new HTMLStyleElement(styleTag, document, false)); } void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicString& value) @@ -75,10 +78,11 @@ void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr else if (name == mediaAttr) { m_styleSheetOwner.setMedia(value); if (sheet()) { - sheet()->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(value)); - if (inDocument() && document().hasLivingRenderTree()) - document().styleResolverChanged(RecalcStyleImmediately); - } + sheet()->setMediaQueries(MediaQuerySet::create(value)); + if (auto* scope = m_styleSheetOwner.styleScope()) + scope->didChangeStyleSheetContents(); + } else + m_styleSheetOwner.childrenChanged(*this); } else if (name == typeAttr) m_styleSheetOwner.setContentType(value); else @@ -93,19 +97,18 @@ void HTMLStyleElement::finishParsingChildren() Node::InsertionNotificationRequest HTMLStyleElement::insertedInto(ContainerNode& insertionPoint) { - HTMLElement::insertedInto(insertionPoint); - if (insertionPoint.inDocument()) - m_styleSheetOwner.insertedIntoDocument(document(), *this); - - return InsertionDone; + bool wasInDocument = isConnected(); + auto result = HTMLElement::insertedInto(insertionPoint); + if (insertionPoint.isConnected() && !wasInDocument) + m_styleSheetOwner.insertedIntoDocument(*this); + return result; } void HTMLStyleElement::removedFrom(ContainerNode& insertionPoint) { HTMLElement::removedFrom(insertionPoint); - - if (insertionPoint.inDocument()) - m_styleSheetOwner.removedFromDocument(document(), *this); + if (insertionPoint.isConnected() && !isConnected()) + m_styleSheetOwner.removedFromDocument(*this); } void HTMLStyleElement::childrenChanged(const ChildChange& change) @@ -133,7 +136,7 @@ void HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources(bool errorOcc if (m_firedLoad) return; m_loadedSheet = !errorOccurred; - styleLoadEventSender().dispatchEventSoon(this); + styleLoadEventSender().dispatchEventSoon(*this); m_firedLoad = true; } @@ -141,8 +144,12 @@ void HTMLStyleElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const { HTMLElement::addSubresourceAttributeURLs(urls); - if (CSSStyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet()) - styleSheet->contents().addSubresourceStyleURLs(urls); + if (auto* styleSheet = this->sheet()) { + styleSheet->contents().traverseSubresources([&] (auto& resource) { + urls.add(resource.url()); + return false; + }); + } } bool HTMLStyleElement::disabled() const |