layout/style/CSSVariableDeclarations.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/CSSVariableDeclarations.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* CSS Custom Property assignments for a Declaration at a given priority */
    1.10 +
    1.11 +#ifndef mozilla_CSSVariableDeclarations_h
    1.12 +#define mozilla_CSSVariableDeclarations_h
    1.13 +
    1.14 +#include "nsDataHashtable.h"
    1.15 +
    1.16 +namespace mozilla {
    1.17 +class CSSVariableResolver;
    1.18 +}
    1.19 +class nsRuleData;
    1.20 +
    1.21 +namespace mozilla {
    1.22 +
    1.23 +class CSSVariableDeclarations
    1.24 +{
    1.25 +public:
    1.26 +  CSSVariableDeclarations();
    1.27 +  CSSVariableDeclarations(const CSSVariableDeclarations& aOther);
    1.28 +#ifdef DEBUG
    1.29 +  ~CSSVariableDeclarations();
    1.30 +#endif
    1.31 +  CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther);
    1.32 +
    1.33 +  /**
    1.34 +   * Returns whether this set of variable declarations includes a variable
    1.35 +   * with a given name.
    1.36 +   *
    1.37 +   * @param aName The variable name (not including any "--" prefix that would
    1.38 +   *   be part of the custom property name).
    1.39 +   */
    1.40 +  bool Has(const nsAString& aName) const;
    1.41 +
    1.42 +  /**
    1.43 +   * Represents the type of a variable value.
    1.44 +   */
    1.45 +  enum Type {
    1.46 +    eTokenStream,  // a stream of CSS tokens (the usual type for variables)
    1.47 +    eInitial,      // 'initial'
    1.48 +    eInherit,      // 'inherit'
    1.49 +    eUnset         // 'unset'
    1.50 +  };
    1.51 +
    1.52 +  /**
    1.53 +   * Gets the value of a variable in this set of variable declarations.
    1.54 +   *
    1.55 +   * @param aName The variable name (not including any "--" prefix that would
    1.56 +   *   be part of the custom property name).
    1.57 +   * @param aType Out parameter into which the type of the variable value will
    1.58 +   *   be stored.
    1.59 +   * @param aValue Out parameter into which the value of the variable will
    1.60 +   *   be stored.  If the variable is 'initial', 'inherit' or 'unset', this will
    1.61 +   *   be the empty string.
    1.62 +   * @return Whether a variable with the given name was found.  When false
    1.63 +   *   is returned, aType and aValue will not be modified.
    1.64 +   */
    1.65 +  bool Get(const nsAString& aName, Type& aType, nsString& aValue) const;
    1.66 +
    1.67 +  /**
    1.68 +   * Adds or modifies an existing entry in this set of variable declarations
    1.69 +   * to have the value 'initial'.
    1.70 +   *
    1.71 +   * @param aName The variable name (not including any "--" prefix that would
    1.72 +   *   be part of the custom property name) whose value is to be set.
    1.73 +   */
    1.74 +  void PutInitial(const nsAString& aName);
    1.75 +
    1.76 +  /**
    1.77 +   * Adds or modifies an existing entry in this set of variable declarations
    1.78 +   * to have the value 'inherit'.
    1.79 +   *
    1.80 +   * @param aName The variable name (not including any "--" prefix that would
    1.81 +   *   be part of the custom property name) whose value is to be set.
    1.82 +   */
    1.83 +  void PutInherit(const nsAString& aName);
    1.84 +
    1.85 +  /**
    1.86 +   * Adds or modifies an existing entry in this set of variable declarations
    1.87 +   * to have the value 'unset'.
    1.88 +   *
    1.89 +   * @param aName The variable name (not including any "--" prefix that would
    1.90 +   *   be part of the custom property name) whose value is to be set.
    1.91 +   */
    1.92 +  void PutUnset(const nsAString& aName);
    1.93 +
    1.94 +  /**
    1.95 +   * Adds or modifies an existing entry in this set of variable declarations
    1.96 +   * to have a token stream value.
    1.97 +   *
    1.98 +   * @param aName The variable name (not including any "--" prefix that would
    1.99 +   *   be part of the custom property name) whose value is to be set.
   1.100 +   * @param aTokenStream The CSS token stream.
   1.101 +   */
   1.102 +  void PutTokenStream(const nsAString& aName, const nsString& aTokenStream);
   1.103 +
   1.104 +  /**
   1.105 +   * Removes an entry in this set of variable declarations.
   1.106 +   *
   1.107 +   * @param aName The variable name (not including any "--" prefix that would
   1.108 +   *   be part of the custom property name) whose entry is to be removed.
   1.109 +   */
   1.110 +  void Remove(const nsAString& aName);
   1.111 +
   1.112 +  /**
   1.113 +   * Returns the number of entries in this set of variable declarations.
   1.114 +   */
   1.115 +  uint32_t Count() const { return mVariables.Count(); }
   1.116 +
   1.117 +  /**
   1.118 +   * Copies each variable value from this object into aRuleData, unless that
   1.119 +   * variable already exists on aRuleData.
   1.120 +   */
   1.121 +  void MapRuleInfoInto(nsRuleData* aRuleData);
   1.122 +
   1.123 +  /**
   1.124 +   * Copies the variables from this object into aResolver, marking them as
   1.125 +   * specified values.
   1.126 +   */
   1.127 +  void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
   1.128 +
   1.129 +  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
   1.130 +
   1.131 +private:
   1.132 +  /**
   1.133 +   * Adds all the variable declarations from aOther into this object.
   1.134 +   */
   1.135 +  void CopyVariablesFrom(const CSSVariableDeclarations& aOther);
   1.136 +  static PLDHashOperator EnumerateVariableForCopy(const nsAString& aName,
   1.137 +                                                  nsString aValue,
   1.138 +                                                  void* aData);
   1.139 +  static PLDHashOperator
   1.140 +    EnumerateVariableForMapRuleInfoInto(const nsAString& aName,
   1.141 +                                        nsString aValue,
   1.142 +                                        void* aData);
   1.143 +  static PLDHashOperator
   1.144 +    EnumerateVariableForAddVariablesToResolver(const nsAString& aName,
   1.145 +                                               nsString aValue,
   1.146 +                                               void* aData);
   1.147 +
   1.148 +  nsDataHashtable<nsStringHashKey, nsString> mVariables;
   1.149 +};
   1.150 +
   1.151 +} // namespace mozilla
   1.152 +
   1.153 +#endif

mercurial