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

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

Issue 2837023005: Move MediaQuery classes off BlinkGC heap (Closed)
Patch Set: fix 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 media_feature_ == shapeMediaFeature; 211 media_feature_ == shapeMediaFeature;
212 } 212 }
213 213
214 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) 214 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other)
215 : media_feature_(other.MediaFeature()), exp_value_(other.ExpValue()) {} 215 : media_feature_(other.MediaFeature()), exp_value_(other.ExpValue()) {}
216 216
217 MediaQueryExp::MediaQueryExp(const String& media_feature, 217 MediaQueryExp::MediaQueryExp(const String& media_feature,
218 const MediaQueryExpValue& exp_value) 218 const MediaQueryExpValue& exp_value)
219 : media_feature_(media_feature), exp_value_(exp_value) {} 219 : media_feature_(media_feature), exp_value_(exp_value) {}
220 220
221 MediaQueryExp* MediaQueryExp::CreateIfValid( 221 MediaQueryExp MediaQueryExp::Create(
222 const String& media_feature, 222 const String& media_feature,
223 const Vector<CSSParserToken, 4>& token_list) { 223 const Vector<CSSParserToken, 4>& token_list) {
224 DCHECK(!media_feature.IsNull()); 224 DCHECK(!media_feature.IsNull());
225 225
226 MediaQueryExpValue exp_value; 226 MediaQueryExpValue exp_value;
227 String lower_media_feature = 227 String lower_media_feature =
228 AttemptStaticStringCreation(media_feature.DeprecatedLower()); 228 AttemptStaticStringCreation(media_feature.DeprecatedLower());
229 229
230 // Create value for media query expression that must have 1 or more values. 230 // Create value for media query expression that must have 1 or more values.
231 if (token_list.size() == 0 && FeatureWithoutValue(lower_media_feature)) { 231 if (token_list.size() == 0 && FeatureWithoutValue(lower_media_feature)) {
232 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue 232 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue
233 } else if (token_list.size() == 1) { 233 } else if (token_list.size() == 1) {
234 CSSParserToken token = token_list.front(); 234 CSSParserToken token = token_list.front();
235 235
236 if (token.GetType() == kIdentToken) { 236 if (token.GetType() == kIdentToken) {
237 CSSValueID ident = token.Id(); 237 CSSValueID ident = token.Id();
238 if (!FeatureWithValidIdent(lower_media_feature, ident)) 238 if (!FeatureWithValidIdent(lower_media_feature, ident))
239 return nullptr; 239 return Invalid();
240 exp_value.id = ident; 240 exp_value.id = ident;
241 exp_value.is_id = true; 241 exp_value.is_id = true;
242 } else if (token.GetType() == kNumberToken || 242 } else if (token.GetType() == kNumberToken ||
243 token.GetType() == kPercentageToken || 243 token.GetType() == kPercentageToken ||
244 token.GetType() == kDimensionToken) { 244 token.GetType() == kDimensionToken) {
245 // Check for numeric token types since it is only safe for these types to 245 // Check for numeric token types since it is only safe for these types to
246 // call numericValue. 246 // call numericValue.
247 if (FeatureWithValidDensity(lower_media_feature, token) || 247 if (FeatureWithValidDensity(lower_media_feature, token) ||
248 FeatureWithValidPositiveLength(lower_media_feature, token)) { 248 FeatureWithValidPositiveLength(lower_media_feature, token)) {
249 // Media features that must have non-negative <density>, ie. dppx, dpi 249 // Media features that must have non-negative <density>, ie. dppx, dpi
250 // or dpcm, or Media features that must have non-negative <length> or 250 // or dpcm, or Media features that must have non-negative <length> or
251 // number value. 251 // number value.
252 exp_value.value = token.NumericValue(); 252 exp_value.value = token.NumericValue();
253 exp_value.unit = token.GetUnitType(); 253 exp_value.unit = token.GetUnitType();
254 exp_value.is_value = true; 254 exp_value.is_value = true;
255 } else if (FeatureWithPositiveInteger(lower_media_feature, token) || 255 } else if (FeatureWithPositiveInteger(lower_media_feature, token) ||
256 FeatureWithPositiveNumber(lower_media_feature, token) || 256 FeatureWithPositiveNumber(lower_media_feature, token) ||
257 FeatureWithZeroOrOne(lower_media_feature, token)) { 257 FeatureWithZeroOrOne(lower_media_feature, token)) {
258 // Media features that must have non-negative integer value, 258 // Media features that must have non-negative integer value,
259 // or media features that must have non-negative number value, 259 // or media features that must have non-negative number value,
260 // or media features that must have (0|1) value. 260 // or media features that must have (0|1) value.
261 exp_value.value = token.NumericValue(); 261 exp_value.value = token.NumericValue();
262 exp_value.unit = CSSPrimitiveValue::UnitType::kNumber; 262 exp_value.unit = CSSPrimitiveValue::UnitType::kNumber;
263 exp_value.is_value = true; 263 exp_value.is_value = true;
264 } else { 264 } else {
265 return nullptr; 265 return Invalid();
266 } 266 }
267 } else { 267 } else {
268 return nullptr; 268 return Invalid();
269 } 269 }
270 } else if (token_list.size() == 3 && 270 } else if (token_list.size() == 3 &&
271 FeatureWithAspectRatio(lower_media_feature)) { 271 FeatureWithAspectRatio(lower_media_feature)) {
272 // TODO(timloh): <ratio> is supposed to allow whitespace around the '/' 272 // TODO(timloh): <ratio> is supposed to allow whitespace around the '/'
273 // Applicable to device-aspect-ratio and aspect-ratio. 273 // Applicable to device-aspect-ratio and aspect-ratio.
274 const CSSParserToken& numerator = token_list[0]; 274 const CSSParserToken& numerator = token_list[0];
275 const CSSParserToken& delimiter = token_list[1]; 275 const CSSParserToken& delimiter = token_list[1];
276 const CSSParserToken& denominator = token_list[2]; 276 const CSSParserToken& denominator = token_list[2];
277 if (delimiter.GetType() != kDelimiterToken || delimiter.Delimiter() != '/') 277 if (delimiter.GetType() != kDelimiterToken || delimiter.Delimiter() != '/')
278 return nullptr; 278 return Invalid();
279 if (numerator.GetType() != kNumberToken || numerator.NumericValue() <= 0 || 279 if (numerator.GetType() != kNumberToken || numerator.NumericValue() <= 0 ||
280 numerator.GetNumericValueType() != kIntegerValueType) 280 numerator.GetNumericValueType() != kIntegerValueType)
281 return nullptr; 281 return Invalid();
282 if (denominator.GetType() != kNumberToken || 282 if (denominator.GetType() != kNumberToken ||
283 denominator.NumericValue() <= 0 || 283 denominator.NumericValue() <= 0 ||
284 denominator.GetNumericValueType() != kIntegerValueType) 284 denominator.GetNumericValueType() != kIntegerValueType)
285 return nullptr; 285 return Invalid();
286 286
287 exp_value.numerator = (unsigned)numerator.NumericValue(); 287 exp_value.numerator = (unsigned)numerator.NumericValue();
288 exp_value.denominator = (unsigned)denominator.NumericValue(); 288 exp_value.denominator = (unsigned)denominator.NumericValue();
289 exp_value.is_ratio = true; 289 exp_value.is_ratio = true;
290 } else { 290 } else {
291 return nullptr; 291 return Invalid();
292 } 292 }
293 293
294 return new MediaQueryExp(lower_media_feature, exp_value); 294 return MediaQueryExp(lower_media_feature, exp_value);
295 } 295 }
296 296
297 MediaQueryExp::~MediaQueryExp() {} 297 MediaQueryExp::~MediaQueryExp() {}
298 298
299 bool MediaQueryExp::operator==(const MediaQueryExp& other) const { 299 bool MediaQueryExp::operator==(const MediaQueryExp& other) const {
300 return (other.media_feature_ == media_feature_) && 300 return (other.media_feature_ == media_feature_) &&
301 ((!other.exp_value_.IsValid() && !exp_value_.IsValid()) || 301 ((!other.exp_value_.IsValid() && !exp_value_.IsValid()) ||
302 (other.exp_value_.IsValid() && exp_value_.IsValid() && 302 (other.exp_value_.IsValid() && exp_value_.IsValid() &&
303 other.exp_value_.Equals(exp_value_))); 303 other.exp_value_.Equals(exp_value_)));
304 } 304 }
(...skipping 25 matching lines...) Expand all
330 output.Append('/'); 330 output.Append('/');
331 output.Append(PrintNumber(denominator)); 331 output.Append(PrintNumber(denominator));
332 } else if (is_id) { 332 } else if (is_id) {
333 output.Append(getValueName(id)); 333 output.Append(getValueName(id));
334 } 334 }
335 335
336 return output.ToString(); 336 return output.ToString();
337 } 337 }
338 338
339 } // namespace blink 339 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698