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

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

Issue 2346853002: Add a DOM.getLayoutTreeNodes devtools command (Closed)
Patch Set: Fix iframe font path 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 v8::Local<v8::Value> nodeV8Value(v8::Local<v8::Context> context, Node* node) { 132 v8::Local<v8::Value> nodeV8Value(v8::Local<v8::Context> context, Node* node) {
131 v8::Isolate* isolate = context->GetIsolate(); 133 v8::Isolate* isolate = context->GetIsolate();
132 if (!node || 134 if (!node ||
133 !BindingSecurity::shouldAllowAccessTo( 135 !BindingSecurity::shouldAllowAccessTo(
134 currentDOMWindow(isolate), node, 136 currentDOMWindow(isolate), node,
135 BindingSecurity::ErrorReportOption::DoNotReport)) 137 BindingSecurity::ErrorReportOption::DoNotReport))
136 return v8::Null(isolate); 138 return v8::Null(isolate);
137 return toV8(node, context->Global(), isolate); 139 return toV8(node, context->Global(), isolate);
138 } 140 }
139 141
142 std::unique_ptr<protocol::DOM::Rect> buildRectForFloatRect(
143 const FloatRect& rect) {
144 return protocol::DOM::Rect::create()
145 .setX(rect.x())
146 .setY(rect.y())
147 .setWidth(rect.width())
148 .setHeight(rect.height())
149 .build();
150 }
151
140 } // namespace 152 } // namespace
141 153
142 class InspectorRevalidateDOMTask final 154 class InspectorRevalidateDOMTask final
143 : public GarbageCollectedFinalized<InspectorRevalidateDOMTask> { 155 : public GarbageCollectedFinalized<InspectorRevalidateDOMTask> {
144 public: 156 public:
145 explicit InspectorRevalidateDOMTask(InspectorDOMAgent*); 157 explicit InspectorRevalidateDOMTask(InspectorDOMAgent*);
146 void scheduleStyleAttrRevalidationFor(Element*); 158 void scheduleStyleAttrRevalidationFor(Element*);
147 void reset() { m_timer.stop(); } 159 void reset() { m_timer.stop(); }
148 void onTimer(TimerBase*); 160 void onTimer(TimerBase*);
149 DECLARE_TRACE(); 161 DECLARE_TRACE();
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (!m_document) { 526 if (!m_document) {
515 *errorString = "Document is not available"; 527 *errorString = "Document is not available";
516 return; 528 return;
517 } 529 }
518 530
519 discardFrontendBindings(); 531 discardFrontendBindings();
520 532
521 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()); 533 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get());
522 } 534 }
523 535
536 void InspectorDOMAgent::getLayoutTreeNodes(
537 ErrorString* errorString,
538 std::unique_ptr<protocol::Array<protocol::DOM::LayoutTreeNode>>*
539 layoutTreeNodes) {
540 layoutTreeNodes->reset(new protocol::Array<protocol::DOM::LayoutTreeNode>);
541 visitLayoutTreeNodes(m_document.get(), *layoutTreeNodes->get());
542 }
543
544 void InspectorDOMAgent::visitLayoutTreeNodes(
545 Node* node,
546 protocol::Array<protocol::DOM::LayoutTreeNode>& layoutTreeNodes) {
547 for (; node; node = NodeTraversal::next(*node)) {
548 // Visit shadow dom nodes.
549 if (node->isElementNode()) {
550 const Element* element = toElement(node);
551 ElementShadow* elementShadow = element->shadow();
552 if (elementShadow) {
553 visitLayoutTreeNodes(&elementShadow->youngestShadowRoot(),
554 layoutTreeNodes);
555 }
556 }
557
558 // Pierce iframe boundaries.
559 if (node->isFrameOwnerElement()) {
560 visitLayoutTreeNodes(
561 toHTMLFrameOwnerElement(node)->contentDocument()->documentElement(),
562 layoutTreeNodes);
563 }
564
565 LayoutObject* layoutObject = node->layoutObject();
566 if (!layoutObject)
567 continue;
568
569 int backendNodeId = DOMNodeIds::idForNode(node);
570 std::unique_ptr<protocol::DOM::LayoutTreeNode> layoutTreeNode =
571 protocol::DOM::LayoutTreeNode::create()
572 .setBackendNodeId(backendNodeId)
573 .setBoundingBox(buildRectForFloatRect(
574 node->isElementNode()
575 ? FloatRect(toElement(node)->boundsInViewport())
576 : layoutObject->absoluteBoundingBoxRect()))
577 .build();
578
579 if (layoutObject->isText()) {
580 LayoutText* layoutText = toLayoutText(layoutObject);
581 layoutTreeNode->setLayoutText(layoutText->text());
582 if (layoutText->hasTextBoxes()) {
583 std::unique_ptr<protocol::Array<protocol::DOM::InlineTextBox>>
584 inlineTextNodes(
585 new protocol::Array<protocol::DOM::InlineTextBox>());
586 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox;
587 textBox = textBox->nextTextBox()) {
588 FloatRect localCoordsTextBoxRect(textBox->calculateBoundaries());
589 FloatRect absoluteCoordsTextBoxRect =
590 layoutObject->localToAbsoluteQuad(localCoordsTextBoxRect)
591 .boundingBox();
592 inlineTextNodes->addItem(protocol::DOM::InlineTextBox::create()
593 .setStartCharacterIndex(textBox->start())
594 .setNumCharacters(textBox->len())
595 .setBoundingBox(buildRectForFloatRect(
596 absoluteCoordsTextBoxRect))
597 .build());
598 }
599 layoutTreeNode->setInlineTextNodes(std::move(inlineTextNodes));
600 }
601 }
602
603 layoutTreeNodes.addItem(std::move(layoutTreeNode));
604 }
605 }
606
524 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) { 607 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) {
525 Node* node = nodeForId(nodeId); 608 Node* node = nodeForId(nodeId);
526 if (!node || (!node->isElementNode() && !node->isDocumentNode() && 609 if (!node || (!node->isElementNode() && !node->isDocumentNode() &&
527 !node->isDocumentFragment())) 610 !node->isDocumentFragment()))
528 return; 611 return;
529 612
530 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); 613 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId);
531 614
532 if (m_childrenRequested.contains(nodeId)) { 615 if (m_childrenRequested.contains(nodeId)) {
533 if (depth <= 1) 616 if (depth <= 1)
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 visitor->trace(m_idToNodesMap); 2366 visitor->trace(m_idToNodesMap);
2284 visitor->trace(m_document); 2367 visitor->trace(m_document);
2285 visitor->trace(m_revalidateTask); 2368 visitor->trace(m_revalidateTask);
2286 visitor->trace(m_searchResults); 2369 visitor->trace(m_searchResults);
2287 visitor->trace(m_history); 2370 visitor->trace(m_history);
2288 visitor->trace(m_domEditor); 2371 visitor->trace(m_domEditor);
2289 InspectorBaseAgent::trace(visitor); 2372 InspectorBaseAgent::trace(visitor);
2290 } 2373 }
2291 2374
2292 } // namespace blink 2375 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698