Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: Source/core/css/Pair.h

Issue 1317523002: Changed Pair to be a CSSValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@add_const_to_primvalue
Patch Set: Fixed some callsites from bad rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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/CoreExport.h"
25 #include "core/css/CSSPrimitiveValue.h"
26 #include "wtf/PassRefPtr.h"
27 #include "wtf/RefCounted.h"
28 #include "wtf/text/StringBuilder.h"
29
30 namespace blink {
31
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
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).
36 class CORE_EXPORT Pair final : public RefCountedWillBeGarbageCollected<Pair> {
37 public:
38 enum IdenticalValuesPolicy { DropIdenticalValues, KeepIdenticalValues };
39
40 static PassRefPtrWillBeRawPtr<Pair> create(PassRefPtrWillBeRawPtr<CSSPrimiti veValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second,
41 IdenticalValuesPolicy identicalValuesPolicy)
42 {
43 return adoptRefWillBeNoop(new Pair(first, second, identicalValuesPolicy) );
44 }
45
46 CSSPrimitiveValue* first() const { return m_first.get(); }
47 CSSPrimitiveValue* second() const { return m_second.get(); }
48
49 String cssText() const
50 {
51 return generateCSSString(first()->cssText(), second()->cssText(), m_iden ticalValuesPolicy);
52 }
53
54 bool equals(const Pair& other) const
55 {
56 return compareCSSValuePtr(m_first, other.m_first)
57 && compareCSSValuePtr(m_second, other.m_second)
58 && m_identicalValuesPolicy == other.m_identicalValuesPolicy;
59 }
60
61 DECLARE_TRACE();
62
63 private:
64 Pair(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr <CSSPrimitiveValue> second, IdenticalValuesPolicy identicalValuesPolicy)
65 : m_first(first)
66 , m_second(second)
67 , m_identicalValuesPolicy(identicalValuesPolicy) { }
68
69 static String generateCSSString(const String& first, const String& second, I denticalValuesPolicy identicalValuesPolicy)
70 {
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;
79 };
80
81 } // namespace
82
83 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698