| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef Pair_h | 21 #ifndef Pair_h |
| 22 #define Pair_h | 22 #define Pair_h |
| 23 | 23 |
| 24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
| 25 #include "core/css/CSSPrimitiveValue.h" | 25 #include "core/css/CSSValue.h" |
| 26 #include "wtf/PassRefPtr.h" | 26 #include "wtf/PassRefPtr.h" |
| 27 #include "wtf/RefCounted.h" | 27 #include "wtf/RefCounted.h" |
| 28 #include "wtf/text/StringBuilder.h" | 28 #include "wtf/text/StringBuilder.h" |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 | 31 |
| 32 // A primitive value representing a pair. This is useful for properties like bo
rder-radius, background-size/position, | 32 // A primitive value representing a pair. This is useful for properties like bo
rder-radius, background-size/position, |
| 33 // and border-spacing (all of which are space-separated sets of two values). At
the moment we are only using it for | 33 // and border-spacing (all of which are space-separated sets of two values). At
the moment we are only using it for |
| 34 // border-radius and background-size, but (FIXME) border-spacing and background-
position could be converted over to use | 34 // border-radius and background-size, but (FIXME) border-spacing and background-
position could be converted over to use |
| 35 // it (eliminating some extra -webkit- internal properties). | 35 // it (eliminating some extra -webkit- internal properties). |
| 36 class CORE_EXPORT Pair final : public RefCountedWillBeGarbageCollected<Pair> { | 36 class CORE_EXPORT Pair final : public RefCountedWillBeGarbageCollectedFinalized<
Pair> { |
| 37 public: | 37 public: |
| 38 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues }; | 38 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues }; |
| 39 | 39 |
| 40 static PassRefPtrWillBeRawPtr<Pair> create(PassRefPtrWillBeRawPtr<CSSPrimiti
veValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second, | 40 static PassRefPtrWillBeRawPtr<Pair> create(const CSSPrimitiveValue& first, c
onst CSSPrimitiveValue& second, |
| 41 IdenticalValuesPolicy identicalValuesPolicy) | 41 IdenticalValuesPolicy identicalValuesPolicy) |
| 42 { | 42 { |
| 43 return adoptRefWillBeNoop(new Pair(first, second, identicalValuesPolicy)
); | 43 return adoptRefWillBeNoop(new Pair(first, second, identicalValuesPolicy)
); |
| 44 } | 44 } |
| 45 | 45 |
| 46 CSSPrimitiveValue* first() const { return m_first.get(); } | 46 const CSSPrimitiveValue& first() const { return toCSSPrimitiveValue(m_first)
; } |
| 47 CSSPrimitiveValue* second() const { return m_second.get(); } | 47 const CSSPrimitiveValue& second() const { return toCSSPrimitiveValue(m_secon
d); } |
| 48 | 48 |
| 49 String cssText() const | 49 String cssText() const |
| 50 { | 50 { |
| 51 return generateCSSString(first()->cssText(), second()->cssText(), m_iden
ticalValuesPolicy); | 51 return generateCSSString(first().cssText(), second().cssText(), m_identi
calValuesPolicy); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool equals(const Pair& other) const | 54 bool equals(const Pair& other) const |
| 55 { | 55 { |
| 56 return compareCSSValuePtr(m_first, other.m_first) | 56 return m_first == other.m_first |
| 57 && compareCSSValuePtr(m_second, other.m_second) | 57 && m_second == other.m_second |
| 58 && m_identicalValuesPolicy == other.m_identicalValuesPolicy; | 58 && m_identicalValuesPolicy == other.m_identicalValuesPolicy; |
| 59 } | 59 } |
| 60 | 60 |
| 61 DECLARE_TRACE(); | 61 DECLARE_TRACE(); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 Pair(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr
<CSSPrimitiveValue> second, IdenticalValuesPolicy identicalValuesPolicy) | 64 Pair(const CSSPrimitiveValue& first, const CSSPrimitiveValue& second, Identi
calValuesPolicy identicalValuesPolicy) |
| 65 : m_first(first) | 65 : m_first(first) |
| 66 , m_second(second) | 66 , m_second(second) |
| 67 , m_identicalValuesPolicy(identicalValuesPolicy) { } | 67 , m_identicalValuesPolicy(identicalValuesPolicy) { } |
| 68 | 68 |
| 69 static String generateCSSString(const String& first, const String& second, I
denticalValuesPolicy identicalValuesPolicy) | 69 static String generateCSSString(const String& first, const String& second, I
denticalValuesPolicy identicalValuesPolicy) |
| 70 { | 70 { |
| 71 if (identicalValuesPolicy == DropIdenticalValues && first == second) | 71 if (identicalValuesPolicy == DropIdenticalValues && first == second) |
| 72 return first; | 72 return first; |
| 73 return first + ' ' + second; | 73 return first + ' ' + second; |
| 74 } | 74 } |
| 75 | 75 |
| 76 RefPtrWillBeMember<CSSPrimitiveValue> m_first; | 76 CSSValue m_first; |
| 77 RefPtrWillBeMember<CSSPrimitiveValue> m_second; | 77 CSSValue m_second; |
| 78 IdenticalValuesPolicy m_identicalValuesPolicy; | 78 IdenticalValuesPolicy m_identicalValuesPolicy; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 #endif | 83 #endif |
| OLD | NEW |