+2012-04-11 Antti Koivisto <antti@apple.com>
+
+ Split CSSStyleSheet into internal and CSSOM type
+ https://bugs.webkit.org/show_bug.cgi?id=83612
+
+ Reviewed by Andreas Kling.
+
+ This will complete the separation of our style sheet data structures from CSSOM.
+
+ The internal parts of CSSStyleSheet move to StyleSheetInternal. CSS parser
+ and style selector will now operate on internal types. Unlike other CSSOM types
+ CSSStyleSheets are still always instantiated to hold the top level author stylesheets
+ (by Nodes).
+
+ * css/CSSFontFaceSrcValue.cpp:
+ (WebCore::CSSFontFaceSrcValue::addSubresourceStyleURLs):
+ * css/CSSFontFaceSrcValue.h:
+ (CSSFontFaceSrcValue):
+ * css/CSSImportRule.cpp:
+ (WebCore::StyleRuleImport::create):
+ (WebCore::StyleRuleImport::StyleRuleImport):
+ (WebCore::StyleRuleImport::setCSSStyleSheet):
+ (WebCore::StyleRuleImport::requestStyleSheet):
+ (WebCore::CSSImportRule::~CSSImportRule):
+ (WebCore):
+ (WebCore::CSSImportRule::styleSheet):
+ * css/CSSImportRule.h:
+ (WebCore):
+ (StyleRuleImport):
+ (WebCore::StyleRuleImport::parentStyleSheet):
+ (WebCore::StyleRuleImport::styleSheet):
+ (CSSImportRule):
+ * css/CSSMediaRule.cpp:
+ (WebCore::CSSMediaRule::insertRule):
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::parseSheet):
+ (WebCore::CSSParser::parseRule):
+ (WebCore::CSSParser::parseKeyframeRule):
+ (WebCore::CSSParser::parseFontFaceValue):
+ (WebCore::CSSParser::parseValue):
+ (WebCore::CSSParser::parseSelector):
+ (WebCore::CSSParser::parseDeclaration):
+ (WebCore::CSSParser::setStyleSheet):
+ (WebCore::CSSParser::parseFlowThread):
+ * css/CSSParser.h:
+ (WebCore):
+ (CSSParser):
+ * css/CSSPrimitiveValue.cpp:
+ (WebCore::CSSPrimitiveValue::addSubresourceStyleURLs):
+ * css/CSSPrimitiveValue.h:
+ (CSSPrimitiveValue):
+ * css/CSSReflectValue.cpp:
+ (WebCore::CSSReflectValue::addSubresourceStyleURLs):
+ * css/CSSReflectValue.h:
+ (CSSReflectValue):
+ * css/CSSRule.h:
+ (CSSRule):
+ * css/CSSStyleSelector.cpp:
+ (RuleSet):
+ (WebCore):
+ (WebCore::CSSStyleSelector::CSSStyleSelector):
+ (WebCore::CSSStyleSelector::addAuthorRulesAndCollectUserRulesFromSheets):
+ (WebCore::CSSStyleSelector::determineScope):
+ (WebCore::CSSStyleSelector::appendAuthorStylesheets):
+ (WebCore::parseUASheet):
+ (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+ * css/CSSStyleSelector.h:
+ (CSSStyleSelector):
+
+ Add a set for root CSSStyleSheet objects so that the wrappers created in ensureFullCSSOMWrapperForInspector
+ stay valid.
+
+ * css/CSSStyleSheet.cpp:
+ (WebCore::StyleSheetInternal::StyleSheetInternal):
+ (WebCore::StyleSheetInternal::~StyleSheetInternal):
+ (WebCore::StyleSheetInternal::parserAppendRule):
+ (WebCore::StyleSheetInternal::createChildRuleCSSOMWrapper):
+ (WebCore::StyleSheetInternal::ruleCount):
+ (WebCore::StyleSheetInternal::clearCharsetRule):
+ (WebCore::StyleSheetInternal::clearRules):
+ (WebCore::StyleSheetInternal::parserSetEncodingFromCharsetRule):
+ (WebCore::StyleSheetInternal::wrapperInsertRule):
+ (WebCore::StyleSheetInternal::wrapperDeleteRule):
+ (WebCore::StyleSheetInternal::addNamespace):
+ (WebCore::StyleSheetInternal::determineNamespace):
+ (WebCore::StyleSheetInternal::parseString):
+ (WebCore::StyleSheetInternal::parseStringAtLine):
+ (WebCore::StyleSheetInternal::isLoading):
+ (WebCore::StyleSheetInternal::checkLoaded):
+ (WebCore::StyleSheetInternal::notifyLoadedSheet):
+ (WebCore::StyleSheetInternal::startLoadingDynamicSheet):
+ (WebCore::StyleSheetInternal::findStyleSheetOwnerNode):
+ (WebCore::StyleSheetInternal::findDocument):
+ (WebCore::StyleSheetInternal::setMediaQueries):
+ (WebCore::StyleSheetInternal::styleSheetChanged):
+ (WebCore):
+ (WebCore::StyleSheetInternal::baseURL):
+ (WebCore::StyleSheetInternal::completeURL):
+ (WebCore::StyleSheetInternal::addSubresourceStyleURLs):
+ (WebCore::StyleSheetInternal::parentStyleSheet):
+ (WebCore::CSSStyleSheet::CSSStyleSheet):
+ (WebCore::CSSStyleSheet::~CSSStyleSheet):
+ (WebCore::CSSStyleSheet::setDisabled):
+ (WebCore::CSSStyleSheet::length):
+ (WebCore::CSSStyleSheet::item):
+ (WebCore::CSSStyleSheet::rules):
+ (WebCore::CSSStyleSheet::insertRule):
+ (WebCore::CSSStyleSheet::addRule):
+ (WebCore::CSSStyleSheet::cssRules):
+ (WebCore::CSSStyleSheet::deleteRule):
+ (WebCore::CSSStyleSheet::media):
+ (WebCore::CSSStyleSheet::parentStyleSheet):
+ * css/CSSStyleSheet.h:
+ (WebCore):
+ (WebCore::StyleSheetInternal::create):
+ (WebCore::StyleSheetInternal::createInline):
+ (StyleSheetInternal):
+ (WebCore::StyleSheetInternal::ownerNode):
+ (WebCore::StyleSheetInternal::clearOwnerNode):
+ (WebCore::StyleSheetInternal::ownerRule):
+ (WebCore::StyleSheetInternal::originalURL):
+ (WebCore::StyleSheetInternal::title):
+ (WebCore::StyleSheetInternal::setTitle):
+ (WebCore::StyleSheetInternal::setFinalURL):
+ (WebCore::StyleSheetInternal::finalURL):
+ (CSSStyleSheet):
+ (WebCore::CSSStyleSheet::create):
+ (WebCore::CSSStyleSheet::removeRule):
+ (WebCore::CSSStyleSheet::clearOwnerRule):
+ (WebCore::CSSStyleSheet::styleSheetChanged):
+ (WebCore::CSSStyleSheet::findDocument):
+ (WebCore::CSSStyleSheet::internal):
+ (WebCore::CSSStyleSheet::isCSSStyleSheet):
+ (WebCore::CSSStyleSheet::type):
+ * css/CSSValue.cpp:
+ (WebCore::CSSValue::addSubresourceStyleURLs):
+ * css/CSSValue.h:
+ (WebCore):
+ (CSSValue):
+ * css/CSSValueList.cpp:
+ (WebCore::CSSValueList::addSubresourceStyleURLs):
+ * css/CSSValueList.h:
+ (CSSValueList):
+ * css/CSSValuePool.cpp:
+ (WebCore::CSSValuePool::createFontFaceValue):
+ * css/CSSValuePool.h:
+ (WebCore):
+ (CSSValuePool):
+ * css/PropertySetCSSStyleDeclaration.cpp:
+ (WebCore::PropertySetCSSStyleDeclaration::setCssText):
+ (WebCore::PropertySetCSSStyleDeclaration::setProperty):
+ (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
+ * css/PropertySetCSSStyleDeclaration.h:
+ (WebCore):
+ * css/StylePropertySet.cpp:
+ (WebCore::StylePropertySet::setProperty):
+ (WebCore::StylePropertySet::parseDeclaration):
+ (WebCore::StylePropertySet::addSubresourceStyleURLs):
+ * css/StylePropertySet.h:
+ (WebCore):
+ (StylePropertySet):
+ * css/StyleSheet.cpp:
+ (WebCore):
+ * css/StyleSheet.h:
+ (StyleSheet):
+ (WebCore::StyleSheet::media):
+ (WebCore::StyleSheet::ownerRule):
+ (WebCore::StyleSheet::isXSLStyleSheet):
+ * css/WebKitCSSKeyframesRule.cpp:
+ (WebCore::WebKitCSSKeyframesRule::insertRule):
+ * dom/DOMImplementation.cpp:
+ (WebCore::DOMImplementation::createCSSStyleSheet):
+ * dom/Document.cpp:
+ (WebCore::Document::updateBaseURL):
+ (WebCore::Document::pageUserSheet):
+ (WebCore::Document::pageGroupUserSheets):
+ (WebCore::Document::addUserSheet):
+ (WebCore::Document::elementSheet):
+ (WebCore::Document::testAddedStylesheetRequiresStyleRecalc):
+ (WebCore::Document::analyzeStylesheetChange):
+ * dom/Document.h:
+ (WebCore):
+ (Document):
+ (WebCore::Document::documentUserSheets):
+ * dom/ElementAttributeData.cpp:
+ (WebCore::ElementAttributeData::updateInlineStyleAvoidingMutation):
+ * dom/ProcessingInstruction.cpp:
+ (WebCore::ProcessingInstruction::setCSSStyleSheet):
+ (WebCore::ProcessingInstruction::parseStyleSheet):
+ * dom/StyleElement.cpp:
+ (WebCore::StyleElement::createSheet):
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::setInlineStyleProperty):
+ (WebCore::StyledElement::addSubresourceAttributeURLs):
+ (WebCore):
+ (WebCore::StyledElement::addPropertyToAttributeStyle):
+ * dom/StyledElement.h:
+ (WebCore):
+ * html/HTMLFontElement.cpp:
+ (WebCore::HTMLFontElement::collectStyleForAttribute):
+ * html/HTMLLinkElement.cpp:
+ (WebCore::HTMLLinkElement::parseAttribute):
+ (WebCore::HTMLLinkElement::setCSSStyleSheet):
+ (WebCore::HTMLLinkElement::styleSheetIsLoading):
+ (WebCore::HTMLLinkElement::addSubresourceAttributeURLs):
+ * html/HTMLStyleElement.cpp:
+ (WebCore::HTMLStyleElement::parseAttribute):
+ (WebCore::HTMLStyleElement::addSubresourceAttributeURLs):
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::fillMediaListChain):
+ (WebCore::InspectorStyle::setPropertyText):
+ (WebCore::InspectorStyleSheet::styleSheetURL):
+ (WebCore::InspectorStyleSheet::reparseStyleSheet):
+ (WebCore::InspectorStyleSheet::ensureSourceData):
+ (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges):
+ * page/PageSerializer.cpp:
+ (WebCore::PageSerializer::serializeCSSStyleSheet):
+ * svg/SVGStyleElement.cpp:
+ (WebCore::SVGStyleElement::parseAttribute):
+ * xml/XSLStyleSheet.h:
+ (XSLStyleSheet):
+ (WebCore::XSLStyleSheet::finalURL):
+ * xml/XSLStyleSheetLibxslt.cpp:
+ (WebCore::XSLStyleSheet::XSLStyleSheet):
+ (WebCore::XSLStyleSheet::isLoading):
+
2012-04-11 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r113912.
return result;
}
-void CSSFontFaceSrcValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
+void CSSFontFaceSrcValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetInternal* styleSheet)
{
if (!isLocal())
addSubresourceURL(urls, styleSheet->completeURL(m_resource));
String customCssText() const;
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
CachedFont* cachedFont(Document*);
namespace WebCore {
-PassRefPtr<StyleRuleImport> StyleRuleImport::create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
+PassRefPtr<StyleRuleImport> StyleRuleImport::create(StyleSheetInternal* parent, const String& href, PassRefPtr<MediaQuerySet> media)
{
return adoptRef(new StyleRuleImport(parent, href, media));
}
-StyleRuleImport::StyleRuleImport(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
+StyleRuleImport::StyleRuleImport(StyleSheetInternal* parent, const String& href, PassRefPtr<MediaQuerySet> media)
: StyleRuleBase(Import, 0)
, m_parentStyleSheet(parent)
, m_styleSheetClient(this)
{
if (m_styleSheet)
m_styleSheet->clearOwnerRule();
- m_styleSheet = CSSStyleSheet::create(this, href, baseURL, charset);
+ m_styleSheet = StyleSheetInternal::create(this, href, baseURL, charset);
bool crossOriginCSS = false;
bool validMIMEType = false;
crossOriginCSS = true;
if (crossOriginCSS && !validMIMEType && !m_styleSheet->hasSyntacticallyValidCSSHeader())
- m_styleSheet = CSSStyleSheet::create(this, href, baseURL, charset);
+ m_styleSheet = StyleSheetInternal::create(this, href, baseURL, charset);
if (isStrictParserMode(cssParserMode) && needsSiteSpecificQuirks) {
// Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>.
// while the other lacks the second trailing newline.
if (baseURL.string().endsWith(slashKHTMLFixesDotCss) && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText)
&& sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1) {
- ASSERT(m_styleSheet->length() == 1);
- ExceptionCode ec;
- m_styleSheet->deleteRule(0, ec);
+ ASSERT(m_styleSheet->childRules().size() == 1);
+ m_styleSheet->clearRules();
}
}
// Check for a cycle in our import chain. If we encounter a stylesheet
// in our parent chain with the same URL, then just bail.
- CSSStyleSheet* rootSheet = m_parentStyleSheet;
- for (CSSStyleSheet* sheet = m_parentStyleSheet; sheet; sheet = sheet->parentStyleSheet()) {
+ StyleSheetInternal* rootSheet = m_parentStyleSheet;
+ for (StyleSheetInternal* sheet = m_parentStyleSheet; sheet; sheet = sheet->parentStyleSheet()) {
// FIXME: This is wrong if the finalURL was updated via document::updateBaseURL.
if (absHref == sheet->finalURL().string())
return;
{
}
+CSSImportRule::~CSSImportRule()
+{
+ if (m_styleSheetCSSOMWrapper)
+ m_styleSheetCSSOMWrapper->clearOwnerRule();
+}
+
MediaList* CSSImportRule::media()
{
return m_importRule->mediaQueries()->ensureMediaList(parentStyleSheet());
return result.toString();
}
+CSSStyleSheet* CSSImportRule::styleSheet() const
+{
+ if (!m_importRule->styleSheet())
+ return 0;
+
+ if (!m_styleSheetCSSOMWrapper)
+ m_styleSheetCSSOMWrapper = CSSStyleSheet::create(m_importRule->styleSheet(), const_cast<CSSImportRule*>(this));
+ return m_styleSheetCSSOMWrapper.get();
+}
+
+
} // namespace WebCore
class CachedCSSStyleSheet;
class MediaList;
class MediaQuerySet;
+class StyleSheetInternal;
class StyleRuleImport : public StyleRuleBase {
public:
- static PassRefPtr<StyleRuleImport> create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
+ static PassRefPtr<StyleRuleImport> create(StyleSheetInternal* parent, const String& href, PassRefPtr<MediaQuerySet>);
~StyleRuleImport();
- CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
+ StyleSheetInternal* parentStyleSheet() const { return m_parentStyleSheet; }
void clearParentStyleSheet() { m_parentStyleSheet = 0; }
String href() const { return m_strHref; }
- CSSStyleSheet* styleSheet() const { return m_styleSheet.get(); }
+ StyleSheetInternal* styleSheet() const { return m_styleSheet.get(); }
// Not part of the CSSOM.
bool isLoading() const;
void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
friend class ImportedStyleSheetClient;
- StyleRuleImport(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
+ StyleRuleImport(StyleSheetInternal* parent, const String& href, PassRefPtr<MediaQuerySet>);
- // FXIME: This needs to go away.
- CSSStyleSheet* m_parentStyleSheet;
+ StyleSheetInternal* m_parentStyleSheet;
ImportedStyleSheetClient m_styleSheetClient;
String m_strHref;
RefPtr<MediaQuerySet> m_mediaQueries;
- RefPtr<CSSStyleSheet> m_styleSheet;
+ RefPtr<StyleSheetInternal> m_styleSheet;
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
bool m_loading;
};
class CSSImportRule : public CSSRule {
public:
static PassRefPtr<CSSImportRule> create(StyleRuleImport* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSImportRule(rule, sheet)); }
+
+ ~CSSImportRule();
String href() const { return m_importRule->href(); }
MediaList* media();
- CSSStyleSheet* styleSheet() const { return m_importRule->styleSheet(); }
+ CSSStyleSheet* styleSheet() const;
String cssText() const;
CSSImportRule(StyleRuleImport*, CSSStyleSheet*);
RefPtr<StyleRuleImport> m_importRule;
+
+ mutable RefPtr<CSSStyleSheet> m_styleSheetCSSOMWrapper;
};
} // namespace WebCore
/**
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2002, 2005, 2006, 2012 Apple Computer, Inc.
* Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
*
* This library is free software; you can redistribute it and/or
return 0;
}
- CSSParser p(cssParserMode());
- RefPtr<StyleRuleBase> newRule = p.parseRule(parentStyleSheet(), ruleString);
+ CSSStyleSheet* styleSheet = parentStyleSheet();
+ CSSParser parser(styleSheet ? styleSheet->internal()->cssParserMode() : CSSStrictMode);
+ RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->internal() : 0, ruleString);
if (!newRule) {
// SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
ec = SYNTAX_ERR;
resetRuleBodyMarks();
}
-void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string, int startLineNumber, StyleRuleRangeMap* ruleRangeMap)
+void CSSParser::parseSheet(StyleSheetInternal* sheet, const String& string, int startLineNumber, StyleRuleRangeMap* ruleRangeMap)
{
setStyleSheet(sheet);
m_defaultNamespace = starAtom; // Reset the default namespace.
m_rule = 0;
}
-PassRefPtr<StyleRuleBase> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
+PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetInternal* sheet, const String& string)
{
setStyleSheet(sheet);
m_allowNamespaceDeclarations = false;
return m_rule.release();
}
-PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string)
+PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetInternal* sheet, const String &string)
{
setStyleSheet(sheet);
setupParser("@-webkit-keyframe-rule{ ", string, "} ");
return true;
}
-PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string, CSSStyleSheet* contextStyleSheet)
+PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string, StyleSheetInternal* contextStyleSheet)
{
RefPtr<StylePropertySet> dummyStyle = StylePropertySet::create();
if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, contextStyleSheet))
return static_pointer_cast<CSSValueList>(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily));
}
-bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, CSSStyleSheet* contextStyleSheet)
+bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetInternal* contextStyleSheet)
{
if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
return true;
return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
}
-bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSStyleSheet* contextStyleSheet)
+bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetInternal* contextStyleSheet)
{
setStyleSheet(contextStyleSheet);
void CSSParser::parseSelector(const String& string, Document* doc, CSSSelectorList& selectorList)
{
- RefPtr<CSSStyleSheet> dummyStyleSheet = CSSStyleSheet::create(doc);
+ RefPtr<StyleSheetInternal> dummyStyleSheet = StyleSheetInternal::create(doc);
setStyleSheet(dummyStyleSheet.get());
m_selectorListForParseSelector = &selectorList;
ASSERT(dummyStyleSheet->hasOneRef());
}
-bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, RefPtr<CSSStyleSourceData>* styleSourceData, CSSStyleSheet* contextStyleSheet)
+bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, RefPtr<CSSStyleSourceData>* styleSourceData, StyleSheetInternal* contextStyleSheet)
{
// Length of the "@-webkit-decls{" prefix.
static const unsigned prefixLength = 15;
m_hasFontFaceOnlyValues = false;
}
-void CSSParser::setStyleSheet(CSSStyleSheet* styleSheet)
+void CSSParser::setStyleSheet(StyleSheetInternal* styleSheet)
{
m_styleSheet = styleSheet;
}
ASSERT(doc);
ASSERT(doc->cssRegionsEnabled());
- RefPtr<CSSStyleSheet> dummyStyleSheet = CSSStyleSheet::create(doc);
+ RefPtr<StyleSheetInternal> dummyStyleSheet = StyleSheetInternal::create(doc);
setStyleSheet(dummyStyleSheet.get());
setupParser("@-webkit-decls{-webkit-flow-into:", flowName, "}");
class CSSPrimitiveValue;
class CSSProperty;
class CSSSelectorList;
-class CSSStyleSheet;
class CSSValue;
class CSSValueList;
class CSSWrapShape;
class StyleRuleBase;
class StyleRuleKeyframes;
class StyleKeyframe;
+class StyleSheetInternal;
class StyledElement;
class CSSParser {
~CSSParser();
- void parseSheet(CSSStyleSheet*, const String&, int startLineNumber = 0, StyleRuleRangeMap* ruleRangeMap = 0);
- PassRefPtr<StyleRuleBase> parseRule(CSSStyleSheet*, const String&);
- PassRefPtr<StyleKeyframe> parseKeyframeRule(CSSStyleSheet*, const String&);
- static bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, CSSParserMode, CSSStyleSheet*);
+ void parseSheet(StyleSheetInternal*, const String&, int startLineNumber = 0, StyleRuleRangeMap* = 0);
+ PassRefPtr<StyleRuleBase> parseRule(StyleSheetInternal*, const String&);
+ PassRefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetInternal*, const String&);
+ static bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetInternal*);
static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool parseSystemColor(RGBA32& color, const String&, Document*);
- static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&, CSSStyleSheet* contextStyleSheet);
+ static PassRefPtr<CSSValueList> parseFontFaceValue(const AtomicString&, StyleSheetInternal* contextStyleSheet);
PassRefPtr<CSSPrimitiveValue> parseValidPrimitive(int ident, CSSParserValue*);
- bool parseDeclaration(StylePropertySet*, const String&, RefPtr<CSSStyleSourceData>*, CSSStyleSheet* contextStyleSheet);
+ bool parseDeclaration(StylePropertySet*, const String&, RefPtr<CSSStyleSourceData>*, StyleSheetInternal* contextStyleSheet);
PassOwnPtr<MediaQuery> parseMediaQuery(const String&);
Document* findDocument() const;
CSSParserMode m_cssParserMode;
bool m_important;
CSSPropertyID m_id;
- CSSStyleSheet* m_styleSheet;
+ StyleSheetInternal* m_styleSheet;
RefPtr<StyleRuleBase> m_rule;
RefPtr<StyleKeyframe> m_keyframe;
OwnPtr<MediaQuery> m_mediaQuery;
inline void detectDashToken(int);
inline void detectAtToken(int, bool);
- void setStyleSheet(CSSStyleSheet*);
+ void setStyleSheet(StyleSheetInternal*);
inline bool inStrictMode() const { return m_cssParserMode == CSSStrictMode || m_cssParserMode == SVGAttributeMode; }
inline bool inQuirksMode() const { return m_cssParserMode == CSSQuirksMode; }
bool isGeneratedImageValue(CSSParserValue*) const;
bool parseGeneratedImage(CSSParserValueList*, RefPtr<CSSValue>&);
- bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, CSSStyleSheet* contextStyleSheet);
+ bool parseValue(StylePropertySet*, CSSPropertyID, const String&, bool important, StyleSheetInternal* contextStyleSheet);
enum SizeParameterType {
None,
return text;
}
-void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
+void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetInternal* styleSheet)
{
if (m_primitiveUnitType == CSS_URI)
addSubresourceURL(urls, styleSheet->completeURL(m_value.string));
bool isQuirkValue() { return m_isQuirkValue; }
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
Length viewportPercentageLength();
return result;
}
-void CSSReflectValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
+void CSSReflectValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetInternal* styleSheet)
{
if (m_mask)
m_mask->addSubresourceStyleURLs(urls, styleSheet);
String customCssText() const;
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
private:
CSSReflectValue(CSSReflectionDirection direction, PassRefPtr<CSSPrimitiveValue> offset, PassRefPtr<CSSValue> mask)
bool isRegionRule() const { return type() == WEBKIT_REGION_RULE; }
bool isImportRule() const { return type() == IMPORT_RULE; }
- CSSParserMode cssParserMode() const
- {
- if (parentRule())
- return parentRule()->cssParserMode();
- if (parentStyleSheet())
- return parentStyleSheet()->cssParserMode();
- return CSSStrictMode;
- }
-
void setParentStyleSheet(CSSStyleSheet* styleSheet)
{
m_parentIsRule = false;
String cssText() const;
void setCssText(const String&, ExceptionCode&);
- KURL baseURL() const
- {
- if (CSSStyleSheet* parentSheet = parentStyleSheet())
- return parentSheet->baseURL();
- return KURL();
- }
-
protected:
CSSRule(CSSStyleSheet* parent, Type type)
: m_hasCachedSelectorText(false)
typedef HashMap<AtomicStringImpl*, OwnPtr<Vector<RuleData> > > AtomRuleMap;
- void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0, const ContainerNode* = 0);
+ void addRulesFromSheet(StyleSheetInternal*, const MediaQueryEvaluator&, CSSStyleSelector* = 0, const ContainerNode* = 0);
void addStyleRule(StyleRule*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
void addRule(StyleRule*, CSSSelector*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
static RuleSet* defaultQuirksStyle;
static RuleSet* defaultPrintStyle;
static RuleSet* defaultViewSourceStyle;
-static CSSStyleSheet* simpleDefaultStyleSheet;
-static CSSStyleSheet* defaultStyleSheet;
-static CSSStyleSheet* quirksStyleSheet;
-static CSSStyleSheet* svgStyleSheet;
-static CSSStyleSheet* mathMLStyleSheet;
-static CSSStyleSheet* mediaControlsStyleSheet;
-static CSSStyleSheet* fullscreenStyleSheet;
+static StyleSheetInternal* simpleDefaultStyleSheet;
+static StyleSheetInternal* defaultStyleSheet;
+static StyleSheetInternal* quirksStyleSheet;
+static StyleSheetInternal* svgStyleSheet;
+static StyleSheetInternal* mathMLStyleSheet;
+static StyleSheetInternal* mediaControlsStyleSheet;
+static StyleSheetInternal* fullscreenStyleSheet;
RenderStyle* CSSStyleSelector::s_styleNotYetAvailable;
// FIXME: This sucks! The user sheet is reparsed every time!
OwnPtr<RuleSet> tempUserStyle = RuleSet::create();
- if (CSSStyleSheet* pageUserSheet = document->pageUserSheet())
+ if (StyleSheetInternal* pageUserSheet = document->pageUserSheet())
tempUserStyle->addRulesFromSheet(pageUserSheet, *m_medium, this);
addAuthorRulesAndCollectUserRulesFromSheets(document->pageGroupUserSheets(), *tempUserStyle);
addAuthorRulesAndCollectUserRulesFromSheets(document->documentUserSheets(), *tempUserStyle);
appendAuthorStylesheets(0, document->styleSheets()->vector());
}
-void CSSStyleSelector::addAuthorRulesAndCollectUserRulesFromSheets(const Vector<RefPtr<CSSStyleSheet> >* userSheets, RuleSet& userStyle)
+void CSSStyleSelector::addAuthorRulesAndCollectUserRulesFromSheets(const Vector<RefPtr<StyleSheetInternal> >* userSheets, RuleSet& userStyle)
{
if (!userSheets)
return;
unsigned length = userSheets->size();
for (unsigned i = 0; i < length; i++) {
- const RefPtr<CSSStyleSheet>& sheet = userSheets->at(i);
+ const RefPtr<StyleSheetInternal>& sheet = userSheets->at(i);
if (sheet->isUserStyleSheet())
userStyle.addRulesFromSheet(sheet.get(), *m_medium, this);
else
}
#if ENABLE(STYLE_SCOPED)
-const ContainerNode* CSSStyleSelector::determineScope(const CSSStyleSheet* sheet)
+const ContainerNode* CSSStyleSelector::determineScope(const StyleSheetInternal* sheet)
{
ASSERT(sheet);
if (!stylesheets[i]->isCSSStyleSheet() || stylesheets[i]->disabled())
continue;
CSSStyleSheet* cssSheet = static_cast<CSSStyleSheet*>(stylesheets[i].get());
+ StyleSheetInternal* sheet = cssSheet->internal();
#if ENABLE(STYLE_SCOPED)
- const ContainerNode* scope = determineScope(cssSheet);
+ const ContainerNode* scope = determineScope(sheet);
if (scope) {
ScopedRuleSetMap::AddResult addResult = m_scopedAuthorStyles.add(scope, nullptr);
if (addResult.isNewEntry)
addResult.iterator->second = RuleSet::create();
- addResult.iterator->second->addRulesFromSheet(cssSheet, *m_medium, this, scope);
+ addResult.iterator->second->addRulesFromSheet(sheet, *m_medium, this, scope);
continue;
}
#endif
- m_authorStyle->addRulesFromSheet(cssSheet, *m_medium, this);
+ m_authorStyle->addRulesFromSheet(sheet, *m_medium, this);
if (!m_styleRuleToCSSOMWrapperMap.isEmpty())
collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, cssSheet);
}
usesLinkRules = false;
}
-static CSSStyleSheet* parseUASheet(const String& str)
+static StyleSheetInternal* parseUASheet(const String& str)
{
- CSSStyleSheet* sheet = CSSStyleSheet::create().leakRef(); // leak the sheet on purpose
+ StyleSheetInternal* sheet = StyleSheetInternal::create().leakRef(); // leak the sheet on purpose
sheet->parseString(str);
return sheet;
}
-static CSSStyleSheet* parseUASheet(const char* characters, unsigned size)
+static StyleSheetInternal* parseUASheet(const char* characters, unsigned size)
{
return parseUASheet(String(characters, size));
}
return false;
}
-bool CSSStyleSelector::determineStylesheetSelectorScopes(CSSStyleSheet* stylesheet, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes)
+bool CSSStyleSelector::determineStylesheetSelectorScopes(StyleSheetInternal* stylesheet, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes)
{
ASSERT(!stylesheet->isLoading());
m_regionSelectorsAndRuleSets.append(RuleSetSelectorPair(regionRule->selectorList().first(), regionRuleSet.release()));
}
-void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector, const ContainerNode* scope)
+void RuleSet::addRulesFromSheet(StyleSheetInternal* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector, const ContainerNode* scope)
{
ASSERT(sheet);
}
}
-static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, Document* document)
+static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, HashSet<RefPtr<CSSStyleSheet> >& sheetWrapperSet, StyleSheetInternal* styleSheet)
+{
+ if (!styleSheet)
+ return;
+ RefPtr<CSSStyleSheet> styleSheetWrapper = CSSStyleSheet::create(styleSheet);
+ sheetWrapperSet.add(styleSheetWrapper);
+ collectCSSOMWrappers(wrapperMap, styleSheetWrapper.get());
+}
+
+static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, HashSet<RefPtr<CSSStyleSheet> >& sheetWrapperSet, Document* document)
{
const Vector<RefPtr<StyleSheet> >& styleSheets = document->styleSheets()->vector();
for (unsigned i = 0; i < styleSheets.size(); ++i) {
continue;
collectCSSOMWrappers(wrapperMap, static_cast<CSSStyleSheet*>(styleSheet));
}
- collectCSSOMWrappers(wrapperMap, document->pageUserSheet());
+ collectCSSOMWrappers(wrapperMap, sheetWrapperSet, document->pageUserSheet());
}
CSSStyleRule* CSSStyleSelector::ensureFullCSSOMWrapperForInspector(StyleRule* rule)
{
if (m_styleRuleToCSSOMWrapperMap.isEmpty()) {
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, simpleDefaultStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, defaultStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, quirksStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, svgStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, mathMLStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, mediaControlsStyleSheet);
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, fullscreenStyleSheet);
-
- collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, document());
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, simpleDefaultStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, defaultStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, quirksStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, svgStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, mathMLStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, mediaControlsStyleSheet);
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, fullscreenStyleSheet);
+
+ collectCSSOMWrappers(m_styleRuleToCSSOMWrapperMap, m_styleSheetCSSOMWrapperSet, document());
}
return m_styleRuleToCSSOMWrapperMap.get(rule).get();
}
class StyleRuleRegion;
class StyleShader;
class StyleSheet;
+class StyleSheetInternal;
class StyleSheetList;
class StyledElement;
class WebKitCSSFilterValue;
void appendAuthorStylesheets(unsigned firstNew, const Vector<RefPtr<StyleSheet> >&);
// Find the ids or classes the selectors on a stylesheet are scoped to. The selectors only apply to elements in subtrees where the root element matches the scope.
- static bool determineStylesheetSelectorScopes(CSSStyleSheet*, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes);
+ static bool determineStylesheetSelectorScopes(StyleSheetInternal*, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes);
private:
void initForStyleResolve(Element*, RenderStyle* parentStyle = 0, PseudoId = NOPSEUDO);
private:
static RenderStyle* s_styleNotYetAvailable;
- void addAuthorRulesAndCollectUserRulesFromSheets(const Vector<RefPtr<CSSStyleSheet> >*, RuleSet& userStyle);
+ void addAuthorRulesAndCollectUserRulesFromSheets(const Vector<RefPtr<StyleSheetInternal> >*, RuleSet& userStyle);
void cacheBorderAndBackground();
const CSSStyleApplyProperty& m_applyProperty;
HashMap<StyleRule*, RefPtr<CSSStyleRule> > m_styleRuleToCSSOMWrapperMap;
+ HashSet<RefPtr<CSSStyleSheet> > m_styleSheetCSSOMWrapperSet;
#if ENABLE(CSS_SHADERS)
bool m_hasPendingShaders;
#endif
#if ENABLE(STYLE_SCOPED)
- static const ContainerNode* determineScope(const CSSStyleSheet*);
+ static const ContainerNode* determineScope(const StyleSheetInternal*);
typedef HashMap<const ContainerNode*, OwnPtr<RuleSet> > ScopedRuleSetMap;
/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
}
#endif
-CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& baseURL, const String& charset)
- : StyleSheet(parentNode, href, baseURL)
+StyleSheetInternal::StyleSheetInternal(Node* parentNode, const String& originalURL, const KURL& finalURL, const String& charset)
+ : m_ownerNode(parentNode)
, m_ownerRule(0)
+ , m_originalURL(originalURL)
+ , m_finalURL(finalURL)
, m_charset(charset)
, m_loadCompleted(false)
, m_cssParserMode(CSSQuirksMode)
ASSERT(isAcceptableCSSStyleSheetParent(parentNode));
}
-CSSStyleSheet::CSSStyleSheet(StyleRuleImport* ownerRule, const String& href, const KURL& baseURL, const String& charset)
- : StyleSheet(href, baseURL)
+StyleSheetInternal::StyleSheetInternal(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
+ : m_ownerNode(0)
, m_ownerRule(ownerRule)
+ , m_originalURL(originalURL)
+ , m_finalURL(finalURL)
, m_charset(charset)
, m_loadCompleted(false)
, m_cssParserMode((ownerRule && ownerRule->parentStyleSheet()) ? ownerRule->parentStyleSheet()->cssParserMode() : CSSStrictMode)
, m_hasSyntacticallyValidCSSHeader(true)
, m_didLoadErrorOccur(false)
{
- CSSStyleSheet* parentSheet = ownerRule ? ownerRule->parentStyleSheet() : 0;
+ StyleSheetInternal* parentSheet = ownerRule ? ownerRule->parentStyleSheet() : 0;
m_isUserStyleSheet = parentSheet ? parentSheet->isUserStyleSheet() : false;
}
-CSSStyleSheet::~CSSStyleSheet()
+StyleSheetInternal::~StyleSheetInternal()
{
clearRules();
}
-void CSSStyleSheet::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
+void StyleSheetInternal::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
{
ASSERT(!rule->isCharsetRule());
if (rule->isImportRule()) {
m_childRules.append(rule);
}
-PassRefPtr<CSSRule> CSSStyleSheet::createChildRuleCSSOMWrapper(unsigned index)
+PassRefPtr<CSSRule> StyleSheetInternal::createChildRuleCSSOMWrapper(unsigned index, CSSStyleSheet* parentWrapper)
{
- ASSERT(index < length());
+ ASSERT(index < ruleCount());
unsigned childVectorIndex = index;
if (hasCharsetRule()) {
if (index == 0)
- return CSSCharsetRule::create(this, m_encodingFromCharsetRule);
+ return CSSCharsetRule::create(parentWrapper, m_encodingFromCharsetRule);
--childVectorIndex;
}
if (childVectorIndex < m_importRules.size())
- return m_importRules[childVectorIndex]->createCSSOMWrapper(this);
+ return m_importRules[childVectorIndex]->createCSSOMWrapper(parentWrapper);
childVectorIndex -= m_importRules.size();
- return m_childRules[childVectorIndex]->createCSSOMWrapper(this);
+ return m_childRules[childVectorIndex]->createCSSOMWrapper(parentWrapper);
}
-unsigned CSSStyleSheet::length() const
+unsigned StyleSheetInternal::ruleCount() const
{
unsigned result = 0;
result += hasCharsetRule() ? 1 : 0;
return result;
}
-CSSRule* CSSStyleSheet::item(unsigned index)
-{
- unsigned ruleCount = length();
- if (index >= ruleCount)
- return 0;
-
- if (m_childRuleCSSOMWrappers.isEmpty())
- m_childRuleCSSOMWrappers.grow(ruleCount);
- ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount);
-
- RefPtr<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index];
- if (!cssRule)
- cssRule = createChildRuleCSSOMWrapper(index);
- return cssRule.get();
-}
-
-void CSSStyleSheet::clearCharsetRule()
+void StyleSheetInternal::clearCharsetRule()
{
m_encodingFromCharsetRule = String();
}
-void CSSStyleSheet::clearRules()
+void StyleSheetInternal::clearRules()
{
- // For style rules outside the document, .parentStyleSheet can become null even if the style rule
- // is still observable from JavaScript. This matches the behavior of .parentNode for nodes, but
- // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection.
- for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
- if (m_childRuleCSSOMWrappers[i])
- m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0);
- }
- m_childRuleCSSOMWrappers.clear();
-
for (unsigned i = 0; i < m_importRules.size(); ++i) {
ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
m_importRules[i]->clearParentStyleSheet();
clearCharsetRule();
}
-void CSSStyleSheet::parserSetEncodingFromCharsetRule(const String& encoding)
+void StyleSheetInternal::parserSetEncodingFromCharsetRule(const String& encoding)
{
// Parser enforces that there is ever only one @charset.
ASSERT(m_encodingFromCharsetRule.isNull());
m_encodingFromCharsetRule = encoding;
}
-PassRefPtr<CSSRuleList> CSSStyleSheet::rules()
-{
- KURL url = finalURL();
- Document* document = findDocument();
- if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
- return 0;
- // IE behavior.
- RefPtr<StaticCSSRuleList> nonCharsetRules = StaticCSSRuleList::create();
- unsigned ruleCount = length();
- for (unsigned i = 0; i < ruleCount; ++i) {
- CSSRule* rule = item(i);
- if (rule->isCharsetRule())
- continue;
- nonCharsetRules->rules().append(rule);
- }
- return nonCharsetRules.release();
-}
-
-unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
+bool StyleSheetInternal::wrapperInsertRule(PassRefPtr<StyleRuleBase> rule, unsigned index)
{
- ec = 0;
- if (index > length()) {
- ec = INDEX_SIZE_ERR;
- return 0;
- }
- CSSParser p(cssParserMode());
- RefPtr<StyleRuleBase> rule = p.parseRule(this, ruleString);
-
- if (!rule) {
- ec = SYNTAX_ERR;
- return 0;
- }
+ ASSERT(index <= ruleCount());
// Parser::parseRule doesn't currently allow @charset so we don't need to deal with it.
ASSERT(!rule->isCharsetRule());
if (hasCharsetRule()) {
if (childVectorIndex == 0) {
// Nothing can be inserted before @charset.
- ec = HIERARCHY_REQUEST_ERR;
- return 0;
+ return false;
}
--childVectorIndex;
}
if (childVectorIndex < m_importRules.size() || (childVectorIndex == m_importRules.size() && rule->isImportRule())) {
// Inserting non-import rule before @import is not allowed.
- if (!rule->isImportRule()) {
- ec = HIERARCHY_REQUEST_ERR;
- return 0;
- }
+ if (!rule->isImportRule())
+ return false;
m_importRules.insert(childVectorIndex, static_cast<StyleRuleImport*>(rule.get()));
m_importRules[childVectorIndex]->requestStyleSheet();
- goto success;
+ // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
+ styleSheetChanged();
+ return true;
}
// Inserting @import rule after a non-import rule is not allowed.
- if (rule->isImportRule()) {
- ec = HIERARCHY_REQUEST_ERR;
- return 0;
- }
+ if (rule->isImportRule())
+ return false;
childVectorIndex -= m_importRules.size();
- m_childRules.insert(childVectorIndex, rule.release());
+ m_childRules.insert(childVectorIndex, rule);
-success:
- if (!m_childRuleCSSOMWrappers.isEmpty())
- m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
-
- // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
styleSheetChanged();
- return index;
-}
-
-int CSSStyleSheet::addRule(const String& selector, const String& style, int index, ExceptionCode& ec)
-{
- insertRule(selector + " { " + style + " }", index, ec);
-
- // As per Microsoft documentation, always return -1.
- return -1;
-}
-
-int CSSStyleSheet::addRule(const String& selector, const String& style, ExceptionCode& ec)
-{
- return addRule(selector, style, length(), ec);
+ return true;
}
-PassRefPtr<CSSRuleList> CSSStyleSheet::cssRules()
+void StyleSheetInternal::wrapperDeleteRule(unsigned index)
{
- KURL url = finalURL();
- Document* document = findDocument();
- if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
- return 0;
- if (!m_ruleListCSSOMWrapper)
- m_ruleListCSSOMWrapper = adoptPtr(new StyleSheetCSSRuleList(this));
- return m_ruleListCSSOMWrapper.get();
-}
+ ASSERT(index < ruleCount());
-void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
-{
- if (index >= length()) {
- ec = INDEX_SIZE_ERR;
- return;
- }
-
- ec = 0;
unsigned childVectorIndex = index;
if (hasCharsetRule()) {
if (childVectorIndex == 0) {
clearCharsetRule();
- goto success;
+ styleSheetChanged();
+ return;
}
--childVectorIndex;
}
if (childVectorIndex < m_importRules.size()) {
m_importRules[childVectorIndex]->clearParentStyleSheet();
m_importRules.remove(childVectorIndex);
- goto success;
+ styleSheetChanged();
+ return;
}
childVectorIndex -= m_importRules.size();
m_childRules.remove(childVectorIndex);
-
-success:
- if (!m_childRuleCSSOMWrappers.isEmpty()) {
- if (m_childRuleCSSOMWrappers[index])
- m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
- m_childRuleCSSOMWrappers.remove(index);
- }
-
styleSheetChanged();
}
-void CSSStyleSheet::addNamespace(CSSParser* p, const AtomicString& prefix, const AtomicString& uri)
+void StyleSheetInternal::addNamespace(CSSParser* p, const AtomicString& prefix, const AtomicString& uri)
{
if (uri.isNull())
return;
p->m_defaultNamespace = uri;
}
-const AtomicString& CSSStyleSheet::determineNamespace(const AtomicString& prefix)
+const AtomicString& StyleSheetInternal::determineNamespace(const AtomicString& prefix)
{
if (prefix.isNull())
return nullAtom; // No namespace. If an element/attribute has a namespace, we won't match it.
return nullAtom; // Assume we won't match any namespaces.
}
-bool CSSStyleSheet::parseString(const String &string, CSSParserMode cssParserMode)
+bool StyleSheetInternal::parseString(const String &string, CSSParserMode cssParserMode)
{
return parseStringAtLine(string, cssParserMode, 0);
}
-bool CSSStyleSheet::parseStringAtLine(const String& string, CSSParserMode cssParserMode, int startLineNumber)
+bool StyleSheetInternal::parseStringAtLine(const String& string, CSSParserMode cssParserMode, int startLineNumber)
{
setCSSParserMode(cssParserMode);
CSSParser p(cssParserMode);
return true;
}
-bool CSSStyleSheet::isLoading()
+bool StyleSheetInternal::isLoading() const
{
for (unsigned i = 0; i < m_importRules.size(); ++i) {
if (m_importRules[i]->isLoading())
return false;
}
-void CSSStyleSheet::checkLoaded()
+void StyleSheetInternal::checkLoaded()
{
if (isLoading())
return;
// Avoid |this| being deleted by scripts that run via
// ScriptableDocumentParser::executeScriptsWaitingForStylesheets().
// See <rdar://problem/6622300>.
- RefPtr<CSSStyleSheet> protector(this);
- if (CSSStyleSheet* styleSheet = parentStyleSheet())
+ RefPtr<StyleSheetInternal> protector(this);
+ if (StyleSheetInternal* styleSheet = parentStyleSheet())
styleSheet->checkLoaded();
RefPtr<Node> owner = ownerNode();
}
}
-void CSSStyleSheet::notifyLoadedSheet(const CachedCSSStyleSheet* sheet)
+void StyleSheetInternal::notifyLoadedSheet(const CachedCSSStyleSheet* sheet)
{
ASSERT(sheet);
m_didLoadErrorOccur |= sheet->errorOccurred();
}
-void CSSStyleSheet::startLoadingDynamicSheet()
+void StyleSheetInternal::startLoadingDynamicSheet()
{
if (Node* owner = ownerNode())
owner->startLoadingDynamicSheet();
}
-Node* CSSStyleSheet::findStyleSheetOwnerNode() const
+Node* StyleSheetInternal::findStyleSheetOwnerNode() const
{
- for (const CSSStyleSheet* sheet = this; sheet; sheet = sheet->parentStyleSheet()) {
+ for (const StyleSheetInternal* sheet = this; sheet; sheet = sheet->parentStyleSheet()) {
if (Node* ownerNode = sheet->ownerNode())
return ownerNode;
}
return 0;
}
-Document* CSSStyleSheet::findDocument()
+Document* StyleSheetInternal::findDocument()
{
Node* ownerNode = findStyleSheetOwnerNode();
return ownerNode ? ownerNode->document() : 0;
}
-
-MediaList* CSSStyleSheet::media() const
-{
- if (!m_mediaQueries)
- return 0;
- return m_mediaQueries->ensureMediaList(const_cast<CSSStyleSheet*>(this));
-}
-void CSSStyleSheet::setMediaQueries(PassRefPtr<MediaQuerySet> mediaQueries)
+void StyleSheetInternal::setMediaQueries(PassRefPtr<MediaQuerySet> mediaQueries)
{
m_mediaQueries = mediaQueries;
}
-void CSSStyleSheet::styleSheetChanged()
+void StyleSheetInternal::styleSheetChanged()
{
- CSSStyleSheet* rootSheet = this;
- while (CSSStyleSheet* parent = rootSheet->parentStyleSheet())
+ StyleSheetInternal* rootSheet = this;
+ while (StyleSheetInternal* parent = rootSheet->parentStyleSheet())
rootSheet = parent;
/* FIXME: We don't need to do everything updateStyleSelector does,
if (Document* documentToUpdate = rootSheet->findDocument())
documentToUpdate->styleSelectorChanged(DeferRecalcStyle);
}
+
+KURL StyleSheetInternal::baseURL() const
+{
+ if (!m_finalURL.isNull())
+ return m_finalURL;
+ if (StyleSheetInternal* parentSheet = parentStyleSheet())
+ return parentSheet->baseURL();
+ if (!m_ownerNode)
+ return KURL();
+ return m_ownerNode->document()->baseURL();
+}
-KURL CSSStyleSheet::completeURL(const String& url) const
+KURL StyleSheetInternal::completeURL(const String& url) const
{
// Always return a null URL when passed a null string.
// FIXME: Should we change the KURL constructor to have this behavior?
return KURL(baseURL(), url, encoding);
}
-void CSSStyleSheet::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
+void StyleSheetInternal::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
{
- Deque<CSSStyleSheet*> styleSheetQueue;
+ Deque<StyleSheetInternal*> styleSheetQueue;
styleSheetQueue.append(this);
while (!styleSheetQueue.isEmpty()) {
- CSSStyleSheet* styleSheet = styleSheetQueue.takeFirst();
+ StyleSheetInternal* styleSheet = styleSheetQueue.takeFirst();
for (unsigned i = 0; i < styleSheet->m_importRules.size(); ++i) {
StyleRuleImport* importRule = styleSheet->m_importRules[i].get();
}
}
-CSSImportRule* CSSStyleSheet::ensureCSSOMWrapper(StyleRuleImport* importRule)
+StyleSheetInternal* StyleSheetInternal::parentStyleSheet() const
{
- for (unsigned i = 0; i < m_importRules.size(); ++i) {
- if (m_importRules[i] == importRule)
- return static_cast<CSSImportRule*>(item(i));
- }
- ASSERT_NOT_REACHED();
- return 0;
+ return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
}
-CSSImportRule* CSSStyleSheet::ownerRule() const
-{
- return parentStyleSheet() ? parentStyleSheet()->ensureCSSOMWrapper(m_ownerRule) : 0;
+CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetInternal> styleSheet, CSSImportRule* ownerRule)
+ : m_internal(styleSheet)
+ , m_isDisabled(false)
+ , m_ownerRule(ownerRule)
+{
}
-CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const
+CSSStyleSheet::~CSSStyleSheet()
{
- ASSERT(isCSSStyleSheet());
- return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
+ // For style rules outside the document, .parentStyleSheet can become null even if the style rule
+ // is still observable from JavaScript. This matches the behavior of .parentNode for nodes, but
+ // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection.
+ for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+ if (m_childRuleCSSOMWrappers[i])
+ m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0);
+ }
+}
+
+void CSSStyleSheet::setDisabled(bool disabled)
+{
+ if (disabled == m_isDisabled)
+ return;
+ m_isDisabled = disabled;
+ m_internal->styleSheetChanged();
+}
+
+unsigned CSSStyleSheet::length() const
+{
+ return m_internal->ruleCount();
+}
+
+CSSRule* CSSStyleSheet::item(unsigned index)
+{
+ unsigned ruleCount = length();
+ if (index >= ruleCount)
+ return 0;
+
+ if (m_childRuleCSSOMWrappers.isEmpty())
+ m_childRuleCSSOMWrappers.grow(ruleCount);
+ ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount);
+
+ RefPtr<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index];
+ if (!cssRule)
+ cssRule = m_internal->createChildRuleCSSOMWrapper(index, this);
+ return cssRule.get();
+}
+
+PassRefPtr<CSSRuleList> CSSStyleSheet::rules()
+{
+ KURL url = m_internal->finalURL();
+ Document* document = m_internal->findDocument();
+ if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
+ return 0;
+ // IE behavior.
+ RefPtr<StaticCSSRuleList> nonCharsetRules = StaticCSSRuleList::create();
+ unsigned ruleCount = length();
+ for (unsigned i = 0; i < ruleCount; ++i) {
+ CSSRule* rule = item(i);
+ if (rule->isCharsetRule())
+ continue;
+ nonCharsetRules->rules().append(rule);
+ }
+ return nonCharsetRules.release();
+}
+
+unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
+{
+ ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_internal->ruleCount());
+
+ ec = 0;
+ if (index > length()) {
+ ec = INDEX_SIZE_ERR;
+ return 0;
+ }
+ CSSParser p(m_internal->cssParserMode());
+ RefPtr<StyleRuleBase> rule = p.parseRule(m_internal.get(), ruleString);
+
+ if (!rule) {
+ ec = SYNTAX_ERR;
+ return 0;
+ }
+ bool success = m_internal->wrapperInsertRule(rule, index);
+ if (!success) {
+ ec = HIERARCHY_REQUEST_ERR;
+ return 0;
+ }
+ if (!m_childRuleCSSOMWrappers.isEmpty())
+ m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
+ return index;
+}
+
+void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
+{
+ ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_internal->ruleCount());
+
+ ec = 0;
+ if (index >= length()) {
+ ec = INDEX_SIZE_ERR;
+ return;
+ }
+ m_internal->wrapperDeleteRule(index);
+
+ if (!m_childRuleCSSOMWrappers.isEmpty()) {
+ if (m_childRuleCSSOMWrappers[index])
+ m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
+ m_childRuleCSSOMWrappers.remove(index);
+ }
+}
+
+int CSSStyleSheet::addRule(const String& selector, const String& style, int index, ExceptionCode& ec)
+{
+ insertRule(selector + " { " + style + " }", index, ec);
+
+ // As per Microsoft documentation, always return -1.
+ return -1;
+}
+
+int CSSStyleSheet::addRule(const String& selector, const String& style, ExceptionCode& ec)
+{
+ return addRule(selector, style, length(), ec);
+}
+
+
+PassRefPtr<CSSRuleList> CSSStyleSheet::cssRules()
+{
+ KURL url = m_internal->finalURL();
+ Document* document = m_internal->findDocument();
+ if (!url.isEmpty() && document && !document->securityOrigin()->canRequest(url))
+ return 0;
+ if (!m_ruleListCSSOMWrapper)
+ m_ruleListCSSOMWrapper = adoptPtr(new StyleSheetCSSRuleList(this));
+ return m_ruleListCSSOMWrapper.get();
+}
+
+MediaList* CSSStyleSheet::media() const
+{
+ if (!m_internal->mediaQueries())
+ return 0;
+ return m_internal->mediaQueries()->ensureMediaList(const_cast<CSSStyleSheet*>(this));
+}
+
+CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const
+{
+ return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
+}
+
+void CSSStyleSheet::clearChildRuleCSSOMWrappers()
+{
+ m_childRuleCSSOMWrappers.clear();
}
}
/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
class CSSParser;
class CSSRule;
class CSSRuleList;
+class CSSStyleSheet;
class CachedCSSStyleSheet;
class CachedResourceLoader;
class Document;
typedef int ExceptionCode;
-class CSSStyleSheet : public StyleSheet {
+class StyleSheetInternal : public RefCounted<StyleSheetInternal> {
public:
- static PassRefPtr<CSSStyleSheet> create()
+ static PassRefPtr<StyleSheetInternal> create()
{
- return adoptRef(new CSSStyleSheet(static_cast<StyleRuleImport*>(0), String(), KURL(), String()));
+ return adoptRef(new StyleSheetInternal(static_cast<StyleRuleImport*>(0), String(), KURL(), String()));
}
- static PassRefPtr<CSSStyleSheet> create(Node* ownerNode)
+ static PassRefPtr<StyleSheetInternal> create(Node* ownerNode)
{
- return adoptRef(new CSSStyleSheet(ownerNode, String(), KURL(), String()));
+ return adoptRef(new StyleSheetInternal(ownerNode, String(), KURL(), String()));
}
- static PassRefPtr<CSSStyleSheet> create(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset)
+ static PassRefPtr<StyleSheetInternal> create(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset)
{
- return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, charset));
+ return adoptRef(new StyleSheetInternal(ownerNode, originalURL, finalURL, charset));
}
- static PassRefPtr<CSSStyleSheet> create(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
+ static PassRefPtr<StyleSheetInternal> create(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
{
- return adoptRef(new CSSStyleSheet(ownerRule, originalURL, finalURL, charset));
+ return adoptRef(new StyleSheetInternal(ownerRule, originalURL, finalURL, charset));
}
- static PassRefPtr<CSSStyleSheet> createInline(Node* ownerNode, const KURL& finalURL)
+ static PassRefPtr<StyleSheetInternal> createInline(Node* ownerNode, const KURL& finalURL)
{
- return adoptRef(new CSSStyleSheet(ownerNode, finalURL.string(), finalURL, String()));
+ return adoptRef(new StyleSheetInternal(ownerNode, finalURL.string(), finalURL, String()));
}
- virtual ~CSSStyleSheet();
-
- virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
-
- PassRefPtr<CSSRuleList> cssRules();
- unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
- void deleteRule(unsigned index, ExceptionCode&);
-
- // IE Extensions
- PassRefPtr<CSSRuleList> rules();
- int addRule(const String& selector, const String& style, int index, ExceptionCode&);
- int addRule(const String& selector, const String& style, ExceptionCode&);
- void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
+ ~StyleSheetInternal();
void addNamespace(CSSParser*, const AtomicString& prefix, const AtomicString& uri);
const AtomicString& determineNamespace(const AtomicString& prefix);
void styleSheetChanged();
- virtual bool parseString(const String&, CSSParserMode = CSSStrictMode);
+ bool parseString(const String&, CSSParserMode = CSSStrictMode);
bool parseStringAtLine(const String&, CSSParserMode, int startLineNumber);
- virtual bool isLoading();
+ bool isLoading() const;
void checkLoaded();
void startLoadingDynamicSheet();
void clearRules();
- unsigned length() const;
- CSSRule* item(unsigned index);
-
// Rules other than @charset and @import.
const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
const Vector<RefPtr<StyleRuleImport> >& importRules() const { return m_importRules; }
- virtual MediaList* media() const OVERRIDE;
-
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
void setMediaQueries(PassRefPtr<MediaQuerySet>);
void notifyLoadedSheet(const CachedCSSStyleSheet*);
- virtual CSSImportRule* ownerRule() const OVERRIDE;
+ StyleSheetInternal* parentStyleSheet() const;
+ Node* ownerNode() const { return m_ownerNode; }
+ void clearOwnerNode() { m_ownerNode = 0; }
+ StyleRuleImport* ownerRule() const { return m_ownerRule; }
void clearOwnerRule() { m_ownerRule = 0; }
- CSSImportRule* ensureCSSOMWrapper(StyleRuleImport*);
+ // Note that href is the URL that started the redirect chain that led to
+ // this style sheet. This property probably isn't useful for much except
+ // the JavaScript binding (which needs to use this value for security).
+ String originalURL() const { return m_originalURL; }
+ String title() const { return m_title; }
+ void setTitle(const String& title) { m_title = title; }
+
+ void setFinalURL(const KURL& finalURL) { m_finalURL = finalURL; }
+ const KURL& finalURL() const { return m_finalURL; }
+ KURL baseURL() const;
-private:
- CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
- CSSStyleSheet(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
+ unsigned ruleCount() const;
+
+ bool wrapperInsertRule(PassRefPtr<StyleRuleBase>, unsigned index);
+ void wrapperDeleteRule(unsigned index);
- virtual bool isCSSStyleSheet() const { return true; }
- virtual String type() const { return "text/css"; }
+ PassRefPtr<CSSRule> createChildRuleCSSOMWrapper(unsigned index, CSSStyleSheet* parentWrapper);
+
+private:
+ StyleSheetInternal(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
+ StyleSheetInternal(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
void clearCharsetRule();
bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull(); }
- PassRefPtr<CSSRule> createChildRuleCSSOMWrapper(unsigned index);
-
+ Node* m_ownerNode;
StyleRuleImport* m_ownerRule;
+
+ String m_originalURL;
+ KURL m_finalURL;
+ String m_title;
+
String m_encodingFromCharsetRule;
Vector<RefPtr<StyleRuleImport> > m_importRules;
Vector<RefPtr<StyleRuleBase> > m_childRules;
bool m_isUserStyleSheet : 1;
bool m_hasSyntacticallyValidCSSHeader : 1;
bool m_didLoadErrorOccur : 1;
+};
+
+class CSSStyleSheet : public StyleSheet {
+public:
+ static RefPtr<CSSStyleSheet> create(PassRefPtr<StyleSheetInternal> sheet, CSSImportRule* ownerRule = 0)
+ {
+ return adoptRef(new CSSStyleSheet(sheet, ownerRule));
+ }
+
+ virtual ~CSSStyleSheet();
+
+ virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
+ virtual Node* ownerNode() const OVERRIDE { return m_internal->ownerNode(); }
+ virtual MediaList* media() const OVERRIDE;
+ virtual String href() const OVERRIDE { return m_internal->originalURL(); }
+ virtual String title() const OVERRIDE { return m_internal->title(); }
+ virtual bool disabled() const OVERRIDE { return m_isDisabled; }
+ virtual void setDisabled(bool) OVERRIDE;
+
+ PassRefPtr<CSSRuleList> cssRules();
+ unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
+ void deleteRule(unsigned index, ExceptionCode&);
+
+ // IE Extensions
+ PassRefPtr<CSSRuleList> rules();
+ int addRule(const String& selector, const String& style, int index, ExceptionCode&);
+ int addRule(const String& selector, const String& style, ExceptionCode&);
+ void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
+
+ // For CSSRuleList.
+ unsigned length() const;
+ CSSRule* item(unsigned index);
+
+ virtual void clearOwnerNode() OVERRIDE { m_internal->clearOwnerNode(); }
+ virtual CSSImportRule* ownerRule() const OVERRIDE { return m_ownerRule; }
+ virtual KURL baseURL() const OVERRIDE { return m_internal->baseURL(); }
+ virtual bool isLoading() const OVERRIDE { return m_internal->isLoading(); }
+
+ void clearOwnerRule() { m_ownerRule = 0; }
+ void styleSheetChanged() { m_internal->styleSheetChanged(); }
+ Document* findDocument() { return m_internal->findDocument(); }
+
+ void clearChildRuleCSSOMWrappers();
+
+ StyleSheetInternal* internal() const { return m_internal.get(); }
+
+private:
+ CSSStyleSheet(PassRefPtr<StyleSheetInternal>, CSSImportRule* ownerRule);
+
+ virtual bool isCSSStyleSheet() const { return true; }
+ virtual String type() const { return "text/css"; }
+
+ RefPtr<StyleSheetInternal> m_internal;
+ bool m_isDisabled;
+ CSSImportRule* m_ownerRule;
mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
};
return CSS_CUSTOM;
}
-void CSSValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
+void CSSValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetInternal* styleSheet)
{
// This should get called for internal instances only.
ASSERT(!isCSSOMSafe());
namespace WebCore {
-class CSSStyleSheet;
+class StyleSheetInternal;
// FIXME: The current CSSValue and subclasses should be turned into internal types (StyleValue).
// The few subtypes that are actually exposed in CSSOM can be seen in the cloneForCSSOM() function.
PassRefPtr<CSSValue> cloneForCSSOM() const;
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
protected:
return result.toString();
}
-void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
+void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetInternal* styleSheet)
{
size_t size = m_values.size();
for (size_t i = 0; i < size; ++i)
String customCssText() const;
- void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetInternal*);
PassRefPtr<CSSValueList> cloneForCSSOM() const;
return value;
}
-PassRefPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& string, CSSStyleSheet* contextStyleSheet)
+PassRefPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& string, StyleSheetInternal* contextStyleSheet)
{
// Just wipe out the cache and start rebuilding if it gets too big.
const int maximumFontFaceCacheSize = 128;
namespace WebCore {
class CSSValueList;
+class StyleSheetInternal;
class CSSValuePool {
public:
- PassRefPtr<CSSValueList> createFontFaceValue(const AtomicString&, CSSStyleSheet* contextStyleSheet);
+ PassRefPtr<CSSValueList> createFontFaceValue(const AtomicString&, StyleSheetInternal* contextStyleSheet);
PassRefPtr<CSSPrimitiveValue> createFontFamilyValue(const String&);
PassRefPtr<CSSInheritedValue> createInheritedValue() { return m_inheritedValue; }
PassRefPtr<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue; }
return clonedValue.get();
}
-CSSStyleSheet* PropertySetCSSStyleDeclaration::parentStyleSheet() const
+StyleSheetInternal* PropertySetCSSStyleDeclaration::contextStyleSheet() const
{
- return contextStyleSheet();
+ CSSStyleSheet* cssStyleSheet = parentStyleSheet();
+ return cssStyleSheet ? cssStyleSheet->internal() : 0;
}
PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
void StyleRuleCSSStyleDeclaration::setNeedsStyleRecalc()
{
- if (CSSStyleSheet* styleSheet = contextStyleSheet()) {
+ if (CSSStyleSheet* styleSheet = parentStyleSheet()) {
if (Document* document = styleSheet->findDocument())
document->styleSelectorChanged(DeferRecalcStyle);
}
}
-
-CSSStyleSheet* StyleRuleCSSStyleDeclaration::contextStyleSheet() const
+
+CSSStyleSheet* StyleRuleCSSStyleDeclaration::parentStyleSheet() const
{
return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
}
return;
}
-CSSStyleSheet* InlineCSSStyleDeclaration::contextStyleSheet() const
+CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
{
return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
}
class CSSRule;
class CSSProperty;
-class CSSStyleSheet;
class CSSValue;
class StylePropertySet;
+class StyleSheetInternal;
class StyledElement;
class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
virtual StyledElement* parentElement() const { return 0; }
virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
- virtual CSSStyleSheet* contextStyleSheet() const { return 0; }
+ StyleSheetInternal* contextStyleSheet() const;
virtual void ref() OVERRIDE;
virtual void deref() OVERRIDE;
virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&) OVERRIDE;
virtual bool cssPropertyMatches(const CSSProperty*) const OVERRIDE;
- virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
virtual PassRefPtr<StylePropertySet> copy() const OVERRIDE;
virtual PassRefPtr<StylePropertySet> makeMutable() OVERRIDE;
virtual void setNeedsStyleRecalc() { }
StyleRuleCSSStyleDeclaration(StylePropertySet*, CSSRule*);
virtual ~StyleRuleCSSStyleDeclaration();
+ virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
+
virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule; }
virtual void setNeedsStyleRecalc() OVERRIDE;
- virtual CSSStyleSheet* contextStyleSheet() const OVERRIDE;
unsigned m_refCount;
CSSRule* m_parentRule;
}
private:
+ virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
virtual StyledElement* parentElement() const OVERRIDE { return m_parentElement; }
virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }
virtual void setNeedsStyleRecalc() OVERRIDE;
- virtual CSSStyleSheet* contextStyleSheet() const OVERRIDE;
StyledElement* m_parentElement;
};
return property ? property->isImplicit() : false;
}
-bool StylePropertySet::setProperty(CSSPropertyID propertyID, const String& value, bool important, CSSStyleSheet* contextStyleSheet)
+bool StylePropertySet::setProperty(CSSPropertyID propertyID, const String& value, bool important, StyleSheetInternal* contextStyleSheet)
{
// Setting the value to an empty string just removes the property in both IE and Gecko.
// Setting it to null seems to produce less consistent results, but we treat it just the same.
return true;
}
-void StylePropertySet::parseDeclaration(const String& styleDeclaration, CSSStyleSheet* contextStyleSheet)
+void StylePropertySet::parseDeclaration(const String& styleDeclaration, StyleSheetInternal* contextStyleSheet)
{
m_properties.clear();
CSSParser parser(cssParserMode());
}
}
-void StylePropertySet::addSubresourceStyleURLs(ListHashSet<KURL>& urls, CSSStyleSheet* contextStyleSheet)
+void StylePropertySet::addSubresourceStyleURLs(ListHashSet<KURL>& urls, StyleSheetInternal* contextStyleSheet)
{
size_t size = m_properties.size();
for (size_t i = 0; i < size; ++i)
class PropertySetCSSStyleDeclaration;
class StyledElement;
class StylePropertyShorthand;
+class StyleSheetInternal;
class StylePropertySet : public RefCounted<StylePropertySet> {
public:
bool isPropertyImplicit(CSSPropertyID) const;
// These expand shorthand properties into multiple properties.
- bool setProperty(CSSPropertyID, const String& value, bool important = false, CSSStyleSheet* contextStyleSheet = 0);
+ bool setProperty(CSSPropertyID, const String& value, bool important = false, StyleSheetInternal* contextStyleSheet = 0);
void setProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important = false);
// These do not. FIXME: This is too messy, we can do better.
bool removeProperty(CSSPropertyID, String* returnText = 0);
- void parseDeclaration(const String& styleDeclaration, CSSStyleSheet* contextStyleSheet);
+ void parseDeclaration(const String& styleDeclaration, StyleSheetInternal* contextStyleSheet);
void addParsedProperties(const CSSProperty*, int numProperties);
void addParsedProperty(const CSSProperty&);
void setCSSParserMode(CSSParserMode cssParserMode) { m_cssParserMode = cssParserMode; }
CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cssParserMode); }
- void addSubresourceStyleURLs(ListHashSet<KURL>&, CSSStyleSheet* contextStyleSheet);
+ void addSubresourceStyleURLs(ListHashSet<KURL>&, StyleSheetInternal* contextStyleSheet);
PassRefPtr<StylePropertySet> copy() const;
// Used by StyledElement::copyNonAttributeProperties().
#include "config.h"
#include "StyleSheet.h"
-#include "CSSImportRule.h"
-#include "CSSStyleSheet.h"
-#include "Document.h"
-#include "Node.h"
-
namespace WebCore {
-StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
- : m_disabled(false)
- , m_ownerNode(parentNode)
- , m_originalURL(originalURL)
- , m_finalURL(finalURL)
-{
-}
-
-StyleSheet::StyleSheet(const String& originalURL, const KURL& finalURL)
- : m_disabled(false)
- , m_ownerNode(0)
- , m_originalURL(originalURL)
- , m_finalURL(finalURL)
-{
-}
-
StyleSheet::~StyleSheet()
{
}
-KURL StyleSheet::baseURL() const
-{
- if (!m_finalURL.isNull())
- return m_finalURL;
- if (StyleSheet* parentSheet = parentStyleSheet())
- return parentSheet->baseURL();
- if (!m_ownerNode)
- return KURL();
- return m_ownerNode->document()->baseURL();
-}
-
-void StyleSheet::setDisabled(bool disabled)
-{
- m_disabled = disabled;
- if (isCSSStyleSheet())
- static_cast<CSSStyleSheet*>(this)->styleSheetChanged();
-}
-
}
/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2008, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
public:
virtual ~StyleSheet();
- bool disabled() const { return m_disabled; }
- void setDisabled(bool);
-
- Node* ownerNode() const { return m_ownerNode; }
- void clearOwnerNode() { m_ownerNode = 0; }
-
- virtual CSSImportRule* ownerRule() const { return 0; }
-
+ virtual bool disabled() const = 0;
+ virtual void setDisabled(bool) = 0;
+ virtual Node* ownerNode() const = 0;
virtual StyleSheet* parentStyleSheet() const { return 0; }
-
- // Note that href is the URL that started the redirect chain that led to
- // this style sheet. This property probably isn't useful for much except
- // the JavaScript binding (which needs to use this value for security).
- const String& href() const { return m_originalURL; }
-
- void setFinalURL(const KURL& finalURL) { m_finalURL = finalURL; }
- const KURL& finalURL() const { return m_finalURL; }
-
- const String& title() const { return m_strTitle; }
- void setTitle(const String& s) { m_strTitle = s; }
+ virtual String href() const = 0;
+ virtual String title() const = 0;
virtual MediaList* media() const { return 0; }
-
virtual String type() const = 0;
- virtual bool isLoading() = 0;
-
- virtual bool parseString(const String&, CSSParserMode = CSSStrictMode) = 0;
+ virtual CSSImportRule* ownerRule() const { return 0; }
+ virtual void clearOwnerNode() = 0;
+ virtual KURL baseURL() const = 0;
+ virtual bool isLoading() const = 0;
virtual bool isCSSStyleSheet() const { return false; }
virtual bool isXSLStyleSheet() const { return false; }
-
- KURL baseURL() const;
-
-protected:
- StyleSheet(Node* ownerNode, const String& href, const KURL& finalURL);
- StyleSheet(const String& href, const KURL& finalURL);
-
-private:
- bool m_disabled;
- Node* m_ownerNode;
- String m_originalURL;
- KURL m_finalURL;
- String m_strTitle;
};
} // namespace
{
ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size());
- CSSParser p(cssParserMode());
- RefPtr<StyleKeyframe> keyframe = p.parseKeyframeRule(parentStyleSheet(), ruleText);
+ CSSStyleSheet* styleSheet = parentStyleSheet();
+ CSSParser parser(styleSheet ? styleSheet->internal()->cssParserMode() : CSSStrictMode);
+ RefPtr<StyleKeyframe> keyframe = parser.parseKeyframeRule(styleSheet ? styleSheet->internal() : 0, ruleText);
if (!keyframe)
return;
{
// FIXME: Title should be set.
// FIXME: Media could have wrong syntax, in which case we should generate an exception.
- RefPtr<CSSStyleSheet> sheet = CSSStyleSheet::create();
+ RefPtr<StyleSheetInternal> sheet = StyleSheetInternal::create();
sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(media));
- return sheet.release();
+ return CSSStyleSheet::create(sheet);
}
static const char* const validXMLMIMETypeChars = "[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]"; // per RFCs: 3023, 2045
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* (C) 2006 Alexey Proskuryakov (ap@webkit.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
m_baseURL = KURL();
if (m_elemSheet)
- m_elemSheet->setFinalURL(m_baseURL);
+ m_elemSheet->internal()->setFinalURL(m_baseURL);
if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) {
// Base URL change changes any relative visited links.
return true;
}
-CSSStyleSheet* Document::pageUserSheet()
+StyleSheetInternal* Document::pageUserSheet()
{
if (m_pageUserSheet)
return m_pageUserSheet.get();
return 0;
// Parse the sheet and cache it.
- m_pageUserSheet = CSSStyleSheet::createInline(this, settings()->userStyleSheetLocation());
+ m_pageUserSheet = StyleSheetInternal::createInline(this, settings()->userStyleSheetLocation());
m_pageUserSheet->setIsUserStyleSheet(true);
m_pageUserSheet->parseString(userSheetText, strictToCSSParserMode(!inQuirksMode()));
return m_pageUserSheet.get();
styleSelectorChanged(RecalcStyleImmediately);
}
-const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
+const Vector<RefPtr<StyleSheetInternal> >* Document::pageGroupUserSheets() const
{
if (m_pageGroupUserSheetCacheValid)
return m_pageGroupUserSheets.get();
continue;
if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist()))
continue;
- RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url());
+ RefPtr<StyleSheetInternal> parsedSheet = StyleSheetInternal::createInline(const_cast<Document*>(this), sheet->url());
parsedSheet->setIsUserStyleSheet(sheet->level() == UserStyleUserLevel);
parsedSheet->parseString(sheet->source(), strictToCSSParserMode(!inQuirksMode()));
if (!m_pageGroupUserSheets)
- m_pageGroupUserSheets = adoptPtr(new Vector<RefPtr<CSSStyleSheet> >);
+ m_pageGroupUserSheets = adoptPtr(new Vector<RefPtr<StyleSheetInternal> >);
m_pageGroupUserSheets->append(parsedSheet.release());
}
}
styleSelectorChanged(RecalcStyleImmediately);
}
-void Document::addUserSheet(PassRefPtr<CSSStyleSheet> userSheet)
+void Document::addUserSheet(PassRefPtr<StyleSheetInternal> userSheet)
{
if (!m_userSheets)
- m_userSheets = adoptPtr(new Vector<RefPtr<CSSStyleSheet> >);
+ m_userSheets = adoptPtr(new Vector<RefPtr<StyleSheetInternal> >);
m_userSheets->append(userSheet);
styleSelectorChanged(RecalcStyleImmediately);
}
CSSStyleSheet* Document::elementSheet()
{
if (!m_elemSheet)
- m_elemSheet = CSSStyleSheet::createInline(this, m_baseURL);
+ m_elemSheet = CSSStyleSheet::create(StyleSheetInternal::createInline(this, m_baseURL));
return m_elemSheet.get();
}
}
}
-bool Document::testAddedStylesheetRequiresStyleRecalc(CSSStyleSheet* stylesheet)
+bool Document::testAddedStylesheetRequiresStyleRecalc(StyleSheetInternal* stylesheet)
{
- if (stylesheet->disabled())
- return false;
// See if all rules on the sheet are scoped to some specific ids or classes.
// Then test if we actually have any of those in the tree at the moment.
// FIXME: Even we if we find some, we could just invalidate those subtrees instead of invalidating the entire style.
for (unsigned i = oldStylesheetCount; i < newStylesheetCount; ++i) {
if (!newStylesheets[i]->isCSSStyleSheet())
return;
- if (testAddedStylesheetRequiresStyleRecalc(static_cast<CSSStyleSheet*>(newStylesheets[i].get())))
+ if (newStylesheets[i]->disabled())
+ continue;
+ if (testAddedStylesheetRequiresStyleRecalc(static_cast<CSSStyleSheet*>(newStylesheets[i].get())->internal()))
return;
}
requiresFullStyleRecalc = false;
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* (C) 2006 Alexey Proskuryakov (ap@webkit.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2011 Google Inc. All rights reserved.
class SegmentedString;
class Settings;
class StyleSheet;
+class StyleSheetInternal;
class StyleSheetList;
class Text;
class TextResourceDecoder;
bool canNavigate(Frame* targetFrame);
bool canBeAccessedByEveryAncestorFrame();
- CSSStyleSheet* pageUserSheet();
+ StyleSheetInternal* pageUserSheet();
void clearPageUserSheet();
void updatePageUserSheet();
- const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
+ const Vector<RefPtr<StyleSheetInternal> >* pageGroupUserSheets() const;
void clearPageGroupUserSheets();
void updatePageGroupUserSheets();
- const Vector<RefPtr<CSSStyleSheet> >* documentUserSheets() const { return m_userSheets.get(); }
- void addUserSheet(PassRefPtr<CSSStyleSheet> userSheet);
+ const Vector<RefPtr<StyleSheetInternal> >* documentUserSheets() const { return m_userSheets.get(); }
+ void addUserSheet(PassRefPtr<StyleSheetInternal> userSheet);
CSSStyleSheet* elementSheet();
bool updateActiveStylesheets(StyleSelectorUpdateFlag);
void collectActiveStylesheets(Vector<RefPtr<StyleSheet> >&);
- bool testAddedStylesheetRequiresStyleRecalc(CSSStyleSheet*);
+ bool testAddedStylesheetRequiresStyleRecalc(StyleSheetInternal*);
void analyzeStylesheetChange(StyleSelectorUpdateFlag, const Vector<RefPtr<StyleSheet> >& newStylesheets, bool& requiresStyleSelectorReset, bool& requiresFullStyleRecalc);
void deleteCustomFonts();
bool m_hasNodesWithPlaceholderStyle;
RefPtr<CSSStyleSheet> m_elemSheet;
- RefPtr<CSSStyleSheet> m_pageUserSheet;
- mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
- OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_userSheets;
+ RefPtr<StyleSheetInternal> m_pageUserSheet;
+ mutable OwnPtr<Vector<RefPtr<StyleSheetInternal> > > m_pageGroupUserSheets;
+ OwnPtr<Vector<RefPtr<StyleSheetInternal> > > m_userSheets;
mutable bool m_pageGroupUserSheetCacheValid;
bool m_printing;
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Peter Kelly (pmk@post.com)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2010, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
*
* This library is free software; you can redistribute it and/or
#include "config.h"
#include "ElementAttributeData.h"
+#include "CSSStyleSheet.h"
#include "StyledElement.h"
namespace WebCore {
m_inlineStyleDecl = StylePropertySet::create();
m_inlineStyleDecl->setCSSParserMode(strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode()));
}
- m_inlineStyleDecl->parseDeclaration(text, element->document()->elementSheet());
+ m_inlineStyleDecl->parseDeclaration(text, element->document()->elementSheet()->internal());
}
void ElementAttributeData::destroyInlineStyle(StyledElement* element)
}
ASSERT(m_isCSS);
- RefPtr<CSSStyleSheet> newSheet = CSSStyleSheet::create(this, href, baseURL, charset);
- m_sheet = newSheet;
+ RefPtr<StyleSheetInternal> newSheet = StyleSheetInternal::create(this, href, baseURL, charset);
+ m_sheet = CSSStyleSheet::create(newSheet);
// We don't need the cross-origin security check here because we are
// getting the sheet text in "strict" mode. This enforces a valid CSS MIME
// type.
- parseStyleSheet(sheet->sheetText(true));
newSheet->setTitle(m_title);
newSheet->setMediaQueries(MediaQuerySet::create(m_media));
- newSheet->setDisabled(m_alternate);
+ m_sheet->setDisabled(m_alternate);
+
+ parseStyleSheet(sheet->sheetText(true));
}
#if ENABLE(XSLT)
void ProcessingInstruction::parseStyleSheet(const String& sheet)
{
- m_sheet->parseString(sheet, CSSStrictMode);
+ if (m_isCSS)
+ static_cast<CSSStyleSheet*>(m_sheet.get())->internal()->parseString(sheet, CSSStrictMode);
+ else if (m_isXSL)
+ static_cast<XSLStyleSheet*>(m_sheet.get())->parseString(sheet);
+
if (m_cachedSheet)
m_cachedSheet->removeClient(this);
m_cachedSheet = 0;
m_loading = false;
if (m_isCSS)
- static_cast<CSSStyleSheet*>(m_sheet.get())->checkLoaded();
+ static_cast<CSSStyleSheet*>(m_sheet.get())->internal()->checkLoaded();
#if ENABLE(XSLT)
else if (m_isXSL)
static_cast<XSLStyleSheet*>(m_sheet.get())->checkLoaded();
ASSERT(!m_cachedSheet);
ASSERT(!m_loading);
m_sheet = sheet;
- m_sheet->setTitle(m_title);
- m_sheet->setDisabled(m_alternate);
+ sheet->internal()->setTitle(m_title);
+ sheet->setDisabled(m_alternate);
}
bool ProcessingInstruction::offsetInCharacters() const
if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.get())) {
document->addPendingSheet();
m_loading = true;
- m_sheet = CSSStyleSheet::create(e, String(), KURL(), document->inputEncoding());
- m_sheet->parseStringAtLine(text, strictToCSSParserMode(!document->inQuirksMode()), startLineNumber);
- m_sheet->setMediaQueries(mediaQueries.release());
- m_sheet->setTitle(e->title());
+ RefPtr<StyleSheetInternal> styleSheet = StyleSheetInternal::create(e, String(), KURL(), document->inputEncoding());
+ styleSheet->parseStringAtLine(text, strictToCSSParserMode(!document->inQuirksMode()), startLineNumber);
+ styleSheet->setMediaQueries(mediaQueries.release());
+ styleSheet->setTitle(e->title());
+ m_sheet = CSSStyleSheet::create(styleSheet);
m_loading = false;
}
}
if (m_sheet)
- m_sheet->checkLoaded();
+ m_sheet->internal()->checkLoaded();
}
bool StyleElement::isLoading() const
bool StyledElement::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, bool important)
{
- bool changes = ensureAttributeData()->ensureMutableInlineStyle(this)->setProperty(propertyID, value, important, document()->elementSheet());
+ bool changes = ensureAttributeData()->ensureMutableInlineStyle(this)->setProperty(propertyID, value, important, document()->elementSheet()->internal());
if (changes)
inlineStyleChanged();
return changes;
void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
{
if (StylePropertySet* inlineStyle = attributeData() ? attributeData()->inlineStyle() : 0)
- inlineStyle->addSubresourceStyleURLs(urls, document()->elementSheet());
+ inlineStyle->addSubresourceStyleURLs(urls, document()->elementSheet()->internal());
}
static inline bool attributeNameSort(const pair<AtomicStringImpl*, AtomicString>& p1, const pair<AtomicStringImpl*, AtomicString>& p2)
{
style->setProperty(propertyID, cssValuePool().createValue(value, unit));
}
+
+void StyledElement::addPropertyToAttributeStyle(StylePropertySet* style, CSSPropertyID propertyID, const String& value)
+{
+ style->setProperty(propertyID, value, false, document()->elementSheet()->internal());
+}
}
return attributeData() ? attributeData()->attributeStyle() : 0;
}
-inline void StyledElement::addPropertyToAttributeStyle(StylePropertySet* style, CSSPropertyID propertyID, const String& value)
-{
- style->setProperty(propertyID, value, false, document()->elementSheet());
-}
-
} //namespace
#endif
#include "Attribute.h"
#include "CSSPropertyNames.h"
+#include "CSSStyleSheet.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "CSSValuePool.h"
} else if (attr->name() == colorAttr)
addHTMLColorToStyle(style, CSSPropertyColor, attr->value());
else if (attr->name() == faceAttr) {
- if (RefPtr<CSSValueList> fontFaceValue = cssValuePool().createFontFaceValue(attr->value(), document()->elementSheet()))
+ if (RefPtr<CSSValueList> fontFaceValue = cssValuePool().createFontFaceValue(attr->value(), document()->elementSheet()->internal()))
style->setProperty(CSSProperty(CSSPropertyFontFamily, fontFaceValue.release()));
} else
HTMLElement::collectStyleForAttribute(attr, style);
setAttributeEventListener(eventNames().errorEvent, createAttributeEventListener(this, attr));
else {
if (attr->name() == titleAttr && m_sheet)
- m_sheet->setTitle(attr->value());
+ m_sheet->internal()->setTitle(attr->value());
HTMLElement::parseAttribute(attr);
}
}
return;
}
- m_sheet = CSSStyleSheet::create(this, href, baseURL, charset);
+ RefPtr<StyleSheetInternal> styleSheet = StyleSheetInternal::create(this, href, baseURL, charset);
bool strictParsing = !document()->inQuirksMode();
bool enforceMIMEType = strictParsing;
#endif
String sheetText = sheet->sheetText(enforceMIMEType, &validMIMEType);
- m_sheet->parseString(sheetText, strictToCSSParserMode(strictParsing));
+ styleSheet->parseString(sheetText, strictToCSSParserMode(strictParsing));
// If we're loading a stylesheet cross-origin, and the MIME type is not
// standard, require the CSS to at least start with a syntactically
if (!document()->securityOrigin()->canRequest(baseURL))
crossOriginCSS = true;
- if (crossOriginCSS && !validMIMEType && !m_sheet->hasSyntacticallyValidCSSHeader())
- m_sheet = CSSStyleSheet::create(this, href, baseURL, charset);
+ if (crossOriginCSS && !validMIMEType && !styleSheet->hasSyntacticallyValidCSSHeader())
+ styleSheet = StyleSheetInternal::create(this, href, baseURL, charset);
if (strictParsing && needsSiteSpecificQuirks) {
// Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>.
// while the other lacks the second trailing newline.
if (baseURL.string().endsWith(slashKHTMLFixesDotCss) && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText)
&& sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1) {
- ASSERT(m_sheet->length() == 1);
- ExceptionCode ec;
- m_sheet->deleteRule(0, ec);
+ ASSERT(styleSheet->ruleCount() == 1);
+ styleSheet->clearRules();
}
}
+ m_sheet = CSSStyleSheet::create(styleSheet);
- m_sheet->setTitle(title());
+ styleSheet->setTitle(title());
RefPtr<MediaQuerySet> media = MediaQuerySet::createAllowingDescriptionSyntax(m_media);
- m_sheet->setMediaQueries(media.release());
+ styleSheet->setMediaQueries(media.release());
m_loading = false;
- m_sheet->notifyLoadedSheet(sheet);
- m_sheet->checkLoaded();
+ styleSheet->notifyLoadedSheet(sheet);
+ styleSheet->checkLoaded();
}
bool HTMLLinkElement::styleSheetIsLoading() const
return true;
if (!m_sheet)
return false;
- return m_sheet->isLoading();
+ return m_sheet->internal()->isLoading();
}
void HTMLLinkElement::linkLoaded()
// Walk the URLs linked by the linked-to stylesheet.
if (CSSStyleSheet* styleSheet = const_cast<HTMLLinkElement*>(this)->sheet())
- styleSheet->addSubresourceStyleURLs(urls);
+ styleSheet->internal()->addSubresourceStyleURLs(urls);
}
void HTMLLinkElement::addPendingSheet(PendingSheetType type)
void HTMLStyleElement::parseAttribute(Attribute* attr)
{
if (attr->name() == titleAttr && m_sheet)
- m_sheet->setTitle(attr->value());
+ m_sheet->internal()->setTitle(attr->value());
else if (attr->name() == onloadAttr)
setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
else if (attr->name() == onerrorAttr)
HTMLElement::addSubresourceAttributeURLs(urls);
if (CSSStyleSheet* styleSheet = const_cast<HTMLStyleElement*>(this)->sheet())
- styleSheet->addSubresourceStyleURLs(urls);
+ styleSheet->internal()->addSubresourceStyleURLs(urls);
}
bool HTMLStyleElement::disabled() const
mediaList = 0;
if (parentStyleSheet) {
- sourceURL = parentStyleSheet->finalURL();
+ sourceURL = parentStyleSheet->internal()->finalURL();
if (sourceURL.isEmpty())
sourceURL = InspectorDOMAgent::documentURLString(parentStyleSheet->findDocument());
} else
Document* doc = styleSheet->findDocument();
if (doc)
sourceURL = doc->url();
- else if (!styleSheet->finalURL().isEmpty())
- sourceURL = styleSheet->finalURL();
+ else if (!styleSheet->internal()->finalURL().isEmpty())
+ sourceURL = styleSheet->internal()->finalURL();
else
sourceURL = "";
mediaArray->addItem(buildMediaObject(mediaList, styleSheet->ownerNode() ? MediaListSourceLinkedSheet : MediaListSourceInlineSheet, sourceURL));
RefPtr<StylePropertySet> tempMutableStyle = StylePropertySet::create();
RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create();
CSSParser p;
- p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", &sourceData, m_style->parentStyleSheet());
+ p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", &sourceData, m_style->parentStyleSheet()->internal());
Vector<CSSPropertySourceData>& propertyData = sourceData->propertyData;
unsigned propertyCount = propertyData.size();
// static
String InspectorStyleSheet::styleSheetURL(CSSStyleSheet* pageStyleSheet)
{
- if (pageStyleSheet && !pageStyleSheet->finalURL().isEmpty())
- return pageStyleSheet->finalURL().string();
+ if (pageStyleSheet && !pageStyleSheet->internal()->finalURL().isEmpty())
+ return pageStyleSheet->internal()->finalURL().string();
return emptyString();
}
void InspectorStyleSheet::reparseStyleSheet(const String& text)
{
- m_pageStyleSheet->clearRules();
- m_pageStyleSheet->parseString(text, m_pageStyleSheet->cssParserMode());
+ m_pageStyleSheet->internal()->clearRules();
+ m_pageStyleSheet->internal()->parseString(text, m_pageStyleSheet->internal()->cssParserMode());
+ m_pageStyleSheet->clearChildRuleCSSOMWrappers();
m_pageStyleSheet->styleSheetChanged();
m_inspectorStyles.clear();
fireStyleSheetChanged();
if (!m_parsedStyleSheet->hasText())
return false;
- RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create();
+ RefPtr<StyleSheetInternal> newStyleSheet = StyleSheetInternal::create();
CSSParser p;
StyleRuleRangeMap ruleRangeMap;
p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap);
OwnPtr<ParsedStyleSheet::SourceData> rangesVector(adoptPtr(new ParsedStyleSheet::SourceData));
Vector<CSSStyleRule*> rules;
- RefPtr<CSSRuleList> ruleList = asCSSRuleList(newStyleSheet.get());
+ RefPtr<CSSRuleList> ruleList = asCSSRuleList(CSSStyleSheet::create(newStyleSheet).get());
collectFlatRules(ruleList, &rules);
for (unsigned i = 0, size = rules.size(); i < size; ++i) {
StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i)->styleRule());
RefPtr<StylePropertySet> tempDeclaration = StylePropertySet::create();
CSSParser p;
- p.parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet());
+ p.parseDeclaration(tempDeclaration.get(), m_styleText, result, m_element->document()->elementSheet()->internal());
return true;
}
if (url.isValid() && !m_resourceURLs.contains(url)) {
// FIXME: We should check whether a charset has been specified and if none was found add one.
- TextEncoding textEncoding(styleSheet->charset());
+ TextEncoding textEncoding(styleSheet->internal()->charset());
ASSERT(textEncoding.isValid());
String textString = cssText.toString();
CString text = textEncoding.encode(textString.characters(), textString.length(), EntitiesForUnencodables);
if (attr->name() == SVGNames::titleAttr) {
if (m_sheet)
- m_sheet->setTitle(attr->value());
+ m_sheet->internal()->setTitle(attr->value());
return;
}
/*
* This file is part of the XSL implementation.
*
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2008, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
}
virtual ~XSLStyleSheet();
-
- virtual bool isXSLStyleSheet() const { return true; }
-
- virtual String type() const { return "text/xml"; }
- virtual bool parseString(const String&, CSSParserMode cssParseMode = CSSStrictMode);
+ bool parseString(const String&);
- virtual bool isLoading();
void checkLoaded();
+
+ const KURL& finalURL() const { return m_finalURL; }
void loadChildSheets();
void loadChildSheet(const String& href);
CachedResourceLoader* cachedResourceLoader();
Document* ownerDocument();
- XSLStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
+ virtual XSLStyleSheet* parentStyleSheet() const OVERRIDE { return m_parentStyleSheet; }
void setParentStyleSheet(XSLStyleSheet* parent);
#if USE(QXMLQUERY)
void markAsProcessed();
bool processed() const { return m_processed; }
+
+ virtual String type() const OVERRIDE { return "text/xml"; }
+ virtual bool disabled() const OVERRIDE { return m_isDisabled; }
+ virtual void setDisabled(bool b) OVERRIDE { m_isDisabled = b; }
+ virtual Node* ownerNode() const OVERRIDE { return m_ownerNode; }
+ virtual String href() const OVERRIDE { return m_originalURL; }
+ virtual String title() const OVERRIDE { return emptyString(); }
+
+ virtual void clearOwnerNode() OVERRIDE { m_ownerNode = 0; }
+ virtual KURL baseURL() const OVERRIDE { return m_finalURL; }
+ virtual bool isLoading() const OVERRIDE;
+
+ virtual bool isXSLStyleSheet() const OVERRIDE { return true; }
private:
XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded);
#if !USE(QXMLQUERY)
XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
#endif
+
+ Node* m_ownerNode;
+ String m_originalURL;
+ KURL m_finalURL;
+ bool m_isDisabled;
Vector<OwnPtr<XSLImportRule> > m_children;
/*
* This file is part of the XSL implementation.
*
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
namespace WebCore {
XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& originalURL, const KURL& finalURL)
- : StyleSheet(static_cast<Node*>(0), originalURL, finalURL)
+ : m_ownerNode(0)
+ , m_originalURL(originalURL)
+ , m_finalURL(finalURL)
+ , m_isDisabled(false)
, m_embedded(false)
, m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them.
, m_stylesheetDoc(0)
}
XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded)
- : StyleSheet(parentNode, originalURL, finalURL)
+ : m_ownerNode(parentNode)
+ , m_originalURL(originalURL)
+ , m_finalURL(finalURL)
+ , m_isDisabled(false)
, m_embedded(embedded)
, m_processed(true) // The root sheet starts off processed.
, m_stylesheetDoc(0)
}
}
-bool XSLStyleSheet::isLoading()
+bool XSLStyleSheet::isLoading() const
{
for (unsigned i = 0; i < m_children.size(); ++i) {
if (m_children.at(i)->isLoading())
return document->cachedResourceLoader();
}
-bool XSLStyleSheet::parseString(const String& string, CSSParserMode)
+bool XSLStyleSheet::parseString(const String& string)
{
// Parse in a single chunk into an xmlDocPtr
const UChar BOM = 0xFEFF;
namespace WebCore {
XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded)
- : StyleSheet(parentNode, originalURL, finalURL)
+ : m_ownerNode(parentNode)
+ , m_originalURL(originalURL)
+ , m_finalURL(finalURL)
+ , m_isDisabled(false)
, m_embedded(embedded)
{
}
}
}
-bool XSLStyleSheet::isLoading()
+bool XSLStyleSheet::isLoading() const
{
notImplemented();
return false;
return document->cachedResourceLoader();
}
-bool XSLStyleSheet::parseString(const String& string, CSSParserMode)
+bool XSLStyleSheet::parseString(const String& string)
{
// FIXME: Fix QXmlQuery so that it allows compiling the stylesheet before setting the document
// to be transformed. This way we could not only check if the stylesheet is correct before using it
{
RefPtr<Document> document = unwrap<Document>();
- RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::create(document.get());
+ RefPtr<StyleSheetInternal> parsedSheet = StyleSheetInternal::create(document.get());
parsedSheet->setIsUserStyleSheet(level == UserStyleUserLevel);
parsedSheet->parseString(sourceCode, strictToCSSParserMode(!document->inQuirksMode()));
document->addUserSheet(parsedSheet.release());