Chromium Code Reviews| 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/css/CSSPrimitiveValue.h" | 9 #include "core/dom/NodeComputedStyle.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/inspector/InspectorCSSAgent.h" | 11 #include "core/inspector/InspectorCSSAgent.h" |
| 12 #include "core/inspector/InspectorHighlight.h" | 12 #include "core/inspector/InspectorHighlight.h" |
| 13 #include "core/layout/LayoutBox.h" | 13 #include "core/layout/LayoutBox.h" |
| 14 #include "core/layout/LayoutInline.h" | 14 #include "core/layout/LayoutInline.h" |
| 15 #include "core/layout/LayoutObject.h" | 15 #include "core/layout/LayoutObject.h" |
| 16 #include "core/style/ComputedStyle.h" | |
| 16 #include "platform/JSONValues.h" | 17 #include "platform/JSONValues.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 PassRefPtr<JSONObject> createAnchor(const FloatPoint& point, const String& type, const String& propertyName, FloatPoint deltaVector, PassRefPtr<JSONObject> valu eDescription) | 23 PassRefPtr<JSONObject> createAnchor(const FloatPoint& point, const String& type, const String& propertyName, FloatPoint deltaVector, PassRefPtr<JSONObject> valu eDescription) |
| 23 { | 24 { |
| 24 RefPtr<JSONObject> object = JSONObject::create(); | 25 RefPtr<JSONObject> object = JSONObject::create(); |
| 25 object->setNumber("x", point.x()); | 26 object->setNumber("x", point.x()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 { | 104 { |
| 104 FloatQuad result; | 105 FloatQuad result; |
| 105 result.setP1(projection(projectOn.p1(), orthogonals.p1(), translatePoint(ori gin.p1(), orthogonals.p1(), distance))); | 106 result.setP1(projection(projectOn.p1(), orthogonals.p1(), translatePoint(ori gin.p1(), orthogonals.p1(), distance))); |
| 106 result.setP2(projection(projectOn.p2(), orthogonals.p2(), translatePoint(ori gin.p2(), orthogonals.p2(), distance))); | 107 result.setP2(projection(projectOn.p2(), orthogonals.p2(), translatePoint(ori gin.p2(), orthogonals.p2(), distance))); |
| 107 // We want to translate at top and bottom point in the same direction, so we use p1 here. | 108 // We want to translate at top and bottom point in the same direction, so we use p1 here. |
| 108 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))); |
| 109 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))); |
| 110 return result; | 111 return result; |
| 111 } | 112 } |
| 112 | 113 |
| 114 bool isMutableUnitType(CSSPrimitiveValue::UnitType unitType) | |
| 115 { | |
| 116 return unitType == CSSPrimitiveValue::UnitType::Pixels || unitType == CSSPri mitiveValue::UnitType::Ems || unitType == CSSPrimitiveValue::UnitType::Percentag e || unitType == CSSPrimitiveValue::UnitType::Rems; | |
| 117 } | |
| 118 | |
| 113 } // namespace | 119 } // namespace |
| 114 | 120 |
| 115 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) | 121 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) |
| 116 : m_element(nullptr) | 122 : m_element(nullptr) |
| 117 , m_cssAgent(cssAgent) | 123 , m_cssAgent(cssAgent) |
| 118 , m_changingProperty(CSSPropertyInvalid) | 124 , m_changingProperty(CSSPropertyInvalid) |
| 119 , m_propertyInitialValue(0) | 125 , m_propertyInitialValue(0) |
| 120 { | 126 { |
| 121 } | 127 } |
| 122 | 128 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 182 } |
| 177 | 183 |
| 178 PassRefPtr<JSONObject> LayoutEditor::createValueDescription(const String& proper tyName) const | 184 PassRefPtr<JSONObject> LayoutEditor::createValueDescription(const String& proper tyName) const |
| 179 { | 185 { |
| 180 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(cssProp ertyID(propertyName)); | 186 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(cssProp ertyID(propertyName)); |
| 181 if (cssValue && !(cssValue->isLength() || cssValue->isPercentage())) | 187 if (cssValue && !(cssValue->isLength() || cssValue->isPercentage())) |
| 182 return nullptr; | 188 return nullptr; |
| 183 | 189 |
| 184 RefPtr<JSONObject> object = JSONObject::create(); | 190 RefPtr<JSONObject> object = JSONObject::create(); |
| 185 object->setNumber("value", cssValue ? cssValue->getFloatValue() : 0); | 191 object->setNumber("value", cssValue ? cssValue->getFloatValue() : 0); |
| 186 object->setString("unit", CSSPrimitiveValue::unitTypeToString(cssValue ? css Value->typeWithCalcResolved() : CSSPrimitiveValue::UnitType::Pixels)); | 192 CSSPrimitiveValue::UnitType unitType = cssValue ? cssValue->typeWithCalcReso lved() : CSSPrimitiveValue::UnitType::Pixels; |
| 193 object->setString("unit", CSSPrimitiveValue::unitTypeToString(unitType)); | |
| 187 // TODO: Support an editing of other popular units like: em, rem | 194 // TODO: Support an editing of other popular units like: em, rem |
| 188 object->setBoolean("mutable", !cssValue || cssValue->isPx()); | 195 object->setBoolean("mutable", isMutableUnitType(unitType)); |
| 189 return object.release(); | 196 return object.release(); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void LayoutEditor::appendAnchorFor(JSONArray* anchors, const String& type, const String& propertyName, const FloatPoint& position, const FloatPoint& orthogonalV ector) const | 199 void LayoutEditor::appendAnchorFor(JSONArray* anchors, const String& type, const String& propertyName, const FloatPoint& position, const FloatPoint& orthogonalV ector) const |
| 193 { | 200 { |
| 194 RefPtr<JSONObject> description = createValueDescription(propertyName); | 201 RefPtr<JSONObject> description = createValueDescription(propertyName); |
| 195 if (description) | 202 if (description) |
| 196 anchors->pushObject(createAnchor(position, type, propertyName, orthogona lVector, description.release())); | 203 anchors->pushObject(createAnchor(position, type, propertyName, orthogona lVector, description.release())); |
| 197 } | 204 } |
| 198 | 205 |
| 199 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) | 206 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) |
| 200 { | 207 { |
| 201 m_changingProperty = cssPropertyID(anchorName); | 208 m_changingProperty = cssPropertyID(anchorName); |
| 202 if (!m_element || !m_changingProperty) | 209 if (!m_element || !m_changingProperty) |
| 203 return; | 210 return; |
| 204 | 211 |
| 205 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(m_chang ingProperty); | 212 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(m_chang ingProperty); |
| 206 if (cssValue && !cssValue->isPx()) | 213 m_valueUnitType = cssValue ? cssValue->typeWithCalcResolved() : CSSPrimitive Value::UnitType::Pixels; |
| 214 if (!isMutableUnitType(m_valueUnitType)) | |
| 207 return; | 215 return; |
| 208 | 216 |
| 217 switch (m_valueUnitType) { | |
| 218 case CSSPrimitiveValue::UnitType::Pixels: | |
| 219 m_factor = 1; | |
| 220 break; | |
| 221 case CSSPrimitiveValue::UnitType::Ems: | |
| 222 m_factor = m_element->computedStyle()->computedFontSize(); | |
| 223 break; | |
| 224 case CSSPrimitiveValue::UnitType::Percentage: | |
| 225 // It is hard to correctly support percentages, so we decided hack it th is way: 100% = 1000px | |
| 226 m_factor = 10; | |
|
dgozman
2015/08/15 00:33:47
Let's try with offsetParent.
sergeyv
2015/08/17 23:52:18
OffsetParent isn't the parent against which the wi
| |
| 227 break; | |
| 228 case CSSPrimitiveValue::UnitType::Rems: | |
| 229 m_factor = m_element->document().computedStyle()->computedFontSize(); | |
| 230 break; | |
| 231 default: | |
| 232 ASSERT_NOT_REACHED(); | |
| 233 break; | |
| 234 } | |
| 209 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; | 235 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; |
| 210 } | 236 } |
| 211 | 237 |
| 212 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 238 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
| 213 { | 239 { |
| 214 if (m_changingProperty) { | 240 if (m_changingProperty) { |
|
dgozman
2015/08/15 00:33:47
&& m_factor
sergeyv
2015/08/17 23:52:18
Done.
| |
| 215 String errorString; | 241 String errorString; |
| 216 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, String::number(cssDelta + m_propertyInitialValue) + "px"); | 242 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, String::format("%.2f", cssDelta / m_factor + m_propertyInitialValue) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); |
| 217 } | 243 } |
| 218 } | 244 } |
| 219 | 245 |
| 220 void LayoutEditor::overlayEndedPropertyChange() | 246 void LayoutEditor::overlayEndedPropertyChange() |
| 221 { | 247 { |
| 222 m_changingProperty = CSSPropertyInvalid; | 248 m_changingProperty = CSSPropertyInvalid; |
| 223 m_propertyInitialValue = 0; | 249 m_propertyInitialValue = 0; |
| 250 m_factor = 0; | |
| 251 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; | |
| 224 } | 252 } |
| 225 | 253 |
| 226 } // namespace blink | 254 } // namespace blink |
| OLD | NEW |