| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/css/cssom/SimpleLength.h" | 5 #include "core/css/cssom/SimpleLength.h" |
| 6 | 6 |
| 7 #include "core/css/CSSPrimitiveValue.h" | 7 #include "core/css/CSSPrimitiveValue.h" |
| 8 #include "core/css/cssom/StyleCalcLength.h" | 8 #include "core/css/cssom/StyleCalcLength.h" |
| 9 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 String SimpleLength::cssString() const | |
| 14 { | |
| 15 StringBuilder s; | |
| 16 s.appendNumber(m_value); | |
| 17 s.append(unit()); | |
| 18 return s.toString(); | |
| 19 } | |
| 20 | |
| 21 PassRefPtrWillBeRawPtr<CSSValue> SimpleLength::toCSSValue() const | 13 PassRefPtrWillBeRawPtr<CSSValue> SimpleLength::toCSSValue() const |
| 22 { | 14 { |
| 23 // TODO: Don't re-parse the unit. | 15 return cssValuePool().createValue(m_value, LengthValue::lengthTypeToPrimitiv
eType(m_unit)); |
| 24 return cssValuePool().createValue(m_value, CSSPrimitiveValue::fromName(unit(
))); | |
| 25 } | 16 } |
| 26 | 17 |
| 27 LengthValue* SimpleLength::addInternal(const LengthValue* other, ExceptionState&
exceptionState) | 18 LengthValue* SimpleLength::addInternal(const LengthValue* other, ExceptionState&
exceptionState) |
| 28 { | 19 { |
| 29 const SimpleLength* o = toSimpleLength(other); | 20 const SimpleLength* o = toSimpleLength(other); |
| 30 if (m_unit == o->m_unit) | 21 if (m_unit == o->m_unit) |
| 31 return create(m_value + o->value(), m_unit); | 22 return create(m_value + o->value(), m_unit); |
| 32 | 23 |
| 33 // Different units resolve to a calc. | 24 // Different units resolve to a calc. |
| 34 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); | 25 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 50 { | 41 { |
| 51 return create(m_value * x, m_unit); | 42 return create(m_value * x, m_unit); |
| 52 } | 43 } |
| 53 | 44 |
| 54 LengthValue* SimpleLength::divideInternal(double x, ExceptionState& exceptionSta
te) | 45 LengthValue* SimpleLength::divideInternal(double x, ExceptionState& exceptionSta
te) |
| 55 { | 46 { |
| 56 return create(m_value / x, m_unit); | 47 return create(m_value / x, m_unit); |
| 57 } | 48 } |
| 58 | 49 |
| 59 } // namespace blink | 50 } // namespace blink |
| OLD | NEW |