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

Side by Side Diff: Source/core/inspector/LayoutEditor.cpp

Issue 1311783003: Devtools[LayoutEditor]: Rework layout-editor workflow (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@resize
Patch Set: Address comments Created 5 years, 3 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
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"
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
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_isDirty(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::selectNode(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 ASSERT(!m_isDirty);
168 m_element = element;
160 m_changingProperty = CSSPropertyInvalid; 169 m_changingProperty = CSSPropertyInvalid;
161 m_propertyInitialValue = 0; 170 m_propertyInitialValue = 0;
171
162 } 172 }
163 173
164 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const 174 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const
165 { 175 {
166 if (!m_element) 176 if (!m_element)
167 return nullptr; 177 return nullptr;
168 178
169 FloatQuad content, padding, border, margin; 179 FloatQuad content, padding, border, margin;
170 InspectorHighlight::buildNodeQuads(m_element.get(), &content, &padding, &bor der, &margin); 180 InspectorHighlight::buildNodeQuads(m_element.get(), &content, &padding, &bor der, &margin);
171 FloatQuad orthogonals = orthogonalVectors(padding); 181 FloatQuad orthogonals = orthogonalVectors(padding);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 266 }
257 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; 267 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0;
258 } 268 }
259 269
260 void LayoutEditor::overlayPropertyChanged(float cssDelta) 270 void LayoutEditor::overlayPropertyChanged(float cssDelta)
261 { 271 {
262 if (m_changingProperty && m_factor) { 272 if (m_changingProperty && m_factor) {
263 String errorString; 273 String errorString;
264 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); 274 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)); 275 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType));
276 if (!errorString)
277 m_isDirty = true;
266 } 278 }
267 } 279 }
268 280
269 void LayoutEditor::overlayEndedPropertyChange() 281 void LayoutEditor::overlayEndedPropertyChange()
270 { 282 {
271 m_changingProperty = CSSPropertyInvalid; 283 m_changingProperty = CSSPropertyInvalid;
272 m_propertyInitialValue = 0; 284 m_propertyInitialValue = 0;
273 m_factor = 0; 285 m_factor = 0;
274 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; 286 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown;
275 } 287 }
276 288
289 void LayoutEditor::clearSelection(bool commitChanges)
290 {
291 ErrorString errorString;
292 if (commitChanges)
293 m_domAgent->markUndoableState(&errorString);
294 else if (m_isDirty)
295 m_domAgent->undo(&errorString);
296
297 m_element.clear();
298 m_isDirty = false;
299 }
300
301
302
277 } // namespace blink 303 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/LayoutEditor.h ('k') | Source/devtools/front_end/components/InspectElementModeController.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698