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

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

Issue 2608423002: Fix RGBA alpha parsing and serialization to adhere to W3 standard. (Closed)
Patch Set: NeedsRebaseline for failed layout tests Created 3 years, 11 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/parser/CSSParserFastPaths.h" 5 #include "core/css/parser/CSSParserFastPaths.h"
6 6
7 #include "core/StylePropertyShorthand.h" 7 #include "core/StylePropertyShorthand.h"
8 #include "core/css/CSSColorValue.h" 8 #include "core/css/CSSColorValue.h"
9 #include "core/css/CSSFunctionValue.h" 9 #include "core/css/CSSFunctionValue.h"
10 #include "core/css/CSSIdentifierValue.h" 10 #include "core/css/CSSIdentifierValue.h"
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 return false; 362 return false;
363 } 363 }
364 364
365 if (length == 2 && string[0] != '.') { 365 if (length == 2 && string[0] != '.') {
366 value = !negative && string[0] == '1' ? 255 : 0; 366 value = !negative && string[0] == '1' ? 255 : 0;
367 string = end; 367 string = end;
368 return true; 368 return true;
369 } 369 }
370 370
371 if (isTenthAlpha(string, length - 1)) { 371 if (isTenthAlpha(string, length - 1)) {
372 static const int tenthAlphaValues[] = {0, 25, 51, 76, 102, 372 // Fast conversions for 0.1 steps of alpha values between 0.0 and 0.9,
373 127, 153, 179, 204, 230}; 373 // where 0.1 alpha is value 26 (25.5 rounded) and so on.
374 static const int tenthAlphaValues[] = {0, 26, 51, 77, 102,
375 128, 153, 179, 204, 230};
374 value = negative ? 0 : tenthAlphaValues[string[length - 2] - '0']; 376 value = negative ? 0 : tenthAlphaValues[string[length - 2] - '0'];
375 string = end; 377 string = end;
376 return true; 378 return true;
377 } 379 }
378 380
379 double alpha = 0; 381 double alpha = 0;
380 if (!parseDouble(string, end, terminator, alpha)) 382 if (!parseDouble(string, end, terminator, alpha))
381 return false; 383 return false;
382 value = negative 384 value =
383 ? 0 385 negative ? 0 : static_cast<int>(roundf(std::min(alpha, 1.0) * 255.0f));
384 : static_cast<int>(std::min(alpha, 1.0) * nextafter(256.0, 0.0));
385 string = end; 386 string = end;
386 return true; 387 return true;
387 } 388 }
388 389
389 template <typename CharacterType> 390 template <typename CharacterType>
390 static inline bool mightBeRGBA(const CharacterType* characters, 391 static inline bool mightBeRGBA(const CharacterType* characters,
391 unsigned length) { 392 unsigned length) {
392 if (length < 5) 393 if (length < 5)
393 return false; 394 return false;
394 return characters[4] == '(' && 395 return characters[4] == '(' &&
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 if (isColorPropertyID(propertyID)) 1208 if (isColorPropertyID(propertyID))
1208 return parseColor(string, parserMode); 1209 return parseColor(string, parserMode);
1209 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode)) 1210 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode))
1210 return keyword; 1211 return keyword;
1211 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) 1212 if (CSSValue* transform = parseSimpleTransform(propertyID, string))
1212 return transform; 1213 return transform;
1213 return nullptr; 1214 return nullptr;
1214 } 1215 }
1215 1216
1216 } // namespace blink 1217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698