Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp

Issue 2403423002: [CSSTypedOM] Computed StylePropertyMap use ComputedStyle for Lengths (Closed)
Patch Set: sasha's comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 CSSCalcLength* CSSCalcLength::fromCSSValue(const CSSPrimitiveValue& value) { 84 CSSCalcLength* CSSCalcLength::fromCSSValue(const CSSPrimitiveValue& value) {
85 std::unique_ptr<UnitData> unitData = 85 std::unique_ptr<UnitData> unitData =
86 UnitData::fromExpressionNode(value.cssCalcValue()->expressionNode()); 86 UnitData::fromExpressionNode(value.cssCalcValue()->expressionNode());
87 if (unitData) 87 if (unitData)
88 return new CSSCalcLength(*unitData); 88 return new CSSCalcLength(*unitData);
89 return nullptr; 89 return nullptr;
90 } 90 }
91 91
92 CSSCalcLength* CSSCalcLength::fromLength(const Length& length) {
93 DCHECK(length.isCalculated());
94 PixelsAndPercent values = length.getPixelsAndPercent();
95 UnitData unitData;
96 unitData.set(CSSPrimitiveValue::UnitType::Pixels, values.pixels);
97 unitData.set(CSSPrimitiveValue::UnitType::Percentage, values.percent);
98 CSSCalcLength* result = new CSSCalcLength(unitData);
99 return result;
100 }
101
92 bool CSSCalcLength::containsPercent() const { 102 bool CSSCalcLength::containsPercent() const {
93 return m_unitData.has(CSSPrimitiveValue::UnitType::Percentage); 103 return m_unitData.has(CSSPrimitiveValue::UnitType::Percentage);
94 } 104 }
95 105
96 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other) { 106 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other) {
97 UnitData result = m_unitData; 107 UnitData result = m_unitData;
98 if (other->type() == SimpleLengthType) { 108 if (other->type() == SimpleLengthType) {
99 const CSSSimpleLength* simpleLength = toCSSSimpleLength(other); 109 const CSSSimpleLength* simpleLength = toCSSSimpleLength(other);
100 result.set( 110 result.set(
101 simpleLength->lengthUnit(), 111 simpleLength->lengthUnit(),
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void CSSCalcLength::UnitData::divide(double x) { 233 void CSSCalcLength::UnitData::divide(double x) {
224 DCHECK_NE(x, 0); 234 DCHECK_NE(x, 0);
225 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 235 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
226 if (hasAtIndex(i)) { 236 if (hasAtIndex(i)) {
227 setAtIndex(i, getAtIndex(i) / x); 237 setAtIndex(i, getAtIndex(i) / x);
228 } 238 }
229 } 239 }
230 } 240 }
231 241
232 } // namespace blink 242 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698