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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 return number.left(number.length() - removeCount);
132 }
133
134 float toValidValue(CSSPropertyID propertyId, float newValue)
135 {
136 if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddi ngTop)
137 return newValue >= 0 ? newValue : 0;
138
139 return newValue;
140 }
119 } // namespace 141 } // namespace
120 142
121 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) 143 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent)
122 : m_element(nullptr) 144 : m_element(nullptr)
123 , m_cssAgent(cssAgent) 145 , m_cssAgent(cssAgent)
124 , m_changingProperty(CSSPropertyInvalid) 146 , m_changingProperty(CSSPropertyInvalid)
125 , m_propertyInitialValue(0) 147 , m_propertyInitialValue(0)
126 { 148 {
127 } 149 }
128 150
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ASSERT_NOT_REACHED(); 254 ASSERT_NOT_REACHED();
233 break; 255 break;
234 } 256 }
235 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; 257 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0;
236 } 258 }
237 259
238 void LayoutEditor::overlayPropertyChanged(float cssDelta) 260 void LayoutEditor::overlayPropertyChanged(float cssDelta)
239 { 261 {
240 if (m_changingProperty && m_factor) { 262 if (m_changingProperty && m_factor) {
241 String errorString; 263 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)); 264 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue);
265 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType));
243 } 266 }
244 } 267 }
245 268
246 void LayoutEditor::overlayEndedPropertyChange() 269 void LayoutEditor::overlayEndedPropertyChange()
247 { 270 {
248 m_changingProperty = CSSPropertyInvalid; 271 m_changingProperty = CSSPropertyInvalid;
249 m_propertyInitialValue = 0; 272 m_propertyInitialValue = 0;
250 m_factor = 0; 273 m_factor = 0;
251 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; 274 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown;
252 } 275 }
253 276
254 } // namespace blink 277 } // namespace blink
OLDNEW
« 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