StyleSheetContents.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef StyleSheetContents_h
  21. #define StyleSheetContents_h
  22. #include "CSSParserMode.h"
  23. #include "KURL.h"
  24. #include <wtf/HashMap.h>
  25. #include <wtf/ListHashSet.h>
  26. #include <wtf/RefCounted.h>
  27. #include <wtf/Vector.h>
  28. #include <wtf/text/AtomicStringHash.h>
  29. namespace WebCore {
  30. class CSSStyleSheet;
  31. class CachedCSSStyleSheet;
  32. class Document;
  33. class Node;
  34. class SecurityOrigin;
  35. class StyleRuleBase;
  36. class StyleRuleImport;
  37. class StyleSheetContents : public RefCounted<StyleSheetContents> {
  38. public:
  39. static PassRefPtr<StyleSheetContents> create(const CSSParserContext& context = CSSParserContext(CSSStrictMode))
  40. {
  41. return adoptRef(new StyleSheetContents(0, String(), context));
  42. }
  43. static PassRefPtr<StyleSheetContents> create(const String& originalURL, const CSSParserContext& context)
  44. {
  45. return adoptRef(new StyleSheetContents(0, originalURL, context));
  46. }
  47. static PassRefPtr<StyleSheetContents> create(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
  48. {
  49. return adoptRef(new StyleSheetContents(ownerRule, originalURL, context));
  50. }
  51. ~StyleSheetContents();
  52. const CSSParserContext& parserContext() const { return m_parserContext; }
  53. const AtomicString& determineNamespace(const AtomicString& prefix);
  54. void parseAuthorStyleSheet(const CachedCSSStyleSheet*, const SecurityOrigin*);
  55. bool parseString(const String&);
  56. bool parseStringAtLine(const String&, int startLineNumber, bool);
  57. bool isCacheable() const;
  58. bool isLoading() const;
  59. void checkLoaded();
  60. void startLoadingDynamicSheet();
  61. StyleSheetContents* rootStyleSheet() const;
  62. Node* singleOwnerNode() const;
  63. Document* singleOwnerDocument() const;
  64. const String& charset() const { return m_parserContext.charset; }
  65. bool loadCompleted() const { return m_loadCompleted; }
  66. bool hasFailedOrCanceledSubresources() const;
  67. KURL completeURL(const String& url) const;
  68. void addSubresourceStyleURLs(ListHashSet<KURL>&);
  69. void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
  70. bool isUserStyleSheet() const { return m_isUserStyleSheet; }
  71. void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
  72. bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
  73. void parserAddNamespace(const AtomicString& prefix, const AtomicString& uri);
  74. void parserAppendRule(PassRefPtr<StyleRuleBase>);
  75. void parserSetEncodingFromCharsetRule(const String& encoding);
  76. void parserSetUsesRemUnits(bool b) { m_usesRemUnits = b; }
  77. void clearRules();
  78. bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull(); }
  79. String encodingFromCharsetRule() const { return m_encodingFromCharsetRule; }
  80. // Rules other than @charset and @import.
  81. const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
  82. const Vector<RefPtr<StyleRuleImport> >& importRules() const { return m_importRules; }
  83. void notifyLoadedSheet(const CachedCSSStyleSheet*);
  84. StyleSheetContents* parentStyleSheet() const;
  85. StyleRuleImport* ownerRule() const { return m_ownerRule; }
  86. void clearOwnerRule() { m_ownerRule = 0; }
  87. // Note that href is the URL that started the redirect chain that led to
  88. // this style sheet. This property probably isn't useful for much except
  89. // the JavaScript binding (which needs to use this value for security).
  90. String originalURL() const { return m_originalURL; }
  91. const KURL& baseURL() const { return m_parserContext.baseURL; }
  92. unsigned ruleCount() const;
  93. StyleRuleBase* ruleAt(unsigned index) const;
  94. bool usesRemUnits() const { return m_usesRemUnits; }
  95. unsigned estimatedSizeInBytes() const;
  96. bool wrapperInsertRule(PassRefPtr<StyleRuleBase>, unsigned index);
  97. void wrapperDeleteRule(unsigned index);
  98. PassRefPtr<StyleSheetContents> copy() const { return adoptRef(new StyleSheetContents(*this)); }
  99. void registerClient(CSSStyleSheet*);
  100. void unregisterClient(CSSStyleSheet*);
  101. bool hasOneClient() { return m_clients.size() == 1; }
  102. bool isMutable() const { return m_isMutable; }
  103. void setMutable() { m_isMutable = true; }
  104. bool isInMemoryCache() const { return m_isInMemoryCache; }
  105. void addedToMemoryCache();
  106. void removedFromMemoryCache();
  107. void shrinkToFit();
  108. private:
  109. StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext&);
  110. StyleSheetContents(const StyleSheetContents&);
  111. void clearCharsetRule();
  112. StyleRuleImport* m_ownerRule;
  113. String m_originalURL;
  114. String m_encodingFromCharsetRule;
  115. Vector<RefPtr<StyleRuleImport> > m_importRules;
  116. Vector<RefPtr<StyleRuleBase> > m_childRules;
  117. typedef HashMap<AtomicString, AtomicString> PrefixNamespaceURIMap;
  118. PrefixNamespaceURIMap m_namespaces;
  119. bool m_loadCompleted : 1;
  120. bool m_isUserStyleSheet : 1;
  121. bool m_hasSyntacticallyValidCSSHeader : 1;
  122. bool m_didLoadErrorOccur : 1;
  123. bool m_usesRemUnits : 1;
  124. bool m_isMutable : 1;
  125. bool m_isInMemoryCache : 1;
  126. CSSParserContext m_parserContext;
  127. Vector<CSSStyleSheet*> m_clients;
  128. };
  129. } // namespace
  130. #endif