tor-browser

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

CSSKeywordValue.cpp (2343B)


      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 "mozilla/dom/CSSKeywordValue.h"
      8 
      9 #include "mozilla/AlreadyAddRefed.h"
     10 #include "mozilla/ErrorResult.h"
     11 #include "mozilla/RefPtr.h"
     12 #include "mozilla/dom/BindingDeclarations.h"
     13 #include "mozilla/dom/CSSKeywordValueBinding.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 CSSKeywordValue::CSSKeywordValue(nsCOMPtr<nsISupports> aParent,
     18                                 const nsACString& aValue)
     19    : CSSStyleValue(std::move(aParent), ValueType::KeywordValue),
     20      mValue(aValue) {}
     21 
     22 JSObject* CSSKeywordValue::WrapObject(JSContext* aCx,
     23                                      JS::Handle<JSObject*> aGivenProto) {
     24  return CSSKeywordValue_Binding::Wrap(aCx, this, aGivenProto);
     25 }
     26 
     27 // start of CSSKeywordValue Web IDL implementation
     28 
     29 // https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-csskeywordvalue
     30 //
     31 // static
     32 already_AddRefed<CSSKeywordValue> CSSKeywordValue::Constructor(
     33    const GlobalObject& aGlobal, const nsACString& aValue, ErrorResult& aRv) {
     34  // Step 1.
     35 
     36  if (aValue.IsEmpty()) {
     37    aRv.ThrowTypeError("CSSKeywordValue does not support empty strings");
     38    return nullptr;
     39  }
     40 
     41  // Step 2.
     42 
     43  return MakeAndAddRef<CSSKeywordValue>(aGlobal.GetAsSupports(), aValue);
     44 }
     45 
     46 void CSSKeywordValue::GetValue(nsCString& aRetVal) const { aRetVal = mValue; }
     47 
     48 // https://drafts.css-houdini.org/css-typed-om-1/#dom-csskeywordvalue-value
     49 void CSSKeywordValue::SetValue(const nsACString& aArg, ErrorResult& aRv) {
     50  // Step 1.
     51 
     52  if (aArg.IsEmpty()) {
     53    aRv.ThrowTypeError("CSSKeywordValue does not support empty strings");
     54    return;
     55  }
     56 
     57  // Step 2.
     58 
     59  mValue = aArg;
     60 }
     61 
     62 // end of CSSKeywordValue Web IDL implementation
     63 
     64 void CSSKeywordValue::ToCssTextWithProperty(const CSSPropertyId& aPropertyId,
     65                                            nsACString& aDest) const {
     66  aDest.Append(mValue);
     67 }
     68 
     69 CSSKeywordValue& CSSStyleValue::GetAsCSSKeywordValue() {
     70  MOZ_DIAGNOSTIC_ASSERT(mValueType == ValueType::KeywordValue);
     71 
     72  return *static_cast<CSSKeywordValue*>(this);
     73 }
     74 
     75 }  // namespace mozilla::dom