Chromium Code Reviews| 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 "core/css/CSSCalculationValue.h" | 7 #include "core/css/CSSCalculationValue.h" |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/cssom/CSSCalcDictionary.h" | 9 #include "core/css/cssom/CSSCalcDictionary.h" |
| 10 #include "core/css/cssom/CSSSimpleLength.h" | 10 #include "core/css/cssom/CSSSimpleLength.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 setFromDictValue(in, In, Inches) | 61 setFromDictValue(in, In, Inches) |
| 62 setFromDictValue(pc, Pc, Picas) | 62 setFromDictValue(pc, Pc, Picas) |
| 63 setFromDictValue(pt, Pt, Points) | 63 setFromDictValue(pt, Pt, Points) |
| 64 | 64 |
| 65 if (numSet == 0) { | 65 if (numSet == 0) { |
| 66 exceptionState.throwTypeError("Must specify at least one value in CSSCal cDictionary for creating a CSSCalcLength."); | 66 exceptionState.throwTypeError("Must specify at least one value in CSSCal cDictionary for creating a CSSCalcLength."); |
| 67 } | 67 } |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 CSSCalcLength* CSSCalcLength::fromLength(const Length& length) | |
| 72 { | |
| 73 DCHECK(length.isSpecified()); | |
| 74 PixelsAndPercent values = length.getPixelsAndPercent(); | |
| 75 CSSCalcLength* result = new CSSCalcLength(); | |
| 76 if (length.isFixed()) { | |
| 77 result->set(values.pixels, CSSPrimitiveValue::UnitType::Pixels); | |
|
meade_UTC10
2016/09/22 05:34:35
Shouldn't fixed lengths become CSSSimpleLengths? (
rjwright
2016/09/23 04:50:03
This is not even reached so I just removed it.
| |
| 78 return result; | |
| 79 } | |
| 80 if (length.isPercent()) { | |
| 81 result->set(values.percent, CSSPrimitiveValue::UnitType::Percentage); | |
| 82 return result; | |
| 83 } | |
| 84 result->set(values.pixels, CSSPrimitiveValue::UnitType::Pixels); | |
| 85 result->set(values.percent, CSSPrimitiveValue::UnitType::Percentage); | |
| 86 return result; | |
| 87 } | |
| 88 | |
| 71 bool CSSCalcLength::containsPercent() const | 89 bool CSSCalcLength::containsPercent() const |
| 72 { | 90 { |
| 73 return has(CSSPrimitiveValue::UnitType::Percentage); | 91 return has(CSSPrimitiveValue::UnitType::Percentage); |
| 74 } | 92 } |
| 75 | 93 |
| 76 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other, Exceptio nState& exceptionState) | 94 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other, Exceptio nState& exceptionState) |
| 77 { | 95 { |
| 78 CSSCalcLength* result = CSSCalcLength::create(other, exceptionState); | 96 CSSCalcLength* result = CSSCalcLength::create(other, exceptionState); |
| 79 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { | 97 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
| 80 if (hasAtIndex(i)) { | 98 if (hasAtIndex(i)) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 } | 160 } |
| 143 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); | 161 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); |
| 144 } | 162 } |
| 145 | 163 |
| 146 int CSSCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) | 164 int CSSCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) |
| 147 { | 165 { |
| 148 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp e::Percentage)); | 166 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp e::Percentage)); |
| 149 } | 167 } |
| 150 | 168 |
| 151 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |