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

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: 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
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()
54 : m_node(node) 55 : m_node(nullptr)
56 , m_cssAgent(nullptr)
57 , m_changingProperty(CSSPropertyInvalid)
58 , m_propertyInitialValue(0)
55 { 59 {
56 } 60 }
57 61
58 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const 62 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const
59 { 63 {
64 if (!m_node || !m_cssAgent)
65 return nullptr;
66
60 LayoutObject* layoutObject = m_node->layoutObject(); 67 LayoutObject* layoutObject = m_node->layoutObject();
61 68
62 if (!layoutObject) 69 if (!layoutObject)
63 return nullptr; 70 return nullptr;
64 71
65 FrameView* containingView = layoutObject->frameView(); 72 FrameView* containingView = layoutObject->frameView();
66 if (!containingView) 73 if (!containingView)
67 return nullptr; 74 return nullptr;
68 if (!layoutObject->isBox() && !layoutObject->isLayoutInline()) 75 if (!layoutObject->isBox() && !layoutObject->isLayoutInline())
69 return nullptr; 76 return nullptr;
(...skipping 28 matching lines...) Expand all
98 float yRight = (padding.p2().y() + padding.p3().y()) / 2; 105 float yRight = (padding.p2().y() + padding.p3().y()) / 2;
99 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo int(1, 0)); 106 FloatPoint orthoRight = orthogonalVector(padding.p2(), padding.p3(), FloatPo int(1, 0));
100 107
101 RefPtr<JSONObject> object = JSONObject::create(); 108 RefPtr<JSONObject> object = JSONObject::create();
102 RefPtr<JSONArray> anchors = JSONArray::create(); 109 RefPtr<JSONArray> anchors = JSONArray::create();
103 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft)); 110 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft));
104 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight )); 111 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight ));
105 object->setArray("anchors", anchors.release()); 112 object->setArray("anchors", anchors.release());
106 113
107 return object.release(); 114 return object.release();
115 }
108 116
117 void LayoutEditor::overlayStartedPropertyChange(const String& anchorName)
118 {
119 m_changingProperty = cssPropertyID(anchorName);
120 if (!m_node || !m_changingProperty)
121 return;
122
123 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSCompu tedStyleDeclaration::create(m_node, true);
124 RefPtrWillBeRawPtr<CSSValue> cssValue = computedStyleInfo->getPropertyCSSVal ue(m_changingProperty);
125 if (!cssValue->isPrimitiveValue())
126 return;
127
128 m_propertyInitialValue = toCSSPrimitiveValue(cssValue.get())->getFloatValue( );
129 }
130
131 void LayoutEditor::overlayPropertyChanged(float delta)
132 {
133 if (m_cssAgent && m_changingProperty)
134 m_cssAgent->updateCSSProperty(m_node.get(), m_changingProperty, delta + m_propertyInitialValue);
135 }
136
137 void LayoutEditor::overlayEndedPropertyChange()
138 {
139 m_changingProperty = CSSPropertyInvalid;
140 m_propertyInitialValue = 0;
109 } 141 }
110 142
111 } // namespace blink 143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698