tor-browser

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

ServoCSSRuleList.h (3127B)


      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 /* representation of CSSRuleList for stylo */
      8 
      9 #ifndef mozilla_ServoCSSRuleList_h
     10 #define mozilla_ServoCSSRuleList_h
     11 
     12 #include "mozilla/ServoBindingTypes.h"
     13 #include "mozilla/dom/CSSRuleList.h"
     14 
     15 namespace mozilla {
     16 
     17 namespace dom {
     18 class CSSStyleRule;
     19 }  // namespace dom
     20 class StyleSheet;
     21 namespace css {
     22 class GroupRule;
     23 class Rule;
     24 }  // namespace css
     25 
     26 class ServoCSSRuleList final : public dom::CSSRuleList {
     27 public:
     28  ServoCSSRuleList(already_AddRefed<StyleLockedCssRules> aRawRules,
     29                   StyleSheet* aSheet, css::GroupRule* aParentRule);
     30  css::GroupRule* GetParentRule() const { return mParentRule; }
     31  void DropSheetReference();
     32  void DropParentRuleReference();
     33 
     34  void DropReferences() {
     35    DropSheetReference();
     36    DropParentRuleReference();
     37  }
     38 
     39  NS_DECL_ISUPPORTS_INHERITED
     40  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList, dom::CSSRuleList)
     41 
     42  StyleSheet* GetParentObject() final { return mStyleSheet; }
     43 
     44  css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) final;
     45  uint32_t Length() final { return mRules.Length(); }
     46 
     47  css::Rule* GetRule(uint32_t aIndex);
     48  nsresult InsertRule(const nsACString& aRule, uint32_t aIndex);
     49  nsresult DeleteRule(uint32_t aIndex);
     50 
     51  // aFromClone says whether this comes from a clone of the stylesheet (and thus
     52  // we should also fix up the wrappers for the individual rules in the rule
     53  // lists).
     54  void SetRawContents(RefPtr<StyleLockedCssRules>, bool aFromClone);
     55  void SetRawAfterClone(RefPtr<StyleLockedCssRules> aRules) {
     56    SetRawContents(std::move(aRules), /* aFromClone = */ true);
     57  }
     58 
     59 private:
     60  virtual ~ServoCSSRuleList();
     61 
     62  // XXX Is it possible to have an address lower than or equal to 255?
     63  //     Is it possible to have more than 255 CSS rule types?
     64  static const uintptr_t kMaxRuleType = UINT8_MAX;
     65 
     66  static uintptr_t CastToUint(css::Rule* aPtr) {
     67    return reinterpret_cast<uintptr_t>(aPtr);
     68  }
     69  static css::Rule* CastToPtr(uintptr_t aInt) {
     70    MOZ_ASSERT(aInt > kMaxRuleType);
     71    return reinterpret_cast<css::Rule*>(aInt);
     72  }
     73 
     74  template <typename Func>
     75  void EnumerateInstantiatedRules(Func aCallback);
     76 
     77  void DropAllRules();
     78  void ResetRules();
     79 
     80  bool IsReadOnly() const;
     81 
     82  // mStyleSheet may be nullptr when it drops the reference to us.
     83  StyleSheet* mStyleSheet = nullptr;
     84  // mParentRule is nullptr if it isn't a nested rule list.
     85  css::GroupRule* mParentRule = nullptr;
     86  RefPtr<StyleLockedCssRules> mRawRules;
     87  // Array stores either a number indicating rule type, or a pointer to
     88  // css::Rule. If the value is less than kMaxRuleType, the given rule
     89  // instance has not been constructed, and the value means the type
     90  // of the rule. Otherwise, it is a pointer.
     91  nsTArray<uintptr_t> mRules;
     92 };
     93 
     94 }  // namespace mozilla
     95 
     96 #endif  // mozilla_ServoCSSRuleList_h