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

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

Issue 2873433003: Move MediaQuery classes off BlinkGC heap (Closed)
Patch Set: Created 3 years, 7 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 * CSS Media Query 2 * CSS Media Query
3 * 3 *
4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * Copyright (C) 2013 Apple Inc. All rights reserved. 6 * Copyright (C) 2013 Apple Inc. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 m_mediaFeature == shapeMediaFeature; 209 m_mediaFeature == shapeMediaFeature;
210 } 210 }
211 211
212 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) 212 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other)
213 : m_mediaFeature(other.mediaFeature()), m_expValue(other.expValue()) {} 213 : m_mediaFeature(other.mediaFeature()), m_expValue(other.expValue()) {}
214 214
215 MediaQueryExp::MediaQueryExp(const String& mediaFeature, 215 MediaQueryExp::MediaQueryExp(const String& mediaFeature,
216 const MediaQueryExpValue& expValue) 216 const MediaQueryExpValue& expValue)
217 : m_mediaFeature(mediaFeature), m_expValue(expValue) {} 217 : m_mediaFeature(mediaFeature), m_expValue(expValue) {}
218 218
219 MediaQueryExp* MediaQueryExp::createIfValid( 219 MediaQueryExp MediaQueryExp::create(
220 const String& mediaFeature, 220 const String& mediaFeature,
221 const Vector<CSSParserToken, 4>& tokenList) { 221 const Vector<CSSParserToken, 4>& tokenList) {
222 ASSERT(!mediaFeature.isNull()); 222 ASSERT(!mediaFeature.isNull());
223 223
224 MediaQueryExpValue expValue; 224 MediaQueryExpValue expValue;
225 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower()); 225 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower());
226 226
227 // Create value for media query expression that must have 1 or more values. 227 // Create value for media query expression that must have 1 or more values.
228 if (tokenList.size() == 0 && featureWithoutValue(lowerMediaFeature)) { 228 if (tokenList.size() == 0 && featureWithoutValue(lowerMediaFeature)) {
229 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue 229 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue
230 } else if (tokenList.size() == 1) { 230 } else if (tokenList.size() == 1) {
231 CSSParserToken token = tokenList.front(); 231 CSSParserToken token = tokenList.front();
232 232
233 if (token.type() == IdentToken) { 233 if (token.type() == IdentToken) {
234 CSSValueID ident = token.id(); 234 CSSValueID ident = token.id();
235 if (!featureWithValidIdent(lowerMediaFeature, ident)) 235 if (!featureWithValidIdent(lowerMediaFeature, ident))
236 return nullptr; 236 return invalid();
237 expValue.id = ident; 237 expValue.id = ident;
238 expValue.isID = true; 238 expValue.isID = true;
239 } else if (token.type() == NumberToken || token.type() == PercentageToken || 239 } else if (token.type() == NumberToken || token.type() == PercentageToken ||
240 token.type() == DimensionToken) { 240 token.type() == DimensionToken) {
241 // Check for numeric token types since it is only safe for these types to 241 // Check for numeric token types since it is only safe for these types to
242 // call numericValue. 242 // call numericValue.
243 if (featureWithValidDensity(lowerMediaFeature, token) || 243 if (featureWithValidDensity(lowerMediaFeature, token) ||
244 featureWithValidPositiveLength(lowerMediaFeature, token)) { 244 featureWithValidPositiveLength(lowerMediaFeature, token)) {
245 // Media features that must have non-negative <density>, ie. dppx, dpi 245 // Media features that must have non-negative <density>, ie. dppx, dpi
246 // or dpcm, or Media features that must have non-negative <length> or 246 // or dpcm, or Media features that must have non-negative <length> or
247 // number value. 247 // number value.
248 expValue.value = token.numericValue(); 248 expValue.value = token.numericValue();
249 expValue.unit = token.unitType(); 249 expValue.unit = token.unitType();
250 expValue.isValue = true; 250 expValue.isValue = true;
251 } else if (featureWithPositiveInteger(lowerMediaFeature, token) || 251 } else if (featureWithPositiveInteger(lowerMediaFeature, token) ||
252 featureWithPositiveNumber(lowerMediaFeature, token) || 252 featureWithPositiveNumber(lowerMediaFeature, token) ||
253 featureWithZeroOrOne(lowerMediaFeature, token)) { 253 featureWithZeroOrOne(lowerMediaFeature, token)) {
254 // Media features that must have non-negative integer value, 254 // Media features that must have non-negative integer value,
255 // or media features that must have non-negative number value, 255 // or media features that must have non-negative number value,
256 // or media features that must have (0|1) value. 256 // or media features that must have (0|1) value.
257 expValue.value = token.numericValue(); 257 expValue.value = token.numericValue();
258 expValue.unit = CSSPrimitiveValue::UnitType::Number; 258 expValue.unit = CSSPrimitiveValue::UnitType::Number;
259 expValue.isValue = true; 259 expValue.isValue = true;
260 } else { 260 } else {
261 return nullptr; 261 return invalid();
262 } 262 }
263 } else { 263 } else {
264 return nullptr; 264 return invalid();
265 } 265 }
266 } else if (tokenList.size() == 3 && 266 } else if (tokenList.size() == 3 &&
267 featureWithAspectRatio(lowerMediaFeature)) { 267 featureWithAspectRatio(lowerMediaFeature)) {
268 // TODO(timloh): <ratio> is supposed to allow whitespace around the '/' 268 // TODO(timloh): <ratio> is supposed to allow whitespace around the '/'
269 // Applicable to device-aspect-ratio and aspect-ratio. 269 // Applicable to device-aspect-ratio and aspect-ratio.
270 const CSSParserToken& numerator = tokenList[0]; 270 const CSSParserToken& numerator = tokenList[0];
271 const CSSParserToken& delimiter = tokenList[1]; 271 const CSSParserToken& delimiter = tokenList[1];
272 const CSSParserToken& denominator = tokenList[2]; 272 const CSSParserToken& denominator = tokenList[2];
273 if (delimiter.type() != DelimiterToken || delimiter.delimiter() != '/') 273 if (delimiter.type() != DelimiterToken || delimiter.delimiter() != '/')
274 return nullptr; 274 return invalid();
275 if (numerator.type() != NumberToken || numerator.numericValue() <= 0 || 275 if (numerator.type() != NumberToken || numerator.numericValue() <= 0 ||
276 numerator.numericValueType() != IntegerValueType) 276 numerator.numericValueType() != IntegerValueType)
277 return nullptr; 277 return invalid();
278 if (denominator.type() != NumberToken || denominator.numericValue() <= 0 || 278 if (denominator.type() != NumberToken || denominator.numericValue() <= 0 ||
279 denominator.numericValueType() != IntegerValueType) 279 denominator.numericValueType() != IntegerValueType)
280 return nullptr; 280 return invalid();
281 281
282 expValue.numerator = (unsigned)numerator.numericValue(); 282 expValue.numerator = (unsigned)numerator.numericValue();
283 expValue.denominator = (unsigned)denominator.numericValue(); 283 expValue.denominator = (unsigned)denominator.numericValue();
284 expValue.isRatio = true; 284 expValue.isRatio = true;
285 } else { 285 } else {
286 return nullptr; 286 return invalid();
287 } 287 }
288 288
289 return new MediaQueryExp(lowerMediaFeature, expValue); 289 return MediaQueryExp(lowerMediaFeature, expValue);
290 } 290 }
291 291
292 MediaQueryExp::~MediaQueryExp() {} 292 MediaQueryExp::~MediaQueryExp() {}
293 293
294 bool MediaQueryExp::operator==(const MediaQueryExp& other) const { 294 bool MediaQueryExp::operator==(const MediaQueryExp& other) const {
295 return (other.m_mediaFeature == m_mediaFeature) && 295 return (other.m_mediaFeature == m_mediaFeature) &&
296 ((!other.m_expValue.isValid() && !m_expValue.isValid()) || 296 ((!other.m_expValue.isValid() && !m_expValue.isValid()) ||
297 (other.m_expValue.isValid() && m_expValue.isValid() && 297 (other.m_expValue.isValid() && m_expValue.isValid() &&
298 other.m_expValue.equals(m_expValue))); 298 other.m_expValue.equals(m_expValue)));
299 } 299 }
(...skipping 25 matching lines...) Expand all
325 output.append('/'); 325 output.append('/');
326 output.append(printNumber(denominator)); 326 output.append(printNumber(denominator));
327 } else if (isID) { 327 } else if (isID) {
328 output.append(getValueName(id)); 328 output.append(getValueName(id));
329 } 329 }
330 330
331 return output.toString(); 331 return output.toString();
332 } 332 }
333 333
334 } // namespace blink 334 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/MediaQueryExp.h ('k') | third_party/WebKit/Source/core/css/MediaQueryList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698