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/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 Loading... | |
| 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 Loading... | |
| 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) | |
|
dgozman
2015/06/25 12:30:59
Let's explicitly compare with CSSPropertyInvalid.
sergeyv
2015/06/25 12:54:31
In CSSComputedStyleDeclaration.cpp they do like th
| |
| 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 return; | |
|
dgozman
2015/06/25 12:30:59
m_changingProperty = CSSPropertyInvalid;
sergeyv
2015/06/25 12:54:31
Done.
| |
| 134 | |
| 135 m_propertyInitialValue = toCSSPrimitiveValue(cssValue.get())->getFloatValue( ); | |
| 136 } | |
| 137 | |
| 138 void LayoutEditor::overlayPropertyChanged(float cssDelta) | |
| 139 { | |
| 140 if (m_changingProperty) | |
|
dgozman
2015/06/25 12:31:00
Let's explicitly compare with CSSPropertyInvalid.
sergeyv
2015/06/25 12:54:31
ditto
| |
| 141 m_cssAgent->updateCSSProperty(m_node.get(), m_changingProperty, cssDelta + m_propertyInitialValue); | |
| 142 } | |
| 143 | |
| 144 void LayoutEditor::overlayEndedPropertyChange() | |
| 145 { | |
| 146 m_changingProperty = CSSPropertyInvalid; | |
| 147 m_propertyInitialValue = 0; | |
| 109 } | 148 } |
| 110 | 149 |
| 111 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |