| 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 "core/css/CSSQuadValue.h" | 5 #include "core/css/CSSQuadValue.h" |
| 6 | 6 |
| 7 #include "core/css/serializer/CSSDeserializeStream.h" |
| 8 #include "core/css/serializer/CSSSerializeStream.h" |
| 7 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
| 8 | 10 |
| 9 namespace blink { | 11 namespace blink { |
| 10 | 12 |
| 13 PassRefPtrWillBeRawPtr<CSSQuadValue> CSSQuadValue::deserializeAfterDispatch(CSSD
eserializeStream* stream) |
| 14 { |
| 15 SerializationType serializationType = static_cast<SerializationType>(stream-
>readBool()); |
| 16 RefPtrWillBeRawPtr<CSSValue> top = CSSValue::deserialize(stream); |
| 17 RefPtrWillBeRawPtr<CSSValue> right = CSSValue::deserialize(stream); |
| 18 RefPtrWillBeRawPtr<CSSValue> left = CSSValue::deserialize(stream); |
| 19 RefPtrWillBeRawPtr<CSSValue> bottom = CSSValue::deserialize(stream); |
| 20 return create( |
| 21 toCSSPrimitiveValue(top.get()), |
| 22 toCSSPrimitiveValue(right.get()), |
| 23 toCSSPrimitiveValue(left.get()), |
| 24 toCSSPrimitiveValue(bottom.get()), |
| 25 serializationType); |
| 26 } |
| 27 |
| 11 String CSSQuadValue::customCSSText() const | 28 String CSSQuadValue::customCSSText() const |
| 12 { | 29 { |
| 13 String top = m_top->cssText(); | 30 String top = m_top->cssText(); |
| 14 String right = m_right->cssText(); | 31 String right = m_right->cssText(); |
| 15 String bottom = m_bottom->cssText(); | 32 String bottom = m_bottom->cssText(); |
| 16 String left = m_left->cssText(); | 33 String left = m_left->cssText(); |
| 17 | 34 |
| 18 if (m_serializationType == SerializationType::SerializeAsRect) | 35 if (m_serializationType == SerializationType::SerializeAsRect) |
| 19 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; | 36 return "rect(" + top + ' ' + right + ' ' + bottom + ' ' + left + ')'; |
| 20 | 37 |
| 21 StringBuilder result; | 38 StringBuilder result; |
| 22 // reserve space for the four strings, plus three space separator characters
. | 39 // reserve space for the four strings, plus three space separator characters
. |
| 23 result.reserveCapacity(top.length() + right.length() + bottom.length() + lef
t.length() + 3); | 40 result.reserveCapacity(top.length() + right.length() + bottom.length() + lef
t.length() + 3); |
| 24 result.append(top); | 41 result.append(top); |
| 25 if (right != top || bottom != top || left != top) { | 42 if (right != top || bottom != top || left != top) { |
| 26 result.append(' '); | 43 result.append(' '); |
| 27 result.append(right); | 44 result.append(right); |
| 28 if (bottom != top || right != left) { | 45 if (bottom != top || right != left) { |
| 29 result.append(' '); | 46 result.append(' '); |
| 30 result.append(bottom); | 47 result.append(bottom); |
| 31 if (left != right) { | 48 if (left != right) { |
| 32 result.append(' '); | 49 result.append(' '); |
| 33 result.append(left); | 50 result.append(left); |
| 34 } | 51 } |
| 35 } | 52 } |
| 36 } | 53 } |
| 37 return result.toString(); | 54 return result.toString(); |
| 38 } | 55 } |
| 39 | 56 |
| 57 void CSSQuadValue::serializeAfterDispatch(CSSSerializeStream* stream) const |
| 58 { |
| 59 stream->writeBool(m_serializationType); |
| 60 m_top->serialize(stream); |
| 61 m_right->serialize(stream); |
| 62 m_bottom->serialize(stream); |
| 63 m_left->serialize(stream); |
| 64 } |
| 65 |
| 40 DEFINE_TRACE_AFTER_DISPATCH(CSSQuadValue) | 66 DEFINE_TRACE_AFTER_DISPATCH(CSSQuadValue) |
| 41 { | 67 { |
| 42 visitor->trace(m_top); | 68 visitor->trace(m_top); |
| 43 visitor->trace(m_right); | 69 visitor->trace(m_right); |
| 44 visitor->trace(m_bottom); | 70 visitor->trace(m_bottom); |
| 45 visitor->trace(m_left); | 71 visitor->trace(m_left); |
| 46 CSSValue::traceAfterDispatch(visitor); | 72 CSSValue::traceAfterDispatch(visitor); |
| 47 } | 73 } |
| 48 | 74 |
| 49 } | 75 } |
| OLD | NEW |