OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
6 #include "core/inspector/LayoutEditor.h" | 6 #include "core/inspector/LayoutEditor.h" |
7 | 7 |
8 #include "core/css/CSSComputedStyleDeclaration.h" | 8 #include "core/css/CSSComputedStyleDeclaration.h" |
9 #include "core/dom/NodeComputedStyle.h" | 9 #include "core/dom/NodeComputedStyle.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 result.setP3(projection(projectOn.p3(), orthogonals.p3(), translatePoint(ori gin.p3(), orthogonals.p1(), distance))); | 109 result.setP3(projection(projectOn.p3(), orthogonals.p3(), translatePoint(ori gin.p3(), orthogonals.p1(), distance))); |
110 result.setP4(projection(projectOn.p4(), orthogonals.p4(), translatePoint(ori gin.p4(), orthogonals.p2(), distance))); | 110 result.setP4(projection(projectOn.p4(), orthogonals.p4(), translatePoint(ori gin.p4(), orthogonals.p2(), distance))); |
111 return result; | 111 return result; |
112 } | 112 } |
113 | 113 |
114 bool isMutableUnitType(CSSPrimitiveValue::UnitType unitType) | 114 bool isMutableUnitType(CSSPrimitiveValue::UnitType unitType) |
115 { | 115 { |
116 return unitType == CSSPrimitiveValue::UnitType::Pixels || unitType == CSSPri mitiveValue::UnitType::Ems || unitType == CSSPrimitiveValue::UnitType::Percentag e || unitType == CSSPrimitiveValue::UnitType::Rems; | 116 return unitType == CSSPrimitiveValue::UnitType::Pixels || unitType == CSSPri mitiveValue::UnitType::Ems || unitType == CSSPrimitiveValue::UnitType::Percentag e || unitType == CSSPrimitiveValue::UnitType::Rems; |
117 } | 117 } |
118 | 118 |
119 String truncateZeroes(const String& number) | |
120 { | |
121 if (!number.contains('.')) | |
122 return number; | |
123 | |
124 int removeCount = 0; | |
125 while (number[number.length() - removeCount - 1] == '0') | |
126 removeCount++; | |
127 | |
128 if (number[number.length() - removeCount - 1] == '.') | |
129 removeCount++; | |
130 | |
131 String result = number.left(number.length() - removeCount); | |
132 return result; | |
133 } | |
134 | |
135 bool isValidValue(CSSPropertyID propertyId, float newValue) | |
dgozman
2015/08/21 17:36:33
toValidValue / clampValue / sanitizeValue
sergeyv
2015/08/21 17:59:01
Done.
| |
136 { | |
137 if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddi ngTop) | |
138 return newValue >= 0; | |
139 | |
140 return true; | |
141 } | |
119 } // namespace | 142 } // namespace |
120 | 143 |
121 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) | 144 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) |
122 : m_element(nullptr) | 145 : m_element(nullptr) |
123 , m_cssAgent(cssAgent) | 146 , m_cssAgent(cssAgent) |
124 , m_changingProperty(CSSPropertyInvalid) | 147 , m_changingProperty(CSSPropertyInvalid) |
125 , m_propertyInitialValue(0) | 148 , m_propertyInitialValue(0) |
126 { | 149 { |
127 } | 150 } |
128 | 151 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 ASSERT_NOT_REACHED(); | 255 ASSERT_NOT_REACHED(); |
233 break; | 256 break; |
234 } | 257 } |
235 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; | 258 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; |
236 } | 259 } |
237 | 260 |
238 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 261 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
239 { | 262 { |
240 if (m_changingProperty && m_factor) { | 263 if (m_changingProperty && m_factor) { |
241 String errorString; | 264 String errorString; |
242 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, String::format("%.2f", cssDelta / m_factor + m_propertyInitialValue) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); | 265 float newValue = cssDelta / m_factor + m_propertyInitialValue; |
266 newValue = isValidValue(m_changingProperty, newValue) ? newValue : 0; | |
267 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType)); | |
243 } | 268 } |
244 } | 269 } |
245 | 270 |
246 void LayoutEditor::overlayEndedPropertyChange() | 271 void LayoutEditor::overlayEndedPropertyChange() |
247 { | 272 { |
248 m_changingProperty = CSSPropertyInvalid; | 273 m_changingProperty = CSSPropertyInvalid; |
249 m_propertyInitialValue = 0; | 274 m_propertyInitialValue = 0; |
250 m_factor = 0; | 275 m_factor = 0; |
251 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; | 276 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; |
252 } | 277 } |
253 | 278 |
254 } // namespace blink | 279 } // namespace blink |
OLD | NEW |