| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CSSCalcLength.h" | 5 #include "core/css/cssom/CSSCalcLength.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/css/CSSCalculationValue.h" | 8 #include "core/css/CSSCalculationValue.h" |
| 9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/cssom/CSSCalcDictionary.h" | 10 #include "core/css/cssom/CSSCalcDictionary.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 "CSSCalcLength."); | 67 "CSSCalcLength."); |
| 68 } | 68 } |
| 69 return result; | 69 return result; |
| 70 } | 70 } |
| 71 | 71 |
| 72 CSSCalcLength* CSSCalcLength::fromCSSValue(const CSSPrimitiveValue&) { | 72 CSSCalcLength* CSSCalcLength::fromCSSValue(const CSSPrimitiveValue&) { |
| 73 // TODO(meade): Implement. | 73 // TODO(meade): Implement. |
| 74 return nullptr; | 74 return nullptr; |
| 75 } | 75 } |
| 76 | 76 |
| 77 CSSCalcLength* CSSCalcLength::fromLength(const Length& length) { |
| 78 DCHECK(length.isCalculated()); |
| 79 PixelsAndPercent values = length.getPixelsAndPercent(); |
| 80 CSSCalcLength* result = new CSSCalcLength(); |
| 81 result->set(values.pixels, CSSPrimitiveValue::UnitType::Pixels); |
| 82 result->set(values.percent, CSSPrimitiveValue::UnitType::Percentage); |
| 83 return result; |
| 84 } |
| 85 |
| 77 bool CSSCalcLength::containsPercent() const { | 86 bool CSSCalcLength::containsPercent() const { |
| 78 return has(CSSPrimitiveValue::UnitType::Percentage); | 87 return has(CSSPrimitiveValue::UnitType::Percentage); |
| 79 } | 88 } |
| 80 | 89 |
| 81 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other) { | 90 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other) { |
| 82 CSSCalcLength* result = CSSCalcLength::create(other); | 91 CSSCalcLength* result = CSSCalcLength::create(other); |
| 83 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { | 92 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
| 84 if (hasAtIndex(i)) { | 93 if (hasAtIndex(i)) { |
| 85 result->setAtIndex(getAtIndex(i) + result->getAtIndex(i), i); | 94 result->setAtIndex(getAtIndex(i) + result->getAtIndex(i), i); |
| 86 } | 95 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 153 } |
| 145 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); | 154 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); |
| 146 } | 155 } |
| 147 | 156 |
| 148 int CSSCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) { | 157 int CSSCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) { |
| 149 return (static_cast<int>(unit) - | 158 return (static_cast<int>(unit) - |
| 150 static_cast<int>(CSSPrimitiveValue::UnitType::Percentage)); | 159 static_cast<int>(CSSPrimitiveValue::UnitType::Percentage)); |
| 151 } | 160 } |
| 152 | 161 |
| 153 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |