summaryrefslogtreecommitdiff
path: root/Source/WebCore/css/Pair.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/css/Pair.h')
-rw-r--r--Source/WebCore/css/Pair.h50
1 files changed, 22 insertions, 28 deletions
diff --git a/Source/WebCore/css/Pair.h b/Source/WebCore/css/Pair.h
index 621187379..2166e2ef1 100644
--- a/Source/WebCore/css/Pair.h
+++ b/Source/WebCore/css/Pair.h
@@ -1,6 +1,6 @@
/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2005, 2006, 2015 Apple Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -18,62 +18,56 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef Pair_h
-#define Pair_h
+#pragma once
#include <wtf/RefCounted.h>
-#include "CSSPrimitiveValue.h"
-#include <wtf/PassRefPtr.h>
-#include <wtf/text/StringBuilder.h>
namespace WebCore {
+class CSSPrimitiveValue;
+
// A primitive value representing a pair. This is useful for properties like border-radius, background-size/position,
// and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for
// border-radius and background-size, but (FIXME) border-spacing and background-position could be converted over to use
// it (eliminating some extra -webkit- internal properties).
-class Pair : public RefCounted<Pair> {
+class Pair final : public RefCounted<Pair> {
public:
- static PassRefPtr<Pair> create()
+ enum class IdenticalValueEncoding {
+ DoNotCoalesce,
+ Coalesce
+ };
+
+ static Ref<Pair> create(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second)
{
- return adoptRef(new Pair);
+ return adoptRef(*new Pair(WTFMove(first), WTFMove(second)));
}
- static PassRefPtr<Pair> create(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
+ static Ref<Pair> create(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second, IdenticalValueEncoding encoding)
{
- return adoptRef(new Pair(first, second));
+ return adoptRef(*new Pair(WTFMove(first), WTFMove(second), encoding));
}
virtual ~Pair() { }
CSSPrimitiveValue* first() const { return m_first.get(); }
CSSPrimitiveValue* second() const { return m_second.get(); }
- void setFirst(PassRefPtr<CSSPrimitiveValue> first) { m_first = first; }
- void setSecond(PassRefPtr<CSSPrimitiveValue> second) { m_second = second; }
-
String cssText() const
{
-
- return generateCSSString(first()->cssText(), second()->cssText());
+ String first = this->first()->cssText();
+ String second = this->second()->cssText();
+ if (m_encoding == IdenticalValueEncoding::Coalesce && first == second)
+ return first;
+ return first + ' ' + second;
}
bool equals(const Pair& other) const { return compareCSSValuePtr(m_first, other.m_first) && compareCSSValuePtr(m_second, other.m_second); }
private:
- Pair() : m_first(0), m_second(0) { }
- Pair(PassRefPtr<CSSPrimitiveValue> first, PassRefPtr<CSSPrimitiveValue> second)
- : m_first(first), m_second(second) { }
-
- static String generateCSSString(const String& first, const String& second)
- {
- if (first == second)
- return first;
- return first + ' ' + second;
- }
+ Pair(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second) : m_first(WTFMove(first)), m_second(WTFMove(second)) { }
+ Pair(RefPtr<CSSPrimitiveValue>&& first, RefPtr<CSSPrimitiveValue>&& second, IdenticalValueEncoding encoding) : m_first(WTFMove(first)), m_second(WTFMove(second)), m_encoding(encoding) { }
RefPtr<CSSPrimitiveValue> m_first;
RefPtr<CSSPrimitiveValue> m_second;
+ IdenticalValueEncoding m_encoding { IdenticalValueEncoding::Coalesce };
};
} // namespace
-
-#endif