LCOV - code coverage report
Current view: top level - layout/style - ServoKeyframeRule.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 93 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 45 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "mozilla/ServoKeyframeRule.h"
       8             : 
       9             : #include "nsDOMCSSDeclaration.h"
      10             : #include "mozAutoDocUpdate.h"
      11             : 
      12             : namespace mozilla {
      13             : 
      14             : // -------------------------------------------
      15             : // ServoKeyframeDeclaration
      16             : //
      17             : 
      18             : class ServoKeyframeDeclaration : public nsDOMCSSDeclaration
      19             : {
      20             : public:
      21           0 :   explicit ServoKeyframeDeclaration(ServoKeyframeRule* aRule)
      22           0 :     : mRule(aRule)
      23             :   {
      24             :     mDecls = new ServoDeclarationBlock(
      25           0 :       Servo_Keyframe_GetStyle(aRule->Raw()).Consume());
      26           0 :   }
      27             : 
      28             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      29           0 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
      30             :     ServoKeyframeDeclaration, nsICSSDeclaration)
      31             : 
      32           0 :   NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParent) final
      33             :   {
      34           0 :     *aParent = mRule;
      35           0 :     return NS_OK;
      36             :   }
      37             : 
      38           0 :   void DropReference() { mRule = nullptr; }
      39             : 
      40           0 :   DeclarationBlock* GetCSSDeclaration(Operation aOperation) final
      41             :   {
      42           0 :     return mDecls;
      43             :   }
      44           0 :   nsresult SetCSSDeclaration(DeclarationBlock* aDecls) final
      45             :   {
      46           0 :     if (!mRule) {
      47           0 :       return NS_OK;
      48             :     }
      49           0 :     mRule->UpdateRule([this, aDecls]() {
      50           0 :       if (mDecls != aDecls) {
      51           0 :         mDecls->SetOwningRule(nullptr);
      52           0 :         mDecls = aDecls->AsServo();
      53           0 :         mDecls->SetOwningRule(mRule);
      54           0 :         Servo_Keyframe_SetStyle(mRule->Raw(), mDecls->Raw());
      55             :       }
      56           0 :     });
      57           0 :     return NS_OK;
      58             :   }
      59           0 :   void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) final
      60             :   {
      61           0 :     MOZ_ASSERT_UNREACHABLE("GetCSSParsingEnvironment "
      62             :                            "shouldn't be calling for a Servo rule");
      63             :     GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
      64             :   }
      65           0 :   ServoCSSParsingEnvironment GetServoCSSParsingEnvironment() const final
      66             :   {
      67           0 :     return GetServoCSSParsingEnvironmentForRule(mRule);
      68             :   }
      69           0 :   nsIDocument* DocToUpdate() final { return nullptr; }
      70             : 
      71           0 :   nsINode* GetParentObject() final
      72             :   {
      73           0 :     return mRule ? mRule->GetDocument() : nullptr;
      74             :   }
      75             : 
      76           0 :   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
      77             :   {
      78           0 :     size_t n = aMallocSizeOf(this);
      79             :     // TODO we may want to add size of mDecls as well
      80           0 :     return n;
      81             :   }
      82             : 
      83             : private:
      84           0 :   virtual ~ServoKeyframeDeclaration() {}
      85             : 
      86             :   ServoKeyframeRule* mRule;
      87             :   RefPtr<ServoDeclarationBlock> mDecls;
      88             : };
      89             : 
      90           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(ServoKeyframeDeclaration)
      91           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(ServoKeyframeDeclaration)
      92             : 
      93           0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(ServoKeyframeDeclaration)
      94             : 
      95           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServoKeyframeDeclaration)
      96           0 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
      97           0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
      98             : 
      99             : // -------------------------------------------
     100             : // ServoKeyframeRule
     101             : //
     102             : 
     103           0 : ServoKeyframeRule::~ServoKeyframeRule()
     104             : {
     105           0 : }
     106             : 
     107           0 : NS_IMPL_ADDREF_INHERITED(ServoKeyframeRule, dom::CSSKeyframeRule)
     108           0 : NS_IMPL_RELEASE_INHERITED(ServoKeyframeRule, dom::CSSKeyframeRule)
     109             : 
     110             : // QueryInterface implementation for nsCSSKeyframeRule
     111           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServoKeyframeRule)
     112           0 : NS_INTERFACE_MAP_END_INHERITING(dom::CSSKeyframeRule)
     113             : 
     114             : NS_IMPL_CYCLE_COLLECTION_CLASS(ServoKeyframeRule)
     115             : 
     116           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ServoKeyframeRule,
     117             :                                                 dom::CSSKeyframeRule)
     118           0 :   if (tmp->mDeclaration) {
     119           0 :     tmp->mDeclaration->DropReference();
     120           0 :     tmp->mDeclaration = nullptr;
     121             :   }
     122           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     123           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoKeyframeRule,
     124             :                                                   dom::CSSKeyframeRule)
     125           0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration)
     126           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     127             : 
     128             : bool
     129           0 : ServoKeyframeRule::IsCCLeaf() const
     130             : {
     131           0 :   return Rule::IsCCLeaf() && !mDeclaration;
     132             : }
     133             : 
     134             : /* virtual */ already_AddRefed<css::Rule>
     135           0 : ServoKeyframeRule::Clone() const
     136             : {
     137             :   // Rule::Clone is only used when CSSStyleSheetInner is cloned in
     138             :   // preparation of being mutated. However, ServoStyleSheet never clones
     139             :   // anything, so this method should never be called.
     140           0 :   MOZ_ASSERT_UNREACHABLE("Shouldn't be cloning ServoKeyframeRule");
     141             :   return nullptr;
     142             : }
     143             : 
     144             : #ifdef DEBUG
     145             : /* virtual */ void
     146           0 : ServoKeyframeRule::List(FILE* out, int32_t aIndent) const
     147             : {
     148           0 :   nsAutoCString str;
     149           0 :   for (int32_t i = 0; i < aIndent; i++) {
     150           0 :     str.AppendLiteral("  ");
     151             :   }
     152           0 :   Servo_Keyframe_Debug(mRaw, &str);
     153           0 :   fprintf_stderr(out, "%s\n", str.get());
     154           0 : }
     155             : #endif
     156             : 
     157             : template<typename Func>
     158             : void
     159           0 : ServoKeyframeRule::UpdateRule(Func aCallback)
     160             : {
     161           0 :   nsIDocument* doc = GetDocument();
     162           0 :   MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
     163             : 
     164           0 :   aCallback();
     165             : 
     166           0 :   if (StyleSheet* sheet = GetStyleSheet()) {
     167             :     // FIXME sheet->AsGecko()->SetModifiedByChildRule();
     168           0 :     if (doc) {
     169           0 :       doc->StyleRuleChanged(sheet, this);
     170             :     }
     171             :   }
     172           0 : }
     173             : 
     174             : NS_IMETHODIMP
     175           0 : ServoKeyframeRule::GetKeyText(nsAString& aKeyText)
     176             : {
     177           0 :   Servo_Keyframe_GetKeyText(mRaw, &aKeyText);
     178           0 :   return NS_OK;
     179             : }
     180             : 
     181             : NS_IMETHODIMP
     182           0 : ServoKeyframeRule::SetKeyText(const nsAString& aKeyText)
     183             : {
     184           0 :   NS_ConvertUTF16toUTF8 keyText(aKeyText);
     185           0 :   UpdateRule([this, &keyText]() {
     186           0 :     Servo_Keyframe_SetKeyText(mRaw, &keyText);
     187           0 :   });
     188           0 :   return NS_OK;
     189             : }
     190             : 
     191             : void
     192           0 : ServoKeyframeRule::GetCssTextImpl(nsAString& aCssText) const
     193             : {
     194           0 :   Servo_Keyframe_GetCssText(mRaw, &aCssText);
     195           0 : }
     196             : 
     197             : nsICSSDeclaration*
     198           0 : ServoKeyframeRule::Style()
     199             : {
     200           0 :   if (!mDeclaration) {
     201           0 :     mDeclaration = new ServoKeyframeDeclaration(this);
     202             :   }
     203           0 :   return mDeclaration;
     204             : }
     205             : 
     206             : size_t
     207           0 : ServoKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
     208             : {
     209           0 :   size_t n = aMallocSizeOf(this);
     210           0 :   if (mDeclaration) {
     211           0 :     n += mDeclaration->SizeOfIncludingThis(aMallocSizeOf);
     212             :   }
     213           0 :   return n;
     214             : }
     215             : 
     216             : } // namespace mozilla

Generated by: LCOV version 1.13