Chromium Code Reviews| Index: third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp |
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp |
| index 0f5b4712fe0ab5954057bacea35eee015f31bd09..a8417779659d6ac39d72ce95bd082414bf011ffc 100644 |
| --- a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp |
| +++ b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp |
| @@ -66,7 +66,9 @@ |
| #include "core/inspector/InspectorHistory.h" |
| #include "core/inspector/V8InspectorString.h" |
| #include "core/layout/HitTestResult.h" |
| +#include "core/layout/LayoutInline.h" |
| #include "core/layout/api/LayoutViewItem.h" |
| +#include "core/layout/line/InlineTextBox.h" |
| #include "core/loader/DocumentLoader.h" |
| #include "core/page/FrameTree.h" |
| #include "core/page/Page.h" |
| @@ -528,6 +530,83 @@ void InspectorDOMAgent::getDocument(ErrorString* errorString, std::unique_ptr<pr |
| *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()); |
| } |
| +namespace { |
| +std::unique_ptr<protocol::DOM::Rect> getRectForFloatRect(const FloatRect& rect) |
|
pfeldman
2016/09/16 00:59:35
We call these build*. Also, either move those to t
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Done.
|
| +{ |
| + return protocol::DOM::Rect::create() |
| + .setX(rect.x()) |
| + .setY(rect.y()) |
| + .setWidth(rect.width()) |
| + .setHeight(rect.height()) |
| + .build(); |
| +} |
| + |
| +FloatRect getAbsoluteBoundingBox(LayoutObject* layoutObject) |
|
pfeldman
2016/09/16 00:59:35
Blink does not (yet) use get prefixes.
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Done.
|
| +{ |
| + if (layoutObject->isText()) { |
| + FloatRect localRect(toLayoutText(layoutObject)->linesBoundingBox()); |
| + return layoutObject->localToAbsoluteQuad(localRect).boundingBox(); |
|
pfeldman
2016/09/16 00:59:35
I am not sure this matches your expectations wrt c
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Acknowledged.
|
| + } |
| + if (layoutObject->isLayoutInline()) { |
| + FloatRect localRect(toLayoutInline(layoutObject)->linesBoundingBox()); |
| + return layoutObject->localToAbsoluteQuad(localRect).boundingBox(); |
| + } |
| + if (layoutObject->isBox()) { |
| + FloatRect localRect(toLayoutBox(layoutObject)->borderBoxRect()); |
| + return layoutObject->localToAbsoluteQuad(localRect).boundingBox(); |
| + } |
| + return layoutObject->absoluteBoundingBoxRect(); |
| +} |
| + |
| +} // namespace |
| + |
| +void InspectorDOMAgent::getRenderTreeNodes(ErrorString* errorString, std::unique_ptr<protocol::Array<protocol::DOM::RenderTreeNode>>* renderTreeNodes) |
| +{ |
| + renderTreeNodes->reset(new protocol::Array<protocol::DOM::RenderTreeNode>); |
| + |
| + std::vector<Node*> unvisited; // Neither WTF::Vector or HeapVector allow Node* :( |
| + unvisited.push_back(m_document.get()); |
| + |
| + while (!unvisited.empty()) { |
| + Node* node = unvisited.back(); |
| + unvisited.pop_back(); |
| + LayoutObject* layoutObject = node->layoutObject(); |
| + if (!layoutObject) |
|
pfeldman
2016/09/16 00:59:35
You still might want to go over the dom hierarchy.
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Good point!
|
| + continue; |
| + |
| + int backendNodeId = DOMNodeIds::idForNode(node); |
| + DCHECK(backendNodeId); |
|
pfeldman
2016/09/16 00:59:35
It is always there
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Done.
|
| + std::unique_ptr<protocol::DOM::RenderTreeNode> renderTreeNode = |
| + protocol::DOM::RenderTreeNode::create() |
| + .setBackendNodeId(backendNodeId) |
| + .setBoundingBox(getRectForFloatRect(getAbsoluteBoundingBox(layoutObject))) |
| + .build(); |
| + |
| + if (layoutObject->isText()) { |
| + LayoutText* layoutText = toLayoutText(layoutObject); |
| + renderTreeNode->setLayoutText(layoutText->text()); |
| + if (layoutText->hasTextBoxes()) { |
| + std::unique_ptr<protocol::Array<protocol::DOM::InlineTextBox>> inlineTextNodes(new protocol::Array<protocol::DOM::InlineTextBox>()); |
| + for (const InlineTextBox* itb = layoutText->firstTextBox(); itb; itb = itb->nextTextBox()) { |
| + FloatRect localItbRect(itb->calculateBoundaries()); |
| + FloatRect absoluteItbRect = layoutObject->localToAbsoluteQuad(localItbRect).boundingBox(); |
| + inlineTextNodes->addItem( |
| + protocol::DOM::InlineTextBox::create() |
| + .setText(layoutText->text().substring(itb->start(), itb->len()).utf8().data()) |
| + .setBoundingBox(getRectForFloatRect(absoluteItbRect)) |
| + .build()); |
| + } |
| + renderTreeNode->setInlineTextNodes(std::move(inlineTextNodes)); |
| + } |
| + } |
| + |
| + (*renderTreeNodes)->addItem(std::move(renderTreeNode)); |
| + |
| + for (node = innerFirstChild(node); node; node = innerNextSibling(node)) |
|
pfeldman
2016/09/16 00:59:35
I don't see where you account for the shadow dom.
alex clarke (OOO till 29th)
2016/09/16 10:23:36
Hopefully I've done that now.
|
| + unvisited.push_back(node); |
| + } |
| +} |
| + |
| void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) |
| { |
| Node* node = nodeForId(nodeId); |