blob: 4d707f56e79449ece2a342b5a80172561eef0c3f [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef Pair_h
22#define Pair_h
23
24#include "core/css/CSSPrimitiveValue.h"
25#include <wtf/PassRefPtr.h>
26#include <wtf/RefCounted.h>
27#include <wtf/text/StringBuilder.h>
28
29namespace WebCore {
30
31// A primitive value representing a pair. This is useful for properties like border-radius, background-size/position,
32// and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for
33// border-radius and background-size, but (FIXME) border-spacing and background-position could be converted over to use
34// it (eliminating some extra -webkit- internal properties).
35class Pair : public RefCounted<Pair> {
36public:
37 static PassRefPtr<Pair> create()
38 {
39 return adoptRef(new Pair);
40 }
41 static PassRefPtr<Pair> create(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
42 {
43 return adoptRef(new Pair(first, second));
44 }
45 virtual ~Pair() { }
46
47 CSSPrimitiveValue* first() const { return m_first.get(); }
48 CSSPrimitiveValue* second() const { return m_second.get(); }
49
50 void setFirst(PassRefPtr<CSSPrimitiveValue> first) { m_first = first; }
51 void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; }
52
53 String cssText() const
54 {
55
56 return generateCSSString(first()->cssText(), second()->cssText());
57 }
58
59 bool equals(const Pair& other) const { return compareCSSValuePtr(m_first, other.m_first) && compareCSSValuePtr(m_second, other.m_second); }
60
61 String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
62 {
63 return generateCSSString(first()->customSerializeResolvingVariables(variables),
64 second()->customSerializeResolvingVariables(variables));
65 }
66
67 bool hasVariableReference() const { return first()->hasVariableReference() || second()->hasVariableReference(); }
68
69private:
70 Pair() : m_first(0), m_second(0) { }
71 Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
72 : m_first(first), m_second(second) { }
73
74 static String generateCSSString(const String& first, const String& second)
75 {
76 if (first == second)
77 return first;
78 return first + ' ' + second;
79 }
80
81 RefPtr<CSSPrimitiveValue> m_first;
82 RefPtr<CSSPrimitiveValue> m_second;
83};
84
85} // namespace
86
87#endif