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

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

Issue 1206833003: Devtools[LayoutEditor]: Pass data about property change from InspectorOverlayPage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address pfeldman's comment Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/LayoutEditor.h ('k') | Source/web/InspectorOverlayImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/dom/Node.h" 8 #include "core/css/CSSComputedStyleDeclaration.h"
9 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
11 #include "core/inspector/InspectorCSSAgent.h"
10 #include "core/layout/LayoutBox.h" 12 #include "core/layout/LayoutBox.h"
11 #include "core/layout/LayoutInline.h" 13 #include "core/layout/LayoutInline.h"
12 #include "core/layout/LayoutObject.h" 14 #include "core/layout/LayoutObject.h"
13 #include "platform/JSONValues.h" 15 #include "platform/JSONValues.h"
14 16
15
16 namespace blink { 17 namespace blink {
17 18
18 namespace { 19 namespace {
19 20
20 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)
21 { 22 {
22 RefPtr<JSONObject> object = JSONObject::create(); 23 RefPtr<JSONObject> object = JSONObject::create();
23 object->setNumber("x", x); 24 object->setNumber("x", x);
24 object->setNumber("y", y); 25 object->setNumber("y", y);
25 object->setString("propertyName", propertyName); 26 object->setString("propertyName", propertyName);
(...skipping 17 matching lines...) Expand all
43 FloatPoint orthogonalVector(FloatPoint from, FloatPoint to, FloatPoint defaultVe ctor) 44 FloatPoint orthogonalVector(FloatPoint from, FloatPoint to, FloatPoint defaultVe ctor)
44 { 45 {
45 if (from == to) 46 if (from == to)
46 return defaultVector; 47 return defaultVector;
47 48
48 return FloatPoint(to.y() - from.y(), from.x() - to.x()); 49 return FloatPoint(to.y() - from.y(), from.x() - to.x());
49 } 50 }
50 51
51 } // namespace 52 } // namespace
52 53
53 LayoutEditor::LayoutEditor(Node* node) 54 LayoutEditor::LayoutEditor(InspectorCSSAgent* cssAgent)
54 : m_node(node) 55 : m_node(nullptr)
56 , m_cssAgent(cssAgent)
57 , m_changingProperty(CSSPropertyInvalid)
58 , m_propertyInitialValue(0)
55 { 59 {
56 } 60 }
57 61
62 void LayoutEditor::setNode(Node* node)
63 {
64 m_node = node;
65 m_changingProperty = CSSPropertyInvalid;
66 m_propertyInitialValue = 0;
67 }
68
58 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const 69 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const
59 { 70 {
71 if (!m_node)
72 return nullptr;
73
60 LayoutObject* layoutObject = m_node->layoutObject(); 74 LayoutObject* layoutObject = m_node->layoutObject();
61 75
62 if (!layoutObject) 76 if (!layoutObject)
63 return nullptr; 77 return nullptr;
64 78
65 FrameView* containingView = layoutObject->frameView(); 79 FrameView* containingView = layoutObject->frameView();
66 if (!containingView) 80 if (!containingView)
67 return nullptr; 81 return nullptr;
68 if (!layoutObject->isBox() && !layoutObject->isLayoutInline()) 82 if (!layoutObject->isBox() && !layoutObject->isLayoutInline())
69 return nullptr; 83 return nullptr;
(...skipping 28 matching lines...) Expand all
98 float yRight = (padding.p2().y() + padding.p3().y()) / 2; 112 float yRight = (padding.p2().y() + padding.p3().y()) / 2;
99 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo int(1, 0)); 113 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo int(1, 0));
100 114
101 RefPtr<JSONObject> object = JSONObject::create(); 115 RefPtr<JSONObject> object = JSONObject::create();
102 RefPtr<JSONArray> anchors = JSONArray::create(); 116 RefPtr<JSONArray> anchors = JSONArray::create();
103 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft)); 117 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft));
104 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight )); 118 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight ));
105 object->setArray("anchors", anchors.release()); 119 object->setArray("anchors", anchors.release());
106 120
107 return object.release(); 121 return object.release();
122 }
108 123
124 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName)
125 {
126 m_changingProperty = cssPropertyID(anchorName);
127 if (!m_node || !m_changingProperty)
128 return;
129
130 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(m_node, true);
131 RefPtrWillBeRawPtr<CSSValue> cssValue = computedStyleInfo->getPropertyCSSVal ue(m_changingProperty);
132 if (!cssValue->isPrimitiveValue()) {
133 m_changingProperty = CSSPropertyInvalid;
134 return;
135 }
136
137 m_propertyInitialValue = toCSSPrimitiveValue(cssValue.get())->getFloatValue( );
138 }
139
140 void LayoutEditor::overlayPropertyChanged(float cssDelta)
141 {
142 if (m_changingProperty)
143 m_cssAgent->setCSSPropertyValue(m_node.get(), m_changingProperty, cssDel ta + m_propertyInitialValue);
144 }
145
146 void LayoutEditor::overlayEndedPropertyChange()
147 {
148 m_changingProperty = CSSPropertyInvalid;
149 m_propertyInitialValue = 0;
109 } 150 }
110 151
111 } // namespace blink 152 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/LayoutEditor.h ('k') | Source/web/InspectorOverlayImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698