DOMDetailsSidebarPanel.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.DOMDetailsSidebarPanel = function(identifier, displayName, singularDisplayName, image, keyboardShortcutKey, element) {
  26. WebInspector.DetailsSidebarPanel.call(this, identifier, displayName, singularDisplayName, image, keyboardShortcutKey, element);
  27. this.element.addEventListener("click", this._mouseWasClicked.bind(this), true);
  28. this._domNode = null;
  29. };
  30. WebInspector.DOMDetailsSidebarPanel.prototype = {
  31. constructor: WebInspector.DOMDetailsSidebarPanel,
  32. // Public
  33. inspect: function(objects)
  34. {
  35. // Convert to a single item array if needed.
  36. if (!(objects instanceof Array))
  37. objects = [objects];
  38. var nodeToInspect = null;
  39. // Iterate over the objects to find a WebInspector.DOMNode to inspect.
  40. for (var i = 0; i < objects.length; ++i) {
  41. if (objects[i] instanceof WebInspector.DOMNode) {
  42. nodeToInspect = objects[i];
  43. break;
  44. }
  45. }
  46. if (nodeToInspect && !this.supportsDOMNode(nodeToInspect))
  47. nodeToInspect = null;
  48. this.domNode = nodeToInspect;
  49. return !!this._domNode;
  50. },
  51. get domNode()
  52. {
  53. return this._domNode;
  54. },
  55. set domNode(domNode)
  56. {
  57. if (domNode === this._domNode)
  58. return;
  59. if (this._domNode)
  60. this.removeEventListeners();
  61. this._domNode = domNode;
  62. if (this._domNode)
  63. this.addEventListeners();
  64. this.needsRefresh();
  65. },
  66. supportsDOMNode: function(nodeToInspect)
  67. {
  68. // Implemented by subclasses.
  69. return true;
  70. },
  71. addEventListeners: function()
  72. {
  73. // Implemented by subclasses.
  74. },
  75. removeEventListeners: function()
  76. {
  77. // Implemented by subclasses.
  78. },
  79. // Private
  80. _mouseWasClicked: function(event)
  81. {
  82. if (this._domNode && this._domNode.ownerDocument) {
  83. var mainResource = WebInspector.frameResourceManager.resourceForURL(this._domNode.ownerDocument.documentURL);
  84. if (mainResource)
  85. var parentFrame = mainResource.parentFrame;
  86. }
  87. WebInspector.handlePossibleLinkClick(event, parentFrame);
  88. }
  89. };
  90. WebInspector.DOMDetailsSidebarPanel.prototype.__proto__ = WebInspector.DetailsSidebarPanel.prototype;