Skip to content

Commit cb05144

Browse files
committed
Merge pull request mozilla#2011 from yurydelendik/progress-indeterminate
Adds support of the indeterminate loading progress
2 parents 62e6b43 + 296b98f commit cb05144

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

extensions/firefox/components/PdfStreamConverter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ PdfDataListener.prototype = {
147147
}
148148
this.data.set(chunk, this.loaded);
149149
this.loaded = willBeLoaded;
150-
if (this.length >= 0)
151-
this.onprogress(this.loaded, this.length);
150+
this.onprogress(this.loaded, this.length >= 0 ? this.length : void(0));
152151
},
153152
getData: function PdfDataListener_getData() {
154153
var data = this.data;

src/worker.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,10 @@ var WorkerMessageHandler = {
135135
{
136136
url: source.url,
137137
progress: function getPDFProgress(evt) {
138-
if (evt.lengthComputable) {
139-
handler.send('DocProgress', {
140-
loaded: evt.loaded,
141-
total: evt.total
142-
});
143-
}
138+
handler.send('DocProgress', {
139+
loaded: evt.loaded,
140+
total: evt.lengthComputable ? evt.total : void(0)
141+
});
144142
},
145143
error: function getPDFError(e) {
146144
handler.send('DocError', 'Unexpected server response of ' +

web/viewer.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,28 @@ canvas {
10251025
border-bottom-right-radius: 2px;
10261026
}
10271027

1028+
#loadingBar .progress.indeterminate {
1029+
width: 100%;
1030+
height: 25px;
1031+
background-image: -moz-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
1032+
background-image: -webkit-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
1033+
background-image: -ms-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
1034+
background-image: -o-linear-gradient( 30deg, #404040, #404040 15%, #898989, #404040 85%, #404040);
1035+
background-size: 75px 25px;
1036+
-moz-animation: progressIndeterminate 1s linear infinite;
1037+
-webkit-animation: progressIndeterminate 1s linear infinite;
1038+
}
1039+
1040+
@-moz-keyframes progressIndeterminate {
1041+
from { background-position: 0px 0px; }
1042+
to { background-position: 75px 0px; }
1043+
}
1044+
1045+
@-webkit-keyframes progressIndeterminate {
1046+
from { background-position: 0px 0px; }
1047+
to { background-position: 75px 0px; }
1048+
}
1049+
10281050
.textLayer {
10291051
position: absolute;
10301052
left: 0;

web/viewer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ var ProgressBar = (function ProgressBarClosure() {
6060
this.height = opts.height || 100;
6161
this.width = opts.width || 100;
6262
this.units = opts.units || '%';
63-
this.percent = opts.percent || 0;
6463

6564
// Initialize heights
6665
this.div.style.height = this.height + this.units;
@@ -69,10 +68,18 @@ var ProgressBar = (function ProgressBarClosure() {
6968
ProgressBar.prototype = {
7069

7170
updateBar: function ProgressBar_updateBar() {
71+
if (this._indeterminate) {
72+
this.div.classList.add('indeterminate');
73+
return;
74+
}
75+
7276
var progressSize = this.width * this._percent / 100;
7377

7478
if (this._percent > 95)
7579
this.div.classList.add('full');
80+
else
81+
this.div.classList.remove('full');
82+
this.div.classList.remove('indeterminate');
7683

7784
this.div.style.width = progressSize + this.units;
7885
},
@@ -82,6 +89,7 @@ var ProgressBar = (function ProgressBarClosure() {
8289
},
8390

8491
set percent(val) {
92+
this._indeterminate = isNaN(val);
8593
this._percent = clamp(val, 0, 100);
8694
this.updateBar();
8795
}
@@ -572,6 +580,10 @@ var PDFView = {
572580
}
573581
}
574582
}
583+
584+
var loadingBox = document.getElementById('loadingBox');
585+
loadingBox.setAttribute('hidden', 'true');
586+
575587
//#if !(FIREFOX || MOZCENTRAL)
576588
var errorWrapper = document.getElementById('errorWrapper');
577589
errorWrapper.removeAttribute('hidden');

0 commit comments

Comments
 (0)