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, |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "wtf/text/StringBuilder.h" | 27 #include "wtf/text/StringBuilder.h" |
28 | 28 |
29 namespace WebCore { | 29 namespace WebCore { |
30 | 30 |
31 // A primitive value representing a pair. This is useful for properties like bo rder-radius, background-size/position, | 31 // A primitive value representing a pair. This is useful for properties like bo rder-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 | 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 | 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). | 34 // it (eliminating some extra -webkit- internal properties). |
35 class Pair : public RefCounted<Pair> { | 35 class Pair : public RefCounted<Pair> { |
36 public: | 36 public: |
37 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues }; | |
38 | |
37 static PassRefPtr<Pair> create() | 39 static PassRefPtr<Pair> create() |
38 { | 40 { |
39 return adoptRef(new Pair); | 41 return adoptRef(new Pair); |
40 } | 42 } |
41 static PassRefPtr<Pair> create(PassRefPtr<CSSPrimitiveValue> first, PassRefP tr<CSSPrimitiveValue> second) | 43 static PassRefPtr<Pair> create(PassRefPtr<CSSPrimitiveValue> first, PassRefP tr<CSSPrimitiveValue> second, IdenticalValuesPolicy identicalValuesPolicy) |
42 { | 44 { |
43 return adoptRef(new Pair(first, second)); | 45 return adoptRef(new Pair(first, second, identicalValuesPolicy)); |
44 } | 46 } |
45 virtual ~Pair() { } | 47 virtual ~Pair() { } |
46 | 48 |
47 CSSPrimitiveValue* first() const { return m_first.get(); } | 49 CSSPrimitiveValue* first() const { return m_first.get(); } |
48 CSSPrimitiveValue* second() const { return m_second.get(); } | 50 CSSPrimitiveValue* second() const { return m_second.get(); } |
51 IdenticalValuesPolicy identicalValuesPolicy() const { return m_identicalValu esPolicy; } | |
49 | 52 |
50 void setFirst(PassRefPtr<CSSPrimitiveValue> first) { m_first = first; } | 53 void setFirst(PassRefPtr<CSSPrimitiveValue> first) { m_first = first; } |
51 void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; } | 54 void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; } |
55 void setIdenticalValuesPolicy(IdenticalValuesPolicy identicalValuesPolicy) { m_identicalValuesPolicy = identicalValuesPolicy; } | |
52 | 56 |
53 String cssText() const | 57 String cssText() const |
54 { | 58 { |
55 | 59 return generateCSSString(first()->cssText(), second()->cssText(), m_iden ticalValuesPolicy); |
56 return generateCSSString(first()->cssText(), second()->cssText()); | |
57 } | 60 } |
58 | 61 |
59 bool equals(const Pair& other) const { return compareCSSValuePtr(m_first, ot her.m_first) && compareCSSValuePtr(m_second, other.m_second); } | 62 bool equals(const Pair& other) const |
63 { | |
64 return compareCSSValuePtr(m_first, other.m_first) | |
65 && compareCSSValuePtr(m_second, other.m_second) | |
66 && m_identicalValuesPolicy == other.m_identicalValuesPolicy; | |
67 } | |
60 | 68 |
61 String serializeResolvingVariables(const HashMap<AtomicString, String>& vari ables) const | 69 String serializeResolvingVariables(const HashMap<AtomicString, String>& vari ables) const |
62 { | 70 { |
63 return generateCSSString(first()->customSerializeResolvingVariables(vari ables), | 71 return generateCSSString( |
64 second()->customSerializeResolvingVariables(var iables)); | 72 first()->customSerializeResolvingVariables(variables), |
73 second()->customSerializeResolvingVariables(variables), | |
74 m_identicalValuesPolicy); | |
65 } | 75 } |
66 | 76 |
67 bool hasVariableReference() const { return first()->hasVariableReference() | | second()->hasVariableReference(); } | 77 bool hasVariableReference() const { return first()->hasVariableReference() | | second()->hasVariableReference(); } |
68 | 78 |
69 private: | 79 private: |
70 Pair() : m_first(0), m_second(0) { } | 80 Pair() |
71 Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> seco nd) | 81 : m_first(0) |
72 : m_first(first), m_second(second) { } | 82 , m_second(0) |
83 , m_identicalValuesPolicy(DropIdenticalValues) { } | |
pdr.
2013/08/27 20:07:19
This will be expensive for other users of Pair. Is
mstensho (USE GERRIT)
2013/08/27 20:23:11
What if I subclass Pair and do my stuff there and
mstensho (USE GERRIT)
2013/08/29 13:09:31
If the memory usage increase in Pair is a concern,
| |
73 | 84 |
74 static String generateCSSString(const String& first, const String& second) | 85 Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> seco nd, IdenticalValuesPolicy identicalValuesPolicy) |
86 : m_first(first) | |
87 , m_second(second) | |
88 , m_identicalValuesPolicy(identicalValuesPolicy) { } | |
89 | |
90 static String generateCSSString(const String& first, const String& second, I denticalValuesPolicy identicalValuesPolicy) | |
75 { | 91 { |
76 if (first == second) | 92 if (identicalValuesPolicy == DropIdenticalValues && first == second) |
77 return first; | 93 return first; |
78 return first + ' ' + second; | 94 return first + ' ' + second; |
79 } | 95 } |
80 | 96 |
81 RefPtr<CSSPrimitiveValue> m_first; | 97 RefPtr<CSSPrimitiveValue> m_first; |
82 RefPtr<CSSPrimitiveValue> m_second; | 98 RefPtr<CSSPrimitiveValue> m_second; |
99 IdenticalValuesPolicy m_identicalValuesPolicy; | |
83 }; | 100 }; |
84 | 101 |
85 } // namespace | 102 } // namespace |
86 | 103 |
87 #endif | 104 #endif |
OLD | NEW |