DOMTreeElementPathComponent.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. WebInspector.DOMTreeElementPathComponent = function(domTreeElement, representedObject) {
  26. var node = domTreeElement.representedObject;
  27. var title = null;
  28. var className = null;
  29. switch (node.nodeType()) {
  30. case Node.ELEMENT_NODE:
  31. className = WebInspector.DOMTreeElementPathComponent.DOMElementIconStyleClassName;
  32. title = WebInspector.displayNameForNode(node);
  33. break;
  34. case Node.TEXT_NODE:
  35. className = WebInspector.DOMTreeElementPathComponent.DOMTextNodeIconStyleClassName;
  36. title = "\"" + node.nodeValue().trimEnd(32) + "\"";
  37. break
  38. case Node.COMMENT_NODE:
  39. className = WebInspector.DOMTreeElementPathComponent.DOMCommentIconStyleClassName;
  40. title = "<!--" + node.nodeValue().trimEnd(32) + "-->";
  41. break;
  42. case Node.DOCUMENT_TYPE_NODE:
  43. className = WebInspector.DOMTreeElementPathComponent.DOMDocumentTypeIconStyleClassName;
  44. title = "<!DOCTYPE>";
  45. break;
  46. case Node.DOCUMENT_NODE:
  47. className = WebInspector.DOMTreeElementPathComponent.DOMDocumentIconStyleClassName;
  48. title = node.nodeNameInCorrectCase();
  49. break;
  50. case Node.CDATA_SECTION_NODE:
  51. className = WebInspector.DOMTreeElementPathComponent.DOMCharacterDataIconStyleClassName;
  52. title = "<![CDATA[" + node.trimEnd(32) + "]]>";
  53. break;
  54. case Node.DOCUMENT_FRAGMENT_NODE:
  55. // FIXME: At some point we might want a different icon for this.
  56. // <rdar://problem/12800950> Need icon for DOCUMENT_FRAGMENT_NODE
  57. className = WebInspector.DOMTreeElementPathComponent.DOMDocumentTypeIconStyleClassName;
  58. if (node.isInShadowTree())
  59. title = WebInspector.UIString("Shadow Content");
  60. else
  61. title = WebInspector.displayNameForNode(node);
  62. break;
  63. default:
  64. console.error("Unknown DOM node type: ", node.nodeType());
  65. className = WebInspector.DOMTreeElementPathComponent.DOMNodeIconStyleClassName;
  66. title = node.nodeNameInCorrectCase();
  67. }
  68. WebInspector.HierarchicalPathComponent.call(this, title, className, representedObject || domTreeElement.representedObject);
  69. this._domTreeElement = domTreeElement;
  70. };
  71. WebInspector.DOMTreeElementPathComponent.DOMElementIconStyleClassName = "dom-element-icon";
  72. WebInspector.DOMTreeElementPathComponent.DOMTextNodeIconStyleClassName = "dom-text-node-icon";
  73. WebInspector.DOMTreeElementPathComponent.DOMCommentIconStyleClassName = "dom-comment-icon";
  74. WebInspector.DOMTreeElementPathComponent.DOMDocumentTypeIconStyleClassName = "dom-document-type-icon";
  75. WebInspector.DOMTreeElementPathComponent.DOMDocumentIconStyleClassName = "dom-document-icon";
  76. WebInspector.DOMTreeElementPathComponent.DOMCharacterDataIconStyleClassName = "dom-character-data-icon";
  77. WebInspector.DOMTreeElementPathComponent.DOMNodeIconStyleClassName = "dom-node-icon";
  78. WebInspector.DOMTreeElementPathComponent.prototype = {
  79. constructor: WebInspector.DOMTreeElementPathComponent,
  80. // Public
  81. get domTreeElement()
  82. {
  83. return this._domTreeElement;
  84. },
  85. get previousSibling()
  86. {
  87. if (!this._domTreeElement.previousSibling)
  88. return null;
  89. return new WebInspector.DOMTreeElementPathComponent(this._domTreeElement.previousSibling);
  90. },
  91. get nextSibling()
  92. {
  93. if (!this._domTreeElement.nextSibling)
  94. return null;
  95. if (this._domTreeElement.nextSibling.isCloseTag())
  96. return null;
  97. return new WebInspector.DOMTreeElementPathComponent(this._domTreeElement.nextSibling);
  98. },
  99. // Protected
  100. mouseOver: function()
  101. {
  102. var nodeId = this._domTreeElement.representedObject.id;
  103. WebInspector.domTreeManager.highlightDOMNode(nodeId);
  104. },
  105. mouseOut: function()
  106. {
  107. WebInspector.domTreeManager.hideDOMNodeHighlight();
  108. }
  109. };
  110. WebInspector.DOMTreeElementPathComponent.prototype.__proto__ = WebInspector.HierarchicalPathComponent.prototype;