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

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: Fix regression related to FontDescriptions with isAbsolute=true. Created 6 years, 3 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 CSSValueList* list = toCSSValueList(value); 110 CSSValueList* list = toCSSValueList(value);
111 RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create(); 111 RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create();
112 int len = list->length(); 112 int len = list->length();
113 for (int i = 0; i < len; ++i) { 113 for (int i = 0; i < len; ++i) {
114 CSSFontFeatureValue* feature = toCSSFontFeatureValue(list->item(i)); 114 CSSFontFeatureValue* feature = toCSSFontFeatureValue(list->item(i));
115 settings->append(FontFeature(feature->tag(), feature->value())); 115 settings->append(FontFeature(feature->tag(), feature->value()));
116 } 116 }
117 return settings; 117 return settings;
118 } 118 }
119 119
120 class RedirectSetHasViewportUnits {
121 public:
122 RedirectSetHasViewportUnits(RenderStyle* from, RenderStyle* to)
123 : m_from(from), m_to(to), m_hadViewportUnits(from->hasViewportUnits())
124 {
125 from->setHasViewportUnits(false);
126 }
127 ~RedirectSetHasViewportUnits()
128 {
129 m_to->setHasViewportUnits(m_from->hasViewportUnits());
130 m_from->setHasViewportUnits(m_hadViewportUnits);
131 }
132 private:
133 RenderStyle* m_from;
134 RenderStyle* m_to;
135 bool m_hadViewportUnits;
136 };
137
138 static float computeFontSize(StyleResolverState& state, CSSPrimitiveValue* primi tiveValue, const FontDescription::Size& parentSize)
139 {
140 RedirectSetHasViewportUnits redirect(state.parentStyle(), state.style());
141
142 CSSToLengthConversionData conversionData(state.parentStyle(), state.rootElem entStyle(), state.document().renderView(), 1.0f, true);
143 if (primitiveValue->isLength())
144 return primitiveValue->computeLength<float>(conversionData);
145 if (primitiveValue->isCalculatedPercentageWithLength())
146 return primitiveValue->cssCalcValue()->toCalcValue(conversionData)->eval uate(parentSize.value);
147
148 ASSERT_NOT_REACHED();
149 return 0;
150 }
151
152 FontDescription::Size StyleBuilderConverter::convertFontSize(StyleResolverState& state, CSSValue* value)
153 {
154 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
155
156 FontDescription::Size parentSize(0, 0.0f, false);
157
158 // FIXME: Find out when parentStyle could be 0?
159 if (state.parentStyle())
160 parentSize = state.parentFontDescription().size();
161
162 if (CSSValueID valueID = primitiveValue->getValueID()) {
163 switch (valueID) {
164 case CSSValueXxSmall:
165 case CSSValueXSmall:
166 case CSSValueSmall:
167 case CSSValueMedium:
168 case CSSValueLarge:
169 case CSSValueXLarge:
170 case CSSValueXxLarge:
171 case CSSValueWebkitXxxLarge:
172 return FontDescription::Size(FontSize::keywordSize(valueID), 0.0f, f alse);
173 case CSSValueLarger:
174 return FontDescription::largerSize(parentSize);
175 case CSSValueSmaller:
176 return FontDescription::smallerSize(parentSize);
177 default:
178 ASSERT_NOT_REACHED();
179 return FontBuilder::initialSize();
180 }
181 }
182
183 bool parentIsAbsoluteSize = state.parentFontDescription().isAbsoluteSize();
184
185 if (primitiveValue->isPercentage())
186 return FontDescription::Size(0, (primitiveValue->getFloatValue() * paren tSize.value / 100.0f), parentIsAbsoluteSize);
187
188 return FontDescription::Size(0, computeFontSize(state, primitiveValue, paren tSize), parentIsAbsoluteSize || !primitiveValue->isFontRelativeLength());
189 }
190
120 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, C SSValue* value) 191 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, C SSValue* value)
121 { 192 {
122 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 193 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
123 switch (primitiveValue->getValueID()) { 194 switch (primitiveValue->getValueID()) {
124 case CSSValueBolder: 195 case CSSValueBolder:
125 return FontDescription::bolderWeight(state.parentStyle()->fontDescriptio n().weight()); 196 return FontDescription::bolderWeight(state.parentStyle()->fontDescriptio n().weight());
126 case CSSValueLighter: 197 case CSSValueLighter:
127 return FontDescription::lighterWeight(state.parentStyle()->fontDescripti on().weight()); 198 return FontDescription::lighterWeight(state.parentStyle()->fontDescripti on().weight());
128 default: 199 default:
129 return *primitiveValue; 200 return *primitiveValue;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 { 615 {
545 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 616 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
546 if (primitiveValue->getValueID()) { 617 if (primitiveValue->getValueID()) {
547 float multiplier = convertLineWidth<float>(state, value); 618 float multiplier = convertLineWidth<float>(state, value);
548 return CSSPrimitiveValue::create(multiplier / 48, CSSPrimitiveValue::CSS _EMS)->computeLength<float>(state.cssToLengthConversionData()); 619 return CSSPrimitiveValue::create(multiplier / 48, CSSPrimitiveValue::CSS _EMS)->computeLength<float>(state.cssToLengthConversionData());
549 } 620 }
550 return primitiveValue->computeLength<float>(state.cssToLengthConversionData( )); 621 return primitiveValue->computeLength<float>(state.cssToLengthConversionData( ));
551 } 622 }
552 623
553 } // namespace blink 624 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleBuilderConverter.h ('k') | Source/core/css/resolver/StyleBuilderCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698