Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/inspector/LayoutEditor.h" | |
| 7 | |
| 8 #include "core/dom/Node.h" | |
| 9 #include "core/frame/FrameView.h" | |
| 10 #include "core/layout/LayoutBox.h" | |
| 11 #include "core/layout/LayoutInline.h" | |
| 12 #include "core/layout/LayoutObject.h" | |
| 13 #include "platform/JSONValues.h" | |
| 14 | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 PassRefPtr<JSONObject> createAnchor(float x, float y, const String& propertyName , FloatPoint deltaVector) | |
| 21 { | |
| 22 RefPtr<JSONObject> object = JSONObject::create(); | |
| 23 object->setNumber("x", x); | |
| 24 object->setNumber("y", y); | |
| 25 object->setString("propertyName", propertyName); | |
| 26 | |
| 27 RefPtr<JSONObject> deltaVectorJSON = JSONObject::create(); | |
| 28 deltaVectorJSON->setNumber("x", deltaVector.x()); | |
| 29 deltaVectorJSON->setNumber("y", deltaVector.y()); | |
| 30 object->setObject("deltaVector", deltaVectorJSON.release()); | |
| 31 | |
| 32 return object.release(); | |
| 33 } | |
| 34 | |
| 35 void contentsQuadToViewport(const FrameView* view, FloatQuad& quad) | |
| 36 { | |
| 37 quad.setP1(view->contentsToViewport(roundedIntPoint(quad.p1()))); | |
| 38 quad.setP2(view->contentsToViewport(roundedIntPoint(quad.p2()))); | |
| 39 quad.setP3(view->contentsToViewport(roundedIntPoint(quad.p3()))); | |
| 40 quad.setP4(view->contentsToViewport(roundedIntPoint(quad.p4()))); | |
| 41 } | |
| 42 | |
| 43 FloatPoint orthogonalVector(FloatPoint from, FloatPoint to, FloatPoint defaultVe ctor) | |
| 44 { | |
| 45 if (from == to) | |
| 46 return defaultVector; | |
| 47 | |
| 48 return FloatPoint(to.y() - from.y(), from.x() - to.x()); | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 LayoutEditor::LayoutEditor(Node* node) | |
| 54 : m_node(node) | |
| 55 { | |
| 56 } | |
| 57 | |
| 58 PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const | |
| 59 { | |
| 60 LayoutObject* layoutObject = m_node->layoutObject(); | |
| 61 | |
| 62 if (!layoutObject) | |
| 63 return nullptr; | |
| 64 | |
| 65 FrameView* containingView = layoutObject->frameView(); | |
| 66 if (!containingView) | |
| 67 return nullptr; | |
| 68 if (!layoutObject->isBox() && !layoutObject->isLayoutInline()) | |
| 69 return nullptr; | |
| 70 | |
| 71 LayoutRect paddingBox; | |
| 72 | |
| 73 if (layoutObject->isBox()) { | |
| 74 LayoutBox* layoutBox = toLayoutBox(layoutObject); | |
| 75 | |
| 76 // LayoutBox returns the "pure" content area box, exclusive of the scrol lbars (if present), which also count towards the content area in CSS. | |
| 77 const int verticalScrollbarWidth = layoutBox->verticalScrollbarWidth(); | |
| 78 const int horizontalScrollbarHeight = layoutBox->horizontalScrollbarHeig ht(); | |
| 79 | |
| 80 paddingBox = layoutBox->paddingBoxRect(); | |
| 81 paddingBox.setWidth(paddingBox.width() + verticalScrollbarWidth); | |
| 82 paddingBox.setHeight(paddingBox.height() + horizontalScrollbarHeight); | |
| 83 } else { | |
| 84 LayoutInline* layoutInline = toLayoutInline(layoutObject); | |
| 85 LayoutRect borderBox = LayoutRect(layoutInline->linesBoundingBox()); | |
| 86 paddingBox = LayoutRect(borderBox.x() + layoutInline->borderLeft(), bord erBox.y() + layoutInline->borderTop(), | |
| 87 borderBox.width() - layoutInline->borderLeft() - layoutInline->borde rRight(), borderBox.height() - layoutInline->borderTop() - layoutInline->borderB ottom()); | |
| 88 } | |
| 89 | |
| 90 FloatQuad padding = layoutObject->localToAbsoluteQuad(FloatRect(paddingBox)) ; | |
| 91 contentsQuadToViewport(containingView, padding); | |
| 92 | |
| 93 float xLeft = (padding.p1().x() + padding.p4().x()) / 2; | |
| 94 float yLeft = (padding.p1().y() + padding.p4().y()) / 2; | |
| 95 FloatPoint orthoLeft = orthogonalVector(padding.p4(), padding.p1(), FloatPoi nt(-1, 0)); | |
| 96 | |
| 97 float xRight = (padding.p2().x() + padding.p3().x()) / 2; | |
| 98 float yRight = (padding.p2().y() + padding.p3().y()) / 2; | |
| 99 FloatPoint orthoRight = orthogonalVector(padding.p3(), padding.p2(), FloatPo int(1, 0)); | |
|
dgozman
2015/06/23 17:13:55
p3, p2
sergeyv
2015/06/23 17:21:13
Done.
| |
| 100 | |
| 101 RefPtr<JSONObject> object = JSONObject::create(); | |
| 102 RefPtr<JSONArray> anchors = JSONArray::create(); | |
| 103 anchors->pushObject(createAnchor(xLeft, yLeft, "padding-left", orthoLeft)); | |
| 104 anchors->pushObject(createAnchor(xRight, yRight, "padding-right", orthoRight )); | |
| 105 object->setArray("anchors", anchors.release()); | |
| 106 | |
| 107 return object.release(); | |
| 108 | |
| 109 } | |
| 110 | |
| 111 } // namespace blink | |
| OLD | NEW |