Chromium Code Reviews| Index: Source/core/inspector/LayoutWYSIWYGEditor.cpp |
| diff --git a/Source/core/inspector/LayoutWYSIWYGEditor.cpp b/Source/core/inspector/LayoutWYSIWYGEditor.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..336cd56a0d17604c67906870dc3fabe48dcaad93 |
| --- /dev/null |
| +++ b/Source/core/inspector/LayoutWYSIWYGEditor.cpp |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/inspector/LayoutWYSIWYGEditor.h" |
| + |
| +#include "core/dom/Node.h" |
| +#include "core/frame/FrameView.h" |
| +#include "core/layout/LayoutBox.h" |
| +#include "core/layout/LayoutInline.h" |
| +#include "core/layout/LayoutObject.h" |
| +#include "platform/JSONValues.h" |
| + |
| + |
| +namespace blink { |
| + |
| +LayoutWYSIWIGEditor::LayoutWYSIWIGEditor(Node* node) |
| + : m_node(node) |
| +{ |
| +} |
| + |
| +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.
|
| +{ |
| + RefPtr<JSONObject> object = JSONObject::create(); |
| + object->setNumber("x", x); |
| + object->setNumber("y", y); |
| + return object.release(); |
| +} |
| + |
| +void contentsQuadToViewport(const FrameView* view, FloatQuad& quad) |
|
dgozman
2015/06/23 14:00:30
ditto
sergeyv
2015/06/23 16:36:52
Done.
|
| +{ |
| + quad.setP1(view->contentsToViewport(roundedIntPoint(quad.p1()))); |
| + quad.setP2(view->contentsToViewport(roundedIntPoint(quad.p2()))); |
| + quad.setP3(view->contentsToViewport(roundedIntPoint(quad.p3()))); |
| + quad.setP4(view->contentsToViewport(roundedIntPoint(quad.p4()))); |
| +} |
| + |
| +PassRefPtr<JSONObject> LayoutWYSIWIGEditor::buildJSONInfo() const |
| +{ |
| + |
|
dgozman
2015/06/23 14:00:30
nit: extra blank line
sergeyv
2015/06/23 16:36:52
Done.
|
| + LayoutObject* layoutObject = m_node->layoutObject(); |
| + |
| + if (!layoutObject) |
| + return nullptr; |
| + |
| + FrameView* containingView = layoutObject->frameView(); |
| + if (!containingView) |
| + return nullptr; |
| + if (!layoutObject->isBox() && !layoutObject->isLayoutInline()) |
| + return nullptr; |
| + |
| + LayoutRect paddingBox; |
| + |
| + if (layoutObject->isBox()) { |
| + LayoutBox* layoutBox = toLayoutBox(layoutObject); |
| + |
| + // LayoutBox returns the "pure" content area box, exclusive of the scrollbars (if present), which also count towards the content area in CSS. |
| + const int verticalScrollbarWidth = layoutBox->verticalScrollbarWidth(); |
| + const int horizontalScrollbarHeight = layoutBox->horizontalScrollbarHeight(); |
| + |
| + paddingBox = layoutBox->paddingBoxRect(); |
| + paddingBox.setWidth(paddingBox.width() + verticalScrollbarWidth); |
| + paddingBox.setHeight(paddingBox.height() + horizontalScrollbarHeight); |
| + } else { |
| + LayoutInline* layoutInline = toLayoutInline(layoutObject); |
| + LayoutRect borderBox = LayoutRect(layoutInline->linesBoundingBox()); |
| + paddingBox = LayoutRect(borderBox.x() + layoutInline->borderLeft(), borderBox.y() + layoutInline->borderTop(), |
| + borderBox.width() - layoutInline->borderLeft() - layoutInline->borderRight(), borderBox.height() - layoutInline->borderTop() - layoutInline->borderBottom()); |
| + } |
| + |
| + |
|
dgozman
2015/06/23 14:00:30
nit: extra blank lines
sergeyv
2015/06/23 16:36:52
Done.
|
| + |
| + FloatQuad padding = layoutObject->localToAbsoluteQuad(FloatRect(paddingBox)); |
| + contentsQuadToViewport(containingView, padding); |
| + |
| + float xLeft = (padding.p1().x() + padding.p4().x()) / 2; |
| + float yLeft = (padding.p1().y() + padding.p4().y()) / 2; |
| + |
| + float xRight = (padding.p2().x() + padding.p3().x()) / 2; |
| + float yRight = (padding.p2().y() + padding.p3().y()) / 2; |
| + |
| + RefPtr<JSONObject> object = JSONObject::create(); |
| + RefPtr<JSONArray> anchors = JSONArray::create(); |
| + anchors->pushObject(createAnchor(xLeft, yLeft)); |
| + anchors->pushObject(createAnchor(xRight, yRight)); |
| + 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.
|
| + |
| + return object.release(); |
| + |
| +} |
| + |
| +} // namespace blink |