Commit 959a3c5a authored by hyatt@apple.com's avatar hyatt@apple.com

https://bugs.webkit.org/show_bug.cgi?id=28987, make the Document cache the...

https://bugs.webkit.org/show_bug.cgi?id=28987, make the Document cache the page's user stylesheet in
parsed form.  Allows the sheet to survive across destruction/re-creation of the CSSStyleSelector.

Reviewed by Eric Seidel.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::CSSStyleSelector):
* css/CSSStyleSelector.h:
* dom/Document.cpp:
(WebCore::Document::attach):
(WebCore::Document::pageUserSheet):
(WebCore::Document::clearPageUserSheet):
(WebCore::Document::recalcStyleSelector):
* dom/Document.h:
* loader/PlaceholderDocument.cpp:
(WebCore::PlaceholderDocument::attach):
* page/Page.cpp:
(WebCore::Page::userStyleSheetLocationChanged):
* page/Settings.cpp:
(WebCore::Settings::setUserStyleSheetLocation):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48181 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent eb68b32f
2009-09-04 Dave Hyatt <hyatt@apple.com>
Reviewed by Eric Seidel.
https://bugs.webkit.org/show_bug.cgi?id=28987, make the Document cache the page's user stylesheet in
parsed form. Allows the sheet to survive across destruction/re-creation of the CSSStyleSelector.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::CSSStyleSelector):
* css/CSSStyleSelector.h:
* dom/Document.cpp:
(WebCore::Document::attach):
(WebCore::Document::pageUserSheet):
(WebCore::Document::clearPageUserSheet):
(WebCore::Document::recalcStyleSelector):
* dom/Document.h:
* loader/PlaceholderDocument.cpp:
(WebCore::PlaceholderDocument::attach):
* page/Page.cpp:
(WebCore::Page::userStyleSheetLocationChanged):
* page/Settings.cpp:
(WebCore::Settings::setUserStyleSheetLocation):
2009-09-08 Kenneth Rohde Christiansen <kenneth@webkit.org>
Unreviewed buildfix.
......@@ -1182,8 +1182,6 @@
65DF326109D1E199000BE325 /* UserAgentStyleSheetsData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 656581AF09D14EE6000E61D7 /* UserAgentStyleSheetsData.cpp */; };
65FEA86909833ADE00BED4AB /* Page.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65FEA86809833ADE00BED4AB /* Page.cpp */; };
72626E020EF022FE00A07E20 /* FontFastPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 72626E010EF022FE00A07E20 /* FontFastPath.cpp */; };
7284ADDD0E6FEB31002EEFBD /* UserStyleSheetLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7284ADDB0E6FEB31002EEFBD /* UserStyleSheetLoader.cpp */; };
7284ADDE0E6FEB31002EEFBD /* UserStyleSheetLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 7284ADDC0E6FEB31002EEFBD /* UserStyleSheetLoader.h */; };
75092BFE104B80F9003DD168 /* DOMDispatchTimelineItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 75092BFC104B80F9003DD168 /* DOMDispatchTimelineItem.cpp */; };
75092BFF104B80F9003DD168 /* DOMDispatchTimelineItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 75092BFD104B80F9003DD168 /* DOMDispatchTimelineItem.h */; };
754133A8102E00E800075D00 /* InspectorTimelineAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 754133A7102E00E800075D00 /* InspectorTimelineAgent.h */; };
......@@ -6410,8 +6408,6 @@
65F80697054D9F86008BF776 /* BlockExceptions.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BlockExceptions.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
65FEA86809833ADE00BED4AB /* Page.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Page.cpp; sourceTree = "<group>"; };
72626E010EF022FE00A07E20 /* FontFastPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFastPath.cpp; sourceTree = "<group>"; };
7284ADDB0E6FEB31002EEFBD /* UserStyleSheetLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserStyleSheetLoader.cpp; sourceTree = "<group>"; };
7284ADDC0E6FEB31002EEFBD /* UserStyleSheetLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserStyleSheetLoader.h; sourceTree = "<group>"; };
75092BFC104B80F9003DD168 /* DOMDispatchTimelineItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMDispatchTimelineItem.cpp; sourceTree = "<group>"; };
75092BFD104B80F9003DD168 /* DOMDispatchTimelineItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDispatchTimelineItem.h; sourceTree = "<group>"; };
754133A7102E00E800075D00 /* InspectorTimelineAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorTimelineAgent.h; sourceTree = "<group>"; };
......@@ -408,7 +408,7 @@ static const MediaQueryEvaluator& printEval()
return staticPrintEval;
}
CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, StyleSheetList* styleSheets, CSSStyleSheet* mappedElementSheet, bool strictParsing, bool matchAuthorAndUserStyles)
CSSStyleSelector::CSSStyleSelector(Document* doc, CSSStyleSheet* userSheet, StyleSheetList* styleSheets, CSSStyleSheet* mappedElementSheet, bool strictParsing, bool matchAuthorAndUserStyles)
: m_backgroundData(BackgroundFillLayer)
, m_checker(doc, strictParsing)
, m_fontSelector(CSSFontSelector::create(doc))
......@@ -449,12 +449,9 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet,
}
// FIXME: This sucks! The user sheet is reparsed every time!
if (!userStyleSheet.isEmpty()) {
m_userSheet = CSSStyleSheet::create(doc);
m_userSheet->parseString(userStyleSheet, strictParsing);
if (userSheet) {
m_userStyle = new CSSRuleSet();
m_userStyle->addRulesFromSheet(m_userSheet.get(), *m_medium, this);
m_userStyle->addRulesFromSheet(userSheet, *m_medium, this);
}
// add stylesheets from document
......
......@@ -80,7 +80,8 @@ public:
// This class selects a RenderStyle for a given element based on a collection of stylesheets.
class CSSStyleSelector : public Noncopyable {
public:
CSSStyleSelector(Document*, const String& userStyleSheet, StyleSheetList*, CSSStyleSheet*, bool strictParsing, bool matchAuthorAndUserStyles);
CSSStyleSelector(Document*, CSSStyleSheet* userStyleSheet, StyleSheetList* authorSheets, CSSStyleSheet* mappedElementSheet,
bool strictParsing, bool matchAuthorAndUserStyles);
~CSSStyleSelector();
void initElementAndPseudoState(Element*);
......@@ -175,7 +176,6 @@ public:
CSSRuleSet* m_authorStyle;
CSSRuleSet* m_userStyle;
RefPtr<CSSStyleSheet> m_userSheet;
bool m_hasUAAppearance;
BorderData m_borderData;
......
......@@ -1333,7 +1333,7 @@ void Document::attach()
bool matchAuthorAndUserStyles = true;
if (Settings* docSettings = settings())
matchAuthorAndUserStyles = docSettings->authorAndUserStylesEnabled();
m_styleSelector = new CSSStyleSelector(this, userStyleSheet(), m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
m_styleSelector = new CSSStyleSelector(this, pageUserSheet(), m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
}
recalcStyle(Force);
......@@ -1873,12 +1873,29 @@ String Document::userAgent(const KURL& url) const
return frame() ? frame()->loader()->userAgent(url) : String();
}
String Document::userStyleSheet() const
CSSStyleSheet* Document::pageUserSheet()
{
Page* page = this->page();
if (!page)
return String();
return page->userStyleSheet();
if (m_pageUserSheet)
return m_pageUserSheet.get();
Page* owningPage = page();
if (!owningPage)
return 0;
String userSheetText = owningPage->userStyleSheet();
if (userSheetText.isEmpty())
return 0;
// Parse the sheet and cache it.
m_pageUserSheet = CSSStyleSheet::create(this);
m_pageUserSheet->parseString(userSheetText, !inCompatMode());
return m_pageUserSheet.get();
}
void Document::clearPageUserSheet()
{
m_pageUserSheet = 0;
updateStyleSelector();
}
CSSStyleSheet* Document::elementSheet()
......@@ -2442,7 +2459,7 @@ void Document::recalcStyleSelector()
// Create a new style selector
delete m_styleSelector;
m_styleSelector = new CSSStyleSelector(this, userStyleSheet(), m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
m_styleSelector = new CSSStyleSelector(this, pageUserSheet(), m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
m_didCalculateStyleSelector = true;
}
......
......@@ -439,10 +439,12 @@ public:
virtual String userAgent(const KURL&) const;
String userStyleSheet() const;
CSSStyleSheet* pageUserSheet();
void clearPageUserSheet();
CSSStyleSheet* elementSheet();
CSSStyleSheet* mappedElementSheet();
virtual Tokenizer* createTokenizer();
Tokenizer* tokenizer() { return m_tokenizer; }
......@@ -929,7 +931,8 @@ private:
RefPtr<CSSStyleSheet> m_elemSheet;
RefPtr<CSSStyleSheet> m_mappedElementSheet;
RefPtr<CSSStyleSheet> m_pageUserSheet;
bool m_printing;
bool m_ignoreAutofocus;
......
......@@ -37,7 +37,7 @@ void PlaceholderDocument::attach()
if (!styleSelector()) {
RefPtr<StyleSheetList> styleSheetList = StyleSheetList::create(this);
setStyleSelector(new CSSStyleSelector(this, userStyleSheet(), styleSheetList.get(), 0, true, false));
setStyleSelector(new CSSStyleSelector(this, pageUserSheet(), styleSheetList.get(), 0, true, false));
}
// Skipping Document::attach().
......
......@@ -469,6 +469,11 @@ void Page::userStyleSheetLocationChanged()
return;
}
}
for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (frame->document())
frame->document()->clearPageUserSheet();
}
}
const String& Page::userStyleSheet() const
......
......@@ -273,7 +273,6 @@ void Settings::setUserStyleSheetLocation(const KURL& userStyleSheetLocation)
m_userStyleSheetLocation = userStyleSheetLocation;
m_page->userStyleSheetLocationChanged();
setNeedsReapplyStylesInAllFrames(m_page);
}
void Settings::setShouldPrintBackgrounds(bool shouldPrintBackgrounds)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment