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

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

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Rebase please work Created 4 years, 2 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 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return CSSPrimitiveValue::UFrequency; 80 return CSSPrimitiveValue::UFrequency;
81 case UnitType::DotsPerPixel: 81 case UnitType::DotsPerPixel:
82 case UnitType::DotsPerInch: 82 case UnitType::DotsPerInch:
83 case UnitType::DotsPerCentimeter: 83 case UnitType::DotsPerCentimeter:
84 return CSSPrimitiveValue::UResolution; 84 return CSSPrimitiveValue::UResolution;
85 default: 85 default:
86 return CSSPrimitiveValue::UOther; 86 return CSSPrimitiveValue::UOther;
87 } 87 }
88 } 88 }
89 89
90 bool CSSPrimitiveValue::colorIsDerivedFromElement() const
91 {
92 int valueID = getValueID();
93 switch (valueID) {
94 case CSSValueInternalQuirkInherit:
95 case CSSValueWebkitLink:
96 case CSSValueWebkitActivelink:
97 case CSSValueCurrentcolor:
98 return true;
99 default:
100 return false;
101 }
102 }
103
104 CSSPrimitiveValue* CSSPrimitiveValue::createIdentifier(CSSValueID valueID)
105 {
106 CSSPrimitiveValue* cssValue = cssValuePool().identifierCacheValue(valueID);
107 if (!cssValue)
108 cssValue = cssValuePool().setIdentifierCacheValue(valueID, new CSSPrimit iveValue(valueID));
109 return cssValue;
110 }
111
112 CSSPrimitiveValue* CSSPrimitiveValue::create(double value, UnitType type) 90 CSSPrimitiveValue* CSSPrimitiveValue::create(double value, UnitType type)
113 { 91 {
114 // TODO(timloh): This looks wrong. 92 // TODO(timloh): This looks wrong.
115 if (std::isinf(value)) 93 if (std::isinf(value))
116 value = 0; 94 value = 0;
117 95
118 if (value < 0 || value > CSSValuePool::maximumCacheableIntegerValue) 96 if (value < 0 || value > CSSValuePool::maximumCacheableIntegerValue)
119 return new CSSPrimitiveValue(value, type); 97 return new CSSPrimitiveValue(value, type);
120 98
121 int intValue = static_cast<int>(value); 99 int intValue = static_cast<int>(value);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 case CalcPercentLengthNumber: 157 case CalcPercentLengthNumber:
180 return UnitType::CalcPercentageWithLengthAndNumber; 158 return UnitType::CalcPercentageWithLengthAndNumber;
181 case CalcTime: 159 case CalcTime:
182 return UnitType::Milliseconds; 160 return UnitType::Milliseconds;
183 case CalcOther: 161 case CalcOther:
184 return UnitType::Unknown; 162 return UnitType::Unknown;
185 } 163 }
186 return UnitType::Unknown; 164 return UnitType::Unknown;
187 } 165 }
188 166
189 static const AtomicString& valueName(CSSValueID valueID)
190 {
191 DCHECK_GE(valueID, 0);
192 DCHECK_LT(valueID, numCSSValueKeywords);
193
194 if (valueID < 0)
195 return nullAtom;
196
197 static AtomicString* keywordStrings = new AtomicString[numCSSValueKeywords]; // Leaked intentionally.
198 AtomicString& keywordString = keywordStrings[valueID];
199 if (keywordString.isNull())
200 keywordString = getValueName(valueID);
201 return keywordString;
202 }
203
204 CSSPrimitiveValue::CSSPrimitiveValue(CSSValueID valueID)
205 : CSSValue(PrimitiveClass)
206 {
207 init(UnitType::ValueID);
208 // TODO(sashab): Add a DCHECK_NE(valueID, CSSValueInvalid).
209 m_value.valueID = valueID;
210 }
211
212 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) 167 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type)
213 : CSSValue(PrimitiveClass) 168 : CSSValue(PrimitiveClass)
214 { 169 {
215 init(type); 170 init(type);
216 ASSERT(std::isfinite(num)); 171 ASSERT(std::isfinite(num));
217 m_value.num = num; 172 m_value.num = num;
218 } 173 }
219 174
220 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) 175 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom)
221 : CSSValue(PrimitiveClass) 176 : CSSValue(PrimitiveClass)
222 { 177 {
223 switch (length.type()) { 178 switch (length.type()) {
224 case Auto:
225 init(UnitType::ValueID);
226 m_value.valueID = CSSValueAuto;
227 break;
228 case MinContent:
229 init(UnitType::ValueID);
230 m_value.valueID = CSSValueMinContent;
231 break;
232 case MaxContent:
233 init(UnitType::ValueID);
234 m_value.valueID = CSSValueMaxContent;
235 break;
236 case FillAvailable:
237 init(UnitType::ValueID);
238 m_value.valueID = CSSValueWebkitFillAvailable;
239 break;
240 case FitContent:
241 init(UnitType::ValueID);
242 m_value.valueID = CSSValueFitContent;
243 break;
244 case ExtendToZoom:
245 init(UnitType::ValueID);
246 m_value.valueID = CSSValueInternalExtendToZoom;
247 break;
248 case Percent: 179 case Percent:
249 init(UnitType::Percentage); 180 init(UnitType::Percentage);
250 ASSERT(std::isfinite(length.percent())); 181 ASSERT(std::isfinite(length.percent()));
251 m_value.num = length.percent(); 182 m_value.num = length.percent();
252 break; 183 break;
253 case Fixed: 184 case Fixed:
254 init(UnitType::Pixels); 185 init(UnitType::Pixels);
255 m_value.num = length.value() / zoom; 186 m_value.num = length.value() / zoom;
256 break; 187 break;
257 case Calculated: { 188 case Calculated: {
258 const CalculationValue& calc = length.getCalculationValue(); 189 const CalculationValue& calc = length.getCalculationValue();
259 if (calc.pixels() && calc.percent()) { 190 if (calc.pixels() && calc.percent()) {
260 init(CSSCalcValue::create( 191 init(CSSCalcValue::create(
261 CSSCalcValue::createExpressionNode(calc.pixels() / zoom, calc.pe rcent()), 192 CSSCalcValue::createExpressionNode(calc.pixels() / zoom, calc.pe rcent()),
262 calc.getValueRange())); 193 calc.getValueRange()));
263 break; 194 break;
264 } 195 }
265 if (calc.percent()) { 196 if (calc.percent()) {
266 init(UnitType::Percentage); 197 init(UnitType::Percentage);
267 m_value.num = calc.percent(); 198 m_value.num = calc.percent();
268 } else { 199 } else {
269 init(UnitType::Pixels); 200 init(UnitType::Pixels);
270 m_value.num = calc.pixels() / zoom; 201 m_value.num = calc.pixels() / zoom;
271 } 202 }
272 if (m_value.num < 0 && calc.isNonNegative()) 203 if (m_value.num < 0 && calc.isNonNegative())
273 m_value.num = 0; 204 m_value.num = 0;
274 break; 205 break;
275 } 206 }
207 case Auto:
208 case MinContent:
209 case MaxContent:
210 case FillAvailable:
211 case FitContent:
212 case ExtendToZoom:
276 case DeviceWidth: 213 case DeviceWidth:
277 case DeviceHeight: 214 case DeviceHeight:
278 case MaxSizeNone: 215 case MaxSizeNone:
279 ASSERT_NOT_REACHED(); 216 ASSERT_NOT_REACHED();
280 break; 217 break;
281 } 218 }
282 } 219 }
283 220
284 void CSSPrimitiveValue::init(UnitType type) 221 void CSSPrimitiveValue::init(UnitType type)
285 { 222 {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 return "fr"; 559 return "fr";
623 case UnitType::ViewportWidth: 560 case UnitType::ViewportWidth:
624 return "vw"; 561 return "vw";
625 case UnitType::ViewportHeight: 562 case UnitType::ViewportHeight:
626 return "vh"; 563 return "vh";
627 case UnitType::ViewportMin: 564 case UnitType::ViewportMin:
628 return "vmin"; 565 return "vmin";
629 case UnitType::ViewportMax: 566 case UnitType::ViewportMax:
630 return "vmax"; 567 return "vmax";
631 case UnitType::Unknown: 568 case UnitType::Unknown:
632 case UnitType::ValueID:
633 case UnitType::Calc: 569 case UnitType::Calc:
634 case UnitType::CalcPercentageWithNumber: 570 case UnitType::CalcPercentageWithNumber:
635 case UnitType::CalcPercentageWithLength: 571 case UnitType::CalcPercentageWithLength:
636 case UnitType::CalcLengthWithNumber: 572 case UnitType::CalcLengthWithNumber:
637 case UnitType::CalcPercentageWithLengthAndNumber: 573 case UnitType::CalcPercentageWithLengthAndNumber:
638 break; 574 break;
639 }; 575 };
640 ASSERT_NOT_REACHED(); 576 ASSERT_NOT_REACHED();
641 return ""; 577 return "";
642 } 578 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 case UnitType::Hertz: 617 case UnitType::Hertz:
682 case UnitType::Kilohertz: 618 case UnitType::Kilohertz:
683 case UnitType::Turns: 619 case UnitType::Turns:
684 case UnitType::Fraction: 620 case UnitType::Fraction:
685 case UnitType::ViewportWidth: 621 case UnitType::ViewportWidth:
686 case UnitType::ViewportHeight: 622 case UnitType::ViewportHeight:
687 case UnitType::ViewportMin: 623 case UnitType::ViewportMin:
688 case UnitType::ViewportMax: 624 case UnitType::ViewportMax:
689 text = formatNumber(m_value.num, unitTypeToString(type())); 625 text = formatNumber(m_value.num, unitTypeToString(type()));
690 break; 626 break;
691 case UnitType::ValueID:
692 text = valueName(m_value.valueID);
693 break;
694 case UnitType::Calc: 627 case UnitType::Calc:
695 text = m_value.calc->customCSSText(); 628 text = m_value.calc->customCSSText();
696 break; 629 break;
697 case UnitType::CalcPercentageWithNumber: 630 case UnitType::CalcPercentageWithNumber:
698 case UnitType::CalcPercentageWithLength: 631 case UnitType::CalcPercentageWithLength:
699 case UnitType::CalcLengthWithNumber: 632 case UnitType::CalcLengthWithNumber:
700 case UnitType::CalcPercentageWithLengthAndNumber: 633 case UnitType::CalcPercentageWithLengthAndNumber:
701 ASSERT_NOT_REACHED(); 634 ASSERT_NOT_REACHED();
702 break; 635 break;
703 } 636 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 case UnitType::Seconds: 672 case UnitType::Seconds:
740 case UnitType::Hertz: 673 case UnitType::Hertz:
741 case UnitType::Kilohertz: 674 case UnitType::Kilohertz:
742 case UnitType::Turns: 675 case UnitType::Turns:
743 case UnitType::ViewportWidth: 676 case UnitType::ViewportWidth:
744 case UnitType::ViewportHeight: 677 case UnitType::ViewportHeight:
745 case UnitType::ViewportMin: 678 case UnitType::ViewportMin:
746 case UnitType::ViewportMax: 679 case UnitType::ViewportMax:
747 case UnitType::Fraction: 680 case UnitType::Fraction:
748 return m_value.num == other.m_value.num; 681 return m_value.num == other.m_value.num;
749 case UnitType::ValueID:
750 return m_value.valueID == other.m_value.valueID;
751 case UnitType::Calc: 682 case UnitType::Calc:
752 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 683 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc);
753 case UnitType::Chs: 684 case UnitType::Chs:
754 case UnitType::CalcPercentageWithNumber: 685 case UnitType::CalcPercentageWithNumber:
755 case UnitType::CalcPercentageWithLength: 686 case UnitType::CalcPercentageWithLength:
756 case UnitType::CalcLengthWithNumber: 687 case UnitType::CalcLengthWithNumber:
757 case UnitType::CalcPercentageWithLengthAndNumber: 688 case UnitType::CalcPercentageWithLengthAndNumber:
758 case UnitType::QuirkyEms: 689 case UnitType::QuirkyEms:
759 return false; 690 return false;
760 } 691 }
761 return false; 692 return false;
762 } 693 }
763 694
764 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) 695 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue)
765 { 696 {
766 switch (type()) { 697 switch (type()) {
767 case UnitType::Calc: 698 case UnitType::Calc:
768 visitor->trace(m_value.calc); 699 visitor->trace(m_value.calc);
769 break; 700 break;
770 default: 701 default:
771 break; 702 break;
772 } 703 }
773 CSSValue::traceAfterDispatch(visitor); 704 CSSValue::traceAfterDispatch(visitor);
774 } 705 }
775 706
776 } // namespace blink 707 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSPrimitiveValue.h ('k') | third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698