| 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" | |
| 10 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 11 #include "core/inspector/InspectorCSSAgent.h" | 10 #include "core/inspector/InspectorCSSAgent.h" |
| 12 #include "core/layout/LayoutBox.h" | 11 #include "core/layout/LayoutBox.h" |
| 13 #include "core/layout/LayoutInline.h" | 12 #include "core/layout/LayoutInline.h" |
| 14 #include "core/layout/LayoutObject.h" | 13 #include "core/layout/LayoutObject.h" |
| 15 #include "platform/JSONValues.h" | 14 #include "platform/JSONValues.h" |
| 16 | 15 |
| 17 namespace blink { | 16 namespace blink { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft
, paddingLeftDescription.release())); | 125 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft
, paddingLeftDescription.release())); |
| 127 | 126 |
| 128 RefPtr<JSONObject> paddingRightDescription = createValueDescription("padding
-right"); | 127 RefPtr<JSONObject> paddingRightDescription = createValueDescription("padding
-right"); |
| 129 if (paddingRightDescription) | 128 if (paddingRightDescription) |
| 130 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoR
ight, paddingRightDescription.release())); | 129 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoR
ight, paddingRightDescription.release())); |
| 131 | 130 |
| 132 object->setArray("anchors", anchors.release()); | 131 object->setArray("anchors", anchors.release()); |
| 133 return object.release(); | 132 return object.release(); |
| 134 } | 133 } |
| 135 | 134 |
| 136 RefPtrWillBeRawPtr<CSSPrimitiveValue> LayoutEditor::getPropertyCSSValue(CSSPrope
rtyID property) const | 135 NullableCSSValue LayoutEditor::getPropertyCSSValue(CSSPropertyID property) const |
| 137 { | 136 { |
| 138 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu
tedStyleDeclaration::create(m_node, true); | 137 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu
tedStyleDeclaration::create(m_node, true); |
| 139 RefPtrWillBeRawPtr<CSSValue> cssValue = computedStyleInfo->getPropertyCSSVal
ue(property); | 138 NullableCSSValue cssValue = computedStyleInfo->getPropertyCSSValue(property)
; |
| 140 if (!cssValue->isPrimitiveValue()) | 139 if (!cssValue || !cssValue->isPrimitiveValue()) |
| 141 return nullptr; | 140 return nullptr; |
| 142 | 141 |
| 143 return toCSSPrimitiveValue(cssValue.get()); | 142 return cssValue; |
| 144 } | 143 } |
| 145 | 144 |
| 146 PassRefPtr<JSONObject> LayoutEditor::createValueDescription(const String& proper
tyName) const | 145 PassRefPtr<JSONObject> LayoutEditor::createValueDescription(const String& proper
tyName) const |
| 147 { | 146 { |
| 148 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(cssProp
ertyID(propertyName)); | 147 NullableCSSValue cssValue = getPropertyCSSValue(cssPropertyID(propertyName))
; |
| 149 if (!cssValue) | 148 if (!cssValue) |
| 150 return nullptr; | 149 return nullptr; |
| 151 | 150 |
| 152 RefPtr<JSONObject> object = JSONObject::create(); | 151 RefPtr<JSONObject> object = JSONObject::create(); |
| 153 object->setNumber("value", cssValue->getFloatValue()); | 152 object->setNumber("value", toCSSPrimitiveValue(cssValue)->getFloatValue()); |
| 154 object->setString("unit", "px"); | 153 object->setString("unit", "px"); |
| 155 return object.release(); | 154 return object.release(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) | 157 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) |
| 159 { | 158 { |
| 160 m_changingProperty = cssPropertyID(anchorName); | 159 m_changingProperty = cssPropertyID(anchorName); |
| 161 if (!m_node || !m_changingProperty) | 160 if (!m_node || !m_changingProperty) |
| 162 return; | 161 return; |
| 163 | 162 |
| 164 RefPtrWillBeRawPtr<CSSPrimitiveValue> cssValue = getPropertyCSSValue(m_chang
ingProperty); | 163 NullableCSSValue cssValue = getPropertyCSSValue(m_changingProperty); |
| 165 if (!cssValue) { | 164 if (!cssValue) { |
| 166 m_changingProperty = CSSPropertyInvalid; | 165 m_changingProperty = CSSPropertyInvalid; |
| 167 return; | 166 return; |
| 168 } | 167 } |
| 169 | 168 |
| 170 m_propertyInitialValue = cssValue->getFloatValue(); | 169 m_propertyInitialValue = toCSSPrimitiveValue(cssValue)->getFloatValue(); |
| 171 } | 170 } |
| 172 | 171 |
| 173 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 172 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
| 174 { | 173 { |
| 175 if (m_changingProperty && m_node->isElementNode()) { | 174 if (m_changingProperty && m_node->isElementNode()) { |
| 176 String errorString; | 175 String errorString; |
| 177 m_cssAgent->setCSSPropertyValue(&errorString, toElement(m_node.get()), m
_changingProperty, String::number(cssDelta + m_propertyInitialValue) + "px"); | 176 m_cssAgent->setCSSPropertyValue(&errorString, toElement(m_node.get()), m
_changingProperty, String::number(cssDelta + m_propertyInitialValue) + "px"); |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| 181 void LayoutEditor::overlayEndedPropertyChange() | 180 void LayoutEditor::overlayEndedPropertyChange() |
| 182 { | 181 { |
| 183 m_changingProperty = CSSPropertyInvalid; | 182 m_changingProperty = CSSPropertyInvalid; |
| 184 m_propertyInitialValue = 0; | 183 m_propertyInitialValue = 0; |
| 185 } | 184 } |
| 186 | 185 |
| 187 } // namespace blink | 186 } // namespace blink |
| OLD | NEW |