ProgressIndicator.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2012 Google 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 are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * @constructor
  32. * @implements {WebInspector.Progress}
  33. * @extends {WebInspector.Object}
  34. */
  35. WebInspector.ProgressIndicator = function()
  36. {
  37. this.element = document.createElement("div");
  38. this.element.className = "progress-bar-container";
  39. this._labelElement = this.element.createChild("span");
  40. this._progressElement = this.element.createChild("progress");
  41. this._stopButton = new WebInspector.StatusBarButton(WebInspector.UIString("Cancel"), "progress-bar-stop-button");
  42. this._stopButton.addEventListener("click", this.cancel, this);
  43. this.element.appendChild(this._stopButton.element);
  44. this._isCanceled = false;
  45. this._worked = 0;
  46. }
  47. WebInspector.ProgressIndicator.Events = {
  48. Done: "Done"
  49. }
  50. WebInspector.ProgressIndicator.prototype = {
  51. /**
  52. * @param {Element} parent
  53. */
  54. show: function(parent)
  55. {
  56. parent.appendChild(this.element);
  57. },
  58. hide: function()
  59. {
  60. var parent = this.element.parentElement;
  61. if (parent)
  62. parent.removeChild(this.element);
  63. },
  64. done: function()
  65. {
  66. if (this._isDone)
  67. return;
  68. this._isDone = true;
  69. this.hide();
  70. this.dispatchEventToListeners(WebInspector.ProgressIndicator.Events.Done);
  71. },
  72. cancel: function()
  73. {
  74. this._isCanceled = true;
  75. },
  76. isCanceled: function()
  77. {
  78. return this._isCanceled;
  79. },
  80. /**
  81. * @param {string} title
  82. */
  83. setTitle: function(title)
  84. {
  85. this._labelElement.textContent = title;
  86. },
  87. /**
  88. * @param {number} totalWork
  89. */
  90. setTotalWork: function(totalWork)
  91. {
  92. this._progressElement.max = totalWork;
  93. },
  94. /**
  95. * @param {number} worked
  96. * @param {string=} title
  97. */
  98. setWorked: function(worked, title)
  99. {
  100. this._worked = worked;
  101. this._progressElement.value = worked;
  102. if (title)
  103. this.setTitle(title);
  104. },
  105. /**
  106. * @param {number=} worked
  107. */
  108. worked: function(worked)
  109. {
  110. this.setWorked(this._worked + (worked || 1));
  111. },
  112. __proto__: WebInspector.Object.prototype
  113. }