tor-browser

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

CSSNestedDeclarations.h (3842B)


      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_CSSNestedDeclarations_h
      8 #define mozilla_CSSNestedDeclarations_h
      9 
     10 #include "mozilla/ServoBindingTypes.h"
     11 #include "mozilla/css/Rule.h"
     12 #include "nsDOMCSSDeclaration.h"
     13 
     14 namespace mozilla {
     15 
     16 class DeclarationBlock;
     17 
     18 namespace dom {
     19 class DocGroup;
     20 class CSSNestedDeclarations;
     21 
     22 class CSSNestedDeclarationsDeclaration final : public nsDOMCSSDeclaration {
     23 public:
     24  NS_DECL_ISUPPORTS_INHERITED
     25 
     26  css::Rule* GetParentRule() final;
     27  nsINode* GetAssociatedNode() const final;
     28  nsISupports* GetParentObject() const final;
     29 
     30 protected:
     31  DeclarationBlock* GetOrCreateCSSDeclaration(
     32      Operation aOperation, DeclarationBlock** aCreated) final;
     33  nsresult SetCSSDeclaration(DeclarationBlock* aDecl,
     34                             MutationClosureData* aClosureData) final;
     35  ParsingEnvironment GetParsingEnvironment(
     36      nsIPrincipal* aSubjectPrincipal) const final;
     37 
     38 private:
     39  // For accessing the constructor.
     40  friend class CSSNestedDeclarations;
     41 
     42  explicit CSSNestedDeclarationsDeclaration(
     43      already_AddRefed<StyleLockedDeclarationBlock> aDecls);
     44  ~CSSNestedDeclarationsDeclaration();
     45 
     46  inline CSSNestedDeclarations* Rule();
     47  inline const CSSNestedDeclarations* Rule() const;
     48 
     49  void SetRawAfterClone(RefPtr<StyleLockedDeclarationBlock>);
     50 
     51  RefPtr<DeclarationBlock> mDecls;
     52 };
     53 
     54 class CSSNestedDeclarations final : public css::Rule {
     55 public:
     56  CSSNestedDeclarations(
     57      already_AddRefed<StyleLockedNestedDeclarationsRule> aRawRule,
     58      StyleSheet* aSheet, css::Rule* aParentRule, uint32_t aLine,
     59      uint32_t aColumn);
     60 
     61  NS_DECL_ISUPPORTS_INHERITED
     62  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSNestedDeclarations,
     63                                                         css::Rule)
     64  bool IsCCLeaf() const final MOZ_MUST_OVERRIDE;
     65 
     66  // WebIDL interface
     67  StyleCssRuleType Type() const final;
     68  void GetCssText(nsACString& aCssText) const final;
     69  nsDOMCSSDeclaration* Style() { return &mDecls; }
     70 
     71  StyleLockedNestedDeclarationsRule* Raw() const { return mRawRule.get(); }
     72  const StyleLockedDeclarationBlock* RawStyle() const;
     73  void SetRawAfterClone(RefPtr<StyleLockedNestedDeclarationsRule>);
     74 
     75  // Methods of mozilla::css::Rule
     76  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
     77 #ifdef DEBUG
     78  void List(FILE* out = stdout, int32_t aIndent = 0) const final;
     79 #endif
     80 
     81  JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     82 
     83 private:
     84  ~CSSNestedDeclarations() = default;
     85 
     86  void GetSelectorDataAtIndex(uint32_t aSelectorIndex, bool aDesugared,
     87                              nsACString* aText, uint64_t* aSpecificity);
     88 
     89  // For computing the offset of mDecls.
     90  friend class CSSNestedDeclarationsDeclaration;
     91 
     92  RefPtr<StyleLockedNestedDeclarationsRule> mRawRule;
     93  CSSNestedDeclarationsDeclaration mDecls;
     94 };
     95 
     96 CSSNestedDeclarations* CSSNestedDeclarationsDeclaration::Rule() {
     97  return reinterpret_cast<CSSNestedDeclarations*>(
     98      reinterpret_cast<uint8_t*>(this) -
     99      offsetof(CSSNestedDeclarations, mDecls));
    100 }
    101 
    102 const CSSNestedDeclarations* CSSNestedDeclarationsDeclaration::Rule() const {
    103  return reinterpret_cast<const CSSNestedDeclarations*>(
    104      reinterpret_cast<const uint8_t*>(this) -
    105      offsetof(CSSNestedDeclarations, mDecls));
    106 }
    107 
    108 // CSSNestedDeclarations is the only rule type that doesn't end up with "Rule".
    109 // This alias helps for consistency.
    110 using CSSNestedDeclarationsRule = CSSNestedDeclarations;
    111 
    112 }  // namespace dom
    113 }  // namespace mozilla
    114 
    115 #endif  // mozilla_CSSNestedDeclarations_h