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/dom/NodeComputedStyle.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/InspectorDOMAgent.h" | |
| 12 #include "core/inspector/InspectorHighlight.h" | 13 #include "core/inspector/InspectorHighlight.h" |
| 13 #include "core/layout/LayoutBox.h" | 14 #include "core/layout/LayoutBox.h" |
| 14 #include "core/layout/LayoutInline.h" | 15 #include "core/layout/LayoutInline.h" |
| 15 #include "core/layout/LayoutObject.h" | 16 #include "core/layout/LayoutObject.h" |
| 16 #include "core/style/ComputedStyle.h" | 17 #include "core/style/ComputedStyle.h" |
| 17 #include "platform/JSONValues.h" | 18 #include "platform/JSONValues.h" |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 | 134 |
| 134 float toValidValue(CSSPropertyID propertyId, float newValue) | 135 float toValidValue(CSSPropertyID propertyId, float newValue) |
| 135 { | 136 { |
| 136 if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddi ngTop) | 137 if (CSSPropertyPaddingBottom <= propertyId && propertyId <= CSSPropertyPaddi ngTop) |
| 137 return newValue >= 0 ? newValue : 0; | 138 return newValue >= 0 ? newValue : 0; |
| 138 | 139 |
| 139 return newValue; | 140 return newValue; |
| 140 } | 141 } |
| 141 } // namespace | 142 } // namespace |
| 142 | 143 |
| 143 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent) | 144 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent, InspectorDOMAgent* domAg ent) |
| 144 : m_element(nullptr) | 145 : m_element(nullptr) |
| 145 , m_cssAgent(cssAgent) | 146 , m_cssAgent(cssAgent) |
| 147 , m_domAgent(domAgent) | |
| 146 , m_changingProperty(CSSPropertyInvalid) | 148 , m_changingProperty(CSSPropertyInvalid) |
| 147 , m_propertyInitialValue(0) | 149 , m_propertyInitialValue(0) |
| 150 , m_madeChanges(false) | |
| 148 { | 151 { |
| 149 } | 152 } |
| 150 | 153 |
| 151 DEFINE_TRACE(LayoutEditor) | 154 DEFINE_TRACE(LayoutEditor) |
| 152 { | 155 { |
| 153 visitor->trace(m_element); | 156 visitor->trace(m_element); |
| 154 visitor->trace(m_cssAgent); | 157 visitor->trace(m_cssAgent); |
| 158 visitor->trace(m_domAgent); | |
| 155 } | 159 } |
| 156 | 160 |
| 157 void LayoutEditor::setNode(Node* node) | 161 void LayoutEditor::setNode(Node* node) |
| 158 { | 162 { |
| 159 m_element = node && node->isElementNode() ? toElement(node) : nullptr; | 163 Element* element = node && node->isElementNode() ? toElement(node) : nullptr ; |
| 164 if (element == m_element) | |
| 165 return; | |
| 166 | |
| 167 m_element = element; | |
| 160 m_changingProperty = CSSPropertyInvalid; | 168 m_changingProperty = CSSPropertyInvalid; |
| 161 m_propertyInitialValue = 0; | 169 m_propertyInitialValue = 0; |
| 170 m_madeChanges = false; | |
| 162 } | 171 } |
| 163 | 172 |
| 164 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const | 173 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const |
| 165 { | 174 { |
| 166 if (!m_element) | 175 if (!m_element) |
| 167 return nullptr; | 176 return nullptr; |
| 168 | 177 |
| 169 FloatQuad content, padding, border, margin; | 178 FloatQuad content, padding, border, margin; |
| 170 InspectorHighlight::buildNodeQuads(m_element.get(), &content, &padding, &bor der, &margin); | 179 InspectorHighlight::buildNodeQuads(m_element.get(), &content, &padding, &bor der, &margin); |
| 171 FloatQuad orthogonals = orthogonalVectors(padding); | 180 FloatQuad orthogonals = orthogonalVectors(padding); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 } | 265 } |
| 257 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; | 266 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; |
| 258 } | 267 } |
| 259 | 268 |
| 260 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 269 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
| 261 { | 270 { |
| 262 if (m_changingProperty && m_factor) { | 271 if (m_changingProperty && m_factor) { |
| 263 String errorString; | 272 String errorString; |
| 264 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); | 273 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)); | 274 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType)); |
| 275 m_madeChanges = true; | |
| 266 } | 276 } |
| 267 } | 277 } |
| 268 | 278 |
| 269 void LayoutEditor::overlayEndedPropertyChange() | 279 void LayoutEditor::overlayEndedPropertyChange() |
| 270 { | 280 { |
| 271 m_changingProperty = CSSPropertyInvalid; | 281 m_changingProperty = CSSPropertyInvalid; |
| 272 m_propertyInitialValue = 0; | 282 m_propertyInitialValue = 0; |
| 273 m_factor = 0; | 283 m_factor = 0; |
| 274 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; | 284 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; |
| 275 } | 285 } |
| 276 | 286 |
| 287 void LayoutEditor::clearSelection(bool commitChanges) | |
| 288 { | |
| 289 m_domAgent->resumeSearchingForNode(m_element.get()); | |
| 290 ErrorString errorString; | |
| 291 if (commitChanges) | |
| 292 m_domAgent->markUndoableState(&errorString); | |
| 293 else if (m_madeChanges) | |
| 294 m_domAgent->undo(&errorString); | |
| 295 | |
| 296 m_madeChanges = false; | |
|
pfeldman
2015/08/24 23:18:13
m_isDirty
sergeyv
2015/08/25 17:58:02
Done.
| |
| 297 } | |
| 298 | |
| 277 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |