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

Unified Diff: sky/engine/core/html/HTMLStyleElement.cpp

Issue 780083003: Merge StyleElement into HTMLStyleElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: trim includes. Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/html/HTMLStyleElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/html/HTMLStyleElement.cpp
diff --git a/sky/engine/core/html/HTMLStyleElement.cpp b/sky/engine/core/html/HTMLStyleElement.cpp
index 9d5f56975f5024fff6c05ac43d46a0d854dcd26c..e8ab1d70469747721eacbbe65f39e91b4fbd2c2a 100644
--- a/sky/engine/core/html/HTMLStyleElement.cpp
+++ b/sky/engine/core/html/HTMLStyleElement.cpp
@@ -26,24 +26,32 @@
#include "gen/sky/core/HTMLNames.h"
#include "sky/engine/core/css/MediaList.h"
+#include "sky/engine/core/css/MediaQueryEvaluator.h"
#include "sky/engine/core/dom/Document.h"
+#include "sky/engine/core/dom/Element.h"
+#include "sky/engine/core/dom/StyleEngine.h"
#include "sky/engine/core/dom/shadow/ShadowRoot.h"
-#include "sky/engine/core/events/Event.h"
-#include "sky/engine/core/events/EventSender.h"
+#include "sky/engine/core/frame/LocalFrame.h"
+#include "sky/engine/platform/TraceEvent.h"
namespace blink {
inline HTMLStyleElement::HTMLStyleElement(Document& document, bool createdByParser)
: HTMLElement(HTMLNames::styleTag, document)
- , StyleElement(&document, createdByParser)
+ , m_createdByParser(createdByParser)
+ , m_loading(false)
+ , m_registeredAsCandidate(false)
+ , m_startPosition(TextPosition::belowRangePosition())
{
+ if (createdByParser)
+ m_startPosition = document.parserPosition();
}
HTMLStyleElement::~HTMLStyleElement()
{
-#if !ENABLE(OILPAN)
- StyleElement::clearDocumentData(document(), this);
-#endif
+ clearDocumentData();
+ if (m_sheet)
+ clearSheet();
}
PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document, bool createdByParser)
@@ -63,8 +71,8 @@ void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
void HTMLStyleElement::finishParsingChildren()
{
- StyleElement::finishParsingChildren(this);
- HTMLElement::finishParsingChildren();
+ process();
+ m_createdByParser = false;
}
void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
@@ -74,7 +82,7 @@ void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
if (!inDocument())
return;
- StyleElement::processStyleSheet(document(), this);
+ processStyleSheet();
if (ShadowRoot* scope = containingShadowRoot())
scope->registerScopedHTMLStyleChild();
@@ -95,13 +103,28 @@ void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint)
scopingNode->unregisterScopedHTMLStyleChild();
TreeScope* containingScope = containingShadowRoot();
- StyleElement::removedFromDocument(document(), this, scopingNode, containingScope ? *containingScope : insertionPoint->treeScope());
+ TreeScope& scope = containingScope ? *containingScope : insertionPoint->treeScope();
+
+ if (m_registeredAsCandidate) {
+ document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNode, scope);
+ m_registeredAsCandidate = false;
+ }
+
+ RefPtr<CSSStyleSheet> removedSheet = m_sheet.get();
+
+ if (m_sheet)
+ clearSheet();
+ if (removedSheet)
+ document().removedStyleSheet(removedSheet.get());
}
void HTMLStyleElement::childrenChanged(const ChildrenChange& change)
{
HTMLElement::childrenChanged(change);
- StyleElement::childrenChanged(this);
+
+ if (m_createdByParser)
+ return;
+ process();
}
const AtomicString& HTMLStyleElement::media() const
@@ -125,4 +148,69 @@ ContainerNode* HTMLStyleElement::scopingNode()
return &document();
}
+void HTMLStyleElement::process()
+{
+ if (!inDocument())
+ return;
+ createSheet();
+}
+
+void HTMLStyleElement::clearSheet()
+{
+ ASSERT(m_sheet);
+ m_sheet.release()->clearOwnerNode();
+}
+
+void HTMLStyleElement::createSheet()
+{
+ ASSERT(inDocument());
+
+ if (m_sheet)
+ clearSheet();
+
+ const AtomicString& type = this->type();
+ if (type.isEmpty() || type == "text/css") {
+ RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media());
+
+ MediaQueryEvaluator screenEval("screen", true);
+ MediaQueryEvaluator printEval("print", true);
+ if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.get())) {
+ m_loading = true;
+ const String& text = textFromChildren();
+ TextPosition startPosition = m_startPosition == TextPosition::belowRangePosition() ? TextPosition::minimumPosition() : m_startPosition;
+ m_sheet = document().styleEngine()->createSheet(this, text, startPosition, m_createdByParser);
+ m_sheet->setMediaQueries(mediaQueries.release());
+ m_loading = false;
+ }
+ }
+
+ document().styleResolverChanged();
+}
+
+void HTMLStyleElement::clearDocumentData()
+{
+ if (m_sheet)
+ m_sheet->clearOwnerNode();
+
+ if (inDocument()) {
+ ContainerNode* scopingNode = this->scopingNode();
+ TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope();
+ document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNode, scope);
+ }
+}
+
+void HTMLStyleElement::processStyleSheet()
+{
+ TRACE_EVENT0("blink", "StyleElement::processStyleSheet");
+
+ ASSERT(inDocument());
+
+ m_registeredAsCandidate = true;
+ document().styleEngine()->addStyleSheetCandidateNode(this, m_createdByParser);
+ if (m_createdByParser)
+ return;
+
+ process();
+}
+
}
« no previous file with comments | « sky/engine/core/html/HTMLStyleElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698