BreakpointTreeElement.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.BreakpointTreeElement = function(breakpoint, className, title)
  26. {
  27. console.assert(breakpoint instanceof WebInspector.Breakpoint);
  28. if (!className)
  29. className = WebInspector.BreakpointTreeElement.GenericLineIconStyleClassName;
  30. WebInspector.GeneralTreeElement.call(this, [WebInspector.BreakpointTreeElement.StyleClassName, className], title, null, breakpoint, false);
  31. this._breakpoint = breakpoint;
  32. if (!title)
  33. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.LocationDidChange, this._breakpointLocationDidChange, this);
  34. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.DisabledStateDidChange, this._updateStatus, this);
  35. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.ResolvedStateDidChange, this._updateStatus, this);
  36. this._statusImageElement = document.createElement("img");
  37. this._statusImageElement.className = WebInspector.BreakpointTreeElement.StatusImageElementStyleClassName;
  38. this._statusImageElement.addEventListener("mousedown", this._statusImageElementMouseDown.bind(this));
  39. this._statusImageElement.addEventListener("click", this._statusImageElementClicked.bind(this));
  40. if (!title)
  41. this._updateTitles();
  42. this._updateStatus();
  43. this.status = this._statusImageElement;
  44. this.small = true;
  45. };
  46. WebInspector.BreakpointTreeElement.GenericLineIconStyleClassName = "breakpoint-generic-line-icon";
  47. WebInspector.BreakpointTreeElement.StyleClassName = "breakpoint";
  48. WebInspector.BreakpointTreeElement.StatusImageElementStyleClassName = "status-image";
  49. WebInspector.BreakpointTreeElement.StatusImageResolvedStyleClassName = "resolved";
  50. WebInspector.BreakpointTreeElement.StatusImageDisabledStyleClassName = "disabled";
  51. WebInspector.BreakpointTreeElement.FormattedLocationStyleClassName = "formatted-location";
  52. WebInspector.BreakpointTreeElement.prototype = {
  53. constructor: WebInspector.BreakpointTreeElement,
  54. // Public
  55. get breakpoint()
  56. {
  57. return this._breakpoint;
  58. },
  59. ondelete: function()
  60. {
  61. if (!WebInspector.debuggerManager.isBreakpointRemovable(this._breakpoint))
  62. return false;
  63. WebInspector.debuggerManager.removeBreakpoint(this._breakpoint);
  64. return true;
  65. },
  66. onenter: function()
  67. {
  68. this._breakpoint.disabled = !this._breakpoint.disabled;
  69. return true;
  70. },
  71. onspace: function()
  72. {
  73. this._breakpoint.disabled = !this._breakpoint.disabled;
  74. return true;
  75. },
  76. oncontextmenu: function(event)
  77. {
  78. var contextMenu = new WebInspector.ContextMenu(event);
  79. this._breakpoint.appendContextMenuItems(contextMenu, this._statusImageElement);
  80. contextMenu.show();
  81. },
  82. // Private
  83. _updateTitles: function()
  84. {
  85. var sourceCodeLocation = this._breakpoint.sourceCodeLocation;
  86. var displayLineNumber = sourceCodeLocation.displayLineNumber;
  87. var displayColumnNumber = sourceCodeLocation.displayColumnNumber;
  88. if (displayColumnNumber > 0)
  89. this.mainTitle = WebInspector.UIString("Line %d:%d").format(displayLineNumber + 1, displayColumnNumber + 1); // The user visible line and column numbers are 1-based.
  90. else
  91. this.mainTitle = WebInspector.UIString("Line %d").format(displayLineNumber + 1); // The user visible line number is 1-based.
  92. if (sourceCodeLocation.hasMappedLocation()) {
  93. this.subtitle = sourceCodeLocation.formattedLocationString();
  94. if (sourceCodeLocation.hasFormattedLocation())
  95. this.subtitleElement.classList.add(WebInspector.BreakpointTreeElement.FormattedLocationStyleClassName);
  96. else
  97. this.subtitleElement.classList.remove(WebInspector.BreakpointTreeElement.FormattedLocationStyleClassName);
  98. this.tooltip = this.mainTitle + " \u2014 " + WebInspector.UIString("originally %s").format(sourceCodeLocation.originalLocationString());
  99. }
  100. },
  101. _updateStatus: function()
  102. {
  103. if (this._breakpoint.disabled)
  104. this._statusImageElement.classList.add(WebInspector.BreakpointTreeElement.StatusImageDisabledStyleClassName);
  105. else
  106. this._statusImageElement.classList.remove(WebInspector.BreakpointTreeElement.StatusImageDisabledStyleClassName);
  107. if (this._breakpoint.resolved)
  108. this._statusImageElement.classList.add(WebInspector.BreakpointTreeElement.StatusImageResolvedStyleClassName);
  109. else
  110. this._statusImageElement.classList.remove(WebInspector.BreakpointTreeElement.StatusImageResolvedStyleClassName);
  111. },
  112. _breakpointLocationDidChange: function(event)
  113. {
  114. console.assert(event.target === this._breakpoint);
  115. // The Breakpoint has a new display SourceCode. The sidebar will remove us. Stop listening to the breakpoint.
  116. if (event.data.oldDisplaySourceCode === this._breakpoint.displaySourceCode) {
  117. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.LocationDidChange, this._breakpointLocationDidChange, this);
  118. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.DisabledStateDidChange, this._updateStatus, this);
  119. this._breakpoint.addEventListener(WebInspector.Breakpoint.Event.ResolvedStateDidChange, this._updateStatus, this);
  120. return;
  121. }
  122. this._updateTitles();
  123. },
  124. _statusImageElementMouseDown: function(event)
  125. {
  126. // To prevent the tree element from selecting.
  127. event.stopPropagation();
  128. },
  129. _statusImageElementClicked: function(event)
  130. {
  131. this._breakpoint.disabled = !this._breakpoint.disabled;
  132. }
  133. };
  134. WebInspector.BreakpointTreeElement.prototype.__proto__ = WebInspector.GeneralTreeElement.prototype;