Index: Source/core/dom/StyleEngine.cpp |
diff --git a/Source/core/dom/StyleEngine.cpp b/Source/core/dom/StyleEngine.cpp |
index 186450e231cd08a8d09d9f4ae4cdd546fefecb7e..6e21494cc50b57a80b69041af51dfb65cd2d8236 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; |
esprehn
2013/11/15 10:27:37
No need for the typedefs since they're inside func
tasak
2014/01/09 09:24:50
I tried "DEFINE_STATIC_LOCAL((HashMap<...>), ..)".
|
+ DEFINE_STATIC_LOCAL(TextToSheetCache, cache, ()); |
+ return cache; |
+} |
+ |
+static HashMap<StyleSheetContents*, AtomicString>& sheetToTextCache() |
+{ |
+ typedef HashMap<StyleSheetContents*, AtomicString> SheetToTextCache; |
esprehn
2013/11/15 10:27:37
Ditto.
|
+ DEFINE_STATIC_LOCAL(SheetToTextCache, cache, ()); |
+ return cache; |
+} |
+ |
StyleEngine::StyleEngine(Document& document) |
: m_document(document) |
, m_pendingStylesheets(0) |
@@ -416,4 +431,48 @@ void StyleEngine::appendActiveAuthorStyleSheets(StyleResolver* styleResolver) |
styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); |
} |
+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() |
+{ |
+ textToSheetCache().clear(); |
+ sheetToTextCache().clear(); |
esprehn
2013/11/15 10:27:37
Should not be needed. This is bad too, you're clea
tasak
2014/01/09 09:24:50
I'm still using this method when compatibility mod
|
+} |
+ |
} |