tor-browser

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

CSSUnsupportedValue.cpp (1656B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      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 "CSSUnsupportedValue.h"
      8 
      9 #include "mozilla/Assertions.h"
     10 #include "mozilla/DeclarationBlock.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 CSSUnsupportedValue::CSSUnsupportedValue(nsCOMPtr<nsISupports> aParent,
     15                                         const CSSPropertyId& aPropertyId,
     16                                         RefPtr<DeclarationBlock> aDeclarations)
     17    : CSSStyleValue(std::move(aParent), ValueType::UnsupportedValue),
     18      mPropertyId(aPropertyId),
     19      mDeclarations(std::move(aDeclarations)) {}
     20 
     21 void CSSUnsupportedValue::ToCssTextWithProperty(
     22    const CSSPropertyId& aPropertyId, nsACString& aDest) const {
     23  MOZ_ASSERT(aPropertyId == mPropertyId);
     24 
     25  if (aDest.IsEmpty()) {
     26    mDeclarations->GetPropertyValueById(mPropertyId, aDest);
     27    return;
     28  }
     29 
     30  nsAutoCString value;
     31  mDeclarations->GetPropertyValueById(mPropertyId, value);
     32 
     33  aDest.Append(value);
     34 }
     35 
     36 CSSUnsupportedValue& CSSStyleValue::GetAsCSSUnsupportedValue() {
     37  MOZ_DIAGNOSTIC_ASSERT(mValueType == ValueType::UnsupportedValue);
     38 
     39  return *static_cast<CSSUnsupportedValue*>(this);
     40 }
     41 
     42 const CSSPropertyId* CSSStyleValue::GetPropertyId() {
     43  if (!IsCSSUnsupportedValue()) {
     44    return nullptr;
     45  }
     46 
     47  CSSUnsupportedValue& unsupportedValue = GetAsCSSUnsupportedValue();
     48 
     49  return &unsupportedValue.GetPropertyId();
     50 }
     51 
     52 }  // namespace mozilla::dom