ConsoleGroup.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved.
  3. * Copyright (C) 2009 Joseph Pecoraro
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. WebInspector.ConsoleGroup = function(parentGroup, isNewSession)
  30. {
  31. WebInspector.Object.call(this);
  32. this.parentGroup = parentGroup;
  33. var element = document.createElement("div");
  34. element.className = "console-group";
  35. element.group = this;
  36. this.element = element;
  37. if (isNewSession)
  38. element.classList.add("new-session");
  39. var messagesElement = document.createElement("div");
  40. messagesElement.className = "console-group-messages";
  41. element.appendChild(messagesElement);
  42. this.messagesElement = messagesElement;
  43. };
  44. WebInspector.ConsoleGroup.prototype = {
  45. constructor: WebInspector.ConsoleGroup,
  46. // Public
  47. addMessage: function(msg)
  48. {
  49. var element = msg.toMessageElement();
  50. var wrapper = document.createElement("div");
  51. wrapper.className = WebInspector.LogContentView.ItemWrapperStyleClassName;
  52. wrapper.messageElement = wrapper.appendChild(element);
  53. if (msg.type === WebInspector.ConsoleMessage.MessageType.StartGroup || msg.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed) {
  54. this.messagesElement.parentNode.insertBefore(wrapper, this.messagesElement);
  55. element.addEventListener("click", this._titleClicked.bind(this));
  56. element.addEventListener("mousedown", this._titleMouseDown.bind(this));
  57. var groupElement = element.enclosingNodeOrSelfWithClass("console-group");
  58. if (groupElement && msg.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed)
  59. groupElement.classList.add("collapsed");
  60. } else
  61. this.messagesElement.appendChild(wrapper);
  62. },
  63. hasMessages: function()
  64. {
  65. return !!this.messagesElement.childNodes.length;
  66. },
  67. // Private
  68. _titleMouseDown: function(event)
  69. {
  70. event.preventDefault();
  71. },
  72. _titleClicked: function(event)
  73. {
  74. var groupTitleElement = event.target.enclosingNodeOrSelfWithClass("console-group-title");
  75. if (groupTitleElement) {
  76. var groupElement = groupTitleElement.enclosingNodeOrSelfWithClass("console-group");
  77. if (groupElement)
  78. if (groupElement.classList.contains("collapsed"))
  79. groupElement.classList.remove("collapsed");
  80. else
  81. groupElement.classList.add("collapsed");
  82. groupTitleElement.scrollIntoViewIfNeeded(true);
  83. }
  84. }
  85. };
  86. WebInspector.ConsoleGroup.prototype.__proto__ = WebInspector.Object.prototype;