Index: Source/core/css/CSSPrimitiveValue.cpp |
diff --git a/Source/core/css/CSSPrimitiveValue.cpp b/Source/core/css/CSSPrimitiveValue.cpp |
index a4eb31adb59c44b655d1fcb7e70f63912d60a1b1..2e0f2f04a920e990172d3ef652fd0a0584da416d 100644 |
--- a/Source/core/css/CSSPrimitiveValue.cpp |
+++ b/Source/core/css/CSSPrimitiveValue.cpp |
@@ -168,13 +168,13 @@ static CSSTextCache& cssTextCache() |
CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const |
{ |
- if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VALUE_ID) |
+ if (type() == CSS_PROPERTY_ID || type() == CSS_VALUE_ID) |
return CSS_IDENT; |
- if (m_primitiveUnitType != CSS_CALC) |
- return static_cast<UnitType>(m_primitiveUnitType); |
+ if (type() != CSS_CALC) |
+ return type(); |
- switch (m_value.calc->category()) { |
+ switch (value().calc->category()) { |
case CalcAngle: |
return CSS_DEG; |
case CalcFrequency: |
@@ -220,6 +220,7 @@ static const AtomicString& valueName(CSSValueID valueID) |
CSSPrimitiveValue::CSSPrimitiveValue(CSSValueID valueID) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_VALUE_ID; |
m_value.valueID = valueID; |
} |
@@ -227,6 +228,7 @@ CSSPrimitiveValue::CSSPrimitiveValue(CSSValueID valueID) |
CSSPrimitiveValue::CSSPrimitiveValue(CSSPropertyID propertyID) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_PROPERTY_ID; |
m_value.propertyID = propertyID; |
} |
@@ -234,6 +236,7 @@ CSSPrimitiveValue::CSSPrimitiveValue(CSSPropertyID propertyID) |
CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = type; |
ASSERT(std::isfinite(num)); |
m_value.num = num; |
@@ -242,6 +245,7 @@ CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) |
CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = type; |
m_value.string = str.impl(); |
if (m_value.string) |
@@ -251,12 +255,14 @@ CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) |
CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const ComputedStyle& style) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
init(lengthSize, style); |
} |
CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_RGBCOLOR; |
m_value.rgbcolor = color; |
} |
@@ -264,6 +270,7 @@ CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) |
CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) |
: CSSValue(PrimitiveClass) |
{ |
+ ASSERT(!isTaggedPtr()); |
switch (length.type()) { |
case Auto: |
m_primitiveUnitType = CSS_VALUE_ID; |
@@ -335,6 +342,7 @@ CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) |
void CSSPrimitiveValue::init(const LengthSize& lengthSize, const ComputedStyle& style) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_PAIR; |
m_hasCachedCSSText = false; |
m_value.pair = Pair::create(create(lengthSize.width(), style.effectiveZoom()), create(lengthSize.height(), style.effectiveZoom()), Pair::KeepIdenticalValues).leakRef(); |
@@ -342,6 +350,7 @@ void CSSPrimitiveValue::init(const LengthSize& lengthSize, const ComputedStyle& |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Counter> c) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_COUNTER; |
m_hasCachedCSSText = false; |
m_value.counter = c.leakRef(); |
@@ -349,6 +358,7 @@ void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Counter> c) |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Rect> r) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_RECT; |
m_hasCachedCSSText = false; |
m_value.rect = r.leakRef(); |
@@ -356,6 +366,7 @@ void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Rect> r) |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Quad> quad) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_QUAD; |
m_hasCachedCSSText = false; |
m_value.quad = quad.leakRef(); |
@@ -363,6 +374,7 @@ void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Quad> quad) |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Pair> p) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_PAIR; |
m_hasCachedCSSText = false; |
m_value.pair = p.leakRef(); |
@@ -370,6 +382,7 @@ void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Pair> p) |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSCalcValue> c) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_CALC; |
m_hasCachedCSSText = false; |
m_value.calc = c.leakRef(); |
@@ -377,6 +390,7 @@ void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSCalcValue> c) |
void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSBasicShape> shape) |
{ |
+ ASSERT(!isTaggedPtr()); |
m_primitiveUnitType = CSS_SHAPE; |
m_hasCachedCSSText = false; |
m_value.shape = shape.leakRef(); |
@@ -389,7 +403,10 @@ CSSPrimitiveValue::~CSSPrimitiveValue() |
void CSSPrimitiveValue::cleanup() |
{ |
- switch (static_cast<UnitType>(m_primitiveUnitType)) { |
+ if (isTaggedPtr()) |
+ return; |
+ |
+ switch (type()) { |
case CSS_CUSTOM_IDENT: |
case CSS_STRING: |
case CSS_URI: |
@@ -484,7 +501,7 @@ void CSSPrimitiveValue::cleanup() |
double CSSPrimitiveValue::computeSeconds() |
{ |
ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime)); |
- UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->primitiveType() : static_cast<UnitType>(m_primitiveUnitType); |
+ UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->primitiveType() : type(); |
if (currentType == CSS_S) |
return getDoubleValue(); |
if (currentType == CSS_MS) |
@@ -496,7 +513,7 @@ double CSSPrimitiveValue::computeSeconds() |
double CSSPrimitiveValue::computeDegrees() const |
{ |
ASSERT(isAngle() || (isCalculated() && cssCalcValue()->category() == CalcAngle)); |
- UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->primitiveType() : static_cast<UnitType>(m_primitiveUnitType); |
+ UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->primitiveType() : type(); |
switch (currentType) { |
case CSS_DEG: |
return getDoubleValue(); |
@@ -552,8 +569,8 @@ double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c |
// The logic in this function is duplicated in MediaValues::computeLength |
// because MediaValues::computeLength needs nearly identical logic, but we haven't found a way to make |
// CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance. |
- if (m_primitiveUnitType == CSS_CALC) |
- return m_value.calc->computeLengthPx(conversionData); |
+ if (type() == CSS_CALC) |
+ return value().calc->computeLengthPx(conversionData); |
double factor; |
@@ -623,14 +640,14 @@ void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, CSSLe |
{ |
ASSERT(lengthArray.size() == LengthUnitTypeCount); |
- if (m_primitiveUnitType == CSS_CALC) { |
+ if (type() == CSS_CALC) { |
cssCalcValue()->accumulateLengthArray(lengthArray, lengthTypeArray, multiplier); |
return; |
} |
LengthUnitType lengthType; |
- if (unitTypeToLengthUnitType(static_cast<UnitType>(m_primitiveUnitType), lengthType)) { |
- lengthArray.at(lengthType) += m_value.num * conversionToCanonicalUnitsScaleFactor(static_cast<UnitType>(m_primitiveUnitType)) * multiplier; |
+ if (unitTypeToLengthUnitType(type(), lengthType)) { |
+ lengthArray.at(lengthType) += value().num * conversionToCanonicalUnitsScaleFactor(type()) * multiplier; |
lengthTypeArray.set(lengthType); |
} |
} |
@@ -706,9 +723,11 @@ Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conve |
return Length(cssCalcValue()->toCalcValue(conversionData)); |
} |
-double CSSPrimitiveValue::getDoubleValue() const |
+double CSSPrimitiveValue::getCalcDoubleValue() const |
{ |
- return m_primitiveUnitType != CSS_CALC ? m_value.num : m_value.calc->doubleValue(); |
+ ASSERT(!isTaggedPtr()); |
+ ASSERT(m_primitiveUnitType == CSS_CALC); |
+ return value().calc->doubleValue(); |
} |
CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(UnitCategory category) |
@@ -810,16 +829,16 @@ CSSPrimitiveValue::UnitType CSSPrimitiveValue::lengthUnitTypeToUnitType(LengthUn |
String CSSPrimitiveValue::getStringValue() const |
{ |
- switch (m_primitiveUnitType) { |
+ switch (type()) { |
case CSS_CUSTOM_IDENT: |
case CSS_STRING: |
case CSS_ATTR: |
case CSS_URI: |
- return m_value.string; |
+ return value().string; |
case CSS_VALUE_ID: |
- return valueName(m_value.valueID); |
+ return valueName(value().valueID); |
case CSS_PROPERTY_ID: |
- return propertyName(m_value.propertyID); |
+ return propertyName(value().propertyID); |
default: |
break; |
} |
@@ -937,13 +956,16 @@ const char* CSSPrimitiveValue::unitTypeToString(UnitType type) |
String CSSPrimitiveValue::customCSSText() const |
{ |
- if (m_hasCachedCSSText) { |
+ if (isTaggedPtr() && cssTextCache().contains(this)) |
+ return cssTextCache().get(this); |
+ |
+ if (!isTaggedPtr() && m_hasCachedCSSText) { |
ASSERT(cssTextCache().contains(this)); |
return cssTextCache().get(this); |
} |
String text; |
- switch (m_primitiveUnitType) { |
+ switch (type()) { |
case CSS_UNKNOWN: |
// FIXME |
break; |
@@ -978,29 +1000,29 @@ String CSSPrimitiveValue::customCSSText() const |
case CSS_VH: |
case CSS_VMIN: |
case CSS_VMAX: |
- text = formatNumber(m_value.num, unitTypeToString((UnitType)m_primitiveUnitType)); |
+ text = formatNumber(value().num, unitTypeToString(type())); |
break; |
case CSS_CUSTOM_IDENT: |
- text = quoteCSSStringIfNeeded(m_value.string); |
+ text = quoteCSSStringIfNeeded(value().string); |
break; |
case CSS_STRING: { |
- text = serializeString(m_value.string); |
+ text = serializeString(value().string); |
break; |
} |
case CSS_URI: |
- text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; |
+ text = "url(" + quoteCSSURLIfNeeded(value().string) + ")"; |
break; |
case CSS_VALUE_ID: |
- text = valueName(m_value.valueID); |
+ text = valueName(value().valueID); |
break; |
case CSS_PROPERTY_ID: |
- text = propertyName(m_value.propertyID); |
+ text = propertyName(value().propertyID); |
break; |
case CSS_ATTR: { |
StringBuilder result; |
- result.reserveCapacity(6 + m_value.string->length()); |
+ result.reserveCapacity(6 + value().string->length()); |
result.appendLiteral("attr("); |
- result.append(m_value.string); |
+ result.append(value().string); |
result.append(')'); |
text = result.toString(); |
@@ -1008,19 +1030,19 @@ String CSSPrimitiveValue::customCSSText() const |
} |
case CSS_COUNTER: { |
StringBuilder result; |
- String separator = m_value.counter->separator(); |
+ String separator = value().counter->separator(); |
if (separator.isEmpty()) |
result.appendLiteral("counter("); |
else |
result.appendLiteral("counters("); |
- result.append(m_value.counter->identifier()); |
+ result.append(value().counter->identifier()); |
if (!separator.isEmpty()) { |
result.appendLiteral(", "); |
result.append(serializeString(separator)); |
} |
- String listStyle = m_value.counter->listStyle(); |
- bool isDefaultListStyle = m_value.counter->listStyleIdent() == CSSValueDecimal; |
+ String listStyle = value().counter->listStyle(); |
+ bool isDefaultListStyle = value().counter->listStyleIdent() == CSSValueDecimal; |
if (!listStyle.isEmpty() && !isDefaultListStyle) { |
result.appendLiteral(", "); |
result.append(listStyle); |
@@ -1037,32 +1059,38 @@ String CSSPrimitiveValue::customCSSText() const |
text = getQuadValue()->cssText(); |
break; |
case CSS_RGBCOLOR: { |
- text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); |
+ text = Color(value().rgbcolor).serializedAsCSSComponentValue(); |
break; |
} |
case CSS_PAIR: |
text = getPairValue()->cssText(); |
break; |
case CSS_CALC: |
- text = m_value.calc->cssText(); |
+ text = value().calc->cssText(); |
break; |
case CSS_SHAPE: |
- text = m_value.shape->cssText(); |
+ text = value().shape->cssText(); |
+ break; |
+ case CSS_IDENT: |
+ case CSS_CALC_PERCENTAGE_WITH_NUMBER: |
+ case CSS_CALC_PERCENTAGE_WITH_LENGTH: |
+ case CSS_QEM: |
break; |
} |
ASSERT(!cssTextCache().contains(this)); |
cssTextCache().set(this, text); |
- m_hasCachedCSSText = true; |
+ if (!isTaggedPtr()) |
+ m_hasCachedCSSText = true; |
return text; |
} |
bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const |
{ |
- if (m_primitiveUnitType != other.m_primitiveUnitType) |
+ if (type() != other.type()) |
return false; |
- switch (m_primitiveUnitType) { |
+ switch (type()) { |
case CSS_UNKNOWN: |
return false; |
case CSS_NUMBER: |
@@ -1092,30 +1120,37 @@ bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const |
case CSS_VMIN: |
case CSS_VMAX: |
case CSS_FR: |
- return m_value.num == other.m_value.num; |
+ return value().num == other.value().num; |
case CSS_PROPERTY_ID: |
- return m_value.propertyID == other.m_value.propertyID; |
+ return value().propertyID == other.value().propertyID; |
case CSS_VALUE_ID: |
- return m_value.valueID == other.m_value.valueID; |
+ return value().valueID == other.value().valueID; |
case CSS_CUSTOM_IDENT: |
case CSS_STRING: |
case CSS_URI: |
case CSS_ATTR: |
- return equal(m_value.string, other.m_value.string); |
+ return equal(value().string, other.value().string); |
case CSS_COUNTER: |
- return m_value.counter && other.m_value.counter && m_value.counter->equals(*other.m_value.counter); |
+ return value().counter && other.value().counter && value().counter->equals(*other.value().counter); |
case CSS_RECT: |
- return m_value.rect && other.m_value.rect && m_value.rect->equals(*other.m_value.rect); |
+ return value().rect && other.value().rect && value().rect->equals(*other.value().rect); |
case CSS_QUAD: |
- return m_value.quad && other.m_value.quad && m_value.quad->equals(*other.m_value.quad); |
+ return value().quad && other.value().quad && value().quad->equals(*other.value().quad); |
case CSS_RGBCOLOR: |
- return m_value.rgbcolor == other.m_value.rgbcolor; |
+ return value().rgbcolor == other.value().rgbcolor; |
case CSS_PAIR: |
- return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair); |
+ return value().pair && other.value().pair && value().pair->equals(*other.value().pair); |
case CSS_CALC: |
- return m_value.calc && other.m_value.calc && m_value.calc->equals(*other.m_value.calc); |
+ return value().calc && other.value().calc && value().calc->equals(*other.value().calc); |
case CSS_SHAPE: |
- return m_value.shape && other.m_value.shape && m_value.shape->equals(*other.m_value.shape); |
+ return value().shape && other.value().shape && value().shape->equals(*other.value().shape); |
+ case CSS_IDENT: |
+ case CSS_INTEGER: |
+ case CSS_CHS: |
+ case CSS_CALC_PERCENTAGE_WITH_NUMBER: |
+ case CSS_CALC_PERCENTAGE_WITH_LENGTH: |
+ case CSS_QEM: |
+ return false; |
} |
return false; |
} |
@@ -1123,24 +1158,24 @@ bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const |
DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) |
{ |
#if ENABLE(OILPAN) |
- switch (m_primitiveUnitType) { |
+ switch (type()) { |
case CSS_COUNTER: |
- visitor->trace(m_value.counter); |
+ visitor->trace(value().counter); |
break; |
case CSS_RECT: |
- visitor->trace(m_value.rect); |
+ visitor->trace(value().rect); |
break; |
case CSS_QUAD: |
- visitor->trace(m_value.quad); |
+ visitor->trace(value().quad); |
break; |
case CSS_PAIR: |
- visitor->trace(m_value.pair); |
+ visitor->trace(value().pair); |
break; |
case CSS_CALC: |
- visitor->trace(m_value.calc); |
+ visitor->trace(value().calc); |
break; |
case CSS_SHAPE: |
- visitor->trace(m_value.shape); |
+ visitor->trace(value().shape); |
break; |
default: |
break; |