LCOV - code coverage report
Current view: top level - layout/style - CSSVariableValues.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 35 68 51.5 %
Date: 2017-07-14 16:53:18 Functions: 6 12 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* computed CSS Variable values */
       7             : 
       8             : #include "CSSVariableValues.h"
       9             : 
      10             : #include "CSSVariableResolver.h"
      11             : 
      12             : namespace mozilla {
      13             : 
      14          15 : CSSVariableValues::CSSVariableValues()
      15             : {
      16          15 :   MOZ_COUNT_CTOR(CSSVariableValues);
      17          15 : }
      18             : 
      19           0 : CSSVariableValues::CSSVariableValues(const CSSVariableValues& aOther)
      20             : {
      21           0 :   MOZ_COUNT_CTOR(CSSVariableValues);
      22           0 :   CopyVariablesFrom(aOther);
      23           0 : }
      24             : 
      25             : #ifdef DEBUG
      26          24 : CSSVariableValues::~CSSVariableValues()
      27             : {
      28          12 :   MOZ_COUNT_DTOR(CSSVariableValues);
      29          12 : }
      30             : #endif
      31             : 
      32             : CSSVariableValues&
      33           0 : CSSVariableValues::operator=(const CSSVariableValues& aOther)
      34             : {
      35           0 :   if (this == &aOther) {
      36           0 :     return *this;
      37             :   }
      38             : 
      39           0 :   mVariableIDs.Clear();
      40           0 :   mVariables.Clear();
      41           0 :   CopyVariablesFrom(aOther);
      42           0 :   return *this;
      43             : }
      44             : 
      45             : bool
      46         171 : CSSVariableValues::operator==(const CSSVariableValues& aOther) const
      47             : {
      48         171 :   if (mVariables.Length() != aOther.mVariables.Length()) {
      49           0 :     return false;
      50             :   }
      51             : 
      52        4393 :   for (size_t thisIndex = 0; thisIndex < mVariables.Length(); ++thisIndex) {
      53             :     size_t otherIndex;
      54        4297 :     if (!aOther.mVariableIDs.Get(mVariables[thisIndex].mVariableName,
      55             :                                  &otherIndex)) {
      56          75 :       return false;
      57             :     }
      58        4297 :     const nsString& otherValue = aOther.mVariables[otherIndex].mValue;
      59        4297 :     if (!mVariables[thisIndex].mValue.Equals(otherValue)) {
      60          75 :       return false;
      61             :     }
      62             :   }
      63             : 
      64          96 :   return true;
      65             : }
      66             : 
      67             : size_t
      68           0 : CSSVariableValues::Count() const
      69             : {
      70           0 :   return mVariables.Length();
      71             : }
      72             : 
      73             : bool
      74           0 : CSSVariableValues::Get(const nsAString& aName, nsString& aValue) const
      75             : {
      76             :   size_t id;
      77           0 :   if (!mVariableIDs.Get(aName, &id)) {
      78           0 :     return false;
      79             :   }
      80           0 :   aValue = mVariables[id].mValue;
      81           0 :   return true;
      82             : }
      83             : 
      84             : bool
      85        1054 : CSSVariableValues::Get(const nsAString& aName,
      86             :                        nsString& aValue,
      87             :                        nsCSSTokenSerializationType& aFirstToken,
      88             :                        nsCSSTokenSerializationType& aLastToken) const
      89             : {
      90             :   size_t id;
      91        1054 :   if (!mVariableIDs.Get(aName, &id)) {
      92           0 :     return false;
      93             :   }
      94        1054 :   aValue = mVariables[id].mValue;
      95        1054 :   aFirstToken = mVariables[id].mFirstToken;
      96        1054 :   aLastToken = mVariables[id].mLastToken;
      97        1054 :   return true;
      98             : }
      99             : 
     100             : void
     101           0 : CSSVariableValues::GetVariableAt(size_t aIndex, nsAString& aName) const
     102             : {
     103           0 :   aName = mVariables[aIndex].mVariableName;
     104           0 : }
     105             : 
     106             : void
     107         487 : CSSVariableValues::Put(const nsAString& aName,
     108             :                        nsString aValue,
     109             :                        nsCSSTokenSerializationType aFirstToken,
     110             :                        nsCSSTokenSerializationType aLastToken)
     111             : {
     112             :   size_t id;
     113         487 :   if (mVariableIDs.Get(aName, &id)) {
     114           0 :     mVariables[id].mValue = aValue;
     115           0 :     mVariables[id].mFirstToken = aFirstToken;
     116           0 :     mVariables[id].mLastToken = aLastToken;
     117             :   } else {
     118         487 :     id = mVariables.Length();
     119         487 :     mVariableIDs.Put(aName, id);
     120         487 :     mVariables.AppendElement(Variable(aName, aValue, aFirstToken, aLastToken));
     121             :   }
     122         487 : }
     123             : 
     124             : void
     125           0 : CSSVariableValues::CopyVariablesFrom(const CSSVariableValues& aOther)
     126             : {
     127           0 :   for (size_t i = 0, n = aOther.mVariables.Length(); i < n; i++) {
     128           0 :     Put(aOther.mVariables[i].mVariableName,
     129           0 :         aOther.mVariables[i].mValue,
     130           0 :         aOther.mVariables[i].mFirstToken,
     131           0 :         aOther.mVariables[i].mLastToken);
     132             :   }
     133           0 : }
     134             : 
     135             : void
     136          12 : CSSVariableValues::AddVariablesToResolver(CSSVariableResolver* aResolver) const
     137             : {
     138         363 :   for (size_t i = 0, n = mVariables.Length(); i < n; i++) {
     139         702 :     aResolver->Put(mVariables[i].mVariableName,
     140         351 :                    mVariables[i].mValue,
     141         351 :                    mVariables[i].mFirstToken,
     142         351 :                    mVariables[i].mLastToken,
     143         351 :                    true);
     144             :   }
     145          12 : }
     146             : 
     147             : } // namespace mozilla

Generated by: LCOV version 1.13