| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "config.h" |    5 #include "config.h" | 
|    6 #include "core/css/parser/CSSParserToken.h" |    6 #include "core/css/parser/CSSParserToken.h" | 
|    7  |    7  | 
|    8 #include "wtf/HashMap.h" |    8 #include "wtf/HashMap.h" | 
|    9 #include "wtf/text/StringHash.h" |    9 #include "wtf/text/StringHash.h" | 
|   10 #include <limits.h> |   10 #include <limits.h> | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   60     m_unit = CSSPrimitiveValue::fromName(unit); |   60     m_unit = CSSPrimitiveValue::fromName(unit); | 
|   61 } |   61 } | 
|   62  |   62  | 
|   63 void CSSParserToken::convertToPercentage() |   63 void CSSParserToken::convertToPercentage() | 
|   64 { |   64 { | 
|   65     ASSERT(m_type == NumberToken); |   65     ASSERT(m_type == NumberToken); | 
|   66     m_type = PercentageToken; |   66     m_type = PercentageToken; | 
|   67     m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; |   67     m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; | 
|   68 } |   68 } | 
|   69  |   69  | 
|   70 // This function is used only for testing |  | 
|   71 // FIXME - This doesn't cover all possible Token types, but it's enough for curr
     ent testing. |  | 
|   72 String CSSParserToken::textForUnitTests() const |  | 
|   73 { |  | 
|   74     if (!m_value.isNull()) |  | 
|   75         return m_value; |  | 
|   76     if (m_type == LeftParenthesisToken) |  | 
|   77         return "("; |  | 
|   78     if (m_type == RightParenthesisToken) |  | 
|   79         return ")"; |  | 
|   80     if (m_type == ColonToken) |  | 
|   81         return ":"; |  | 
|   82     if (m_type == WhitespaceToken) |  | 
|   83         return " "; |  | 
|   84     if (m_delimiter) |  | 
|   85         return String("'") + m_delimiter + '\''; |  | 
|   86  |  | 
|   87     if (m_numericValue) { |  | 
|   88         String unit; |  | 
|   89         if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE) |  | 
|   90             unit = "%"; |  | 
|   91         else if (m_unit == CSSPrimitiveValue::CSS_PX) |  | 
|   92             unit = "px"; |  | 
|   93         else if (m_unit == CSSPrimitiveValue::CSS_EMS) |  | 
|   94             unit = "em"; |  | 
|   95         else if (m_unit != CSSPrimitiveValue::CSS_NUMBER) |  | 
|   96             unit = "other"; |  | 
|   97         if (m_numericValueType == IntegerValueType) |  | 
|   98             return String::number(static_cast<int>(m_numericValue)) + unit; |  | 
|   99         const unsigned fractionalDigits = 6; |  | 
|  100         return String::numberToStringFixedWidth(m_numericValue, fractionalDigits
     ) + unit; |  | 
|  101     } |  | 
|  102     return String(); |  | 
|  103 } |  | 
|  104  |  | 
|  105 UChar CSSParserToken::delimiter() const |   70 UChar CSSParserToken::delimiter() const | 
|  106 { |   71 { | 
|  107     ASSERT(m_type == DelimiterToken); |   72     ASSERT(m_type == DelimiterToken); | 
|  108     return m_delimiter; |   73     return m_delimiter; | 
|  109 } |   74 } | 
|  110  |   75  | 
|  111 NumericValueType CSSParserToken::numericValueType() const |   76 NumericValueType CSSParserToken::numericValueType() const | 
|  112 { |   77 { | 
|  113     ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
     sionToken); |   78     ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
     sionToken); | 
|  114     return m_numericValueType; |   79     return m_numericValueType; | 
|  115 } |   80 } | 
|  116  |   81  | 
|  117 double CSSParserToken::numericValue() const |   82 double CSSParserToken::numericValue() const | 
|  118 { |   83 { | 
|  119     ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
     sionToken); |   84     ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
     sionToken); | 
|  120     return m_numericValue; |   85     return m_numericValue; | 
|  121 } |   86 } | 
|  122  |   87  | 
|  123 } // namespace blink |   88 } // namespace blink | 
| OLD | NEW |