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

Side by Side Diff: Source/core/css/resolver/StyleBuilderConverter.cpp

Issue 468793003: Make style building for 'font-size' less custom. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * * Redistributions of source code must retain the above copyright 4 * * Redistributions of source code must retain the above copyright
5 * notice, this list of conditions and the following disclaimer. 5 * notice, this list of conditions and the following disclaimer.
6 * * Redistributions in binary form must reproduce the above 6 * * Redistributions in binary form must reproduce the above
7 * copyright notice, this list of conditions and the following disclaimer 7 * copyright notice, this list of conditions and the following disclaimer
8 * in the documentation and/or other materials provided with the 8 * in the documentation and/or other materials provided with the
9 * distribution. 9 * distribution.
10 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 CSSValueList* list = toCSSValueList(value); 99 CSSValueList* list = toCSSValueList(value);
100 RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create(); 100 RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create();
101 int len = list->length(); 101 int len = list->length();
102 for (int i = 0; i < len; ++i) { 102 for (int i = 0; i < len; ++i) {
103 CSSFontFeatureValue* feature = toCSSFontFeatureValue(list->item(i)); 103 CSSFontFeatureValue* feature = toCSSFontFeatureValue(list->item(i));
104 settings->append(FontFeature(feature->tag(), feature->value())); 104 settings->append(FontFeature(feature->tag(), feature->value()));
105 } 105 }
106 return settings; 106 return settings;
107 } 107 }
108 108
109 class RedirectSetHasViewportUnits {
110 public:
111 RedirectSetHasViewportUnits(RenderStyle* from, RenderStyle* to)
112 : m_from(from), m_to(to), m_hadViewportUnits(from->hasViewportUnits())
113 {
114 from->setHasViewportUnits(false);
115 }
116 ~RedirectSetHasViewportUnits()
117 {
118 m_to->setHasViewportUnits(m_from->hasViewportUnits());
119 m_from->setHasViewportUnits(m_hadViewportUnits);
120 }
121 private:
122 RenderStyle* m_from;
123 RenderStyle* m_to;
124 bool m_hadViewportUnits;
125 };
126
127 static float computeFontSize(StyleResolverState& state, CSSPrimitiveValue* primi tiveValue, const FontDescription::Size& parentSize)
128 {
129 RedirectSetHasViewportUnits redirect(state.parentStyle(), state.style());
130
131 CSSToLengthConversionData conversionData(state.parentStyle(), state.rootElem entStyle(), state.document().renderView(), 1.0f, true);
132 if (primitiveValue->isLength())
133 return primitiveValue->computeLength<float>(conversionData);
134 if (primitiveValue->isCalculatedPercentageWithLength())
135 return primitiveValue->cssCalcValue()->toCalcValue(conversionData)->eval uate(parentSize.value);
136
137 ASSERT_NOT_REACHED();
138 return 0;
139 }
140
141 FontDescription::Size StyleBuilderConverter::convertFontSize(StyleResolverState& state, CSSValue* value)
142 {
143 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
144
145 FontDescription::Size parentSize(0, 0.0f, false);
146
147 // FIXME: Find out when parentStyle could be 0?
148 if (state.parentStyle())
149 parentSize = state.parentFontDescription().size();
150
151 if (CSSValueID valueID = primitiveValue->getValueID()) {
152 switch (valueID) {
153 case CSSValueXxSmall:
154 case CSSValueXSmall:
155 case CSSValueSmall:
156 case CSSValueMedium:
157 case CSSValueLarge:
158 case CSSValueXLarge:
159 case CSSValueXxLarge:
160 case CSSValueWebkitXxxLarge:
161 return FontDescription::Size(FontSize::keywordSize(valueID), 0.0f, f alse);
162 case CSSValueLarger:
163 return FontDescription::largerSize(parentSize);
164 case CSSValueSmaller:
165 return FontDescription::smallerSize(parentSize);
166 default:
167 ASSERT_NOT_REACHED();
168 return FontBuilder::initialSize();
169 }
170 }
171
172 if (primitiveValue->isPercentage())
173 return FontDescription::Size(0, (primitiveValue->getFloatValue() * paren tSize.value / 100.0f), false);
174
175 return FontDescription::Size(0, computeFontSize(state, primitiveValue, paren tSize), !primitiveValue->isFontRelativeLength());
176 }
177
109 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, C SSValue* value) 178 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, C SSValue* value)
110 { 179 {
111 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 180 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
112 switch (primitiveValue->getValueID()) { 181 switch (primitiveValue->getValueID()) {
113 case CSSValueBolder: 182 case CSSValueBolder:
114 return FontDescription::bolderWeight(state.parentStyle()->fontDescriptio n().weight()); 183 return FontDescription::bolderWeight(state.parentStyle()->fontDescriptio n().weight());
115 case CSSValueLighter: 184 case CSSValueLighter:
116 return FontDescription::lighterWeight(state.parentStyle()->fontDescripti on().weight()); 185 return FontDescription::lighterWeight(state.parentStyle()->fontDescripti on().weight());
117 default: 186 default:
118 return *primitiveValue; 187 return *primitiveValue;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 { 594 {
526 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 595 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
527 if (primitiveValue->getValueID()) { 596 if (primitiveValue->getValueID()) {
528 float multiplier = convertLineWidth<float>(state, value); 597 float multiplier = convertLineWidth<float>(state, value);
529 return CSSPrimitiveValue::create(multiplier / 48, CSSPrimitiveValue::CSS _EMS)->computeLength<float>(state.cssToLengthConversionData()); 598 return CSSPrimitiveValue::create(multiplier / 48, CSSPrimitiveValue::CSS _EMS)->computeLength<float>(state.cssToLengthConversionData());
530 } 599 }
531 return primitiveValue->computeLength<float>(state.cssToLengthConversionData( )); 600 return primitiveValue->computeLength<float>(state.cssToLengthConversionData( ));
532 } 601 }
533 602
534 } // namespace blink 603 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698