Chromium Code Reviews| 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 CSSValuePair_h |
| 22 #define Pair_h | 22 #define CSSValuePair_h |
| 23 | 23 |
| 24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
| 25 #include "core/css/CSSPrimitiveValue.h" | 25 #include "core/css/CSSPrimitiveValue.h" |
| 26 #include "core/css/CSSValue.h" | |
| 27 #include "core/style/ComputedStyle.h" | |
| 28 #include "platform/Length.h" | |
| 26 #include "wtf/PassRefPtr.h" | 29 #include "wtf/PassRefPtr.h" |
| 27 #include "wtf/RefCounted.h" | 30 #include "wtf/RefCounted.h" |
| 28 #include "wtf/text/StringBuilder.h" | 31 #include "wtf/text/StringBuilder.h" |
| 29 | 32 |
| 30 namespace blink { | 33 namespace blink { |
| 31 | 34 |
| 32 // A primitive value representing a pair. This is useful for properties like bo rder-radius, background-size/position, | 35 // A primitive value representing a pair. This is useful for properties like bo rder-radius, background-size/position, |
|
Timothy Loh
2015/08/28 05:51:46
This comment is super outdated, can we drop it?
sashab
2015/08/31 00:33:51
Sure, gone.
| |
| 33 // and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for | 36 // 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 | 37 // 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). | 38 // it (eliminating some extra -webkit- internal properties). |
| 36 class CORE_EXPORT Pair final : public RefCountedWillBeGarbageCollected<Pair> { | 39 class CORE_EXPORT CSSValuePair : public CSSValue { |
| 37 public: | 40 public: |
| 38 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues }; | 41 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues }; |
| 39 | 42 |
| 40 static PassRefPtrWillBeRawPtr<Pair> create(PassRefPtrWillBeRawPtr<CSSPrimiti veValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second, | 43 static PassRefPtrWillBeRawPtr<CSSValuePair> create(PassRefPtrWillBeRawPtr<CS SValue> first, PassRefPtrWillBeRawPtr<CSSValue> second, |
| 41 IdenticalValuesPolicy identicalValuesPolicy) | 44 IdenticalValuesPolicy identicalValuesPolicy) |
| 42 { | 45 { |
| 43 return adoptRefWillBeNoop(new Pair(first, second, identicalValuesPolicy) ); | 46 return adoptRefWillBeNoop(new CSSValuePair(first, second, identicalValue sPolicy)); |
| 44 } | 47 } |
| 45 | 48 |
| 46 CSSPrimitiveValue* first() const { return m_first.get(); } | 49 static PassRefPtrWillBeRawPtr<CSSValuePair> create(const LengthSize& lengthS ize, const ComputedStyle& style) |
| 47 CSSPrimitiveValue* second() const { return m_second.get(); } | |
| 48 | |
| 49 String cssText() const | |
| 50 { | 50 { |
| 51 return generateCSSString(first()->cssText(), second()->cssText(), m_iden ticalValuesPolicy); | 51 return adoptRefWillBeNoop(new CSSValuePair(CSSPrimitiveValue::create(len gthSize.width(), style.effectiveZoom()), CSSPrimitiveValue::create(lengthSize.he ight(), style.effectiveZoom()), KeepIdenticalValues)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool equals(const Pair& other) const | 54 CSSValue* first() const { return m_first.get(); } |
|
Timothy Loh
2015/08/28 05:51:46
can these be const references?
sashab
2015/08/31 00:33:51
Sure, but this is kind of a big change -- I'll do
Timothy Loh
2015/08/31 01:08:04
We discussed a while ago that most usages of CSSVa
sashab
2015/08/31 01:29:47
I'll upload a patch in a minute that changes pair
| |
| 55 CSSValue* second() const { return m_second.get(); } | |
| 56 | |
| 57 String customCSSText() const | |
| 58 { | |
| 59 String first = m_first->cssText(); | |
| 60 String second = m_second->cssText(); | |
| 61 if (m_identicalValuesPolicy == DropIdenticalValues && first == second) | |
| 62 return first; | |
| 63 return first + ' ' + second; | |
| 64 } | |
| 65 | |
| 66 bool equals(const CSSValuePair& other) const | |
| 55 { | 67 { |
| 56 return compareCSSValuePtr(m_first, other.m_first) | 68 return compareCSSValuePtr(m_first, other.m_first) |
| 57 && compareCSSValuePtr(m_second, other.m_second) | 69 && compareCSSValuePtr(m_second, other.m_second) |
| 58 && m_identicalValuesPolicy == other.m_identicalValuesPolicy; | 70 && m_identicalValuesPolicy == other.m_identicalValuesPolicy; |
|
Timothy Loh
2015/08/28 05:51:46
probably we can even assert these are the same.
sashab
2015/08/31 00:33:51
The equals() method should work on all CSSValuePai
Timothy Loh
2015/08/31 01:08:04
We should only be comparing values that were parse
sashab
2015/08/31 01:29:47
Ok, added the assert.
| |
| 59 } | 71 } |
| 60 | 72 |
| 61 DECLARE_TRACE(); | 73 DECLARE_TRACE_AFTER_DISPATCH(); |
| 62 | 74 |
| 63 private: | 75 private: |
| 64 Pair(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr <CSSPrimitiveValue> second, IdenticalValuesPolicy identicalValuesPolicy) | 76 CSSValuePair(PassRefPtrWillBeRawPtr<CSSValue> first, PassRefPtrWillBeRawPtr< CSSValue> second, IdenticalValuesPolicy identicalValuesPolicy) |
| 65 : m_first(first) | 77 : CSSValue(ValuePairClass) |
| 78 , m_first(first) | |
| 66 , m_second(second) | 79 , m_second(second) |
| 67 , m_identicalValuesPolicy(identicalValuesPolicy) { } | 80 , m_identicalValuesPolicy(identicalValuesPolicy) { } |
| 68 | 81 |
| 69 static String generateCSSString(const String& first, const String& second, I denticalValuesPolicy identicalValuesPolicy) | 82 RefPtrWillBeMember<CSSValue> m_first; |
| 70 { | 83 RefPtrWillBeMember<CSSValue> m_second; |
| 71 if (identicalValuesPolicy == DropIdenticalValues && first == second) | |
| 72 return first; | |
| 73 return first + ' ' + second; | |
| 74 } | |
| 75 | |
| 76 RefPtrWillBeMember<CSSPrimitiveValue> m_first; | |
| 77 RefPtrWillBeMember<CSSPrimitiveValue> m_second; | |
| 78 IdenticalValuesPolicy m_identicalValuesPolicy; | 84 IdenticalValuesPolicy m_identicalValuesPolicy; |
| 79 }; | 85 }; |
| 80 | 86 |
| 87 DEFINE_CSS_VALUE_TYPE_CASTS(CSSValuePair, isValuePair()); | |
| 88 | |
| 81 } // namespace | 89 } // namespace |
| 82 | 90 |
| 83 #endif | 91 #endif // CSSValuePair_h |
| OLD | NEW |