DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d38398e5144e)

VCS Links

GenericSpecifiedValues

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 * Generic representation of a container of specified CSS values, which
 * could potentially be Servo- or Gecko- format. Used to make attribute mapping
 * code generic over style backends.
 */

#ifndef mozilla_GenericSpecifiedValues_h
#define mozilla_GenericSpecifiedValues_h

#include "mozilla/ServoUtils.h"
#include "nsCSSProps.h"
#include "nsCSSValue.h"
#include "nsPresContext.h"

struct nsRuleData;

namespace mozilla {

class ServoSpecifiedValues;

// This provides a common interface for attribute mappers (MapAttributesIntoRule)
// to use regardless of the style backend. If the style backend is Gecko,
// this will contain an nsRuleData. If it is Servo, it will be a PropertyDeclarationBlock.
class GenericSpecifiedValues {
protected:
    explicit GenericSpecifiedValues(StyleBackendType aType, nsPresContext* aPresContext,
                                    uint32_t aSIDs)
        : mType(aType), mPresContext(aPresContext), mSIDs(aSIDs) {}

public:
    MOZ_DECL_STYLO_METHODS(nsRuleData, ServoSpecifiedValues)

    // Check if we already contain a certain longhand
    inline bool PropertyIsSet(nsCSSPropertyID aId);
    // Check if we are able to hold longhands from a given
    // style struct. Pass the result of NS_STYLE_INHERIT_BIT to this
    // function. Can accept multiple inherit bits or'd together.
    inline bool ShouldComputeStyleStruct(uint64_t aInheritBits) {
        return aInheritBits & mSIDs;
    }

    inline nsPresContext* PresContext() {
        return mPresContext;
    }

    // Set a property to an identifier (string)
    inline void SetIdentStringValue(nsCSSPropertyID aId, const nsString& aValue);
    inline void SetIdentStringValueIfUnset(nsCSSPropertyID aId, const nsString& aValue);

    // Set a property to a keyword (usually NS_STYLE_* or StyleFoo::*)
    inline void SetKeywordValue(nsCSSPropertyID aId, int32_t aValue);
    inline void SetKeywordValueIfUnset(nsCSSPropertyID aId, int32_t aValue);

    template<typename T,
             typename = typename std::enable_if<std::is_enum<T>::value>::type>
    void SetKeywordValue(nsCSSPropertyID aId, T aValue) {
        static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
                      "aValue must be an enum that fits within 32 bits");
        SetKeywordValue(aId, static_cast<int32_t>(aValue));
    }
    template<typename T,
             typename = typename std::enable_if<std::is_enum<T>::value>::type>
    void SetKeywordValueIfUnset(nsCSSPropertyID aId, T aValue) {
        static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
                      "aValue must be an enum that fits within 32 bits");
        SetKeywordValueIfUnset(aId, static_cast<int32_t>(aValue));
    }

    // Set a property to an integer value
    inline void SetIntValue(nsCSSPropertyID aId, int32_t aValue);
    // Set a property to a pixel value
    inline void SetPixelValue(nsCSSPropertyID aId, float aValue);
    inline void SetPixelValueIfUnset(nsCSSPropertyID aId, float aValue);

    // Set a property to a percent value
    inline void SetPercentValue(nsCSSPropertyID aId, float aValue);
    inline void SetPercentValueIfUnset(nsCSSPropertyID aId, float aValue);

    // Set a property to `auto`
    inline void SetAutoValue(nsCSSPropertyID aId);
    inline void SetAutoValueIfUnset(nsCSSPropertyID aId);

    // Set a property to `currentcolor`
    inline void SetCurrentColor(nsCSSPropertyID aId);
    inline void SetCurrentColorIfUnset(nsCSSPropertyID aId);

    // Set a property to an RGBA nscolor value
    inline void SetColorValue(nsCSSPropertyID aId, nscolor aValue);
    inline void SetColorValueIfUnset(nsCSSPropertyID aId, nscolor aValue);

    // Set font-family to a string
    inline void SetFontFamily(const nsString& aValue);
    // Add a quirks-mode override to the decoration color of elements nested in <a>
    inline void SetTextDecorationColorOverride();

    const mozilla::StyleBackendType mType;
    nsPresContext* const mPresContext;
    const uint32_t mSIDs;
};

} // namespace mozilla

#endif // mozilla_GenericSpecifiedValues_h