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

Side by Side Diff: Source/WebCore/inspector/front-end/ElementsTreeOutline.js

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) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 return populated; 294 return populated;
295 } 295 }
296 } 296 }
297 297
298 WebInspector.ElementsTreeOutline.prototype.__proto__ = TreeOutline.prototype; 298 WebInspector.ElementsTreeOutline.prototype.__proto__ = TreeOutline.prototype;
299 299
300 WebInspector.ElementsTreeElement = function(node, elementCloseTag) 300 WebInspector.ElementsTreeElement = function(node, elementCloseTag)
301 { 301 {
302 this._elementCloseTag = elementCloseTag; 302 this._elementCloseTag = elementCloseTag;
303 var hasChildrenOverride = !elementCloseTag && (node.hasChildNodes() || node. shadowRoot) && !this._showInlineText(node); 303 var hasChildrenOverride = !elementCloseTag && node.hasChildNodes() && !this. _showInlineText(node);
304 304
305 // The title will be updated in onattach. 305 // The title will be updated in onattach.
306 TreeElement.call(this, "", node, hasChildrenOverride); 306 TreeElement.call(this, "", node, hasChildrenOverride);
307 307
308 if (this.representedObject.nodeType() == Node.ELEMENT_NODE && !elementCloseT ag) 308 if (this.representedObject.nodeType() == Node.ELEMENT_NODE && !elementCloseT ag)
309 this._canAddAttributes = true; 309 this._canAddAttributes = true;
310 this._searchQuery = null; 310 this._searchQuery = null;
311 this._expandedChildrenLimit = WebInspector.ElementsTreeElement.InitialChildr enLimit; 311 this._expandedChildrenLimit = WebInspector.ElementsTreeElement.InitialChildr enLimit;
312 } 312 }
313 313
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 elementToSelect = newElement; 602 elementToSelect = newElement;
603 if (treeElement.expandedChildCount > treeElement.exp andedChildrenLimit) 603 if (treeElement.expandedChildCount > treeElement.exp andedChildrenLimit)
604 treeElement.expandedChildrenLimit++; 604 treeElement.expandedChildrenLimit++;
605 } 605 }
606 } 606 }
607 } 607 }
608 608
609 child = child.nextSibling; 609 child = child.nextSibling;
610 ++treeChildIndex; 610 ++treeChildIndex;
611 } 611 }
612 // If we ever had shadow root child, it's going to be second to last (before closing tag)
613 var shadowRootChild = treeElement.children[treeElement.children.leng th - 2];
614 if (shadowRootChild && shadowRootChild.representedObject.nodeType() === Node.SHADOW_ROOT_NODE) {
615 if (!node.shadowRoot)
616 treeElement.removeChild(shadowRootChild);
617 else
618 treeElement.representedObject = node.shadowRoot;
619 } else if (node.shadowRoot)
620 treeElement.insertChildElement(node.shadowRoot, treeChildIndex);
621 } 612 }
622 613
623 // Remove any tree elements that no longer have this node (or this node' s contentDocument) as their parent. 614 // Remove any tree elements that no longer have this node (or this node' s contentDocument) as their parent.
624 for (var i = (this.children.length - 1); i >= 0; --i) { 615 for (var i = (this.children.length - 1); i >= 0; --i) {
625 var currentChild = this.children[i]; 616 var currentChild = this.children[i];
626 var currentNode = currentChild.representedObject; 617 var currentNode = currentChild.representedObject;
627 var currentParentNode = currentNode.parentNode; 618 var currentParentNode = currentNode.parentNode;
628 619
629 if (currentParentNode === this.representedObject) 620 if (currentParentNode === this.representedObject)
630 continue; 621 continue;
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 } else { 1246 } else {
1256 value = value.escapeHTML().replace(/([\/;:\)\]\}])/g, "$1\u200B"); 1247 value = value.escapeHTML().replace(/([\/;:\)\]\}])/g, "$1\u200B");
1257 var attrValueElement = attrSpanElement.createChild("span", "webkit-h tml-attribute-value"); 1248 var attrValueElement = attrSpanElement.createChild("span", "webkit-h tml-attribute-value");
1258 attrValueElement.textContent = value; 1249 attrValueElement.textContent = value;
1259 } 1250 }
1260 1251
1261 if (hasText) 1252 if (hasText)
1262 attrSpanElement.appendChild(document.createTextNode("\"")); 1253 attrSpanElement.appendChild(document.createTextNode("\""));
1263 }, 1254 },
1264 1255
1265 _buildTagDOM: function(parentElement, tagName, isClosingTag, isDistinctTreeE lement, linkify, isShadow) 1256 _buildTagDOM: function(parentElement, tagName, isClosingTag, isDistinctTreeE lement, linkify)
1266 { 1257 {
1267 var node = this.representedObject; 1258 var node = this.representedObject;
1268 var classes = [ "webkit-html-tag" ]; 1259 var classes = [ "webkit-html-tag" ];
1269 if (isClosingTag && isDistinctTreeElement) 1260 if (isClosingTag && isDistinctTreeElement)
1270 classes.push("close"); 1261 classes.push("close");
1271 if (isShadow)
1272 classes.push("shadow");
1273 var tagElement = parentElement.createChild("span", classes.join(" ")); 1262 var tagElement = parentElement.createChild("span", classes.join(" "));
1274 tagElement.appendChild(document.createTextNode("<")); 1263 tagElement.appendChild(document.createTextNode("<"));
1275 var tagNameElement = tagElement.createChild("span", isClosingTag ? "" : "webkit-html-tag-name"); 1264 var tagNameElement = tagElement.createChild("span", isClosingTag ? "" : "webkit-html-tag-name");
1276 tagNameElement.textContent = (isClosingTag ? "/" : "") + tagName; 1265 tagNameElement.textContent = (isClosingTag ? "/" : "") + tagName;
1277
1278 if (!isClosingTag && node.hasAttributes()) { 1266 if (!isClosingTag && node.hasAttributes()) {
1279 var attributes = node.attributes(); 1267 var attributes = node.attributes();
1280 for (var i = 0; i < attributes.length; ++i) { 1268 for (var i = 0; i < attributes.length; ++i) {
1281 var attr = attributes[i]; 1269 var attr = attributes[i];
1282 tagElement.appendChild(document.createTextNode(" ")); 1270 tagElement.appendChild(document.createTextNode(" "));
1283 this._buildAttributeDOM(tagElement, attr.name, attr.value, node, linkify); 1271 this._buildAttributeDOM(tagElement, attr.name, attr.value, node, linkify);
1284 } 1272 }
1285 } 1273 }
1286 tagElement.appendChild(document.createTextNode(">")); 1274 tagElement.appendChild(document.createTextNode(">"));
1287 parentElement.appendChild(document.createTextNode("\u200B")); 1275 parentElement.appendChild(document.createTextNode("\u200B"));
(...skipping 14 matching lines...) Expand all
1302 break; 1290 break;
1303 1291
1304 case Node.ATTRIBUTE_NODE: 1292 case Node.ATTRIBUTE_NODE:
1305 var value = node.value || "\u200B"; // Zero width space to force showing an empty value. 1293 var value = node.value || "\u200B"; // Zero width space to force showing an empty value.
1306 this._buildAttributeDOM(info.titleDOM, node.name, value); 1294 this._buildAttributeDOM(info.titleDOM, node.name, value);
1307 break; 1295 break;
1308 1296
1309 case Node.ELEMENT_NODE: 1297 case Node.ELEMENT_NODE:
1310 var tagName = this.treeOutline.nodeNameToCorrectCase(node.nodeNa me()).escapeHTML(); 1298 var tagName = this.treeOutline.nodeNameToCorrectCase(node.nodeNa me()).escapeHTML();
1311 if (this._elementCloseTag) { 1299 if (this._elementCloseTag) {
1312 this._buildTagDOM(info.titleDOM, tagName, true, true, false, node.inShadowTree()); 1300 this._buildTagDOM(info.titleDOM, tagName, true, true);
1313 info.hasChildren = false; 1301 info.hasChildren = false;
1314 break; 1302 break;
1315 } 1303 }
1316 1304
1317 this._buildTagDOM(info.titleDOM, tagName, false, false, linkify, node.inShadowTree()); 1305 this._buildTagDOM(info.titleDOM, tagName, false, false, linkify) ;
1318 1306
1319 var textChild = this._singleTextChild(node); 1307 var textChild = this._singleTextChild(node);
1320 var showInlineText = textChild && textChild.nodeValue().length < Preferences.maxInlineTextChildLength; 1308 var showInlineText = textChild && textChild.nodeValue().length < Preferences.maxInlineTextChildLength;
1321 1309
1322 if (!this.expanded && (!showInlineText && (this.treeOutline.isXM LMimeType || !WebInspector.ElementsTreeElement.ForbiddenClosingTagElements[tagNa me]))) { 1310 if (!this.expanded && (!showInlineText && (this.treeOutline.isXM LMimeType || !WebInspector.ElementsTreeElement.ForbiddenClosingTagElements[tagNa me]))) {
1323 if (this.hasChildren) { 1311 if (this.hasChildren) {
1324 var textNodeElement = info.titleDOM.createChild("span", "webkit-html-text-node"); 1312 var textNodeElement = info.titleDOM.createChild("span", "webkit-html-text-node");
1325 textNodeElement.textContent = "\u2026"; 1313 textNodeElement.textContent = "\u2026";
1326 info.titleDOM.appendChild(document.createTextNode("\u200 B")); 1314 info.titleDOM.appendChild(document.createTextNode("\u200 B"));
1327 } 1315 }
1328 this._buildTagDOM(info.titleDOM, tagName, true, false, false , node.inShadowTree()); 1316 this._buildTagDOM(info.titleDOM, tagName, true, false, false );
1329 } 1317 }
1330 1318
1331 // If this element only has a single child that is a text node, 1319 // If this element only has a single child that is a text node,
1332 // just show that text and the closing tag inline rather than 1320 // just show that text and the closing tag inline rather than
1333 // create a subtree for them 1321 // create a subtree for them
1334 if (showInlineText) { 1322 if (showInlineText) {
1335 var textNodeElement = info.titleDOM.createChild("span", "web kit-html-text-node"); 1323 var textNodeElement = info.titleDOM.createChild("span", "web kit-html-text-node");
1336 textNodeElement.textContent = textChild.nodeValue().escapeHT ML(); 1324 textNodeElement.textContent = textChild.nodeValue().escapeHT ML();
1337 info.titleDOM.appendChild(document.createTextNode("\u200B")) ; 1325 info.titleDOM.appendChild(document.createTextNode("\u200B")) ;
1338 this._buildTagDOM(info.titleDOM, tagName, true, false, node. inShadowTree()); 1326 this._buildTagDOM(info.titleDOM, tagName, true, false);
1339 info.hasChildren = false; 1327 info.hasChildren = false;
1340 } 1328 }
1341 break; 1329 break;
1342 1330
1343 case Node.TEXT_NODE: 1331 case Node.TEXT_NODE:
1344 if (isNodeWhitespace.call(node)) 1332 if (isNodeWhitespace.call(node))
1345 info.titleDOM.appendChild(document.createTextNode("(whitespa ce)")); 1333 info.titleDOM.appendChild(document.createTextNode("(whitespa ce)"));
1346 else { 1334 else {
1347 if (node.parentNode && node.parentNode.nodeName().toLowerCas e() === "script") { 1335 if (node.parentNode && node.parentNode.nodeName().toLowerCas e() === "script") {
1348 var newNode = info.titleDOM.createChild("span", "webkit- html-text-node webkit-html-js-node"); 1336 var newNode = info.titleDOM.createChild("span", "webkit- html-text-node webkit-html-js-node");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 if (node.internalSubset) 1371 if (node.internalSubset)
1384 docTypeElement.appendChild(document.createTextNode(" [" + no de.internalSubset + "]")); 1372 docTypeElement.appendChild(document.createTextNode(" [" + no de.internalSubset + "]"));
1385 1373
1386 docTypeElement.appendChild(document.createTextNode(">")); 1374 docTypeElement.appendChild(document.createTextNode(">"));
1387 break; 1375 break;
1388 1376
1389 case Node.CDATA_SECTION_NODE: 1377 case Node.CDATA_SECTION_NODE:
1390 var cdataElement = info.titleDOM.createChild("span", "webkit-htm l-text-node"); 1378 var cdataElement = info.titleDOM.createChild("span", "webkit-htm l-text-node");
1391 cdataElement.appendChild(document.createTextNode("<![CDATA[" + n ode.nodeValue().escapeHTML() + "]]>")); 1379 cdataElement.appendChild(document.createTextNode("<![CDATA[" + n ode.nodeValue().escapeHTML() + "]]>"));
1392 break; 1380 break;
1393
1394 case Node.SHADOW_ROOT_NODE:
1395 var cdataElement = info.titleDOM.createChild("span", "dom-shadow -root");
1396 cdataElement.appendChild(document.createTextNode("(shadow)"));
1397 break;
1398
1399 default: 1381 default:
1400 var defaultElement = info.titleDOM.appendChild(document.createTe xtNode(this.treeOutline.nodeNameToCorrectCase(node.nodeName()).collapseWhitespac e().escapeHTML())); 1382 var defaultElement = info.titleDOM.appendChild(document.createTe xtNode(this.treeOutline.nodeNameToCorrectCase(node.nodeName()).collapseWhitespac e().escapeHTML()));
1401 } 1383 }
1402 1384
1403 return info; 1385 return info;
1404 }, 1386 },
1405 1387
1406 _singleTextChild: function(node) 1388 _singleTextChild: function(node)
1407 { 1389 {
1408 if (!node || node.shadowRoot) 1390 if (!node)
1409 return null; 1391 return null;
1410 1392
1411 var firstChild = node.firstChild; 1393 var firstChild = node.firstChild;
1412 if (!firstChild || firstChild.nodeType() !== Node.TEXT_NODE) 1394 if (!firstChild || firstChild.nodeType() !== Node.TEXT_NODE)
1413 return null; 1395 return null;
1414 1396
1415 var sibling = firstChild.nextSibling; 1397 var sibling = firstChild.nextSibling;
1416 return sibling ? null : firstChild; 1398 return sibling ? null : firstChild;
1417 }, 1399 },
1418 1400
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 // Fall back for XPath, etc. matches. 1485 // Fall back for XPath, etc. matches.
1504 if (!matchRanges.length) 1486 if (!matchRanges.length)
1505 matchRanges.push({ offset: 0, length: text.length }); 1487 matchRanges.push({ offset: 0, length: text.length });
1506 1488
1507 this._highlightResult = []; 1489 this._highlightResult = [];
1508 highlightSearchResults(this.listItemElement, matchRanges, this._highligh tResult); 1490 highlightSearchResults(this.listItemElement, matchRanges, this._highligh tResult);
1509 } 1491 }
1510 } 1492 }
1511 1493
1512 WebInspector.ElementsTreeElement.prototype.__proto__ = TreeElement.prototype; 1494 WebInspector.ElementsTreeElement.prototype.__proto__ = TreeElement.prototype;
OLDNEW
« no previous file with comments | « Source/WebCore/inspector/front-end/ElementsPanel.js ('k') | Source/WebCore/inspector/front-end/inspector.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698