| 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/css/CSSPrimitiveValue.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/layout/LayoutBox.h" | 12 #include "core/layout/LayoutBox.h" |
| 13 #include "core/layout/LayoutInline.h" | 13 #include "core/layout/LayoutInline.h" |
| 14 #include "core/layout/LayoutObject.h" | 14 #include "core/layout/LayoutObject.h" |
| 15 #include "platform/JSONValues.h" | 15 #include "platform/JSONValues.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 PassRefPtr<JSONObject> createAnchor(float x, float y, const String& propertyName
, FloatPoint deltaVector) | 21 PassRefPtr<JSONObject> createAnchor(float x, float y, const String& propertyName
, FloatPoint deltaVector, PassRefPtr<JSONObject> valueDescription) |
| 22 { | 22 { |
| 23 RefPtr<JSONObject> object = JSONObject::create(); | 23 RefPtr<JSONObject> object = JSONObject::create(); |
| 24 object->setNumber("x", x); | 24 object->setNumber("x", x); |
| 25 object->setNumber("y", y); | 25 object->setNumber("y", y); |
| 26 object->setString("propertyName", propertyName); | 26 object->setString("propertyName", propertyName); |
| 27 | 27 |
| 28 RefPtr<JSONObject> deltaVectorJSON = JSONObject::create(); | 28 RefPtr<JSONObject> deltaVectorJSON = JSONObject::create(); |
| 29 deltaVectorJSON->setNumber("x", deltaVector.x()); | 29 deltaVectorJSON->setNumber("x", deltaVector.x()); |
| 30 deltaVectorJSON->setNumber("y", deltaVector.y()); | 30 deltaVectorJSON->setNumber("y", deltaVector.y()); |
| 31 object->setObject("deltaVector", deltaVectorJSON.release()); | 31 object->setObject("deltaVector", deltaVectorJSON.release()); |
| 32 | 32 object->setObject("propertyValue", valueDescription); |
| 33 return object.release(); | 33 return object.release(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void contentsQuadToViewport(const FrameView* view, FloatQuad& quad) | 36 void contentsQuadToViewport(const FrameView* view, FloatQuad& quad) |
| 37 { | 37 { |
| 38 quad.setP1(view->contentsToViewport(roundedIntPoint(quad.p1()))); | 38 quad.setP1(view->contentsToViewport(roundedIntPoint(quad.p1()))); |
| 39 quad.setP2(view->contentsToViewport(roundedIntPoint(quad.p2()))); | 39 quad.setP2(view->contentsToViewport(roundedIntPoint(quad.p2()))); |
| 40 quad.setP3(view->contentsToViewport(roundedIntPoint(quad.p3()))); | 40 quad.setP3(view->contentsToViewport(roundedIntPoint(quad.p3()))); |
| 41 quad.setP4(view->contentsToViewport(roundedIntPoint(quad.p4()))); | 41 quad.setP4(view->contentsToViewport(roundedIntPoint(quad.p4()))); |
| 42 } | 42 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 float xLeft = (padding.p1().x() + padding.p4().x()) / 2; | 113 float xLeft = (padding.p1().x() + padding.p4().x()) / 2; |
| 114 float yLeft = (padding.p1().y() + padding.p4().y()) / 2; | 114 float yLeft = (padding.p1().y() + padding.p4().y()) / 2; |
| 115 FloatPoint orthoLeft = orthogonalVector(padding.p4(), padding.p1(), FloatPoi
nt(-1, 0)); | 115 FloatPoint orthoLeft = orthogonalVector(padding.p4(), padding.p1(), FloatPoi
nt(-1, 0)); |
| 116 | 116 |
| 117 float xRight = (padding.p2().x() + padding.p3().x()) / 2; | 117 float xRight = (padding.p2().x() + padding.p3().x()) / 2; |
| 118 float yRight = (padding.p2().y() + padding.p3().y()) / 2; | 118 float yRight = (padding.p2().y() + padding.p3().y()) / 2; |
| 119 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo
int(1, 0)); | 119 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo
int(1, 0)); |
| 120 | 120 |
| 121 RefPtr<JSONObject> object = JSONObject::create(); | 121 RefPtr<JSONObject> object = JSONObject::create(); |
| 122 RefPtr<JSONArray> anchors = JSONArray::create(); | 122 RefPtr<JSONArray> anchors = JSONArray::create(); |
| 123 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft)); | 123 |
| 124 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight
)); | 124 RefPtr<JSONObject> paddingLeftDescription = createValueDescription("padding-
left"); |
| 125 if (paddingLeftDescription) |
| 126 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft
, paddingLeftDescription.release())); |
| 127 |
| 128 RefPtr<JSONObject> paddingRightDescription = createValueDescription("padding
-right"); |
| 129 if (paddingRightDescription) |
| 130 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoR
ight, paddingRightDescription.release())); |
| 131 |
| 125 object->setArray("anchors", anchors.release()); | 132 object->setArray("anchors", anchors.release()); |
| 126 | |
| 127 return object.release(); | 133 return object.release(); |
| 128 } | 134 } |
| 129 | 135 |
| 136 RefPtrWillBeRawPtr<CSSPrimitiveValue> LayoutEditor::getPropertyCSSValue(CSSPrope
rtyID property) const |
| 137 { |
| 138 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu
tedStyleDeclaration::create(m_node, true); |
| 139 RefPtrWillBeRawPtr<CSSValue> cssValue = computedStyleInfo->getPropertyCSSVal
ue(property); |
| 140 if (!cssValue->isPrimitiveValue()) |
| 141 return nullptr; |
| 142 |
| 143 return toCSSPrimitiveValue(cssValue.get()); |
| 144 } |
| 145 |
| 146 PassRefPtr<JSONObject> LayoutEditor::createValueDescription(const String& proper
tyName) const |
| 147 { |
| 148 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(cssProp
ertyID(propertyName)); |
| 149 if (!cssValue) |
| 150 return nullptr; |
| 151 |
| 152 RefPtr<JSONObject> object = JSONObject::create(); |
| 153 object->setNumber("value", cssValue->getFloatValue()); |
| 154 object->setString("unit", "px"); |
| 155 return object.release(); |
| 156 } |
| 157 |
| 130 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) | 158 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) |
| 131 { | 159 { |
| 132 m_changingProperty = cssPropertyID(anchorName); | 160 m_changingProperty = cssPropertyID(anchorName); |
| 133 if (!m_node || !m_changingProperty) | 161 if (!m_node || !m_changingProperty) |
| 134 return; | 162 return; |
| 135 | 163 |
| 136 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu
tedStyleDeclaration::create(m_node, true); | 164 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(m_chang
ingProperty); |
| 137 RefPtrWillBeRawPtr<CSSValue> cssValue = computedStyleInfo->getPropertyCSSVal
ue(m_changingProperty); | 165 if (!cssValue) { |
| 138 if (!cssValue->isPrimitiveValue()) { | |
| 139 m_changingProperty = CSSPropertyInvalid; | 166 m_changingProperty = CSSPropertyInvalid; |
| 140 return; | 167 return; |
| 141 } | 168 } |
| 142 | 169 |
| 143 m_propertyInitialValue = toCSSPrimitiveValue(cssValue.get())->getFloatValue(
); | 170 m_propertyInitialValue = cssValue->getFloatValue(); |
| 144 } | 171 } |
| 145 | 172 |
| 146 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 173 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
| 147 { | 174 { |
| 148 if (m_changingProperty) | 175 if (m_changingProperty) |
| 149 m_cssAgent->setCSSPropertyValue(m_node.get(), m_changingProperty, cssDel
ta + m_propertyInitialValue); | 176 m_cssAgent->setCSSPropertyValue(m_node.get(), m_changingProperty, cssDel
ta + m_propertyInitialValue); |
| 150 } | 177 } |
| 151 | 178 |
| 152 void LayoutEditor::overlayEndedPropertyChange() | 179 void LayoutEditor::overlayEndedPropertyChange() |
| 153 { | 180 { |
| 154 m_changingProperty = CSSPropertyInvalid; | 181 m_changingProperty = CSSPropertyInvalid; |
| 155 m_propertyInitialValue = 0; | 182 m_propertyInitialValue = 0; |
| 156 } | 183 } |
| 157 | 184 |
| 158 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |