Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp

Issue 2346853002: Add a DOM.getLayoutTreeNodes devtools command (Closed)
Patch Set: Changes for Elliott Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "core/html/imports/HTMLImportChild.h" 60 #include "core/html/imports/HTMLImportChild.h"
61 #include "core/html/imports/HTMLImportLoader.h" 61 #include "core/html/imports/HTMLImportLoader.h"
62 #include "core/inspector/DOMEditor.h" 62 #include "core/inspector/DOMEditor.h"
63 #include "core/inspector/DOMPatchSupport.h" 63 #include "core/inspector/DOMPatchSupport.h"
64 #include "core/inspector/IdentifiersFactory.h" 64 #include "core/inspector/IdentifiersFactory.h"
65 #include "core/inspector/InspectedFrames.h" 65 #include "core/inspector/InspectedFrames.h"
66 #include "core/inspector/InspectorHighlight.h" 66 #include "core/inspector/InspectorHighlight.h"
67 #include "core/inspector/InspectorHistory.h" 67 #include "core/inspector/InspectorHistory.h"
68 #include "core/inspector/V8InspectorString.h" 68 #include "core/inspector/V8InspectorString.h"
69 #include "core/layout/HitTestResult.h" 69 #include "core/layout/HitTestResult.h"
70 #include "core/layout/LayoutInline.h"
70 #include "core/layout/api/LayoutViewItem.h" 71 #include "core/layout/api/LayoutViewItem.h"
72 #include "core/layout/line/InlineTextBox.h"
71 #include "core/loader/DocumentLoader.h" 73 #include "core/loader/DocumentLoader.h"
72 #include "core/page/FrameTree.h" 74 #include "core/page/FrameTree.h"
73 #include "core/page/Page.h" 75 #include "core/page/Page.h"
74 #include "core/xml/DocumentXPathEvaluator.h" 76 #include "core/xml/DocumentXPathEvaluator.h"
75 #include "core/xml/XPathResult.h" 77 #include "core/xml/XPathResult.h"
76 #include "platform/PlatformGestureEvent.h" 78 #include "platform/PlatformGestureEvent.h"
77 #include "platform/PlatformMouseEvent.h" 79 #include "platform/PlatformMouseEvent.h"
78 #include "platform/PlatformTouchEvent.h" 80 #include "platform/PlatformTouchEvent.h"
79 #include "wtf/ListHashSet.h" 81 #include "wtf/ListHashSet.h"
80 #include "wtf/PtrUtil.h" 82 #include "wtf/PtrUtil.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 131 }
130 132
131 v8::Local<v8::Value> nodeV8Value(v8::Local<v8::Context> context, Node* node) 133 v8::Local<v8::Value> nodeV8Value(v8::Local<v8::Context> context, Node* node)
132 { 134 {
133 v8::Isolate* isolate = context->GetIsolate(); 135 v8::Isolate* isolate = context->GetIsolate();
134 if (!node || !BindingSecurity::shouldAllowAccessTo(currentDOMWindow(isolate) , node, BindingSecurity::ErrorReportOption::DoNotReport)) 136 if (!node || !BindingSecurity::shouldAllowAccessTo(currentDOMWindow(isolate) , node, BindingSecurity::ErrorReportOption::DoNotReport))
135 return v8::Null(isolate); 137 return v8::Null(isolate);
136 return toV8(node, context->Global(), isolate); 138 return toV8(node, context->Global(), isolate);
137 } 139 }
138 140
141 std::unique_ptr<protocol::DOM::Rect> buildRectForFloatRect(const FloatRect& rect )
142 {
143 return protocol::DOM::Rect::create()
144 .setX(rect.x())
145 .setY(rect.y())
146 .setWidth(rect.width())
147 .setHeight(rect.height())
148 .build();
149 }
150
139 } // namespace 151 } // namespace
140 152
153
141 class InspectorRevalidateDOMTask final : public GarbageCollectedFinalized<Inspec torRevalidateDOMTask> { 154 class InspectorRevalidateDOMTask final : public GarbageCollectedFinalized<Inspec torRevalidateDOMTask> {
142 public: 155 public:
143 explicit InspectorRevalidateDOMTask(InspectorDOMAgent*); 156 explicit InspectorRevalidateDOMTask(InspectorDOMAgent*);
144 void scheduleStyleAttrRevalidationFor(Element*); 157 void scheduleStyleAttrRevalidationFor(Element*);
145 void reset() { m_timer.stop(); } 158 void reset() { m_timer.stop(); }
146 void onTimer(TimerBase*); 159 void onTimer(TimerBase*);
147 DECLARE_TRACE(); 160 DECLARE_TRACE();
148 161
149 private: 162 private:
150 Member<InspectorDOMAgent> m_domAgent; 163 Member<InspectorDOMAgent> m_domAgent;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (!m_document) { 535 if (!m_document) {
523 *errorString = "Document is not available"; 536 *errorString = "Document is not available";
524 return; 537 return;
525 } 538 }
526 539
527 discardFrontendBindings(); 540 discardFrontendBindings();
528 541
529 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()) ; 542 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()) ;
530 } 543 }
531 544
545 void InspectorDOMAgent::getLayoutTreeNodes(ErrorString* errorString, std::unique _ptr<protocol::Array<protocol::DOM::LayoutTreeNode>>* layoutTreeNodes)
546 {
547 layoutTreeNodes->reset(new protocol::Array<protocol::DOM::LayoutTreeNode>);
548 visitLayoutTreeNodes(m_document.get(), *layoutTreeNodes->get());
549 }
550
551 void InspectorDOMAgent::visitLayoutTreeNodes(Node* node, protocol::Array<protoco l::DOM::LayoutTreeNode>& layoutTreeNodes)
552 {
553 for (; node; node = NodeTraversal::next(*node)) {
554 // Visit shadow dom nodes.
555 if (node->isElementNode()) {
556 const Element* element = toElement(node);
557 ElementShadow* elementShadow = element->shadow();
558 if (elementShadow)
559 visitLayoutTreeNodes(&elementShadow->youngestShadowRoot(), layou tTreeNodes);
560 }
561
562 // Pierce iframe boundaries.
563 if (node->isFrameOwnerElement())
564 visitLayoutTreeNodes(toHTMLFrameOwnerElement(node)->contentDocument( )->documentElement(), layoutTreeNodes);
565
566 LayoutObject* layoutObject = node->layoutObject();
567 if (!layoutObject)
568 continue;
569
570 int backendNodeId = DOMNodeIds::idForNode(node);
571 std::unique_ptr<protocol::DOM::LayoutTreeNode> layoutTreeNode =
572 protocol::DOM::LayoutTreeNode::create()
573 .setBackendNodeId(backendNodeId)
574 .setBoundingBox(buildRectForFloatRect(node->isElementNode() ? Fl oatRect(toElement(node)->boundsInViewport()) : layoutObject->absoluteBoundingBox Rect()))
575 .build();
576
577 if (layoutObject->isText()) {
578 LayoutText* layoutText = toLayoutText(layoutObject);
579 layoutTreeNode->setLayoutText(layoutText->text());
580 if (layoutText->hasTextBoxes()) {
581 std::unique_ptr<protocol::Array<protocol::DOM::InlineTextBox>> i nlineTextNodes(new protocol::Array<protocol::DOM::InlineTextBox>());
582 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox; textBox = textBox->nextTextBox()) {
583 FloatRect localCoordsTextBoxRect(textBox->calculateBoundarie s());
584 FloatRect absoluteCoordsTextBoxRect = layoutObject->localToA bsoluteQuad(localCoordsTextBoxRect).boundingBox();
585 inlineTextNodes->addItem(
586 protocol::DOM::InlineTextBox::create()
587 .setStartCharacterIndex(textBox->start())
588 .setNumCharacters(textBox->len())
589 .setBoundingBox(buildRectForFloatRect(absoluteCoords TextBoxRect))
590 .build());
591 }
592 layoutTreeNode->setInlineTextNodes(std::move(inlineTextNodes));
593 }
594 }
595
596 layoutTreeNodes.addItem(std::move(layoutTreeNode));
597 }
598 }
599
532 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) 600 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth)
533 { 601 {
534 Node* node = nodeForId(nodeId); 602 Node* node = nodeForId(nodeId);
535 if (!node || (!node->isElementNode() && !node->isDocumentNode() && !node->is DocumentFragment())) 603 if (!node || (!node->isElementNode() && !node->isDocumentNode() && !node->is DocumentFragment()))
536 return; 604 return;
537 605
538 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); 606 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId);
539 607
540 if (m_childrenRequested.contains(nodeId)) { 608 if (m_childrenRequested.contains(nodeId)) {
541 if (depth <= 1) 609 if (depth <= 1)
(...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 visitor->trace(m_idToNodesMap); 2197 visitor->trace(m_idToNodesMap);
2130 visitor->trace(m_document); 2198 visitor->trace(m_document);
2131 visitor->trace(m_revalidateTask); 2199 visitor->trace(m_revalidateTask);
2132 visitor->trace(m_searchResults); 2200 visitor->trace(m_searchResults);
2133 visitor->trace(m_history); 2201 visitor->trace(m_history);
2134 visitor->trace(m_domEditor); 2202 visitor->trace(m_domEditor);
2135 InspectorBaseAgent::trace(visitor); 2203 InspectorBaseAgent::trace(visitor);
2136 } 2204 }
2137 2205
2138 } // namespace blink 2206 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698