Index: Source/core/dom/StyleEngine.cpp |
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp |
index ad1b08dc15721b063b23e06cf0470b69b81e4777..425b09138ee4714465267938ee409bfd11c42d22 100644 |
--- a/Source/core/dom/StyleEngine.cpp |
+++ b/Source/core/dom/StyleEngine.cpp |
@@ -52,6 +52,21 @@ namespace WebCore { |
using namespace HTMLNames; |
+ |
+static HashMap<AtomicString, StyleSheetContents*>& textToSheetCache() |
+{ |
+ typedef HashMap<AtomicString, StyleSheetContents*> TextToSheetCache; |
+ DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ()); |
+ return cache; |
+} |
+ |
+static HashMap<StyleSheetContents*, AtomicString>& sheetToTextCache() |
+{ |
+ typedef HashMap<StyleSheetContents*, AtomicString> SheetToTextCache; |
+ DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ()); |
+ return cache; |
+} |
+ |
StyleEngine::StyleEngine(Document& document) |
: m_document(document) |
, m_isMaster(HTMLImport::isMaster(&document)) |
@@ -584,4 +599,48 @@ void StyleEngine::markDocumentDirty() |
m_document.import()->master()->styleEngine()->markDocumentDirty(); |
} |
+PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& text, TextPosition startPosition, bool createdByParser) |
+{ |
+ AtomicString textContent(text); |
+ |
+ HashMap<AtomicString, StyleSheetContents*>::AddResult result = textToSheetCache().add(textContent, 0); |
+ |
+ e->document().styleEngine()->addPendingSheet(); |
+ |
+ RefPtr<CSSStyleSheet> styleSheet; |
+ if (result.isNewEntry || !result.iterator->value) { |
+ styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->document().inputEncoding()); |
+ styleSheet->contents()->parseStringAtPosition(text, startPosition, createdByParser); |
+ |
+ if (result.isNewEntry && styleSheet->contents()->maybeCacheable()) { |
+ result.iterator->value = styleSheet->contents(); |
+ sheetToTextCache().add(styleSheet->contents(), textContent); |
+ } |
+ } else { |
+ ASSERT(result.iterator->value->maybeCacheable()); |
+ styleSheet = CSSStyleSheet::createInline(result.iterator->value, e, startPosition); |
+ } |
+ |
+ ASSERT(styleSheet); |
+ styleSheet->setTitle(e->title()); |
+ |
+ return styleSheet; |
+} |
+ |
+void StyleEngine::removeSheet(StyleSheetContents* contents) |
+{ |
+ HashMap<StyleSheetContents*, AtomicString>::iterator it = sheetToTextCache().find(contents); |
+ if (it == sheetToTextCache().end()) |
+ return; |
+ |
+ textToSheetCache().remove(it->value); |
+ sheetToTextCache().remove(contents); |
+} |
+ |
+void StyleEngine::clearSheetCache() |
esprehn
2014/01/09 10:05:32
This method can't exist.
tasak
2014/01/09 11:59:05
Done.
|
+{ |
+ textToSheetCache().clear(); |
+ sheetToTextCache().clear(); |
+} |
+ |
} |