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/LayoutWYSIWYGEditor.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 LayoutWYSIWIGEditor::LayoutWYSIWIGEditor(Node* node) | |
| 19 : m_node(node) | |
| 20 { | |
| 21 } | |
| 22 | |
| 23 PassRefPtr<JSONObject> createAnchor(float x, float y) | |
|
dgozman
2015/06/23 14:00:30
Either static or anonymous namespace.
sergeyv
2015/06/23 16:36:52
Done.
| |
| 24 { | |
| 25 RefPtr<JSONObject> object = JSONObject::create(); | |
| 26 object->setNumber("x", x); | |
| 27 object->setNumber("y", y); | |
| 28 return object.release(); | |
| 29 } | |
| 30 | |
| 31 void contentsQuadToViewport(const FrameView* view, FloatQuad& quad) | |
|
dgozman
2015/06/23 14:00:30
ditto
sergeyv
2015/06/23 16:36:52
Done.
| |
| 32 { | |
| 33 quad.setP1(view->contentsToViewport(roundedIntPoint(quad.p1()))); | |
| 34 quad.setP2(view->contentsToViewport(roundedIntPoint(quad.p2()))); | |
| 35 quad.setP3(view->contentsToViewport(roundedIntPoint(quad.p3()))); | |
| 36 quad.setP4(view->contentsToViewport(roundedIntPoint(quad.p4()))); | |
| 37 } | |
| 38 | |
| 39 PassRefPtr<JSONObject> LayoutWYSIWIGEditor::buildJSONInfo() const | |
| 40 { | |
| 41 | |
|
dgozman
2015/06/23 14:00:30
nit: extra blank line
sergeyv
2015/06/23 16:36:52
Done.
| |
| 42 LayoutObject* layoutObject = m_node->layoutObject(); | |
| 43 | |
| 44 if (!layoutObject) | |
| 45 return nullptr; | |
| 46 | |
| 47 FrameView* containingView = layoutObject->frameView(); | |
| 48 if (!containingView) | |
| 49 return nullptr; | |
| 50 if (!layoutObject->isBox() && !layoutObject->isLayoutInline()) | |
| 51 return nullptr; | |
| 52 | |
| 53 LayoutRect paddingBox; | |
| 54 | |
| 55 if (layoutObject->isBox()) { | |
| 56 LayoutBox* layoutBox = toLayoutBox(layoutObject); | |
| 57 | |
| 58 // LayoutBox returns the "pure" content area box, exclusive of the scrol lbars (if present), which also count towards the content area in CSS. | |
| 59 const int verticalScrollbarWidth = layoutBox->verticalScrollbarWidth(); | |
| 60 const int horizontalScrollbarHeight = layoutBox->horizontalScrollbarHeig ht(); | |
| 61 | |
| 62 paddingBox = layoutBox->paddingBoxRect(); | |
| 63 paddingBox.setWidth(paddingBox.width() + verticalScrollbarWidth); | |
| 64 paddingBox.setHeight(paddingBox.height() + horizontalScrollbarHeight); | |
| 65 } else { | |
| 66 LayoutInline* layoutInline = toLayoutInline(layoutObject); | |
| 67 LayoutRect borderBox = LayoutRect(layoutInline->linesBoundingBox()); | |
| 68 paddingBox = LayoutRect(borderBox.x() + layoutInline->borderLeft(), bord erBox.y() + layoutInline->borderTop(), | |
| 69 borderBox.width() - layoutInline->borderLeft() - layoutInline->borde rRight(), borderBox.height() - layoutInline->borderTop() - layoutInline->borderB ottom()); | |
| 70 } | |
| 71 | |
| 72 | |
|
dgozman
2015/06/23 14:00:30
nit: extra blank lines
sergeyv
2015/06/23 16:36:52
Done.
| |
| 73 | |
| 74 FloatQuad padding = layoutObject->localToAbsoluteQuad(FloatRect(paddingBox)) ; | |
| 75 contentsQuadToViewport(containingView, padding); | |
| 76 | |
| 77 float xLeft = (padding.p1().x() + padding.p4().x()) / 2; | |
| 78 float yLeft = (padding.p1().y() + padding.p4().y()) / 2; | |
| 79 | |
| 80 float xRight = (padding.p2().x() + padding.p3().x()) / 2; | |
| 81 float yRight = (padding.p2().y() + padding.p3().y()) / 2; | |
| 82 | |
| 83 RefPtr<JSONObject> object = JSONObject::create(); | |
| 84 RefPtr<JSONArray> anchors = JSONArray::create(); | |
| 85 anchors->pushObject(createAnchor(xLeft, yLeft)); | |
| 86 anchors->pushObject(createAnchor(xRight, yRight)); | |
| 87 object->setArray("anchors", anchors.release()); | |
|
dgozman
2015/06/23 14:00:30
Let's add name/id and delta vector?
sergeyv
2015/06/23 16:36:52
Done.
| |
| 88 | |
| 89 return object.release(); | |
| 90 | |
| 91 } | |
| 92 | |
| 93 } // namespace blink | |
| OLD | NEW |