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

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: Address 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..180fb21b5bba6efd69f7af6df1471f7b08fc39d4 100644
--- a/Source/core/inspector/LayoutEditor.cpp
+++ b/Source/core/inspector/LayoutEditor.cpp
@@ -116,6 +116,28 @@ 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++;
+
+ return number.left(number.length() - removeCount);
+}
+
+float toValidValue(CSSPropertyID propertyId, float newValue)
+{
+ if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddingTop)
+ return newValue >= 0 ? newValue : 0;
+
+ return newValue;
+}
} // namespace
LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent)
@@ -239,7 +261,8 @@ 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 = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue);
+ 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