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

Side by Side Diff: Source/WebCore/inspector/InspectorDOMAgent.cpp

Issue 7147011: Merge 88331 - 2011-06-07 Andrey Kosyakov <caseq@chromium.org> (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 years, 6 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "InspectorState.h" 68 #include "InspectorState.h"
69 #include "InstrumentingAgents.h" 69 #include "InstrumentingAgents.h"
70 #include "MutationEvent.h" 70 #include "MutationEvent.h"
71 #include "Node.h" 71 #include "Node.h"
72 #include "NodeList.h" 72 #include "NodeList.h"
73 #include "Page.h" 73 #include "Page.h"
74 #include "Pasteboard.h" 74 #include "Pasteboard.h"
75 #include "RenderStyle.h" 75 #include "RenderStyle.h"
76 #include "RenderStyleConstants.h" 76 #include "RenderStyleConstants.h"
77 #include "ScriptEventListener.h" 77 #include "ScriptEventListener.h"
78 #include "ShadowRoot.h"
79 #include "StyleSheetList.h" 78 #include "StyleSheetList.h"
80 #include "Text.h" 79 #include "Text.h"
81 80
82 #if ENABLE(XPATH) 81 #if ENABLE(XPATH)
83 #include "XPathResult.h" 82 #include "XPathResult.h"
84 #endif 83 #endif
85 84
86 #include "markup.h" 85 #include "markup.h"
87 86
88 #include <wtf/text/CString.h> 87 #include <wtf/text/CString.h>
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 RefPtr<Document> doc = m_document; 443 RefPtr<Document> doc = m_document;
445 reset(); 444 reset();
446 m_document = doc; 445 m_document = doc;
447 446
448 *root = buildObjectForNode(m_document.get(), 2, &m_documentNodeToIdMap); 447 *root = buildObjectForNode(m_document.get(), 2, &m_documentNodeToIdMap);
449 } 448 }
450 449
451 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId) 450 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId)
452 { 451 {
453 Node* node = nodeForId(nodeId); 452 Node* node = nodeForId(nodeId);
454 if (!node || !isContainerNode(*node)) 453 if (!node || (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE && node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE))
455 return; 454 return;
456 if (m_childrenRequested.contains(nodeId)) 455 if (m_childrenRequested.contains(nodeId))
457 return; 456 return;
458 457
459 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); 458 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId);
460 RefPtr<InspectorArray> children = buildArrayForContainerChildren(node, 1, no deMap); 459 RefPtr<InspectorArray> children = buildArrayForContainerChildren(node, 1, no deMap);
461 m_frontend->setChildNodes(nodeId, children.release()); 460 m_frontend->setChildNodes(nodeId, children.release());
462 } 461 }
463 462
464 void InspectorDOMAgent::discardBindings() 463 void InspectorDOMAgent::discardBindings()
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1050
1052 switch (node->nodeType()) { 1051 switch (node->nodeType()) {
1053 case Node::TEXT_NODE: 1052 case Node::TEXT_NODE:
1054 case Node::COMMENT_NODE: 1053 case Node::COMMENT_NODE:
1055 case Node::CDATA_SECTION_NODE: 1054 case Node::CDATA_SECTION_NODE:
1056 nodeValue = node->nodeValue(); 1055 nodeValue = node->nodeValue();
1057 break; 1056 break;
1058 case Node::ATTRIBUTE_NODE: 1057 case Node::ATTRIBUTE_NODE:
1059 localName = node->localName(); 1058 localName = node->localName();
1060 break; 1059 break;
1061 case Node::SHADOW_ROOT_NODE:
1062 case Node::DOCUMENT_FRAGMENT_NODE: 1060 case Node::DOCUMENT_FRAGMENT_NODE:
1063 break; 1061 break;
1064 case Node::DOCUMENT_NODE: 1062 case Node::DOCUMENT_NODE:
1065 case Node::ELEMENT_NODE: 1063 case Node::ELEMENT_NODE:
1066 default: 1064 default:
1067 nodeName = node->nodeName(); 1065 nodeName = node->nodeName();
1068 localName = node->localName(); 1066 localName = node->localName();
1069 break; 1067 break;
1070 } 1068 }
1071 1069
1072 value->setNumber("id", id); 1070 value->setNumber("id", id);
1073 value->setNumber("nodeType", node->nodeType()); 1071 value->setNumber("nodeType", node->nodeType());
1074 value->setString("nodeName", nodeName); 1072 value->setString("nodeName", nodeName);
1075 value->setString("localName", localName); 1073 value->setString("localName", localName);
1076 value->setString("nodeValue", nodeValue); 1074 value->setString("nodeValue", nodeValue);
1077 1075
1078 if (isContainerNode(*node)) { 1076 if (node->nodeType() == Node::ELEMENT_NODE || node->nodeType() == Node::DOCU MENT_NODE || node->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) {
1079 int nodeCount = innerChildNodeCount(node); 1077 int nodeCount = innerChildNodeCount(node);
1080 value->setNumber("childNodeCount", nodeCount); 1078 value->setNumber("childNodeCount", nodeCount);
1081 RefPtr<InspectorArray> children = buildArrayForContainerChildren(node, d epth, nodesMap); 1079 RefPtr<InspectorArray> children = buildArrayForContainerChildren(node, d epth, nodesMap);
1082 if (children->length() > 0) 1080 if (children->length() > 0)
1083 value->setArray("children", children.release()); 1081 value->setArray("children", children.release());
1084 1082
1085 if (node->nodeType() == Node::ELEMENT_NODE) { 1083 if (node->nodeType() == Node::ELEMENT_NODE) {
1086 Element* element = static_cast<Element*>(node); 1084 Element* element = static_cast<Element*>(node);
1087 value->setArray("attributes", buildArrayForElementAttributes(element )); 1085 value->setArray("attributes", buildArrayForElementAttributes(element ));
1088 if (node->isFrameOwnerElement()) { 1086 if (node->isFrameOwnerElement()) {
1089 HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerEl ement*>(node); 1087 HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerEl ement*>(node);
1090 value->setString("documentURL", documentURLString(frameOwner->co ntentDocument())); 1088 value->setString("documentURL", documentURLString(frameOwner->co ntentDocument()));
1091 } 1089 }
1092 if (ShadowRoot* shadowRoot = element->shadowRoot())
1093 value->setObject("shadowRoot", buildObjectForNode(shadowRoot, de pth, nodesMap));
1094 } else if (node->nodeType() == Node::DOCUMENT_NODE) { 1090 } else if (node->nodeType() == Node::DOCUMENT_NODE) {
1095 Document* document = static_cast<Document*>(node); 1091 Document* document = static_cast<Document*>(node);
1096 value->setString("documentURL", documentURLString(document)); 1092 value->setString("documentURL", documentURLString(document));
1097 value->setString("xmlVersion", document->xmlVersion()); 1093 value->setString("xmlVersion", document->xmlVersion());
1098 } 1094 }
1099 } else if (node->nodeType() == Node::DOCUMENT_TYPE_NODE) { 1095 } else if (node->nodeType() == Node::DOCUMENT_TYPE_NODE) {
1100 DocumentType* docType = static_cast<DocumentType*>(node); 1096 DocumentType* docType = static_cast<DocumentType*>(node);
1101 value->setString("publicId", docType->publicId()); 1097 value->setString("publicId", docType->publicId());
1102 value->setString("systemId", docType->systemId()); 1098 value->setString("systemId", docType->systemId());
1103 value->setString("internalSubset", docType->internalSubset()); 1099 value->setString("internalSubset", docType->internalSubset());
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1252 }
1257 1253
1258 void InspectorDOMAgent::didInsertDOMNode(Node* node) 1254 void InspectorDOMAgent::didInsertDOMNode(Node* node)
1259 { 1255 {
1260 if (isWhitespace(node)) 1256 if (isWhitespace(node))
1261 return; 1257 return;
1262 1258
1263 // We could be attaching existing subtree. Forget the bindings. 1259 // We could be attaching existing subtree. Forget the bindings.
1264 unbind(node, &m_documentNodeToIdMap); 1260 unbind(node, &m_documentNodeToIdMap);
1265 1261
1266 ContainerNode* parent = node->isShadowRoot() ? node->shadowHost() : node->pa rentNode(); 1262 ContainerNode* parent = node->parentNode();
1267 int parentId = m_documentNodeToIdMap.get(parent); 1263 int parentId = m_documentNodeToIdMap.get(parent);
1268 // Return if parent is not mapped yet. 1264 // Return if parent is not mapped yet.
1269 if (!parentId) 1265 if (!parentId)
1270 return; 1266 return;
1271 1267
1272 if (node->isShadowRoot()) {
1273 RefPtr<InspectorObject> value = buildObjectForNode(node, 0, &m_documentN odeToIdMap);
1274 m_frontend->shadowRootUpdated(parentId, value.release());
1275 return;
1276 }
1277 if (!m_childrenRequested.contains(parentId)) { 1268 if (!m_childrenRequested.contains(parentId)) {
1278 // No children are mapped yet -> only notify on changes of hasChildren. 1269 // No children are mapped yet -> only notify on changes of hasChildren.
1279 m_frontend->childNodeCountUpdated(parentId, innerChildNodeCount(parent)) ; 1270 m_frontend->childNodeCountUpdated(parentId, innerChildNodeCount(parent)) ;
1280 } else { 1271 } else {
1281 // Children have been requested -> return value of a new child. 1272 // Children have been requested -> return value of a new child.
1282 Node* prevSibling = innerPreviousSibling(node); 1273 Node* prevSibling = innerPreviousSibling(node);
1283 int prevId = prevSibling ? m_documentNodeToIdMap.get(prevSibling) : 0; 1274 int prevId = prevSibling ? m_documentNodeToIdMap.get(prevSibling) : 0;
1284 RefPtr<InspectorObject> value = buildObjectForNode(node, 0, &m_documentN odeToIdMap); 1275 RefPtr<InspectorObject> value = buildObjectForNode(node, 0, &m_documentN odeToIdMap);
1285 m_frontend->childNodeInserted(parentId, prevId, value.release()); 1276 m_frontend->childNodeInserted(parentId, prevId, value.release());
1286 } 1277 }
1287 } 1278 }
1288 1279
1289 void InspectorDOMAgent::didRemoveDOMNode(Node* node) 1280 void InspectorDOMAgent::didRemoveDOMNode(Node* node)
1290 { 1281 {
1291 if (isWhitespace(node)) 1282 if (isWhitespace(node))
1292 return; 1283 return;
1293 1284
1294 ContainerNode* parent = node->isShadowRoot() ? node->shadowHost() : node->pa rentNode(); 1285 ContainerNode* parent = node->parentNode();
1295 int parentId = m_documentNodeToIdMap.get(parent); 1286 int parentId = m_documentNodeToIdMap.get(parent);
1296 // If parent is not mapped yet -> ignore the event. 1287 // If parent is not mapped yet -> ignore the event.
1297 if (!parentId) 1288 if (!parentId)
1298 return; 1289 return;
1299 1290
1300 if (m_domListener) 1291 if (m_domListener)
1301 m_domListener->didRemoveDOMNode(node); 1292 m_domListener->didRemoveDOMNode(node);
1302 1293
1303 if (node->isShadowRoot()) 1294 if (!m_childrenRequested.contains(parentId)) {
1304 m_frontend->shadowRootUpdated(parentId, 0);
1305 else if (!m_childrenRequested.contains(parentId)) {
1306 // No children are mapped yet -> only notify on changes of hasChildren. 1295 // No children are mapped yet -> only notify on changes of hasChildren.
1307 if (innerChildNodeCount(parent) == 1) 1296 if (innerChildNodeCount(parent) == 1)
1308 m_frontend->childNodeCountUpdated(parentId, 0); 1297 m_frontend->childNodeCountUpdated(parentId, 0);
1309 } else 1298 } else
1310 m_frontend->childNodeRemoved(parentId, m_documentNodeToIdMap.get(node)); 1299 m_frontend->childNodeRemoved(parentId, m_documentNodeToIdMap.get(node));
1311 unbind(node, &m_documentNodeToIdMap); 1300 unbind(node, &m_documentNodeToIdMap);
1312 } 1301 }
1313 1302
1314 void InspectorDOMAgent::didModifyDOMAttr(Element* element) 1303 void InspectorDOMAgent::didModifyDOMAttr(Element* element)
1315 { 1304 {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 mode = DOMNodeHighlighter::HighlightContent; 1433 mode = DOMNodeHighlighter::HighlightContent;
1445 else if (m_highlightMode == "padding") 1434 else if (m_highlightMode == "padding")
1446 mode = DOMNodeHighlighter::HighlightPadding; 1435 mode = DOMNodeHighlighter::HighlightPadding;
1447 else if (m_highlightMode == "border") 1436 else if (m_highlightMode == "border")
1448 mode = DOMNodeHighlighter::HighlightBorder; 1437 mode = DOMNodeHighlighter::HighlightBorder;
1449 else if (m_highlightMode == "margin") 1438 else if (m_highlightMode == "margin")
1450 mode = DOMNodeHighlighter::HighlightMargin; 1439 mode = DOMNodeHighlighter::HighlightMargin;
1451 DOMNodeHighlighter::DrawNodeHighlight(context, m_highlightedNode.get(), mode ); 1440 DOMNodeHighlighter::DrawNodeHighlight(context, m_highlightedNode.get(), mode );
1452 } 1441 }
1453 1442
1454 bool InspectorDOMAgent::isContainerNode(const Node& node)
1455 {
1456 Node::NodeType type = node.nodeType();
1457 return type == Node::ELEMENT_NODE
1458 || type == Node::DOCUMENT_NODE
1459 || type == Node::DOCUMENT_FRAGMENT_NODE
1460 || type == Node::SHADOW_ROOT_NODE;
1461 }
1462
1463 } // namespace WebCore 1443 } // namespace WebCore
1464 1444
1465 #endif // ENABLE(INSPECTOR) 1445 #endif // ENABLE(INSPECTOR)
OLDNEW
« no previous file with comments | « Source/WebCore/inspector/InspectorDOMAgent.h ('k') | Source/WebCore/inspector/front-end/DOMAgent.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698