tor-browser

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

CSSCustomMediaRule.cpp (3859B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=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 #include "mozilla/dom/CSSCustomMediaRule.h"
      8 
      9 #include "mozilla/DeclarationBlock.h"
     10 #include "mozilla/ServoBindings.h"
     11 #include "mozilla/dom/CSSCustomMediaRuleBinding.h"
     12 #include "mozilla/dom/CSSCustomMediaRuleBindingFwd.h"
     13 #include "mozilla/dom/MediaList.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 CSSCustomMediaRule::CSSCustomMediaRule(RefPtr<StyleCustomMediaRule> aRawRule,
     18                                       StyleSheet* aSheet,
     19                                       css::Rule* aParentRule, uint32_t aLine,
     20                                       uint32_t aColumn)
     21    : css::Rule(aSheet, aParentRule, aLine, aColumn),
     22      mRawRule(std::move(aRawRule)) {}
     23 
     24 CSSCustomMediaRule::~CSSCustomMediaRule() {
     25  if (mMediaList) {
     26    mMediaList->SetStyleSheet(nullptr);
     27  }
     28 }
     29 
     30 NS_IMPL_ADDREF_INHERITED(CSSCustomMediaRule, Rule)
     31 NS_IMPL_RELEASE_INHERITED(CSSCustomMediaRule, Rule)
     32 
     33 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSCustomMediaRule)
     34 
     35 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSCustomMediaRule)
     36 NS_INTERFACE_MAP_END_INHERITING(Rule)
     37 
     38 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSCustomMediaRule, css::Rule)
     39  if (tmp->mMediaList) {
     40    tmp->mMediaList->SetStyleSheet(nullptr);
     41    tmp->mMediaList = nullptr;
     42  }
     43 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     44 
     45 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSCustomMediaRule, css::Rule)
     46  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaList)
     47 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     48 
     49 bool CSSCustomMediaRule::IsCCLeaf() const {
     50  return Rule::IsCCLeaf() && !mMediaList;
     51 }
     52 
     53 /* virtual */
     54 void CSSCustomMediaRule::DropSheetReference() {
     55  if (mMediaList) {
     56    mMediaList->SetStyleSheet(nullptr);
     57  }
     58  Rule::DropSheetReference();
     59 }
     60 
     61 void CSSCustomMediaRule::SetRawAfterClone(RefPtr<StyleCustomMediaRule> aRaw) {
     62  mRawRule = std::move(aRaw);
     63  if (mMediaList) {
     64    mMediaList->SetRawAfterClone(
     65        Servo_CustomMediaRule_GetCondition(mRawRule, nullptr).Consume());
     66    mMediaList->SetStyleSheet(nullptr);
     67    mMediaList->SetStyleSheet(GetStyleSheet());
     68  }
     69 }
     70 
     71 // WebIDL interfaces
     72 StyleCssRuleType CSSCustomMediaRule::Type() const {
     73  return StyleCssRuleType::CustomMedia;
     74 }
     75 
     76 // CSSRule implementation
     77 
     78 void CSSCustomMediaRule::GetCssText(nsACString& aCssText) const {
     79  Servo_CustomMediaRule_GetCssText(mRawRule, &aCssText);
     80 }
     81 
     82 void CSSCustomMediaRule::GetName(nsACString& aName) const {
     83  auto* name = Servo_CustomMediaRule_GetName(mRawRule);
     84  name->ToUTF8String(aName);
     85 }
     86 
     87 void CSSCustomMediaRule::GetQuery(OwningCustomMediaQuery& aQuery) {
     88  if (mMediaList) {
     89    aQuery.SetAsMediaList() = mMediaList;
     90    return;
     91  }
     92  bool value = false;
     93  RefPtr rawMediaList =
     94      Servo_CustomMediaRule_GetCondition(mRawRule, &value).Consume();
     95  if (!rawMediaList) {
     96    aQuery.SetAsBoolean() = value;
     97    return;
     98  }
     99 
    100  mMediaList = new MediaList(rawMediaList.forget());
    101  mMediaList->SetStyleSheet(GetStyleSheet());
    102  aQuery.SetAsMediaList() = mMediaList;
    103 }
    104 
    105 size_t CSSCustomMediaRule::SizeOfIncludingThis(
    106    MallocSizeOf aMallocSizeOf) const {
    107  // TODO Implement this!
    108  return aMallocSizeOf(this);
    109 }
    110 
    111 #ifdef DEBUG
    112 void CSSCustomMediaRule::List(FILE* out, int32_t aIndent) const {
    113  nsAutoCString str;
    114  for (int32_t i = 0; i < aIndent; i++) {
    115    str.AppendLiteral("  ");
    116  }
    117  Servo_CustomMediaRule_Debug(mRawRule, &str);
    118  fprintf_stderr(out, "%s\n", str.get());
    119 }
    120 #endif
    121 
    122 JSObject* CSSCustomMediaRule::WrapObject(JSContext* aCx,
    123                                         JS::Handle<JSObject*> aGivenProto) {
    124  return CSSCustomMediaRule_Binding::Wrap(aCx, this, aGivenProto);
    125 }
    126 
    127 }  // namespace mozilla::dom