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

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

Issue 2382653006: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Make check-webkit-style happy 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return CSSPrimitiveValue::UFrequency; 79 return CSSPrimitiveValue::UFrequency;
80 case UnitType::DotsPerPixel: 80 case UnitType::DotsPerPixel:
81 case UnitType::DotsPerInch: 81 case UnitType::DotsPerInch:
82 case UnitType::DotsPerCentimeter: 82 case UnitType::DotsPerCentimeter:
83 return CSSPrimitiveValue::UResolution; 83 return CSSPrimitiveValue::UResolution;
84 default: 84 default:
85 return CSSPrimitiveValue::UOther; 85 return CSSPrimitiveValue::UOther;
86 } 86 }
87 } 87 }
88 88
89 bool CSSPrimitiveValue::colorIsDerivedFromElement() const {
90 int valueID = getValueID();
91 switch (valueID) {
92 case CSSValueInternalQuirkInherit:
93 case CSSValueWebkitLink:
94 case CSSValueWebkitActivelink:
95 case CSSValueCurrentcolor:
96 return true;
97 default:
98 return false;
99 }
100 }
101
102 CSSPrimitiveValue* CSSPrimitiveValue::createIdentifier(CSSValueID valueID) {
103 CSSPrimitiveValue* cssValue = cssValuePool().identifierCacheValue(valueID);
104 if (!cssValue)
105 cssValue = cssValuePool().setIdentifierCacheValue(
106 valueID, new CSSPrimitiveValue(valueID));
107 return cssValue;
108 }
109
110 CSSPrimitiveValue* CSSPrimitiveValue::create(double value, UnitType type) { 89 CSSPrimitiveValue* CSSPrimitiveValue::create(double value, UnitType type) {
111 // TODO(timloh): This looks wrong. 90 // TODO(timloh): This looks wrong.
112 if (std::isinf(value)) 91 if (std::isinf(value))
113 value = 0; 92 value = 0;
114 93
115 if (value < 0 || value > CSSValuePool::maximumCacheableIntegerValue) 94 if (value < 0 || value > CSSValuePool::maximumCacheableIntegerValue)
116 return new CSSPrimitiveValue(value, type); 95 return new CSSPrimitiveValue(value, type);
117 96
118 int intValue = static_cast<int>(value); 97 int intValue = static_cast<int>(value);
119 if (value != intValue) 98 if (value != intValue)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 case CalcPercentLengthNumber: 158 case CalcPercentLengthNumber:
180 return UnitType::CalcPercentageWithLengthAndNumber; 159 return UnitType::CalcPercentageWithLengthAndNumber;
181 case CalcTime: 160 case CalcTime:
182 return UnitType::Milliseconds; 161 return UnitType::Milliseconds;
183 case CalcOther: 162 case CalcOther:
184 return UnitType::Unknown; 163 return UnitType::Unknown;
185 } 164 }
186 return UnitType::Unknown; 165 return UnitType::Unknown;
187 } 166 }
188 167
189 static const AtomicString& valueName(CSSValueID valueID) {
190 DCHECK_GE(valueID, 0);
191 DCHECK_LT(valueID, numCSSValueKeywords);
192
193 if (valueID < 0)
194 return nullAtom;
195
196 static AtomicString* keywordStrings =
197 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 init(UnitType::ValueID);
207 // TODO(sashab): Add a DCHECK_NE(valueID, CSSValueInvalid).
208 m_value.valueID = valueID;
209 }
210
211 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) 168 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type)
212 : CSSValue(PrimitiveClass) { 169 : CSSValue(PrimitiveClass) {
213 init(type); 170 init(type);
214 ASSERT(std::isfinite(num)); 171 ASSERT(std::isfinite(num));
215 m_value.num = num; 172 m_value.num = num;
216 } 173 }
217 174
218 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) 175 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom)
219 : CSSValue(PrimitiveClass) { 176 : CSSValue(PrimitiveClass) {
220 switch (length.type()) { 177 switch (length.type()) {
221 case Auto:
222 init(UnitType::ValueID);
223 m_value.valueID = CSSValueAuto;
224 break;
225 case MinContent:
226 init(UnitType::ValueID);
227 m_value.valueID = CSSValueMinContent;
228 break;
229 case MaxContent:
230 init(UnitType::ValueID);
231 m_value.valueID = CSSValueMaxContent;
232 break;
233 case FillAvailable:
234 init(UnitType::ValueID);
235 m_value.valueID = CSSValueWebkitFillAvailable;
236 break;
237 case FitContent:
238 init(UnitType::ValueID);
239 m_value.valueID = CSSValueFitContent;
240 break;
241 case ExtendToZoom:
242 init(UnitType::ValueID);
243 m_value.valueID = CSSValueInternalExtendToZoom;
244 break;
245 case Percent: 178 case Percent:
246 init(UnitType::Percentage); 179 init(UnitType::Percentage);
247 ASSERT(std::isfinite(length.percent())); 180 ASSERT(std::isfinite(length.percent()));
248 m_value.num = length.percent(); 181 m_value.num = length.percent();
249 break; 182 break;
250 case Fixed: 183 case Fixed:
251 init(UnitType::Pixels); 184 init(UnitType::Pixels);
252 m_value.num = length.value() / zoom; 185 m_value.num = length.value() / zoom;
253 break; 186 break;
254 case Calculated: { 187 case Calculated: {
255 const CalculationValue& calc = length.getCalculationValue(); 188 const CalculationValue& calc = length.getCalculationValue();
256 if (calc.pixels() && calc.percent()) { 189 if (calc.pixels() && calc.percent()) {
257 init(CSSCalcValue::create(CSSCalcValue::createExpressionNode( 190 init(CSSCalcValue::create(CSSCalcValue::createExpressionNode(
258 calc.pixels() / zoom, calc.percent()), 191 calc.pixels() / zoom, calc.percent()),
259 calc.getValueRange())); 192 calc.getValueRange()));
260 break; 193 break;
261 } 194 }
262 if (calc.percent()) { 195 if (calc.percent()) {
263 init(UnitType::Percentage); 196 init(UnitType::Percentage);
264 m_value.num = calc.percent(); 197 m_value.num = calc.percent();
265 } else { 198 } else {
266 init(UnitType::Pixels); 199 init(UnitType::Pixels);
267 m_value.num = calc.pixels() / zoom; 200 m_value.num = calc.pixels() / zoom;
268 } 201 }
269 if (m_value.num < 0 && calc.isNonNegative()) 202 if (m_value.num < 0 && calc.isNonNegative())
270 m_value.num = 0; 203 m_value.num = 0;
271 break; 204 break;
272 } 205 }
206 case Auto:
207 case MinContent:
208 case MaxContent:
209 case FillAvailable:
210 case FitContent:
211 case ExtendToZoom:
273 case DeviceWidth: 212 case DeviceWidth:
274 case DeviceHeight: 213 case DeviceHeight:
275 case MaxSizeNone: 214 case MaxSizeNone:
276 ASSERT_NOT_REACHED(); 215 ASSERT_NOT_REACHED();
277 break; 216 break;
278 } 217 }
279 } 218 }
280 219
281 void CSSPrimitiveValue::init(UnitType type) { 220 void CSSPrimitiveValue::init(UnitType type) {
282 m_primitiveUnitType = static_cast<unsigned>(type); 221 m_primitiveUnitType = static_cast<unsigned>(type);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 return "fr"; 567 return "fr";
629 case UnitType::ViewportWidth: 568 case UnitType::ViewportWidth:
630 return "vw"; 569 return "vw";
631 case UnitType::ViewportHeight: 570 case UnitType::ViewportHeight:
632 return "vh"; 571 return "vh";
633 case UnitType::ViewportMin: 572 case UnitType::ViewportMin:
634 return "vmin"; 573 return "vmin";
635 case UnitType::ViewportMax: 574 case UnitType::ViewportMax:
636 return "vmax"; 575 return "vmax";
637 case UnitType::Unknown: 576 case UnitType::Unknown:
638 case UnitType::ValueID:
639 case UnitType::Calc: 577 case UnitType::Calc:
640 case UnitType::CalcPercentageWithNumber: 578 case UnitType::CalcPercentageWithNumber:
641 case UnitType::CalcPercentageWithLength: 579 case UnitType::CalcPercentageWithLength:
642 case UnitType::CalcLengthWithNumber: 580 case UnitType::CalcLengthWithNumber:
643 case UnitType::CalcPercentageWithLengthAndNumber: 581 case UnitType::CalcPercentageWithLengthAndNumber:
644 break; 582 break;
645 }; 583 };
646 ASSERT_NOT_REACHED(); 584 ASSERT_NOT_REACHED();
647 return ""; 585 return "";
648 } 586 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 case UnitType::Hertz: 624 case UnitType::Hertz:
687 case UnitType::Kilohertz: 625 case UnitType::Kilohertz:
688 case UnitType::Turns: 626 case UnitType::Turns:
689 case UnitType::Fraction: 627 case UnitType::Fraction:
690 case UnitType::ViewportWidth: 628 case UnitType::ViewportWidth:
691 case UnitType::ViewportHeight: 629 case UnitType::ViewportHeight:
692 case UnitType::ViewportMin: 630 case UnitType::ViewportMin:
693 case UnitType::ViewportMax: 631 case UnitType::ViewportMax:
694 text = formatNumber(m_value.num, unitTypeToString(type())); 632 text = formatNumber(m_value.num, unitTypeToString(type()));
695 break; 633 break;
696 case UnitType::ValueID:
697 text = valueName(m_value.valueID);
698 break;
699 case UnitType::Calc: 634 case UnitType::Calc:
700 text = m_value.calc->customCSSText(); 635 text = m_value.calc->customCSSText();
701 break; 636 break;
702 case UnitType::CalcPercentageWithNumber: 637 case UnitType::CalcPercentageWithNumber:
703 case UnitType::CalcPercentageWithLength: 638 case UnitType::CalcPercentageWithLength:
704 case UnitType::CalcLengthWithNumber: 639 case UnitType::CalcLengthWithNumber:
705 case UnitType::CalcPercentageWithLengthAndNumber: 640 case UnitType::CalcPercentageWithLengthAndNumber:
706 ASSERT_NOT_REACHED(); 641 ASSERT_NOT_REACHED();
707 break; 642 break;
708 } 643 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 case UnitType::Seconds: 678 case UnitType::Seconds:
744 case UnitType::Hertz: 679 case UnitType::Hertz:
745 case UnitType::Kilohertz: 680 case UnitType::Kilohertz:
746 case UnitType::Turns: 681 case UnitType::Turns:
747 case UnitType::ViewportWidth: 682 case UnitType::ViewportWidth:
748 case UnitType::ViewportHeight: 683 case UnitType::ViewportHeight:
749 case UnitType::ViewportMin: 684 case UnitType::ViewportMin:
750 case UnitType::ViewportMax: 685 case UnitType::ViewportMax:
751 case UnitType::Fraction: 686 case UnitType::Fraction:
752 return m_value.num == other.m_value.num; 687 return m_value.num == other.m_value.num;
753 case UnitType::ValueID:
754 return m_value.valueID == other.m_value.valueID;
755 case UnitType::Calc: 688 case UnitType::Calc:
756 return m_value.calc && other.m_value.calc && 689 return m_value.calc && other.m_value.calc &&
757 m_value.calc->equals(*other.m_value.calc); 690 m_value.calc->equals(*other.m_value.calc);
758 case UnitType::Chs: 691 case UnitType::Chs:
759 case UnitType::CalcPercentageWithNumber: 692 case UnitType::CalcPercentageWithNumber:
760 case UnitType::CalcPercentageWithLength: 693 case UnitType::CalcPercentageWithLength:
761 case UnitType::CalcLengthWithNumber: 694 case UnitType::CalcLengthWithNumber:
762 case UnitType::CalcPercentageWithLengthAndNumber: 695 case UnitType::CalcPercentageWithLengthAndNumber:
763 case UnitType::QuirkyEms: 696 case UnitType::QuirkyEms:
764 return false; 697 return false;
765 } 698 }
766 return false; 699 return false;
767 } 700 }
768 701
769 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) { 702 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) {
770 switch (type()) { 703 switch (type()) {
771 case UnitType::Calc: 704 case UnitType::Calc:
772 visitor->trace(m_value.calc); 705 visitor->trace(m_value.calc);
773 break; 706 break;
774 default: 707 default:
775 break; 708 break;
776 } 709 }
777 CSSValue::traceAfterDispatch(visitor); 710 CSSValue::traceAfterDispatch(visitor);
778 } 711 }
779 712
780 } // namespace blink 713 } // 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