Index: Source/core/inspector/LayoutEditor.cpp |
diff --git a/Source/core/inspector/LayoutEditor.cpp b/Source/core/inspector/LayoutEditor.cpp |
index 3d5b0fa531f10db30e56b9ccef9e9920c0c5ecf7..aae16c9289bdb31e8c28d37376673871de0d2107 100644 |
--- a/Source/core/inspector/LayoutEditor.cpp |
+++ b/Source/core/inspector/LayoutEditor.cpp |
@@ -116,6 +116,29 @@ bool isMutableUnitType(CSSPrimitiveValue::UnitType unitType) |
return unitType == CSSPrimitiveValue::UnitType::Pixels || unitType == CSSPrimitiveValue::UnitType::Ems || unitType == CSSPrimitiveValue::UnitType::Percentage || unitType == CSSPrimitiveValue::UnitType::Rems; |
} |
+String truncateZeroes(const String& number) |
+{ |
+ if (!number.contains('.')) |
+ return number; |
+ |
+ int removeCount = 0; |
+ while (number[number.length() - removeCount - 1] == '0') |
+ removeCount++; |
+ |
+ if (number[number.length() - removeCount - 1] == '.') |
+ removeCount++; |
+ |
+ String result = number.left(number.length() - removeCount); |
+ return result; |
+} |
+ |
+bool isValidValue(CSSPropertyID propertyId, float newValue) |
dgozman
2015/08/21 17:36:33
toValidValue / clampValue / sanitizeValue
sergeyv
2015/08/21 17:59:01
Done.
|
+{ |
+ if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddingTop) |
+ return newValue >= 0; |
+ |
+ return true; |
+} |
} // namespace |
LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) |
@@ -239,7 +262,9 @@ void LayoutEditor::overlayPropertyChanged(float cssDelta) |
{ |
if (m_changingProperty && m_factor) { |
String errorString; |
- m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changingProperty, String::format("%.2f", cssDelta / m_factor + m_propertyInitialValue) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); |
+ float newValue = cssDelta / m_factor + m_propertyInitialValue; |
+ newValue = isValidValue(m_changingProperty, newValue) ? newValue : 0; |
+ m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changingProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); |
} |
} |