layout/style/nsICSSDeclaration.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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/. */
     6 /*
     7  * faster version of nsIDOMCSSStyleDeclaration using enums instead of
     8  * strings, for internal use
     9  */
    11 #ifndef nsICSSDeclaration_h__
    12 #define nsICSSDeclaration_h__
    14 /**
    15  * This interface provides access to methods analogous to those of
    16  * nsIDOMCSSStyleDeclaration; the difference is that these use
    17  * nsCSSProperty enums for the prop names instead of using strings.
    18  * This is meant for use in performance-sensitive code only!  Most
    19  * consumers should continue to use nsIDOMCSSStyleDeclaration.
    20  */
    22 #include "mozilla/Attributes.h"
    23 #include "nsIDOMCSSStyleDeclaration.h"
    24 #include "nsCSSProperty.h"
    25 #include "CSSValue.h"
    26 #include "nsWrapperCache.h"
    27 #include "nsString.h"
    28 #include "nsIDOMCSSRule.h"
    29 #include "nsIDOMCSSValue.h"
    30 #include "mozilla/ErrorResult.h"
    31 #include "nsAutoPtr.h"
    32 #include "nsCOMPtr.h"
    33 #include "nsINode.h"
    35 // dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f
    36 #define NS_ICSSDECLARATION_IID \
    37 { 0xdbeabbfa, 0x6cb3, 0x4f5c, \
    38  { 0xae, 0xc2, 0xdd, 0x55, 0x8d, 0x9d, 0x68, 0x1f } }
    40 class nsICSSDeclaration : public nsIDOMCSSStyleDeclaration,
    41                           public nsWrapperCache
    42 {
    43 public:
    44   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSDECLARATION_IID)
    46   /**
    47    * Method analogous to nsIDOMCSSStyleDeclaration::GetPropertyValue,
    48    * which obeys all the same restrictions.
    49    */
    50   NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID,
    51                               nsAString& aValue) = 0;
    53   NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName,
    54                                       nsAString& aValue) = 0;
    56   /**
    57    * Method analogous to nsIDOMCSSStyleDeclaration::SetProperty.  This
    58    * method does NOT allow setting a priority (the priority will
    59    * always be set to default priority).
    60    */
    61   NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID,
    62                               const nsAString& aValue) = 0;
    64   virtual nsINode *GetParentObject() = 0;
    66   // Also have to declare all the nsIDOMCSSStyleDeclaration methods,
    67   // since we want to be able to call them from the WebIDL versions.
    68   NS_IMETHOD GetCssText(nsAString& aCssText) MOZ_OVERRIDE = 0;
    69   NS_IMETHOD SetCssText(const nsAString& aCssText) MOZ_OVERRIDE = 0;
    70   NS_IMETHOD GetPropertyValue(const nsAString& aPropName,
    71                               nsAString& aValue) MOZ_OVERRIDE = 0;
    72   virtual already_AddRefed<mozilla::dom::CSSValue>
    73     GetPropertyCSSValue(const nsAString& aPropertyName,
    74                         mozilla::ErrorResult& aRv) = 0;
    75   NS_IMETHOD GetPropertyCSSValue(const nsAString& aProp, nsIDOMCSSValue** aVal) MOZ_OVERRIDE
    76   {
    77     mozilla::ErrorResult error;
    78     nsRefPtr<mozilla::dom::CSSValue> val = GetPropertyCSSValue(aProp, error);
    79     if (error.Failed()) {
    80       return error.ErrorCode();
    81     }
    83     nsCOMPtr<nsIDOMCSSValue> xpVal = do_QueryInterface(val);
    84     xpVal.forget(aVal);
    85     return NS_OK;
    86   }
    87   NS_IMETHOD RemoveProperty(const nsAString& aPropertyName,
    88                             nsAString& aReturn) MOZ_OVERRIDE = 0;
    89   NS_IMETHOD GetPropertyPriority(const nsAString& aPropertyName,
    90                                  nsAString& aReturn) MOZ_OVERRIDE = 0;
    91   NS_IMETHOD SetProperty(const nsAString& aPropertyName,
    92                          const nsAString& aValue,
    93                          const nsAString& aPriority) MOZ_OVERRIDE = 0;
    94   NS_IMETHOD GetLength(uint32_t* aLength) MOZ_OVERRIDE = 0;
    95   NS_IMETHOD Item(uint32_t aIndex, nsAString& aReturn) MOZ_OVERRIDE
    96   {
    97     bool found;
    98     IndexedGetter(aIndex, found, aReturn);
    99     if (!found) {
   100       aReturn.Truncate();
   101     }
   102     return NS_OK;
   103   }
   104   NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0;
   106   // WebIDL interface for CSSStyleDeclaration
   107   void SetCssText(const nsAString& aString, mozilla::ErrorResult& rv) {
   108     rv = SetCssText(aString);
   109   }
   110   void GetCssText(nsString& aString) {
   111     // Cast to nsAString& so we end up calling our virtual
   112     // |GetCssText(nsAString& aCssText)| overload, which does the real work.
   113     GetCssText(static_cast<nsAString&>(aString));
   114   }
   115   uint32_t Length() {
   116     uint32_t length;
   117     GetLength(&length);
   118     return length;
   119   }
   120   void Item(uint32_t aIndex, nsString& aPropName) {
   121     Item(aIndex, static_cast<nsAString&>(aPropName));
   122   }
   124   // The actual implementation of the Item method and the WebIDL indexed getter
   125   virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) = 0;
   127   void GetPropertyValue(const nsAString& aPropName, nsString& aValue,
   128                         mozilla::ErrorResult& rv) {
   129     rv = GetPropertyValue(aPropName, aValue);
   130   }
   131   void GetAuthoredPropertyValue(const nsAString& aPropName, nsString& aValue,
   132                                 mozilla::ErrorResult& rv) {
   133     rv = GetAuthoredPropertyValue(aPropName, aValue);
   134   }
   135   void GetPropertyPriority(const nsAString& aPropName, nsString& aPriority) {
   136     GetPropertyPriority(aPropName, static_cast<nsAString&>(aPriority));
   137   }
   138   void SetProperty(const nsAString& aPropName, const nsAString& aValue,
   139                    const nsAString& aPriority, mozilla::ErrorResult& rv) {
   140     rv = SetProperty(aPropName, aValue, aPriority);
   141   }
   142   void RemoveProperty(const nsAString& aPropName, nsString& aRetval,
   143                       mozilla::ErrorResult& rv) {
   144     rv = RemoveProperty(aPropName, aRetval);
   145   }
   146   already_AddRefed<nsIDOMCSSRule> GetParentRule() {
   147     nsCOMPtr<nsIDOMCSSRule> rule;
   148     GetParentRule(getter_AddRefs(rule));
   149     return rule.forget();
   150   }
   151 };
   153 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID)
   155 #define NS_DECL_NSICSSDECLARATION                                   \
   156   NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID,          \
   157                               nsAString& aValue);                   \
   158   NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName,   \
   159                                       nsAString& aValue);           \
   160   NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID,          \
   161                               const nsAString& aValue);
   163 #define NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER \
   164   NS_IMETHOD GetCssText(nsAString & aCssText); \
   165   NS_IMETHOD SetCssText(const nsAString & aCssText); \
   166   NS_IMETHOD GetPropertyValue(const nsAString & propertyName, nsAString & _retval); \
   167   NS_IMETHOD RemoveProperty(const nsAString & propertyName, nsAString & _retval); \
   168   NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, nsAString & _retval); \
   169   NS_IMETHOD SetProperty(const nsAString & propertyName, const nsAString & value, const nsAString & priority); \
   170   NS_IMETHOD GetLength(uint32_t *aLength); \
   171   NS_IMETHOD Item(uint32_t index, nsAString & _retval); \
   172   NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule);
   174 #endif // nsICSSDeclaration_h__

mercurial