CSSStyleSheet.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2012, 2013 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 CSSStyleSheet_h
  21. #define CSSStyleSheet_h
  22. #include "CSSParserMode.h"
  23. #include "CSSRule.h"
  24. #include "StyleSheet.h"
  25. #include <wtf/HashMap.h>
  26. #include <wtf/Noncopyable.h>
  27. #include <wtf/text/AtomicStringHash.h>
  28. namespace WebCore {
  29. class CSSCharsetRule;
  30. class CSSImportRule;
  31. class CSSParser;
  32. class CSSRule;
  33. class CSSRuleList;
  34. class CSSStyleSheet;
  35. class CachedCSSStyleSheet;
  36. class Document;
  37. class MediaQuerySet;
  38. class SecurityOrigin;
  39. class StyleSheetContents;
  40. typedef int ExceptionCode;
  41. class CSSStyleSheet : public StyleSheet {
  42. public:
  43. static PassRefPtr<CSSStyleSheet> create(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule = 0);
  44. static PassRefPtr<CSSStyleSheet> create(PassRefPtr<StyleSheetContents>, Node* ownerNode);
  45. static PassRefPtr<CSSStyleSheet> createInline(Node*, const KURL&, const String& encoding = String());
  46. virtual ~CSSStyleSheet();
  47. virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
  48. virtual Node* ownerNode() const OVERRIDE { return m_ownerNode; }
  49. virtual MediaList* media() const OVERRIDE;
  50. virtual String href() const OVERRIDE;
  51. virtual String title() const OVERRIDE { return m_title; }
  52. virtual bool disabled() const OVERRIDE { return m_isDisabled; }
  53. virtual void setDisabled(bool) OVERRIDE;
  54. PassRefPtr<CSSRuleList> cssRules();
  55. unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
  56. void deleteRule(unsigned index, ExceptionCode&);
  57. // IE Extensions
  58. PassRefPtr<CSSRuleList> rules();
  59. int addRule(const String& selector, const String& style, int index, ExceptionCode&);
  60. int addRule(const String& selector, const String& style, ExceptionCode&);
  61. void removeRule(unsigned index, ExceptionCode& ec) { deleteRule(index, ec); }
  62. // For CSSRuleList.
  63. unsigned length() const;
  64. CSSRule* item(unsigned index);
  65. virtual void clearOwnerNode() OVERRIDE;
  66. virtual CSSImportRule* ownerRule() const OVERRIDE { return m_ownerRule; }
  67. virtual KURL baseURL() const OVERRIDE;
  68. virtual bool isLoading() const OVERRIDE;
  69. void clearOwnerRule() { m_ownerRule = 0; }
  70. Document* ownerDocument() const;
  71. MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
  72. void setMediaQueries(PassRefPtr<MediaQuerySet>);
  73. void setTitle(const String& title) { m_title = title; }
  74. enum RuleMutationType { OtherMutation, RuleInsertion };
  75. enum WhetherContentsWereClonedForMutation { ContentsWereNotClonedForMutation = 0, ContentsWereClonedForMutation };
  76. class RuleMutationScope {
  77. WTF_MAKE_NONCOPYABLE(RuleMutationScope);
  78. public:
  79. RuleMutationScope(CSSStyleSheet*, RuleMutationType = OtherMutation);
  80. RuleMutationScope(CSSRule*);
  81. ~RuleMutationScope();
  82. private:
  83. CSSStyleSheet* m_styleSheet;
  84. RuleMutationType m_mutationType;
  85. WhetherContentsWereClonedForMutation m_contentsWereClonedForMutation;
  86. };
  87. WhetherContentsWereClonedForMutation willMutateRules();
  88. void didMutateRules(RuleMutationType, WhetherContentsWereClonedForMutation);
  89. void didMutateRuleFromCSSStyleDeclaration();
  90. void didMutate();
  91. void clearChildRuleCSSOMWrappers();
  92. void reattachChildRuleCSSOMWrappers();
  93. StyleSheetContents* contents() const { return m_contents.get(); }
  94. private:
  95. CSSStyleSheet(PassRefPtr<StyleSheetContents>, CSSImportRule* ownerRule);
  96. CSSStyleSheet(PassRefPtr<StyleSheetContents>, Node* ownerNode, bool isInlineStylesheet);
  97. virtual bool isCSSStyleSheet() const { return true; }
  98. virtual String type() const { return ASCIILiteral("text/css"); }
  99. bool canAccessRules() const;
  100. RefPtr<StyleSheetContents> m_contents;
  101. bool m_isInlineStylesheet;
  102. bool m_isDisabled;
  103. String m_title;
  104. RefPtr<MediaQuerySet> m_mediaQueries;
  105. Node* m_ownerNode;
  106. CSSImportRule* m_ownerRule;
  107. mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
  108. mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
  109. mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
  110. };
  111. } // namespace
  112. #endif