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

Side by Side Diff: Source/devtools/front_end/elements/ElementsTreeOutline.js

Issue 1273313002: DevTools: introduce dom markers, decorate hidden, forced state and breakpoint elements using marker… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 this._includeRootDOMNode = !omitRootDOMNode; 66 this._includeRootDOMNode = !omitRootDOMNode;
67 this._selectEnabled = selectEnabled; 67 this._selectEnabled = selectEnabled;
68 /** @type {?WebInspector.DOMNode} */ 68 /** @type {?WebInspector.DOMNode} */
69 this._rootDOMNode = null; 69 this._rootDOMNode = null;
70 /** @type {?WebInspector.DOMNode} */ 70 /** @type {?WebInspector.DOMNode} */
71 this._selectedDOMNode = null; 71 this._selectedDOMNode = null;
72 72
73 this._visible = false; 73 this._visible = false;
74 this._pickNodeMode = false; 74 this._pickNodeMode = false;
75 75
76 this._createNodeDecorators();
77
78 this._popoverHelper = new WebInspector.PopoverHelper(this._element, this._ge tPopoverAnchor.bind(this), this._showPopover.bind(this)); 76 this._popoverHelper = new WebInspector.PopoverHelper(this._element, this._ge tPopoverAnchor.bind(this), this._showPopover.bind(this));
79 this._popoverHelper.setTimeout(0); 77 this._popoverHelper.setTimeout(0);
80 78
81 /** @type {!Map<!WebInspector.DOMNode, !WebInspector.ElementsTreeOutline.Upd ateRecord>} */ 79 /** @type {!Map<!WebInspector.DOMNode, !WebInspector.ElementsTreeOutline.Upd ateRecord>} */
82 this._updateRecords = new Map(); 80 this._updateRecords = new Map();
83 /** @type {!Set<!WebInspector.ElementsTreeElement>} */ 81 /** @type {!Set<!WebInspector.ElementsTreeElement>} */
84 this._treeElementsBeingUpdated = new Set(); 82 this._treeElementsBeingUpdated = new Set();
83
84 this._domModel.addEventListener(WebInspector.DOMModel.Events.MarkersChanged, this._markersChanged, this);
85 } 85 }
86 86
87 /** @typedef {{node: !WebInspector.DOMNode, isCut: boolean}} */ 87 /** @typedef {{node: !WebInspector.DOMNode, isCut: boolean}} */
88 WebInspector.ElementsTreeOutline.ClipboardData; 88 WebInspector.ElementsTreeOutline.ClipboardData;
89 89
90 /** 90 /**
91 * @enum {string} 91 * @enum {string}
92 */ 92 */
93 WebInspector.ElementsTreeOutline.Events = { 93 WebInspector.ElementsTreeOutline.Events = {
94 NodePicked: "NodePicked", 94 NodePicked: "NodePicked",
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 * @param {number} width 223 * @param {number} width
224 */ 224 */
225 setVisibleWidth: function(width) 225 setVisibleWidth: function(width)
226 { 226 {
227 this._visibleWidth = width; 227 this._visibleWidth = width;
228 if (this._multilineEditing) 228 if (this._multilineEditing)
229 this._multilineEditing.setWidth(this._visibleWidth); 229 this._multilineEditing.setWidth(this._visibleWidth);
230 }, 230 },
231 231
232 /** 232 /**
233 * @return {!Array<!WebInspector.ElementsTreeOutline.ElementDecorator>}
234 */
235 nodeDecorators: function()
236 {
237 return this._nodeDecorators;
238 },
239
240 _createNodeDecorators: function()
241 {
242 this._nodeDecorators = [];
243 this._nodeDecorators.push(new WebInspector.ElementsTreeOutline.PseudoSta teDecorator());
244 this._nodeDecorators.push(new WebInspector.ElementsTreeOutline.Breakpoin tDecorator());
245 },
246
247 /**
248 * @param {?WebInspector.ElementsTreeOutline.ClipboardData} data 233 * @param {?WebInspector.ElementsTreeOutline.ClipboardData} data
249 */ 234 */
250 _setClipboardData: function(data) 235 _setClipboardData: function(data)
251 { 236 {
252 if (this._clipboardNodeData) { 237 if (this._clipboardNodeData) {
253 var treeElement = this.findTreeElement(this._clipboardNodeData.node) ; 238 var treeElement = this.findTreeElement(this._clipboardNodeData.node) ;
254 if (treeElement) 239 if (treeElement)
255 treeElement.setInClipboard(false); 240 treeElement.setInClipboard(false);
256 delete this._clipboardNodeData; 241 delete this._clipboardNodeData;
257 } 242 }
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 * @param {!WebInspector.DOMNode} node 1026 * @param {!WebInspector.DOMNode} node
1042 * @param {function(?WebInspector.RemoteObject, boolean=)=} userCallback 1027 * @param {function(?WebInspector.RemoteObject, boolean=)=} userCallback
1043 */ 1028 */
1044 toggleHideElement: function(node, userCallback) 1029 toggleHideElement: function(node, userCallback)
1045 { 1030 {
1046 var pseudoType = node.pseudoType(); 1031 var pseudoType = node.pseudoType();
1047 var effectiveNode = pseudoType ? node.parentNode : node; 1032 var effectiveNode = pseudoType ? node.parentNode : node;
1048 if (!effectiveNode) 1033 if (!effectiveNode)
1049 return; 1034 return;
1050 1035
1036 var hidden = node.marker("hidden");
1037
1051 function resolvedNode(object) 1038 function resolvedNode(object)
1052 { 1039 {
1053 if (!object) 1040 if (!object)
1054 return; 1041 return;
1055 1042
1056 /** 1043 /**
1057 * @param {?string} pseudoType 1044 * @param {?string} pseudoType
1045 * @param {boolean} hidden
1058 * @suppressGlobalPropertiesCheck 1046 * @suppressGlobalPropertiesCheck
1059 * @suppressReceiverCheck 1047 * @suppressReceiverCheck
1060 * @this {!Element} 1048 * @this {!Element}
1061 */ 1049 */
1062 function toggleClassAndInjectStyleRule(pseudoType) 1050 function toggleClassAndInjectStyleRule(pseudoType, hidden)
1063 { 1051 {
1064 const classNamePrefix = "__web-inspector-hide"; 1052 const classNamePrefix = "__web-inspector-hide";
1065 const classNameSuffix = "-shortcut__"; 1053 const classNameSuffix = "-shortcut__";
1066 const styleTagId = "__web-inspector-hide-shortcut-style__"; 1054 const styleTagId = "__web-inspector-hide-shortcut-style__";
1067 var selectors = []; 1055 var selectors = [];
1068 selectors.push(".__web-inspector-hide-shortcut__"); 1056 selectors.push(".__web-inspector-hide-shortcut__");
1069 selectors.push(".__web-inspector-hide-shortcut__ *"); 1057 selectors.push(".__web-inspector-hide-shortcut__ *");
1070 selectors.push(".__web-inspector-hidebefore-shortcut__::before") ; 1058 selectors.push(".__web-inspector-hidebefore-shortcut__::before") ;
1071 selectors.push(".__web-inspector-hideafter-shortcut__::after"); 1059 selectors.push(".__web-inspector-hideafter-shortcut__::after");
1072 var selector = selectors.join(", "); 1060 var selector = selectors.join(", ");
1073 var ruleBody = " visibility: hidden !important;"; 1061 var ruleBody = " visibility: hidden !important;";
1074 var rule = "\n" + selector + "\n{\n" + ruleBody + "\n}\n"; 1062 var rule = "\n" + selector + "\n{\n" + ruleBody + "\n}\n";
1075 var className = classNamePrefix + (pseudoType || "") + className Suffix; 1063 var className = classNamePrefix + (pseudoType || "") + className Suffix;
1076 this.classList.toggle(className); 1064 this.classList.toggle(className, hidden);
1077 1065
1078 var localRoot = this; 1066 var localRoot = this;
1079 while (localRoot.parentNode) 1067 while (localRoot.parentNode)
1080 localRoot = localRoot.parentNode; 1068 localRoot = localRoot.parentNode;
1081 if (localRoot.nodeType === Node.DOCUMENT_NODE) 1069 if (localRoot.nodeType === Node.DOCUMENT_NODE)
1082 localRoot = document.head; 1070 localRoot = document.head;
1083 1071
1084 var style = localRoot.querySelector("style#" + styleTagId); 1072 var style = localRoot.querySelector("style#" + styleTagId);
1085 if (style) 1073 if (style)
1086 return; 1074 return;
1087 1075
1088 style = document.createElement("style"); 1076 style = document.createElement("style");
1089 style.id = styleTagId; 1077 style.id = styleTagId;
1090 style.type = "text/css"; 1078 style.type = "text/css";
1091 style.textContent = rule; 1079 style.textContent = rule;
1092 1080
1093 localRoot.appendChild(style); 1081 localRoot.appendChild(style);
1094 } 1082 }
1095 1083
1096 object.callFunction(toggleClassAndInjectStyleRule, [{ value: pseudoT ype }], userCallback); 1084 object.callFunction(toggleClassAndInjectStyleRule, [{ value: pseudoT ype }, { value: !hidden}], userCallback);
1097 object.release(); 1085 object.release();
1086 node.setMarker("hidden", hidden ? null : true);
1098 } 1087 }
1099 1088
1100 effectiveNode.resolveToObject("", resolvedNode); 1089 effectiveNode.resolveToObject("", resolvedNode);
1101 }, 1090 },
1102 1091
1103 _reset: function() 1092 _reset: function()
1104 { 1093 {
1105 this.rootDOMNode = null; 1094 this.rootDOMNode = null;
1106 this.selectDOMNode(null, false); 1095 this.selectDOMNode(null, false);
1107 this._popoverHelper.hidePopover(); 1096 this._popoverHelper.hidePopover();
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 treeElement.appendChild(new WebInspector.ElementsTreeOutline.Sho rtcutTreeElement(distributedNode)); 1565 treeElement.appendChild(new WebInspector.ElementsTreeOutline.Sho rtcutTreeElement(distributedNode));
1577 } 1566 }
1578 1567
1579 // Insert close tag. 1568 // Insert close tag.
1580 if (node.nodeType() === Node.ELEMENT_NODE && treeElement.isExpandable()) 1569 if (node.nodeType() === Node.ELEMENT_NODE && treeElement.isExpandable())
1581 this.insertChildElement(treeElement, node, treeElement.childCount(), true); 1570 this.insertChildElement(treeElement, node, treeElement.childCount(), true);
1582 1571
1583 this._treeElementsBeingUpdated.delete(treeElement); 1572 this._treeElementsBeingUpdated.delete(treeElement);
1584 }, 1573 },
1585 1574
1575 /**
1576 * @param {!WebInspector.Event} event
1577 */
1578 _markersChanged: function(event)
1579 {
1580 var node = /** @type {!WebInspector.DOMNode} */ (event.data);
1581 var treeElement = node[this._treeElementSymbol];
1582 if (treeElement)
1583 treeElement.updateDecorations();
1584 },
1585
1586 __proto__: TreeOutline.prototype 1586 __proto__: TreeOutline.prototype
1587 } 1587 }
1588 1588
1589 /** 1589 /**
1590 * @interface
1591 */
1592 WebInspector.ElementsTreeOutline.ElementDecorator = function()
1593 {
1594 }
1595
1596 WebInspector.ElementsTreeOutline.ElementDecorator.prototype = {
1597 /**
1598 * @param {!WebInspector.DOMNode} node
1599 * @return {?string}
1600 */
1601 decorate: function(node)
1602 {
1603 },
1604
1605 /**
1606 * @param {!WebInspector.DOMNode} node
1607 * @return {?string}
1608 */
1609 decorateAncestor: function(node)
1610 {
1611 }
1612 }
1613
1614 /**
1615 * @constructor
1616 * @implements {WebInspector.ElementsTreeOutline.ElementDecorator}
1617 */
1618 WebInspector.ElementsTreeOutline.PseudoStateDecorator = function()
1619 {
1620 WebInspector.ElementsTreeOutline.ElementDecorator.call(this);
1621 }
1622
1623 WebInspector.ElementsTreeOutline.PseudoStateDecorator.prototype = {
1624 /**
1625 * @override
1626 * @param {!WebInspector.DOMNode} node
1627 * @return {?string}
1628 */
1629 decorate: function(node)
1630 {
1631 if (node.nodeType() !== Node.ELEMENT_NODE)
1632 return null;
1633 var propertyValue = node.getUserProperty(WebInspector.CSSStyleModel.Pseu doStatePropertyName);
1634 if (!propertyValue)
1635 return null;
1636 return WebInspector.UIString("Element state: %s", ":" + propertyValue.jo in(", :"));
1637 },
1638
1639 /**
1640 * @override
1641 * @param {!WebInspector.DOMNode} node
1642 * @return {?string}
1643 */
1644 decorateAncestor: function(node)
1645 {
1646 if (node.nodeType() !== Node.ELEMENT_NODE)
1647 return null;
1648
1649 var descendantCount = node.descendantUserPropertyCount(WebInspector.CSSS tyleModel.PseudoStatePropertyName);
1650 if (!descendantCount)
1651 return null;
1652 if (descendantCount === 1)
1653 return WebInspector.UIString("%d descendant with forced state", desc endantCount);
1654 return WebInspector.UIString("%d descendants with forced state", descend antCount);
1655 }
1656 }
1657
1658 /**
1659 * @constructor
1660 * @implements {WebInspector.ElementsTreeOutline.ElementDecorator}
1661 */
1662 WebInspector.ElementsTreeOutline.BreakpointDecorator = function()
1663 {
1664 WebInspector.ElementsTreeOutline.ElementDecorator.call(this);
1665 }
1666
1667 WebInspector.ElementsTreeOutline.BreakpointDecorator.prototype = {
1668 /**
1669 * @override
1670 * @param {!WebInspector.DOMNode} node
1671 * @return {?string}
1672 */
1673 decorate: function(node)
1674 {
1675 if (node.nodeType() !== Node.ELEMENT_NODE)
1676 return null;
1677 var propertyValue = node.getUserProperty(WebInspector.DOMBreakpointsSide barPane.BreakpointPropertyName);
1678 if (!propertyValue)
1679 return null;
1680 return WebInspector.UIString("DOM breakpoint is set");
1681 },
1682
1683 /**
1684 * @override
1685 * @param {!WebInspector.DOMNode} node
1686 * @return {?string}
1687 */
1688 decorateAncestor: function(node)
1689 {
1690 if (node.nodeType() !== Node.ELEMENT_NODE)
1691 return null;
1692
1693 var descendantCount = node.descendantUserPropertyCount(WebInspector.DOMB reakpointsSidebarPane.BreakpointPropertyName);
1694 if (!descendantCount)
1695 return null;
1696 if (descendantCount === 1)
1697 return WebInspector.UIString("%d descendant with breakpoints", desce ndantCount);
1698 return WebInspector.UIString("%d descendants with breakpoints", descenda ntCount);
1699 }
1700 }
1701
1702 /**
1703 * @constructor 1590 * @constructor
1704 */ 1591 */
1705 WebInspector.ElementsTreeOutline.UpdateRecord = function() 1592 WebInspector.ElementsTreeOutline.UpdateRecord = function()
1706 { 1593 {
1707 } 1594 }
1708 1595
1709 WebInspector.ElementsTreeOutline.UpdateRecord.prototype = { 1596 WebInspector.ElementsTreeOutline.UpdateRecord.prototype = {
1710 /** 1597 /**
1711 * @param {string} attrName 1598 * @param {string} attrName
1712 */ 1599 */
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 if (node) { 1815 if (node) {
1929 this.treeOutline._selectedDOMNode = node; 1816 this.treeOutline._selectedDOMNode = node;
1930 this.treeOutline._selectedNodeChanged(); 1817 this.treeOutline._selectedNodeChanged();
1931 } 1818 }
1932 } 1819 }
1933 return true; 1820 return true;
1934 }, 1821 },
1935 1822
1936 __proto__: TreeElement.prototype 1823 __proto__: TreeElement.prototype
1937 } 1824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698