LCOV - code coverage report
Current view: top level - layout/style - nsDOMCSSDeclaration.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 6 33.3 %
Date: 2017-07-14 16:53:18 Functions: 3 4 75.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             : /* base class for DOM objects for element.style and cssStyleRule.style */
       7             : 
       8             : #ifndef nsDOMCSSDeclaration_h___
       9             : #define nsDOMCSSDeclaration_h___
      10             : 
      11             : #include "nsICSSDeclaration.h"
      12             : 
      13             : #include "mozilla/Attributes.h"
      14             : #include "mozilla/URLExtraData.h"
      15             : #include "nsIURI.h"
      16             : #include "nsCOMPtr.h"
      17             : #include "nsCompatibility.h"
      18             : 
      19             : class nsIPrincipal;
      20             : class nsIDocument;
      21             : struct JSContext;
      22             : class JSObject;
      23             : 
      24             : namespace mozilla {
      25             : class DeclarationBlock;
      26             : namespace css {
      27             : class Loader;
      28             : class Rule;
      29             : } // namespace css
      30             : } // namespace mozilla
      31             : 
      32           9 : class nsDOMCSSDeclaration : public nsICSSDeclaration
      33             : {
      34             : public:
      35             :   // Only implement QueryInterface; subclasses have the responsibility
      36             :   // of implementing AddRef/Release.
      37             :   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
      38             : 
      39             :   // Declare addref and release so they can be called on us, but don't
      40             :   // implement them.  Our subclasses must handle their own
      41             :   // refcounting.
      42             :   NS_IMETHOD_(MozExternalRefCountType) AddRef() override = 0;
      43             :   NS_IMETHOD_(MozExternalRefCountType) Release() override = 0;
      44             : 
      45             :   NS_DECL_NSICSSDECLARATION
      46             :   using nsICSSDeclaration::GetLength;
      47             : 
      48             :   // Require subclasses to implement |GetParentRule|.
      49             :   //NS_DECL_NSIDOMCSSSTYLEDECLARATION
      50             :   NS_IMETHOD GetCssText(nsAString & aCssText) override;
      51             :   NS_IMETHOD SetCssText(const nsAString & aCssText) override;
      52             :   NS_IMETHOD GetPropertyValue(const nsAString & propertyName,
      53             :                               nsAString & _retval) override;
      54             :   virtual already_AddRefed<mozilla::dom::CSSValue>
      55             :     GetPropertyCSSValue(const nsAString & propertyName,
      56             :                         mozilla::ErrorResult& aRv) override;
      57             :   using nsICSSDeclaration::GetPropertyCSSValue;
      58             :   NS_IMETHOD RemoveProperty(const nsAString & propertyName,
      59             :                             nsAString & _retval) override;
      60             :   NS_IMETHOD GetPropertyPriority(const nsAString & propertyName,
      61             :                                  nsAString & _retval) override;
      62             :   NS_IMETHOD SetProperty(const nsAString & propertyName,
      63             :                          const nsAString & value, const nsAString & priority) override;
      64             :   NS_IMETHOD GetLength(uint32_t *aLength) override;
      65             :   NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) override = 0;
      66             : 
      67             :   // WebIDL interface for CSS2Properties
      68             : #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
      69             : #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_,          \
      70             :                  kwtable_, stylestruct_, stylestructoffset_, animtype_)      \
      71             :   void                                                                       \
      72             :   Get##method_(nsAString& aValue, mozilla::ErrorResult& rv)                  \
      73             :   {                                                                          \
      74             :     rv = GetPropertyValue(eCSSProperty_##id_, aValue);                       \
      75             :   }                                                                          \
      76             :                                                                              \
      77             :   void                                                                       \
      78             :   Set##method_(const nsAString& aValue, mozilla::ErrorResult& rv)            \
      79             :   {                                                                          \
      80             :     rv = SetPropertyValue(eCSSProperty_##id_, aValue);                       \
      81             :   }
      82             : 
      83             : #define CSS_PROP_LIST_EXCLUDE_INTERNAL
      84             : #define CSS_PROP_LIST_INCLUDE_LOGICAL
      85             : #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_)  \
      86             :   CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X)
      87             : #include "nsCSSPropList.h"
      88             : 
      89             : #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_)  \
      90             :   CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X)
      91             : #include "nsCSSPropAliasList.h"
      92             : #undef CSS_PROP_ALIAS
      93             : 
      94             : #undef CSS_PROP_SHORTHAND
      95             : #undef CSS_PROP_LIST_INCLUDE_LOGICAL
      96             : #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
      97             : #undef CSS_PROP
      98             : #undef CSS_PROP_PUBLIC_OR_PRIVATE
      99             : 
     100             :   virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
     101             : 
     102             :   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
     103             : 
     104             : protected:
     105             :   // The reason for calling GetCSSDeclaration.
     106             :   enum Operation {
     107             :     // We are calling GetCSSDeclaration so that we can read from it.  Does not
     108             :     // allocate a new declaration if we don't have one yet; returns nullptr in
     109             :     // this case.
     110             :     eOperation_Read,
     111             : 
     112             :     // We are calling GetCSSDeclaration so that we can set a property on it
     113             :     // or re-parse the whole declaration.  Allocates a new declaration if we
     114             :     // don't have one yet and calls AttributeWillChange.  A nullptr return value
     115             :     // indicates an error allocating the declaration.
     116             :     eOperation_Modify,
     117             : 
     118             :     // We are calling GetCSSDeclaration so that we can remove a property from
     119             :     // it.  Does not allocates a new declaration if we don't have one yet;
     120             :     // returns nullptr in this case.  If we do have a declaration, calls
     121             :     // AttributeWillChange.
     122             :     eOperation_RemoveProperty
     123             :   };
     124             :   virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) = 0;
     125             :   virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) = 0;
     126             :   // Document that we must call BeginUpdate/EndUpdate on around the
     127             :   // calls to SetCSSDeclaration and the style rule mutation that leads
     128             :   // to it.
     129             :   virtual nsIDocument* DocToUpdate() = 0;
     130             : 
     131             :   // Information neded to parse a declaration.  We need the mSheetURI
     132             :   // for error reporting, mBaseURI to resolve relative URIs,
     133             :   // mPrincipal for subresource loads, and mCSSLoader for determining
     134             :   // whether we're in quirks mode.  mBaseURI needs to be a strong
     135             :   // pointer because of xml:base possibly creating base URIs on the
     136             :   // fly.  This is why we don't use CSSParsingEnvironment as a return
     137             :   // value, to avoid multiple-refcounting of mBaseURI.
     138          16 :   struct CSSParsingEnvironment {
     139             :     nsIURI* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
     140             :                            "reference; reference counting here has unacceptable "
     141             :                            "performance overhead (see bug 649163)") mSheetURI;
     142             :     nsCOMPtr<nsIURI> mBaseURI;
     143             :     nsIPrincipal* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
     144             :                                  "reference; reference counting here has unacceptable "
     145             :                                  "performance overhead (see bug 649163)") mPrincipal;
     146             :     mozilla::css::Loader* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
     147             :                                          "reference; reference counting here has unacceptable "
     148             :                                          "performance overhead (see bug 649163)") mCSSLoader;
     149             :   };
     150             : 
     151             :   // Information neded to parse a declaration for Servo side.
     152             :   struct MOZ_STACK_CLASS ServoCSSParsingEnvironment
     153             :   {
     154             :     mozilla::URLExtraData* mUrlExtraData;
     155             :     nsCompatibility mCompatMode;
     156             :     mozilla::css::Loader* mLoader;
     157             : 
     158           0 :     ServoCSSParsingEnvironment(mozilla::URLExtraData* aUrlData,
     159             :                                nsCompatibility aCompatMode,
     160             :                                mozilla::css::Loader* aLoader)
     161           0 :       : mUrlExtraData(aUrlData)
     162             :       , mCompatMode(aCompatMode)
     163           0 :       , mLoader(aLoader)
     164           0 :     {}
     165             :   };
     166             : 
     167             :   // On failure, mPrincipal should be set to null in aCSSParseEnv.
     168             :   // If mPrincipal is null, the other members may not be set to
     169             :   // anything meaningful.
     170             :   virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0;
     171             : 
     172             :   // mUrlExtraData returns URL data for parsing url values in
     173             :   // CSS. Returns nullptr on failure. If mUrlExtraData is nullptr,
     174             :   // mCompatMode may not be set to anything meaningful.
     175             :   virtual ServoCSSParsingEnvironment GetServoCSSParsingEnvironment() const = 0;
     176             : 
     177             :   // An implementation for GetCSSParsingEnvironment for callers wrapping
     178             :   // an css::Rule.
     179             :   static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
     180             :                                               CSSParsingEnvironment& aCSSParseEnv);
     181             : 
     182             :   // An implementation for GetServoCSSParsingEnvironment for callers wrapping
     183             :   // an css::Rule.
     184             :   static ServoCSSParsingEnvironment
     185             :     GetServoCSSParsingEnvironmentForRule(const mozilla::css::Rule* aRule);
     186             : 
     187             :   nsresult ParsePropertyValue(const nsCSSPropertyID aPropID,
     188             :                               const nsAString& aPropValue,
     189             :                               bool aIsImportant);
     190             : 
     191             :   nsresult ParseCustomPropertyValue(const nsAString& aPropertyName,
     192             :                                     const nsAString& aPropValue,
     193             :                                     bool aIsImportant);
     194             : 
     195             :   nsresult RemovePropertyInternal(nsCSSPropertyID aPropID);
     196             :   nsresult RemovePropertyInternal(const nsAString& aProperty);
     197             : 
     198             : protected:
     199             :   virtual ~nsDOMCSSDeclaration();
     200             : 
     201             : private:
     202             :   template<typename GeckoFunc, typename ServoFunc>
     203             :   inline nsresult ModifyDeclaration(GeckoFunc aGeckoFunc, ServoFunc aServoFunc);
     204             : };
     205             : 
     206             : #endif // nsDOMCSSDeclaration_h___

Generated by: LCOV version 1.13