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

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

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Replaced ASSERTs with DCHECKS in presubmit warnings Created 4 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) 2012-2013 Intel Corporation. All rights reserved. 2 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 140 {
141 float defaultValue = ViewportDescription::ValueAuto; 141 float defaultValue = ViewportDescription::ValueAuto;
142 142
143 // UserZoom default value is CSSValueZoom, which maps to true, meaning that 143 // UserZoom default value is CSSValueZoom, which maps to true, meaning that
144 // yes, it is user scalable. When the value is set to CSSValueFixed, we 144 // yes, it is user scalable. When the value is set to CSSValueFixed, we
145 // return false. 145 // return false.
146 if (id == CSSPropertyUserZoom) 146 if (id == CSSPropertyUserZoom)
147 defaultValue = 1; 147 defaultValue = 1;
148 148
149 const CSSValue* value = m_propertySet->getPropertyCSSValue(id); 149 const CSSValue* value = m_propertySet->getPropertyCSSValue(id);
150 if (!value || !value->isPrimitiveValue()) 150 if (!value || !value->isPrimitiveValue() || !value->isIdentifierValue())
Timothy Loh 2016/09/21 07:55:06 This logic (and below in the file) is wrong since
sashab 2016/09/23 01:01:10 Ack, I hate these confusing if-statements!! I want
151 return defaultValue; 151 return defaultValue;
152 152
153 if (value->isIdentifierValue()) {
154 switch (toCSSIdentifierValue(value)->getValueID()) {
155 case CSSValueAuto:
156 return defaultValue;
157 case CSSValueLandscape:
158 return ViewportDescription::ValueLandscape;
159 case CSSValuePortrait:
160 return ViewportDescription::ValuePortrait;
161 case CSSValueZoom:
162 return defaultValue;
163 case CSSValueInternalExtendToZoom:
164 return ViewportDescription::ValueExtendToZoom;
165 case CSSValueFixed:
166 return 0;
167 default:
168 return defaultValue;
169 }
170 }
171
153 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 172 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
154 173
155 if (primitiveValue->isNumber() || primitiveValue->isPx()) 174 if (primitiveValue->isNumber() || primitiveValue->isPx())
156 return primitiveValue->getFloatValue(); 175 return primitiveValue->getFloatValue();
157 176
158 if (primitiveValue->isFontRelativeLength()) 177 if (primitiveValue->isFontRelativeLength())
159 return primitiveValue->getFloatValue() * m_document->computedStyle()->ge tFontDescription().computedSize(); 178 return primitiveValue->getFloatValue() * m_document->computedStyle()->ge tFontDescription().computedSize();
160 179
161 if (primitiveValue->isPercentage()) { 180 if (primitiveValue->isPercentage()) {
162 float percentValue = primitiveValue->getFloatValue() / 100.0f; 181 float percentValue = primitiveValue->getFloatValue() / 100.0f;
163 switch (id) { 182 switch (id) {
164 case CSSPropertyMaxZoom: 183 case CSSPropertyMaxZoom:
165 case CSSPropertyMinZoom: 184 case CSSPropertyMinZoom:
166 case CSSPropertyZoom: 185 case CSSPropertyZoom:
167 return percentValue; 186 return percentValue;
168 default: 187 default:
169 ASSERT_NOT_REACHED(); 188 NOTREACHED();
170 break; 189 break;
171 } 190 }
172 } 191 }
173 192
174 switch (primitiveValue->getValueID()) { 193 NOTREACHED();
175 case CSSValueAuto: 194 return defaultValue;
176 return defaultValue;
177 case CSSValueLandscape:
178 return ViewportDescription::ValueLandscape;
179 case CSSValuePortrait:
180 return ViewportDescription::ValuePortrait;
181 case CSSValueZoom:
182 return defaultValue;
183 case CSSValueInternalExtendToZoom:
184 return ViewportDescription::ValueExtendToZoom;
185 case CSSValueFixed:
186 return 0;
187 default:
188 return defaultValue;
189 }
190 } 195 }
191 196
192 Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const 197 Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const
193 { 198 {
194 ASSERT(id == CSSPropertyMaxHeight 199 ASSERT(id == CSSPropertyMaxHeight
195 || id == CSSPropertyMinHeight 200 || id == CSSPropertyMinHeight
196 || id == CSSPropertyMaxWidth 201 || id == CSSPropertyMaxWidth
197 || id == CSSPropertyMinWidth); 202 || id == CSSPropertyMinWidth);
198 203
199 const CSSValue* value = m_propertySet->getPropertyCSSValue(id); 204 const CSSValue* value = m_propertySet->getPropertyCSSValue(id);
200 if (!value || !value->isPrimitiveValue()) 205 if (!value || !value->isPrimitiveValue() || !value->isIdentifierValue())
201 return Length(); // auto 206 return Length(); // auto
202 207
208 if (value->isIdentifierValue()) {
209 CSSValueID valueID = toCSSIdentifierValue(value)->getValueID();
210 if (valueID == CSSValueInternalExtendToZoom)
211 return Length(ExtendToZoom);
212 if (valueID == CSSValueAuto)
213 return Length(Auto);
214 }
215
203 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 216 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
204
205 if (primitiveValue->getValueID() == CSSValueInternalExtendToZoom)
206 return Length(ExtendToZoom);
207
208 ComputedStyle* documentStyle = m_document->mutableComputedStyle(); 217 ComputedStyle* documentStyle = m_document->mutableComputedStyle();
209 218
210 // If we have viewport units the conversion will mark the document style as having viewport units. 219 // If we have viewport units the conversion will mark the document style as having viewport units.
211 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); 220 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits();
212 documentStyle->setHasViewportUnits(false); 221 documentStyle->setHasViewportUnits(false);
213 222
214 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle) ; 223 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle) ;
215 CSSToLengthConversionData::ViewportSize viewportSize(m_document->layoutViewI tem()); 224 CSSToLengthConversionData::ViewportSize viewportSize(m_document->layoutViewI tem());
216 225
217 if (primitiveValue->getValueID() == CSSValueAuto)
218 return Length(Auto);
219
220 Length result = primitiveValue->convertToLength(CSSToLengthConversionData(do cumentStyle, fontSizes, viewportSize, 1.0f)); 226 Length result = primitiveValue->convertToLength(CSSToLengthConversionData(do cumentStyle, fontSizes, viewportSize, 1.0f));
221 if (documentStyle->hasViewportUnits()) 227 if (documentStyle->hasViewportUnits())
222 m_document->setHasViewportUnits(); 228 m_document->setHasViewportUnits();
223 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); 229 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits);
224 230
225 return result; 231 return result;
226 } 232 }
227 233
228 DEFINE_TRACE(ViewportStyleResolver) 234 DEFINE_TRACE(ViewportStyleResolver)
229 { 235 {
230 visitor->trace(m_propertySet); 236 visitor->trace(m_propertySet);
231 visitor->trace(m_document); 237 visitor->trace(m_document);
232 } 238 }
233 239
234 } // namespace blink 240 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698