diff options
Diffstat (limited to 'Source/WebCore/css/CSSPrimitiveValue.cpp')
| -rw-r--r-- | Source/WebCore/css/CSSPrimitiveValue.cpp | 104 | 
1 files changed, 63 insertions, 41 deletions
diff --git a/Source/WebCore/css/CSSPrimitiveValue.cpp b/Source/WebCore/css/CSSPrimitiveValue.cpp index c433f2094..c1bd02233 100644 --- a/Source/WebCore/css/CSSPrimitiveValue.cpp +++ b/Source/WebCore/css/CSSPrimitiveValue.cpp @@ -21,24 +21,24 @@  #include "config.h"  #include "CSSPrimitiveValue.h" +#include "CSSBasicShapes.h"  #include "CSSCalculationValue.h"  #include "CSSHelper.h"  #include "CSSParser.h"  #include "CSSPropertyNames.h"  #include "CSSValueKeywords.h" -#include "CSSWrapShapes.h"  #include "CalculationValue.h"  #include "Color.h"  #include "Counter.h"  #include "ExceptionCode.h"  #include "Font.h" -#include "MemoryInstrumentation.h"  #include "Node.h"  #include "Pair.h"  #include "RGBColor.h"  #include "Rect.h"  #include "RenderStyle.h"  #include "StyleSheetContents.h" +#include "WebCoreMemoryInstrumentation.h"  #include <wtf/ASCIICType.h>  #include <wtf/DecimalNumber.h>  #include <wtf/StdLibExtras.h> @@ -91,7 +91,9 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit      case CSSPrimitiveValue:: CSS_ATTR:      case CSSPrimitiveValue:: CSS_COUNTER:      case CSSPrimitiveValue:: CSS_COUNTER_NAME: +#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)      case CSSPrimitiveValue:: CSS_DASHBOARD_REGION: +#endif  #if !ENABLE(CSS_IMAGE_RESOLUTION)      case CSSPrimitiveValue:: CSS_DPPX:      case CSSPrimitiveValue:: CSS_DPI: @@ -186,6 +188,10 @@ unsigned short CSSPrimitiveValue::primitiveType() const          return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER;      case CalcPercentLength:          return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH; +#if ENABLE(CSS_VARIABLES) +    case CalcVariable: +        return CSSPrimitiveValue::CSS_UNKNOWN; // The type of a calculation containing a variable cannot be known until the value of the variable is determined. +#endif      case CalcOther:          return CSSPrimitiveValue::CSS_UNKNOWN;      } @@ -347,7 +353,7 @@ void CSSPrimitiveValue::init(PassRefPtr<CSSCalcValue> c)      m_value.calc = c.leakRef();  } -void CSSPrimitiveValue::init(PassRefPtr<CSSWrapShape> shape) +void CSSPrimitiveValue::init(PassRefPtr<CSSBasicShape> shape)  {      m_primitiveUnitType = CSS_SHAPE;      m_hasCachedCSSText = false; @@ -361,11 +367,14 @@ CSSPrimitiveValue::~CSSPrimitiveValue()  void CSSPrimitiveValue::cleanup()  { -    switch (m_primitiveUnitType) { +    switch (static_cast<UnitTypes>(m_primitiveUnitType)) {      case CSS_STRING:      case CSS_URI:      case CSS_ATTR:      case CSS_COUNTER_NAME: +#if ENABLE(CSS_VARIABLES) +    case CSS_VARIABLE_NAME: +#endif      case CSS_PARSER_HEXCOLOR:          if (m_value.string)              m_value.string->deref(); @@ -382,7 +391,7 @@ void CSSPrimitiveValue::cleanup()      case CSS_PAIR:          m_value.pair->deref();          break; -#if ENABLE(DASHBOARD_SUPPORT) +#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION)      case CSS_DASHBOARD_REGION:          if (m_value.region)              m_value.region->deref(); @@ -391,6 +400,10 @@ void CSSPrimitiveValue::cleanup()      case CSS_CALC:          m_value.calc->deref();          break; +    case CSS_CALC_PERCENTAGE_WITH_NUMBER: +    case CSS_CALC_PERCENTAGE_WITH_LENGTH: +        ASSERT_NOT_REACHED(); +        break;      case CSS_SHAPE:          m_value.shape->deref();          break; @@ -417,10 +430,14 @@ void CSSPrimitiveValue::cleanup()      case CSS_VW:      case CSS_VH:      case CSS_VMIN: +    case CSS_DPPX: +    case CSS_DPI: +    case CSS_DPCM:      case CSS_IDENT:      case CSS_RGBCOLOR:      case CSS_DIMENSION:      case CSS_UNKNOWN: +    case CSS_UNICODE_RANGE:      case CSS_PARSER_OPERATOR:      case CSS_PARSER_IDENTIFIER:          break; @@ -462,7 +479,8 @@ template<> unsigned CSSPrimitiveValue::computeLength(RenderStyle* style, RenderS  template<> Length CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, float multiplier, bool computingFontSize)  {  #if ENABLE(SUBPIXEL_LAYOUT) -    return Length(static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)), Fixed); +    double value = computeLengthDouble(style, rootStyle, multiplier, computingFontSize); +    return Length(static_cast<float>(value > intMaxForLayoutUnit || value < intMinForLayoutUnit ? 0.0 : value), Fixed);  #else      return Length(roundForImpreciseConversion<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)), Fixed);  #endif @@ -490,6 +508,10 @@ template<> double CSSPrimitiveValue::computeLength(RenderStyle* style, RenderSty  double CSSPrimitiveValue::computeLengthDouble(RenderStyle* style, RenderStyle* rootStyle, float multiplier, bool computingFontSize)  { +    if (m_primitiveUnitType == CSS_CALC) +        // The multiplier and factor is applied to each value in the calc expression individually +        return m_value.calc->computeLengthPx(style, rootStyle, multiplier, computingFontSize); +              double factor;      switch (primitiveType()) { @@ -536,18 +558,11 @@ double CSSPrimitiveValue::computeLengthDouble(RenderStyle* style, RenderStyle* r              return -1.0;      } -    double computedValue; -    if (m_primitiveUnitType == CSS_CALC) -        // The multiplier is passed in as 1.0 here to ensure it is only applied once -        computedValue = m_value.calc->computeLengthPx(style, rootStyle, 1.0, computingFontSize); -    else -        computedValue = getDoubleValue(); -          // We do not apply the zoom factor when we are computing the value of the font-size property. The zooming      // for font sizes is much more complicated, since we have to worry about enforcing the minimum font size preference      // as well as enforcing the implicit "smart minimum." In addition the CSS property text-size-adjust is used to      // prevent text from zooming at all. Therefore we will not apply the zoom here if we are computing font-size. -    double result = computedValue * factor; +    double result = getDoubleValue() * factor;      if (computingFontSize || isFontRelativeLength())          return result; @@ -948,9 +963,7 @@ String CSSPrimitiveValue::customCssText() const              break;          }          case CSS_COUNTER_NAME: -            text = "counter("; -            text += m_value.string; -            text += ")"; +            text = "counter(" + String(m_value.string) + ')';              break;          case CSS_COUNTER: {              StringBuilder result; @@ -1034,30 +1047,34 @@ String CSSPrimitiveValue::customCssText() const              text = String::adopt(result);              break;          } -        case CSS_PAIR: -            text = m_value.pair->first()->cssText(); +        case CSS_PAIR: { +            StringBuilder result; +            result.append(m_value.pair->first()->cssText());              if (m_value.pair->second() != m_value.pair->first()) { -                text += " "; -                text += m_value.pair->second()->cssText(); +                result.append(' '); +                result.append(m_value.pair->second()->cssText());              } +            text = result.toString();              break; +        }  #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) -        case CSS_DASHBOARD_REGION: +        case CSS_DASHBOARD_REGION: { +            StringBuilder result;              for (DashboardRegion* region = getDashboardRegionValue(); region; region = region->m_next.get()) { -                if (!text.isEmpty()) -                    text.append(' '); +                if (!result.isEmpty()) +                    result.append(' ');  #if ENABLE(DASHBOARD_SUPPORT) && ENABLE(WIDGET_REGION) -                text += region->m_cssFunctionName; +                result.append(region->m_cssFunctionName);  #elif ENABLE(DASHBOARD_SUPPORT) -                text += "dashboard-region("; +                result.appendLiteral("dashboard-region(");  #else -                text += "region("; +                result.appendLiteral("region(");  #endif -                text += region->m_label; +                result.append(region->m_label);                  if (region->m_isCircle) -                    text += " circle"; +                    result.appendLiteral(" circle");                  else if (region->m_isRectangle) -                    text += " rectangle"; +                    result.appendLiteral(" rectangle");                  else                      break;                  if (region->top()->m_primitiveUnitType == CSS_IDENT && region->top()->getIdent() == CSSValueInvalid) { @@ -1068,15 +1085,20 @@ String CSSPrimitiveValue::customCssText() const                      ASSERT(region->bottom()->getIdent() == CSSValueInvalid);                      ASSERT(region->left()->getIdent() == CSSValueInvalid);                  } else { -                    text.append(' '); -                    text += region->top()->cssText() + " "; -                    text += region->right()->cssText() + " "; -                    text += region->bottom()->cssText() + " "; -                    text += region->left()->cssText(); +                    result.append(' '); +                    result.append(region->top()->cssText()); +                    result.append(' '); +                    result.append(region->right()->cssText()); +                    result.append(' '); +                    result.append(region->bottom()->cssText()); +                    result.append(' '); +                    result.append(region->left()->cssText());                  } -                text += ")"; +                result.append(')');              } +            text = result.toString();              break; +        }  #endif          case CSS_PARSER_OPERATOR: {              char c = static_cast<char>(m_value.ident); @@ -1103,9 +1125,7 @@ String CSSPrimitiveValue::customCssText() const              break;  #if ENABLE(CSS_VARIABLES)          case CSS_VARIABLE_NAME: -            text = "-webkit-var("; -            text += m_value.string; -            text += ")"; +            text = "-webkit-var(" + String(m_value.string) + ")";              break;  #endif      } @@ -1119,8 +1139,10 @@ String CSSPrimitiveValue::customCssText() const  #if ENABLE(CSS_VARIABLES)  String CSSPrimitiveValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const  { -    if (m_primitiveUnitType == CSS_VARIABLE_NAME && variables.contains(m_value.string)) +    if (isVariableName() && variables.contains(m_value.string))          return variables.get(m_value.string); +    if (isCalculated()) +        return cssCalcValue()->customSerializeResolvingVariables(variables);      return customCssText();  }  #endif @@ -1241,7 +1263,7 @@ PassRefPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() const  void CSSPrimitiveValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const  { -    MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::CSS); +    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);      switch (m_primitiveUnitType) {      case CSS_ATTR:      case CSS_COUNTER_NAME:  | 
