Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / ui / ProgressIndicator.js
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  */
36 WebInspector.ProgressIndicator = function()
37 {
38     this.element = document.createElementWithClass("div", "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
48 WebInspector.ProgressIndicator.prototype = {
49     /**
50      * @param {!Element} parent
51      */
52     show: function(parent)
53     {
54         parent.appendChild(this.element);
55     },
56
57     hide: function()
58     {
59         var parent = this.element.parentElement;
60         if (parent)
61             parent.removeChild(this.element);
62     },
63
64     done: function()
65     {
66         if (this._isDone)
67             return;
68         this._isDone = true;
69         this.hide();
70         this.dispatchEventToListeners(WebInspector.Progress.Events.Done);
71     },
72
73     cancel: function()
74     {
75         this._isCanceled = true;
76         this.dispatchEventToListeners(WebInspector.Progress.Events.Canceled);
77     },
78
79     /**
80      * @return {boolean}
81      */
82     isCanceled: function()
83     {
84         return this._isCanceled;
85     },
86
87     /**
88      * @param {string} title
89      */
90     setTitle: function(title)
91     {
92         this._labelElement.textContent = title;
93     },
94
95     /**
96      * @param {number} totalWork
97      */
98     setTotalWork: function(totalWork)
99     {
100         this._progressElement.max = totalWork;
101     },
102
103     /**
104      * @param {number} worked
105      * @param {string=} title
106      */
107     setWorked: function(worked, title)
108     {
109         this._worked = worked;
110         this._progressElement.value = worked;
111         if (title)
112             this.setTitle(title);
113     },
114
115     /**
116      * @param {number=} worked
117      */
118     worked: function(worked)
119     {
120         this.setWorked(this._worked + (worked || 1));
121     },
122
123     __proto__: WebInspector.Object.prototype
124 }