/platform/external/webkit/WebCore/css/CSSParserValues.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 84 lines · 56 code · 9 blank · 19 comment · 37 complexity · 9cb2121a1e0e4a6a08e3dd5adc891aa2 MD5 · raw file

  1. /*
  2. * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
  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. #include "config.h"
  21. #include "CSSParserValues.h"
  22. #include "CSSPrimitiveValue.h"
  23. #include "CSSFunctionValue.h"
  24. #include "CSSQuirkPrimitiveValue.h"
  25. namespace WebCore {
  26. bool CSSParserValue::isVariable() const
  27. {
  28. return unit == CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX;
  29. }
  30. CSSParserValueList::~CSSParserValueList()
  31. {
  32. size_t numValues = m_values.size();
  33. for (size_t i = 0; i < numValues; i++) {
  34. if (m_values[i].unit == CSSParserValue::Function)
  35. delete m_values[i].function;
  36. }
  37. }
  38. void CSSParserValueList::addValue(const CSSParserValue& v)
  39. {
  40. if (v.unit == CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX) // isVariable() is not inlined. This is hot.
  41. m_variablesCount++;
  42. m_values.append(v);
  43. }
  44. void CSSParserValueList::deleteValueAt(unsigned i)
  45. {
  46. if (m_values[i].isVariable())
  47. m_variablesCount--;
  48. m_values.remove(i);
  49. }
  50. PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
  51. {
  52. RefPtr<CSSValue> parsedValue;
  53. if (id)
  54. parsedValue = CSSPrimitiveValue::createIdentifier(id);
  55. else if (unit == CSSPrimitiveValue::CSS_IDENT)
  56. parsedValue = CSSPrimitiveValue::create(string, CSSPrimitiveValue::CSS_PARSER_IDENTIFIER);
  57. else if (unit == CSSPrimitiveValue::CSS_NUMBER && isInt)
  58. parsedValue = CSSPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_PARSER_INTEGER);
  59. else if (unit == CSSParserValue::Operator) {
  60. RefPtr<CSSPrimitiveValue> primitiveValue = CSSPrimitiveValue::createIdentifier(iValue);
  61. primitiveValue->setPrimitiveType(CSSPrimitiveValue::CSS_PARSER_OPERATOR);
  62. parsedValue = primitiveValue;
  63. } else if (unit == CSSParserValue::Function)
  64. parsedValue = CSSFunctionValue::create(function);
  65. else if (unit == CSSPrimitiveValue::CSS_STRING || unit == CSSPrimitiveValue::CSS_URI || unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR || isVariable())
  66. parsedValue = CSSPrimitiveValue::create(string, (CSSPrimitiveValue::UnitTypes)unit);
  67. else if (unit >= CSSPrimitiveValue::CSS_NUMBER && unit <= CSSPrimitiveValue::CSS_KHZ)
  68. parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
  69. else if (unit >= CSSPrimitiveValue::CSS_TURN && unit <= CSSPrimitiveValue::CSS_REMS) // CSS3 Values and Units
  70. parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
  71. else if (unit >= CSSParserValue::Q_EMS)
  72. parsedValue = CSSQuirkPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_EMS);
  73. return parsedValue;
  74. }
  75. }