tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CSSStyleRule.h (4640B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_CSSStyleRule_h
      8 #define mozilla_CSSStyleRule_h
      9 
     10 #include "mozilla/ServoBindingTypes.h"
     11 #include "mozilla/css/GroupRule.h"
     12 #include "nsDOMCSSDeclaration.h"
     13 
     14 namespace mozilla {
     15 
     16 class DeclarationBlock;
     17 
     18 namespace dom {
     19 class DocGroup;
     20 class CSSStyleRule;
     21 struct SelectorWarning;
     22 class StylePropertyMap;
     23 
     24 class CSSStyleRuleDeclaration final : public nsDOMCSSDeclaration {
     25 public:
     26  NS_DECL_ISUPPORTS_INHERITED
     27 
     28  css::Rule* GetParentRule() final;
     29  nsINode* GetAssociatedNode() const final;
     30  nsISupports* GetParentObject() const final;
     31 
     32 protected:
     33  DeclarationBlock* GetOrCreateCSSDeclaration(
     34      Operation aOperation, DeclarationBlock** aCreated) final;
     35  nsresult SetCSSDeclaration(DeclarationBlock* aDecl,
     36                             MutationClosureData* aClosureData) final;
     37  ParsingEnvironment GetParsingEnvironment(
     38      nsIPrincipal* aSubjectPrincipal) const final;
     39 
     40 private:
     41  // For accessing the constructor.
     42  friend class CSSStyleRule;
     43 
     44  explicit CSSStyleRuleDeclaration(
     45      already_AddRefed<StyleLockedDeclarationBlock> aDecls);
     46  ~CSSStyleRuleDeclaration();
     47 
     48  inline CSSStyleRule* Rule();
     49  inline const CSSStyleRule* Rule() const;
     50 
     51  void SetRawAfterClone(RefPtr<StyleLockedDeclarationBlock>);
     52 
     53  RefPtr<DeclarationBlock> mDecls;
     54 };
     55 
     56 class CSSStyleRule final : public css::GroupRule {
     57 public:
     58  CSSStyleRule(already_AddRefed<StyleLockedStyleRule> aRawRule,
     59               StyleSheet* aSheet, css::Rule* aParentRule, uint32_t aLine,
     60               uint32_t aColumn);
     61 
     62  NS_DECL_ISUPPORTS_INHERITED
     63  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSStyleRule,
     64                                                         css::GroupRule)
     65  bool IsCCLeaf() const final MOZ_MUST_OVERRIDE;
     66 
     67  uint32_t SelectorCount() const;
     68  void SelectorTextAt(uint32_t aSelectorIndex, bool aDesugared,
     69                      nsACString& aText);
     70  uint64_t SelectorSpecificityAt(uint32_t aSelectorIndex, bool aDesugared);
     71  bool SelectorMatchesElement(uint32_t aSelectorIndex, dom::Element&,
     72                              const nsAString& aPseudo,
     73                              bool aRelevantLinkVisited);
     74  Element* GetScopeRootFor(uint32_t aSelectorIndex, dom::Element&,
     75                           const nsAString& aPseudo, bool aRelevantLinkVisited);
     76  DeclarationBlock& GetDeclarationBlock() const;
     77  void GetSelectorWarnings(nsTArray<SelectorWarning>& aResult) const;
     78  already_AddRefed<nsINodeList> QuerySelectorAll(nsINode& aRoot);
     79 
     80  // WebIDL interface
     81  StyleCssRuleType Type() const final;
     82  void GetCssText(nsACString& aCssText) const final;
     83  void GetSelectorText(nsACString& aSelectorText);
     84  void SetSelectorText(const nsACString& aSelectorText);
     85  nsDOMCSSDeclaration* Style() { return &mDecls; }
     86 
     87  // If we wanted to follow the declaration order in CSSStyleRule.webidl,
     88  // chromeonly Web IDL stuff would be declared here, but it's currently
     89  // declared above.
     90 
     91  StylePropertyMap* StyleMap();
     92 
     93  StyleLockedStyleRule* Raw() const { return mRawRule; }
     94  const StyleLockedDeclarationBlock* RawStyle() const;
     95  void SetRawAfterClone(RefPtr<StyleLockedStyleRule>);
     96  already_AddRefed<StyleLockedCssRules> GetOrCreateRawRules() final;
     97 
     98  // Methods of mozilla::css::Rule
     99  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
    100 #ifdef DEBUG
    101  void List(FILE* out = stdout, int32_t aIndent = 0) const final;
    102 #endif
    103 
    104  JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
    105 
    106 private:
    107  ~CSSStyleRule() = default;
    108 
    109  void GetSelectorDataAtIndex(uint32_t aSelectorIndex, bool aDesugared,
    110                              nsACString* aText, uint64_t* aSpecificity);
    111 
    112  // For computing the offset of mDecls.
    113  friend class CSSStyleRuleDeclaration;
    114 
    115  RefPtr<StyleLockedStyleRule> mRawRule;
    116  RefPtr<StylePropertyMap> mStyleMap;
    117  CSSStyleRuleDeclaration mDecls;
    118 };
    119 
    120 CSSStyleRule* CSSStyleRuleDeclaration::Rule() {
    121  return reinterpret_cast<CSSStyleRule*>(reinterpret_cast<uint8_t*>(this) -
    122                                         offsetof(CSSStyleRule, mDecls));
    123 }
    124 
    125 const CSSStyleRule* CSSStyleRuleDeclaration::Rule() const {
    126  return reinterpret_cast<const CSSStyleRule*>(
    127      reinterpret_cast<const uint8_t*>(this) - offsetof(CSSStyleRule, mDecls));
    128 }
    129 
    130 }  // namespace dom
    131 }  // namespace mozilla
    132 
    133 #endif  // mozilla_CSSStyleRule_h