This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
statusbar.js
1756 lines (1444 loc) · 54.2 KB
/
statusbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Copyright 2012, Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*global Clock, SettingsListener, FtuLauncher, MobileOperator,
SIMSlotManager, Service, Bluetooth, UtilityTray, nfcManager,
layoutManager */
'use strict';
var StatusBar = {
/* all elements that are children nodes of the status bar */
ELEMENTS: ['emergency-cb-notification', 'time', 'connections', 'battery',
'wifi', 'data', 'flight-mode', 'network-activity', 'tethering', 'alarm',
'debugging', 'bluetooth', 'mute', 'headphones', 'bluetooth-headphones',
'bluetooth-transferring', 'recording', 'sms', 'geolocation', 'usb',
'label', 'system-downloads', 'call-forwardings', 'playing', 'nfc'],
// The indices indicate icons priority (lower index = highest priority)
// In each subarray:
// * Index 0 is the icon id
// * Index 1 is the icon element width or null if size is variable
PRIORITIES: [
['emergency-cb-notification', 16 + 4],
['battery', 25 + 4],
['recording', 16 + 4],
['flight-mode', 16 + 4],
['wifi', 16 + 4],
['connections', null], // Width can change
['time', null], // Width can change
['debugging', 16 + 4],
['system-downloads', 16 + 4],
['geolocation', 16 + 4],
['network-activity', 16 + 4],
['tethering', 16 + 4],
['bluetooth-transferring', 16 + 4],
['bluetooth', 16 + 4],
['nfc', 16 + 4],
['usb', 16 + 4],
['alarm', 16 + 4],
['bluetooth-headphones', 16 + 4],
['mute', 16 + 4],
['call-forwardings', null], // Width can change
['playing', 16 + 4],
['headphones', 16 + 4],
//['sms', 16 + 4], // Not currently implemented.
['label', null] // Only visible in the maximized status bar.
],
/* Timeout for 'recently active' indicators */
kActiveIndicatorTimeout: 5 * 1000,
/* Whether or not status bar is actively updating or not */
active: true,
/* Whether or not the lockscreen is displayed */
_inLockScreenMode: false,
/* Some values that sync from mozSettings */
settingValues: {},
/* Keep the DOM element references here */
icons: {},
/* A mapping table between technology names
we would get from API v.s. the icon we want to show. */
mobileDataIconTypes: {
'lte': '4G', // 4G LTE
'ehrpd': '4G', // 4G CDMA
'hspa+': 'H+', // 3.5G HSPA+
'hsdpa': 'H', 'hsupa': 'H', 'hspa': 'H', // 3.5G HSDPA
'evdo0': 'Ev', 'evdoa': 'Ev', 'evdob': 'Ev', // 3G CDMA
'umts': '3G', // 3G
'edge': 'E', // EDGE
'gprs': '2G',
'1xrtt': '1x', 'is95a': '1x', 'is95b': '1x' // 2G CDMA
},
// CDMA types that can support either data call or voice call simultaneously.
dataExclusiveCDMATypes: {
'evdo0': true, 'evdoa': true, 'evdob': true, // data call only
'1xrtt': true, 'is95a': true, 'is95b': true // data call or voice call
},
/* Settings to listen on for changes to statusbar icons. */
settings: {
'ril.radio.disabled': ['signal', 'data'],
'airplaneMode.status': ['flightMode'],
'ril.data.enabled': ['data'],
'wifi.enabled': ['wifi'],
'bluetooth.enabled': ['bluetooth'],
'tethering.usb.enabled': ['tethering'],
'tethering.wifi.enabled': ['tethering'],
'tethering.wifi.connectedClients': ['tethering'],
'tethering.usb.connectedClients': ['tethering'],
'audio.volume.notification': ['mute'],
'alarm.enabled': ['alarm'],
'vibration.enabled': ['vibration'],
'ril.cf.enabled': ['callForwarding'],
'operatorResources.data.icon': ['iconData'],
'statusbar.network-activity.disabled': ['networkActivity'],
'statusbar.show-am-pm': ['time'],
'debugger.remote-mode': ['debugging']
},
/* Track which settings are observed, so we don't add multiple listeners. */
observedSettings: {},
geolocationActive: false,
geolocationTimer: null,
recordingActive: false,
recordingTimer: null,
nfcActive: false,
umsActive: false,
headphonesActive: false,
listeningCallschanged: false,
playingActive: false,
/**
* this keeps how many current installs/updates we do
* it triggers the icon "systemDownloads"
*/
systemDownloadsCount: 0,
systemDownloads: {},
_minimizedStatusBarWidth: window.innerWidth,
_pausedForGesture: false,
/**
* Object used for handling the clock UI element, wraps all related timers
*/
clock: new Clock(),
/* For other modules to acquire */
get height() {
if (document.mozFullScreen ||
(Service.currentApp &&
Service.currentApp.isFullScreen())) {
return 0;
} else {
return this._cacheHeight ||
(this._cacheHeight = this.element.getBoundingClientRect().height);
}
},
init: function sb_init() {
this.getAllElements();
// cache height.
this._cacheHeight = this.element.getBoundingClientRect().height;
this.listeningCallschanged = false;
window.addEventListener('ftudone', this);
window.addEventListener('ftuskip', this);
window.addEventListener('ftuopen', this);
window.addEventListener('apptitlestatechanged', this);
window.addEventListener('activitytitlestatechanged', this);
window.addEventListener('appchromecollapsed', this);
window.addEventListener('appchromeexpanded', this);
window.addEventListener('emergencycallbackstatechanged', this);
},
addSettingsListener: function sb_addSettingsListener(settingKey) {
// Don't add observer if setting is already observered.
if (this.observedSettings[settingKey]) {
return;
}
this.observedSettings[settingKey] = true;
SettingsListener.observe(settingKey, false,
(value) => {
this.settingValues[settingKey] = value;
this.settings[settingKey].forEach(
(name) => this.update[name].call(this)
);
}
);
this.settingValues[settingKey] = false;
},
/**
* Add event listeners associated with mobile connection state.
*/
addConnectionsListeners: function() {
var conns = window.navigator.mozMobileConnections;
if (conns) {
Array.from(conns).forEach(
(conn) => {
conn.addEventListener('voicechange', this);
conn.addEventListener('datachange', this);
this.update.signal.call(this);
this.update.data.call(this);
}
);
}
},
/**
* Remove event listeners associated with mobile connection state.
*/
removeConnectionsListeners: function() {
var conns = window.navigator.mozMobileConnections;
if (conns) {
Array.from(conns).forEach(
(conn) => {
conn.removeEventListener('voicechange', this);
conn.removeEventListener('datachange', this);
}
);
}
},
/**
* Finish all initializing statusbar event handlers
*/
finishInit: function() {
this.createConnectionsElements();
this.createCallForwardingsElements();
// Refresh the time to reflect locale changes
this.toggleTimeLabel(true);
for (var key in this.settings) {
this.addSettingsListener(key);
}
// Listen to events from attention_window
window.addEventListener('attentionopened', this);
window.addEventListener('attentionclosed', this);
window.addEventListener('sheets-gesture-begin', this);
window.addEventListener('sheets-gesture-end', this);
window.addEventListener('utilitytraywillshow', this);
window.addEventListener('utilitytraywillhide', this);
window.addEventListener('utility-tray-overlayopened', this);
window.addEventListener('utility-tray-overlayclosed', this);
window.addEventListener('cardviewshown', this);
window.addEventListener('cardviewclosed', this);
// Listen to 'screenchange' from screen_manager.js
window.addEventListener('screenchange', this);
// mozChromeEvent fired from Gecko is earlier been loaded,
// so we use mozAudioChannelManager to
// check the headphone plugged or not when booting up
var acm = navigator.mozAudioChannelManager;
if (acm) {
this.headphonesActive = acm.headphones;
this.update.headphones.call(this);
}
// Listen to 'geolocation-status' and 'recording-status' mozChromeEvent
window.addEventListener('mozChromeEvent', this);
// Listen to Custom event send by 'media_recording.js'
window.addEventListener('recordingEvent', this);
// Listen to Custom event send by 'nfc_manager.js'
window.addEventListener('nfc-state-changed', this);
// 'bluetoothconnectionchange' fires when the overall bluetooth connection
// changes.
// 'bluetoothprofileconnectionchange' fires when a bluetooth connection of
// a specific profile changes.
window.addEventListener('bluetoothconnectionchange', this);
window.addEventListener('bluetoothprofileconnectionchange', this);
// Listen to 'moztimechange'
window.addEventListener('moztimechange', this);
// Listen to 'timeformatchange'
window.addEventListener('timeformatchange', this);
// Listen to 'lockscreen-appopened', 'lockscreen-appclosing', and
// 'lockpanelchange' in order to correctly set the visibility of
// the statusbar clock depending on the active lockscreen panel
window.addEventListener('lockscreen-appopened', this);
window.addEventListener('lockscreen-appclosing', this);
window.addEventListener('lockpanelchange', this);
// Listen to orientation change and SHB activation/deactivation.
window.addEventListener('system-resize', this);
window.addEventListener('appopening', this);
window.addEventListener('appopened', this);
window.addEventListener('activityopened', this);
window.addEventListener('activityterminated', this);
window.addEventListener('activitydestroyed', this);
window.addEventListener('homescreenopening', this);
window.addEventListener('homescreenopened', this);
window.addEventListener('stackchanged', this);
// Listen to updates dialog
window.addEventListener('updatepromptshown', this);
window.addEventListener('updateprompthidden', this);
// Track Downloads via the Downloads API.
var mozDownloadManager = navigator.mozDownloadManager;
if (mozDownloadManager) {
mozDownloadManager.addEventListener('downloadstart', this);
}
// We need to preventDefault on mouse events until
// https://bugzilla.mozilla.org/show_bug.cgi?id=1005815 lands
var events = ['touchstart', 'touchmove', 'touchend',
'mousedown', 'mousemove', 'mouseup'];
events.forEach(function bindEvents(name) {
this.topPanel.addEventListener(name, this.panelHandler.bind(this));
}, this);
this.statusbarIcons.addEventListener('wheel', this);
this.systemDownloadsCount = 0;
this.setActive(true);
UtilityTray.init();
},
handleEvent: function sb_handleEvent(evt) {
switch (evt.type) {
case 'emergencycallbackstatechanged':
this.updateEmergencyCbNotification(evt.detail);
break;
case 'screenchange':
this.setActive(evt.detail.screenEnabled);
break;
case 'lockscreen-appopened':
// Hide the clock in the statusbar when screen is locked
//
// It seems no need to detect the locked value because
// when the lockscreen lock itself, the value must be true,
// or we have some bugs.
this.toggleTimeLabel(false);
this._updateIconVisibility();
this._inLockScreenMode = true;
this.setAppearance();
break;
case 'lockscreen-appclosing':
// Display the clock in the statusbar when screen is unlocked
this.toggleTimeLabel(true);
this._updateIconVisibility();
this._inLockScreenMode = false;
this.setAppearance(Service.currentApp);
break;
case 'attentionopened':
this.toggleTimeLabel(true);
break;
case 'attentionclosed':
// Hide the clock in the statusbar when screen is locked
this.toggleTimeLabel(!this.isLocked());
break;
case 'sheets-gesture-begin':
this.element.classList.add('hidden');
if (!this._pausedForGesture) {
this.pauseUpdate();
this._pausedForGesture = true;
}
break;
case 'utilitytraywillshow':
case 'utilitytraywillhide':
case 'cardviewshown':
this.pauseUpdate();
break;
case 'utility-tray-overlayopened':
case 'utility-tray-overlayclosed':
case 'cardviewclosed':
this.resumeUpdate();
break;
case 'lockpanelchange':
if (this.screen.classList.contains('locked')) {
// Display the clock in the statusbar if on Emergency Call screen
var isHidden = (evt.detail.panel !== 'emergency-call');
this.toggleTimeLabel(!isHidden);
}
break;
case 'chargingchange':
case 'levelchange':
case 'statuschange':
this.update.battery.call(this);
break;
case 'voicechange':
this.update.signal.call(this);
this.update.label.call(this);
break;
case 'cardstatechange':
this.update.signal.call(this);
this.update.label.call(this);
this.update.data.call(this);
break;
case 'callschanged':
this.update.signal.call(this);
this.update.data.call(this);
break;
case 'simslot-iccinfochange':
this.update.label.call(this);
break;
case 'wifi-statuschange':
this.update.wifi.call(this);
break;
case 'datachange':
this.update.data.call(this);
break;
case 'bluetoothconnectionchange':
this.update.bluetooth.call(this);
break;
case 'bluetoothprofileconnectionchange':
this.update.bluetoothProfiles.call(this);
break;
case 'timeformatchange':
case 'moztimechange':
navigator.mozL10n.ready((function _updateTime() {
// To stop clock for reseting the clock interval which runs every 60
// seconds. The reason to do this is that the time updated will be
// exactly aligned to minutes which means always getting 0 on seconds
// part.
this.toggleTimeLabel(false);
this.toggleTimeLabel(true);
// But we still need to consider if we're locked. So may we need to
// hide it again.
this.toggleTimeLabel(!this.isLocked());
}).bind(this));
break;
case 'recordingEvent':
switch (evt.detail.type) {
case 'recording-state-changed':
this.recordingActive = evt.detail.active;
this.update.recording.call(this);
break;
}
break;
case 'nfc-state-changed':
this.setActiveNfc(evt.detail.active);
break;
case 'mozChromeEvent':
switch (evt.detail.type) {
case 'geolocation-status':
this.geolocationActive = evt.detail.active;
this.update.geolocation.call(this);
break;
case 'volume-state-changed':
this.umsActive = evt.detail.active;
this.update.usb.call(this);
break;
case 'headphones-status-changed':
this.headphonesActive = (evt.detail.state != 'off');
this.update.headphones.call(this);
break;
case 'audio-channel-changed':
// The camera recording fires a audio-channel-changed event to kill
// existing "content" audio channels, in this case we don't show the
// playing icon.
var active = evt.detail.channel === 'content' &&
!this.recordingActive;
if (this.playingActive === active) {
break;
}
this.playingActive = active;
this.update.playing.call(this);
break;
}
break;
case 'moznetworkupload':
case 'moznetworkdownload':
this.update.networkActivity.call(this);
break;
case 'ftuopen':
// If we are upgrading, we can show all the icons.
if (FtuLauncher.isFtuUpgrading()) {
this.finishInit();
} else {
// When first launching FTU, only show battery icon
// and listen for iac step events to show more icons.
this.setActiveBattery(true);
this._updateIconVisibility();
window.addEventListener('iac-ftucomms', this);
}
break;
case 'ftudone':
window.removeEventListener('iac-ftucomms', this);
this.finishInit();
break;
case 'ftuskip':
this.finishInit();
break;
case 'iac-ftucomms':
if (evt.detail.type === 'step') {
this.handleFtuStep(evt.detail.hash);
}
break;
case 'wheel':
if (evt.deltaMode === evt.DOM_DELTA_PAGE && evt.deltaY &&
evt.deltaY < 0 && !this.isLocked()) {
window.dispatchEvent(new CustomEvent('statusbarwheel'));
}
break;
case 'system-resize':
// Reprioritize icons when:
// * Screen orientation changes
// * Software home button is enabled/disabled
this._updateMinimizedStatusBarWidth();
break;
case 'homescreenopening':
case 'appopening':
this.element.classList.add('hidden');
break;
case 'sheets-gesture-end':
this.element.classList.remove('hidden');
this._pausedForGesture = false;
this.resumeUpdate();
break;
case 'stackchanged':
this.setAppearance(Service.currentApp);
this.element.classList.remove('hidden');
break;
case 'appchromecollapsed':
this.setAppearance(evt.detail);
this._updateMinimizedStatusBarWidth();
break;
case 'appopened':
case 'appchromeexpanded':
if (evt.type === 'appopened') {
this.element.classList.toggle('fullscreen',
evt.detail.isFullScreen());
this.element.classList.toggle('fullscreen-layout',
evt.detail.isFullScreenLayout());
}
this.setAppearance(evt.detail);
this.element.classList.remove('hidden');
this._updateMinimizedStatusBarWidth();
break;
case 'activityopened':
this._updateMinimizedStatusBarWidth();
/* falls through */
case 'apptitlestatechanged':
case 'activitytitlestatechanged':
this.setAppearance(evt.detail);
if (!this.isPaused()) {
this.element.classList.remove('hidden');
}
break;
case 'homescreenopened':
// In some cases, if the user has been switching apps so fast and
// quickly he press the home button, we might miss the
// |sheets-gesture-end| event so we must resume the statusbar
// if needed
this.setAppearance(evt.detail);
if (this._pausedForGesture) {
this.resumeUpdate();
this._pausedForGesture = false;
}
this.element.classList.remove('hidden');
this.element.classList.remove('fullscreen');
this.element.classList.remove('fullscreen-layout');
break;
case 'activityterminated':
// In this particular case, we want to restore the original color of
// the bottom window as it will *become* the shown window.
this.setAppearance(evt.detail, true);
this.element.classList.remove('hidden');
break;
case 'activitydestroyed':
this._updateMinimizedStatusBarWidth();
break;
case 'downloadstart':
// New download, track it so we can show or hide the active downloads
// indicator. If you think this logic needs to change, think really hard
// about it and then come and ask @nullaus
this.addSystemDownloadListeners(evt.download);
break;
case 'updatepromptshown':
this.element.classList.remove('light');
break;
case 'updateprompthidden':
this.setAppearance(Service.currentApp);
break;
}
},
addSystemDownloadListeners: function(download) {
var handler = function handleDownloadStateChange(downloadEvent) {
var download = downloadEvent.download;
switch(download.state) {
case 'downloading':
// If this download has not already been tracked as actively
// downloading we'll add it to our list and increment the
// downloads counter.
if (!this.systemDownloads[download.id]) {
this.incSystemDownloads();
this.systemDownloads[download.id] = true;
}
break;
// Once the download is finalized, and only then, is it safe to
// remove our state change listener. If we remove it before then
// we are likely to miss paused or errored downloads being restarted
case 'finalized':
download.removeEventListener('statechange', handler);
break;
// All other state changes indicate the download is no longer
// active, if we were previously tracking the download as active
// we'll decrement the counter now and remove it from active
// download status.
case 'stopped':
case 'succeeded':
if (this.systemDownloads[download.id]) {
this.decSystemDownloads();
delete this.systemDownloads[download.id];
}
break;
default:
console.warn('Unexpected download state = ', download.state);
}
}.bind(this);
download.addEventListener('statechange', handler);
},
setAppearance: function(app, useBottomWindow) {
// The statusbar is always maximised when the phone is locked.
if (this._inLockScreenMode) {
this.element.classList.add('maximized');
return;
}
// Fetch top-most (or bottom-most) window to figure out color theming.
var themeWindow =
useBottomWindow ? app.getBottomMostWindow() : app.getTopMostWindow();
this.element.classList.toggle('light',
!!(themeWindow.appChrome && themeWindow.appChrome.useLightTheming())
);
// Maximized state must be based on the bottom window if we're using it but
// use the currently showing window for other cases.
var maximizedWindow = useBottomWindow ? themeWindow : app;
this.element.classList.toggle('maximized', maximizedWindow.isHomescreen ||
!!(maximizedWindow.appChrome && maximizedWindow.appChrome.isMaximized())
);
},
_getMaximizedStatusBarWidth: function sb_getMaximizedStatusBarWidth() {
// Let's consider the style of the status bar:
// * padding: 0 0.3rem;
return Math.round(layoutManager.width - (3 * 2));
},
_updateMinimizedStatusBarWidth: function sb_updateMinimizedStatusBarWidth() {
var app = Service.currentApp;
app = app && app.getTopMostWindow();
// Get the actual width of the rocketbar, and determine the remaining
// width for the minimized statusbar.
var element = app && app.appChrome && app.appChrome.element &&
app.appChrome.element.querySelector('.urlbar .title');
if (element) {
this._minimizedStatusBarWidth = Math.round(
layoutManager.width -
element.getBoundingClientRect().width -
// Remove padding and margin
5 - 3);
} else {
this._minimizedStatusBarWidth = this._getMaximizedStatusBarWidth();
}
this._updateIconVisibility();
},
_paused: 0,
pauseUpdate: function sb_pauseUpdate() {
this._paused++;
},
resumeUpdate: function sb_resumeUpdate() {
this._paused--;
this._updateIconVisibility();
},
isPaused: function sb_isPaused() {
return this._paused > 0;
},
_updateIconVisibility: function sb_updateIconVisibility() {
if (this._paused !== 0) {
return;
}
// Let's refresh the minimized clone.
this.cloneStatusbar();
var maximizedStatusBarWidth = this._getMaximizedStatusBarWidth();
var minimizedStatusBarWidth = this._minimizedStatusBarWidth;
this.PRIORITIES.forEach(function sb_updateIconVisibilityForEach(iconObj) {
var iconId = iconObj[0];
var icon = this.icons[this.toCamelCase(iconId)];
if (!icon || icon.hidden) {
return;
}
var className = 'sb-hide-' + iconId;
if (maximizedStatusBarWidth < 0) {
this.statusbarIcons.classList.add(className);
return;
}
this.statusbarIcons.classList.remove(className);
this.statusbarIconsMin.classList.remove(className);
var iconWidth = this._getIconWidth(iconObj);
maximizedStatusBarWidth -= iconWidth;
if (maximizedStatusBarWidth < 0) {
// Add a class to the container so that both status bars inherit it.
this.statusbarIcons.classList.add(className);
return;
}
minimizedStatusBarWidth -= iconWidth;
if (minimizedStatusBarWidth < 0) {
// This icon needs to be hidden on the minimized status bar only.
this.statusbarIconsMin.classList.add(className);
}
}.bind(this));
},
_getIconWidth: function sb_getIconWidth(iconObj) {
var iconWidth = iconObj[1];
if (!iconWidth) {
// The width of this icon is not static.
var icon = this.icons[this.toCamelCase(iconObj[0])];
iconWidth = this._getWidthFromDomElementWidth(icon);
}
return iconWidth;
},
_getWidthFromDomElementWidth: function sb_getWidthFromDomElementWidth(icon) {
var style = window.getComputedStyle(icon);
var iconWidth = icon.clientWidth +
parseInt(style.marginLeft, 10) +
parseInt(style.marginRight, 10);
return iconWidth;
},
_getTimeFormat: function sb_getTimeFormat(timeFormat) {
if (this.settingValues['statusbar.show-am-pm']) {
timeFormat = timeFormat.replace('%p', '<span>%p</span>');
} else {
timeFormat = timeFormat.replace('%p', '').trim();
}
return timeFormat;
},
panelHandler: function sb_panelHandler(evt) {
// Do not forward events if FTU is running
if (FtuLauncher.isFtuRunning()) {
return;
}
// Do not forward events is utility-tray is active
if (UtilityTray.active) {
return;
}
var app = Service.query('getTopMostWindow');
app && app.handleStatusbarTouch(evt, this._cacheHeight);
},
/**
* Show pertinent statusbar icons as we recieve FTU step events.
*/
handleFtuStep: function sb_handleFtuStep(stepHash) {
switch (stepHash) {
case '#languages':
this.createConnectionsElements();
this._updateIconVisibility();
this.addConnectionsListeners();
this.addSettingsListener('ril.data.enabled');
break;
case '#wifi':
this.setActiveWifi(true);
this.addSettingsListener('wifi.enabled');
this._updateIconVisibility();
break;
case '#date_and_time':
this.toggleTimeLabel(true);
this._updateIconVisibility();
break;
}
},
setActive: function sb_setActive(active) {
this.active = active;
this.setActiveBattery(active);
if (active) {
this.setActiveNfc(nfcManager.isActive());
this.addConnectionsListeners();
window.addEventListener('simslot-iccinfochange', this);
window.addEventListener('wifi-statuschange', this);
this.setActiveWifi(true);
window.addEventListener('moznetworkupload', this);
window.addEventListener('moznetworkdownload', this);
this.refreshCallListener();
this.toggleTimeLabel(!this.isLocked());
} else {
this.removeConnectionsListeners();
window.removeEventListener('simslot-iccinfochange', this);
window.removeEventListener('wifi-statuschange', this);
window.removeEventListener('moznetworkupload', this);
window.removeEventListener('moznetworkdownload', this);
this.removeCallListener();
// Always prevent the clock from refreshing itself when the screen is off
this.toggleTimeLabel(false);
}
},
setActiveBattery: function sb_setActiveBattery(active) {
var battery = window.navigator.battery;
if (!battery) {
return;
}
if (active) {
battery.addEventListener('chargingchange', this);
battery.addEventListener('levelchange', this);
battery.addEventListener('statuschange', this);
this.update.battery.call(this);
} else {
battery.removeEventListener('chargingchange', this);
battery.removeEventListener('levelchange', this);
battery.removeEventListener('statuschange', this);
}
},
setActiveWifi: function sb_setActiveWifi(active) {
if (active) {
var wifiManager = window.navigator.mozWifiManager;
if (wifiManager) {
wifiManager.onconnectioninfoupdate = this.update.wifi.bind(this);
}
this.update.wifi.call(this);
}
},
setActiveNfc: function sb_setActiveNfc(active) {
this.nfcActive = active;
this.update.nfc.call(this);
},
update: {
iconData: function sb_updateIconData(aData) {
var dataIconValues = this.settingValues['operatorResources.data.icon'];
if (!dataIconValues) {
return;
}
for (var key in dataIconValues) {
//Change only dataIcon values that actually really know
if (this.mobileDataIconTypes[key]) {
this.mobileDataIconTypes[key] = dataIconValues[key];
}
}
},
label: function sb_updateLabel() {
var conns = window.navigator.mozMobileConnections;
var conn;
// Do not show carrier's name if there are multiple sim cards.
if (conns && conns.length == 1) {
conn = conns[0];
}
var self = this;
var label = this.icons.label;
var previousLabelContent = label.textContent;
var l10nArgs = JSON.parse(label.dataset.l10nArgs || '{}');
if (!conn || !conn.voice || !conn.voice.connected ||
conn.voice.emergencyCallsOnly) {
delete l10nArgs.operator;
label.dataset.l10nArgs = JSON.stringify(l10nArgs);
label.dataset.l10nId = '';
label.textContent = l10nArgs.date;
if (previousLabelContent !== label.textContent) {
updateLabelWidth();
}
return;
}
var operatorInfos = MobileOperator.userFacingInfo(conn);
l10nArgs.operator = operatorInfos.operator;
if (operatorInfos.region) {
l10nArgs.operator += ' ' + operatorInfos.region;
}
label.dataset.l10nArgs = JSON.stringify(l10nArgs);
label.dataset.l10nId = 'statusbarLabel';
label.textContent = navigator.mozL10n.get('statusbarLabel', l10nArgs);
if (previousLabelContent !== label.textContent) {
updateLabelWidth();
}
// Update the width of the date element. Called when the content changed.
function updateLabelWidth() {
self.PRIORITIES.some(function(iconObj) {
if (iconObj[0] === 'label') {
iconObj[1] = self._getWidthFromDomElementWidth(label);
return true;
}
return false;
});
}
},
time: function sb_updateTime(now) {