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

Unified Diff: third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl

Issue 2121913002: [Typed OM] Add CSSValue -> CSSNumberValue conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl
diff --git a/third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl b/third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl
index 33b93b0688df90827abc2fb1fed72fcc57280e95..e97ab2b721683f1727fed19e50e423e9a8abddc0 100644
--- a/third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl
+++ b/third_party/WebKit/Source/build/scripts/templates/CSSOMTypes.cpp.tmpl
@@ -9,28 +9,53 @@
#include "core/css/cssom/CSSKeywordValue.h"
#include "core/css/cssom/CSSLengthValue.h"
#include "core/css/cssom/CSSStyleValue.h"
+#include "core/css/cssom/CSSNumberValue.h"
namespace blink {
+namespace {
+
+bool validNumberValue(CSSPropertyID id, double number) {
+ bool integerOnly;
+ bool negativeAllowed;
+ switch (id) {
+ {% for property_id, property in properties.items() if property.number_metadata %}
+ case {{property_id}}:
+ integerOnly = {{ property.number_metadata.integer }};
+ negativeAllowed = {{ property.number_metadata.allow_negative }};
+ break;
+ {% endfor %}
+ default:
+ return false;
+ }
+ if (!negativeAllowed && number < 0)
+ return false;
+ if (integerOnly && std::floor(std::abs(number)) != std::abs(number))
+ return false;
+ return true;
+}
+
+} // namespace
+
bool CSSOMTypes::propertyCanTake(CSSPropertyID id,
const CSSStyleValue& styleValue) {
- // Shortcut special case.
- if (styleValue.type() == CSSStyleValue::SimpleLengthType ||
- styleValue.type() == CSSStyleValue::CalcLengthType) {
- if (toCSSLengthValue(styleValue).containsPercent() &&
- !CSSPropertyMetadata::propertySupportsPercentage(id)) {
+ if (styleValue.type() == CSSStyleValue::KeywordType) {
+ // Keywords are handled differently.
+ return CSSOMKeywords::validKeywordForProperty(id, toCSSKeywordValue(styleValue));
+ } else if (styleValue.type() == CSSStyleValue::SimpleLengthType
+ || styleValue.type() == CSSStyleValue::CalcLengthType) {
+ if (toCSSLengthValue(styleValue).containsPercent()
+ && !CSSPropertyMetadata::propertySupportsPercentage(id)) {
return false;
}
- } else if (styleValue.type() == CSSStyleValue::KeywordType) {
- // Keywords are also handled differently.
- return CSSOMKeywords::validKeywordForProperty(
- id, toCSSKeywordValue(styleValue));
+ } else if (styleValue.type() == CSSStyleValue::NumberType) {
+ return validNumberValue(id, toCSSNumberValue(styleValue).value());
} else if (styleValue.type() == CSSStyleValue::Unknown) {
// The check happens later in this case.
return true;
}
- return CSSOMTypes::propertyCanTakeType(id, styleValue.type());
+ return propertyCanTakeType(id, styleValue.type());
}
bool CSSOMTypes::propertyCanTakeType(CSSPropertyID id,
« no previous file with comments | « third_party/WebKit/Source/build/scripts/make_cssom_types.py ('k') | third_party/WebKit/Source/core/css/CSSProperties.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698