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/** 32 * @constructor 33 * @implements {WebInspector.Progress} 34 * @extends {WebInspector.Object} 35 */ 36WebInspector.ProgressIndicator = function() 37{ 38 this.element = document.createElement("div"); 39 this.element.className = "progress-bar-container"; 40 this._labelElement = this.element.createChild("span"); 41 this._progressElement = this.element.createChild("progress"); 42 this._stopButton = new WebInspector.StatusBarButton(WebInspector.UIString("Cancel"), "progress-bar-stop-button"); 43 this._stopButton.addEventListener("click", this.cancel, this); 44 this.element.appendChild(this._stopButton.element); 45 this._isCanceled = false; 46 this._worked = 0; 47} 48 49WebInspector.ProgressIndicator.Events = { 50 Done: "Done" 51} 52 53WebInspector.ProgressIndicator.prototype = { 54 /** 55 * @param {!Element} parent 56 */ 57 show: function(parent) 58 { 59 parent.appendChild(this.element); 60 }, 61 62 hide: function() 63 { 64 var parent = this.element.parentElement; 65 if (parent) 66 parent.removeChild(this.element); 67 }, 68 69 done: function() 70 { 71 if (this._isDone) 72 return; 73 this._isDone = true; 74 this.hide(); 75 this.dispatchEventToListeners(WebInspector.ProgressIndicator.Events.Done); 76 }, 77 78 cancel: function() 79 { 80 this._isCanceled = true; 81 this.dispatchEventToListeners(WebInspector.Progress.Events.Canceled); 82 }, 83 84 isCanceled: function() 85 { 86 return this._isCanceled; 87 }, 88 89 /** 90 * @param {string} title 91 */ 92 setTitle: function(title) 93 { 94 this._labelElement.textContent = title; 95 }, 96 97 /** 98 * @param {number} totalWork 99 */ 100 setTotalWork: function(totalWork) 101 { 102 this._progressElement.max = totalWork; 103 }, 104 105 /** 106 * @param {number} worked 107 * @param {string=} title 108 */ 109 setWorked: function(worked, title) 110 { 111 this._worked = worked; 112 this._progressElement.value = worked; 113 if (title) 114 this.setTitle(title); 115 }, 116 117 /** 118 * @param {number=} worked 119 */ 120 worked: function(worked) 121 { 122 this.setWorked(this._worked + (worked || 1)); 123 }, 124 125 __proto__: WebInspector.Object.prototype 126} 127