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

Unified Diff: Source/core/inspector/LayoutEditor.cpp

Issue 1307813002: Devtools[LayoutEditor]: Correctly handle new values (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698