#ifndef Pair_h
#define Pair_h
#include "core/css/CSSPrimitiveValue.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
class Pair FINAL : public RefCountedWillBeGarbageCollected<Pair> {
public:
enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues };
static PassRefPtrWillBeRawPtr<Pair> create(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second,
IdenticalValuesPolicy identicalValuesPolicy)
{
return adoptRefWillBeNoop(new Pair(first, second, identicalValuesPolicy));
}
CSSPrimitiveValue* first() const { return m_first.get(); }
CSSPrimitiveValue* second() const { return m_second.get(); }
IdenticalValuesPolicy identicalValuesPolicy() const { return m_identicalValuesPolicy; }
void setFirst(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first) { m_first = first; }
void setSecond(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second) { m_second = second; }
void setIdenticalValuesPolicy(IdenticalValuesPolicy identicalValuesPolicy) { m_identicalValuesPolicy = identicalValuesPolicy; }
String cssText() const
{
return generateCSSString(first()->cssText(), second()->cssText(), m_identicalValuesPolicy);
}
bool equals(const Pair& other) const
{
return compareCSSValuePtr(m_first, other.m_first)
&& compareCSSValuePtr(m_second, other.m_second)
&& m_identicalValuesPolicy == other.m_identicalValuesPolicy;
}
void trace(Visitor*);
private:
Pair()
: m_first(nullptr)
, m_second(nullptr)
, m_identicalValuesPolicy(DropIdenticalValues) { }
Pair(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second, IdenticalValuesPolicy identicalValuesPolicy)
: m_first(first)
, m_second(second)
, m_identicalValuesPolicy(identicalValuesPolicy) { }
static String generateCSSString(const String& first, const String& second, IdenticalValuesPolicy identicalValuesPolicy)
{
if (identicalValuesPolicy == DropIdenticalValues && first == second)
return first;
return first + ' ' + second;
}
RefPtrWillBeMember<CSSPrimitiveValue> m_first;
RefPtrWillBeMember<CSSPrimitiveValue> m_second;
IdenticalValuesPolicy m_identicalValuesPolicy;
};
}
#endif