ginebra2/chrome/bedrockchrome/statusbar.snippet/statusbar.js
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*!
     1 /*!
     2   \file statusbar.js This module contains the StatusBar class.
     2   \file statusbar.js This module contains the StatusBar class.
     3 */
     3 */
     4 
     4 
     5 /*!
     5 /*!
     6   Class to handle displaying and updating the status bar. Only 1 status bar 
     6   Class to handle displaying and updating the status bar. Only 1 status bar
     7   should be created for the browser. This class is not designed to be code
     7   should be created for the browser. This class is not designed to be code
     8   space efficient for creating multiple status bar objects.
     8   space efficient for creating multiple status bar objects.
     9 */
     9 */
    10 function StatusBar()
    10 function StatusBar()
    11 {
    11 {
    38         /*!
    38         /*!
    39           \param title new title
    39           \param title new title
    40         */
    40         */
    41         this.handleTitleChange = function(title)
    41         this.handleTitleChange = function(title)
    42         {
    42         {
    43              if ((!window.views.WebView.currentPageIsSuperPage()) && 
    43              if ((!window.views.WebView.currentPageIsSuperPage()) &&
    44                  window.views.current().type == "webView") {
    44                  window.views.current().type == "webView") {
    45                 if (title != "")
    45                 if (title != "")
    46                     setTitle(title, true);
    46                     setTitle(title, true);
    47             }
    47             }
    48         }
    48         }
    51         /*!
    51         /*!
    52           \param partialUrl new title
    52           \param partialUrl new title
    53         */
    53         */
    54         this.handlePartialUrlChange = function(partialUrl)
    54         this.handlePartialUrlChange = function(partialUrl)
    55         {
    55         {
    56             if ((!window.views.WebView.currentPageIsSuperPage()) && 
    56             if ((!window.views.WebView.currentPageIsSuperPage()) &&
    57                  window.views.current().type == "webView") {
    57                  window.views.current().type == "webView") {
    58                 setTitle(partialUrl, true);
    58                 setTitle(partialUrl, true);
    59             }
    59             }
    60         }
    60         }
    61 
    61 
    62         //! Handles title update in response to current view change signal.
    62         //! Handles title update in response to current view change signal.
    63         this.handleCurrentViewChange = function()
    63         this.handleCurrentViewChange = function()
    64         {
    64         {
    65         	if(window.views.WebView.currentPageIsSuperPage()) {
    65             if (window.views.WebView.currentPageIsSuperPage()) {
    66         	 	   //alert(window.views.WebView.currentSuperPageName());
    66                    //alert(window.views.WebView.currentSuperPageName());
    67         	     if (window.views.WebView.currentSuperPageName() == "BookmarkTreeView") {
    67                  if (window.views.WebView.currentSuperPageName() == "BookmarkTreeView") {
    68                     setTitle(window.localeDelegate.translateText("content_view_menu_bookmarks"), false);
    68                     setTitle(window.localeDelegate.translateText("txt_browser_content_view_menu_nav_bookmarks"), false);
    69                   }
    69                   }
    70                 else if (window.views.WebView.currentSuperPageName() == "BookmarkHistoryView") {
    70                 else if (window.views.WebView.currentSuperPageName() == "BookmarkHistoryView") {
    71                 	     setTitle(window.localeDelegate.translateText("content_view_menu_history"), false);
    71                          setTitle(window.localeDelegate.translateText("txt_browser_content_view_menu_nav_history"), false);
    72                 	   }
    72                        }
    73                 else if (window.views.WebView.currentSuperPageName() == "SettingsView") {
    73                 else if (window.views.WebView.currentSuperPageName() == "SettingsView") {
    74                 	     setTitle(window.localeDelegate.translateText("settings_settings"), false);
    74                          setTitle(window.localeDelegate.translateText("txt_browser_settings_settings"), false);
    75                 }
    75                 }
    76            }
    76            }
    77            else {        	
    77            else {
    78         	     if (window.views.current().type == "webView")  {
    78                  if (window.views.current().type == "webView")  {
    79 	                  /* For new windows, show title as 'New Window' */
    79                       /* For new windows, show title as 'New Window' */
    80 	                if ((window.pageController.currentDocTitle == "") &&
    80                     if ((window.pageController.currentDocTitle == "") && (window.pageController.currentRequestedUrl == "")) {
    81 	                    (window.pageController.currentDocUrl == "")) {
    81                         setTitle(window.localeDelegate.translateText("txt_browser_windows_new_window"), false);
    82 	                    setTitle(window.localeDelegate.translateText("windows_new_window"), false);
    82                     }
    83 	                 }
    83                     else if (window.pageController.currentDocTitle == "") {
    84 	                else if (window.pageController.currentDocTitle == "") {
    84                         if (window.pageController.currentDocUrl == "")  {
    85 	                    setTitle(window.pageController.currentPartialUrl, false);
    85                             setTitle(window.pageController.currentPartialReqUrl, false);
    86 	                  }
    86                         }
    87 	                else {
    87                         else {
    88 	                    setTitle(window.pageController.currentDocTitle, false);
    88                             setTitle(window.pageController.currentPartialUrl, false);
    89 	                   }
    89                         }
    90 	             }
    90                     }
    91 	            else {
    91                     else {
    92 	                if (window.views.current().type == "WindowView")
    92                         setTitle(window.pageController.currentDocTitle, false);
    93 	                    setTitle(window.localeDelegate.translateText("windows_windows"), false);
    93                     }
    94 	            }
    94                  }
    95           	}
    95                 else {
       
    96                     if (window.views.current().type == "WindowView")
       
    97                         setTitle(window.localeDelegate.translateText("txt_browser_windows_windows"), false);
       
    98                 }
       
    99             }
    96          }
   100          }
    97 
   101 
    98     }
   102     }
    99 
   103 
   100     /*!
   104     /*!
   126           }
   130           }
   127 
   131 
   128         //! Handles lock status update in response to current view change signal.
   132         //! Handles lock status update in response to current view change signal.
   129         this.handleCurrentViewChange = function()
   133         this.handleCurrentViewChange = function()
   130         {
   134         {
   131         	  if(window.views.WebView.currentPageIsSuperPage()) {
   135               if (window.views.WebView.currentPageIsSuperPage()) {
   132         	  	this.removeLockIcon();
   136                 this.removeLockIcon();
   133         	  }
   137               }
   134         	  else{
   138               else{
   135 		            if (window.views.current().type == "webView")  {
   139                     if (window.views.current().type == "webView")  {
   136 		                /* Secure icon */
   140                         /* Secure icon */
   137 		                if (window.pageController.secureState)
   141                         if (window.pageController.secureState)
   138 		                    this.showLockIcon();
   142                             this.showLockIcon();
   139 		                else {
   143                         else {
   140 		                    this.removeLockIcon();
   144                             this.removeLockIcon();
   141 		                }
   145                         }
   142 		            }
   146                     }
   143 		            else {
   147                     else {
   144 		                this.removeLockIcon();
   148                         this.removeLockIcon();
   145 		            }
   149                     }
   146             }
   150             }
   147         }
   151         }
   148     }
   152     }
   149 
   153 
   150     /*!
   154     /*!
   165             timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
   169             timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
   166             timeValue += (hours >=12) ? " pm": " am";
   170             timeValue += (hours >=12) ? " pm": " am";
   167             document.getElementById('clock').innerHTML = timeValue;
   171             document.getElementById('clock').innerHTML = timeValue;
   168         }
   172         }
   169     }
   173     }
   170     
   174 
   171     /*!
   175     /*!
   172       Class to handle updating the network status. Only 1 NetworkStatus object 
   176       Class to handle updating the network status. Only 1 NetworkStatus object
   173       should be created for the browser status bar. This class is not designed 
   177       should be created for the browser status bar. This class is not designed
   174       to be code space efficient for creating multiple objects.
   178       to be code space efficient for creating multiple objects.
   175     */
   179     */
   176     function NetworkStatus()
   180     function NetworkStatus()
   177     {
   181     {
   178         // Private Member Variables
   182         // Private Member Variables
   179         var networkIconSrc = new Array(
   183         var networkIconSrc = new Array(
   180             "<img src=\"statusbar.snippet/icons/signal/signal0.png\" alt=\"\">", 
   184             "<img src=\"statusbar.snippet/icons/signal/signal0.png\" alt=\"\">",
   181             "<img src=\"statusbar.snippet/icons/signal/signal0.png\" alt=\"\">", 
   185             "<img src=\"statusbar.snippet/icons/signal/signal0.png\" alt=\"\">",
   182             "<img src=\"statusbar.snippet/icons/signal/signal25.png\" alt=\"\">", 
   186             "<img src=\"statusbar.snippet/icons/signal/signal25.png\" alt=\"\">",
   183             "<img src=\"statusbar.snippet/icons/signal/signal50.png\" alt=\"\">", 
   187             "<img src=\"statusbar.snippet/icons/signal/signal50.png\" alt=\"\">",
   184             "<img src=\"statusbar.snippet/icons/signal/signal75.png\" alt=\"\">", 
   188             "<img src=\"statusbar.snippet/icons/signal/signal75.png\" alt=\"\">",
   185             "<img src=\"statusbar.snippet/icons/signal/signal100.png\" alt=\"\">");
   189             "<img src=\"statusbar.snippet/icons/signal/signal100.png\" alt=\"\">");
   186         var enumNetworkStrengths = new Object();
   190         var enumNetworkStrengths = new Object();
   187         var currentState; // last known signal state - see enumNetworkStrengths
   191         var currentState; // last known signal state - see enumNetworkStrengths
   188         
   192 
   189         enumNetworkStrengths.state = {Offline:0, NoSignal:1, Signal1:2, 
   193         enumNetworkStrengths.state = {Offline:0, NoSignal:1, Signal1:2,
   190             Signal2:3, Signal3:4, Signal4:5}
   194             Signal2:3, Signal3:4, Signal4:5}
   191         
   195 
   192         currentState = enumNetworkStrengths.state.Offline;
   196         currentState = enumNetworkStrengths.state.Offline;
   193         
   197 
   194         //! Encodes the specified string for display in HTML format.
   198         //! Encodes the specified string for display in HTML format.
   195         /*!
   199         /*!
   196           \param str string to encode
   200           \param str string to encode
   197         */
   201         */
   198         // Note: this function doesn't handle partial or double encoding.
   202         // Note: this function doesn't handle partial or double encoding.
   199         function htmlEncode(str)
   203         function htmlEncode(str)
   200         {
   204         {
   201             var s; // function return
   205             var s; // function return
   202             
   206 
   203             // Encode special HTML characters (&, ", <, >, and ').
   207             // Encode special HTML characters (&, ", <, >, and ').
   204             s = str.replace(/&/g, '&amp;');
   208             s = str.replace(/&/g, '&amp;');
   205             s = s.replace(/\"/g, '&quot;');
   209             s = s.replace(/\"/g, '&quot;');
   206             s = s.replace(/</g, '&lt;');
   210             s = s.replace(/</g, '&lt;');
   207             s = s.replace(/>/g, '&gt;');
   211             s = s.replace(/>/g, '&gt;');
   208             s = s.replace(/'/g, '&apos;');
   212             s = s.replace(/'/g, '&apos;');
   209             
   213 
   210             return (s);
   214             return (s);
   211         }
   215         }
   212         
   216 
   213         //! Updates the field width for the network provider name.
   217         //! Updates the field width for the network provider name.
   214         /*!
   218         /*!
   215           \param s network provider name
   219           \param s network provider name
   216         */
   220         */
   217         function updateFieldWidth(s)
   221         function updateFieldWidth(s)
   223                 rulerSpan.innerHTML = s;
   227                 rulerSpan.innerHTML = s;
   224                 fieldWidth = rulerSpan.offsetWidth + 10; // add 10 pixel padding
   228                 fieldWidth = rulerSpan.offsetWidth + 10; // add 10 pixel padding
   225                 document.getElementById('provider').width = fieldWidth + "px";
   229                 document.getElementById('provider').width = fieldWidth + "px";
   226             }
   230             }
   227         }
   231         }
   228         
   232 
   229         //! Converts the specified strength using a scale of -1 to 100 to the 
   233         //! Converts the specified strength using a scale of -1 to 100 to the
   230         //! appropriate signal level state.
   234         //! appropriate signal level state.
   231         /*!
   235         /*!
   232           \param strength signal strength to convert
   236           \param strength signal strength to convert
   233         */
   237         */
   234         function convertStrengthToState(strength)
   238         function convertStrengthToState(strength)
   235         {
   239         {
   236             var state;
   240             var state;
   237             
   241 
   238             if (strength < 0) // unknown network mode or error
   242             if (strength < 0) // unknown network mode or error
   239                 state = enumNetworkStrengths.state.Offline;
   243                 state = enumNetworkStrengths.state.Offline;
   240             else if (strength == 0) // no signal
   244             else if (strength == 0) // no signal
   241                 state = enumNetworkStrengths.state.NoSignal;
   245                 state = enumNetworkStrengths.state.NoSignal;
   242             else if (strength < 40) // less than 40/100
   246             else if (strength < 40) // less than 40/100
   245                 state = enumNetworkStrengths.state.Signal2;
   249                 state = enumNetworkStrengths.state.Signal2;
   246             else if (strength < 90) // less than 90/100
   250             else if (strength < 90) // less than 90/100
   247                 state = enumNetworkStrengths.state.Signal3;
   251                 state = enumNetworkStrengths.state.Signal3;
   248             else // 90/100 or higher - full signal
   252             else // 90/100 or higher - full signal
   249                 state = enumNetworkStrengths.state.Signal4;
   253                 state = enumNetworkStrengths.state.Signal4;
   250             
   254 
   251             return (state);
   255             return (state);
   252         }
   256         }
   253         
   257 
   254         //! Changes the displayed network provider name.
   258         //! Changes the displayed network provider name.
   255         /*!
   259         /*!
   256           \param networkName New network provider name to display
   260           \param networkName New network provider name to display
   257         */
   261         */
   258         function changeName(networkName)
   262         function changeName(networkName)
   266 
   270 
   267             // repaint if status bar exists (first call to this function, it doesn't)
   271             // repaint if status bar exists (first call to this function, it doesn't)
   268             if (window.snippets.StatusBarChromeId)
   272             if (window.snippets.StatusBarChromeId)
   269                 window.snippets.StatusBarChromeId.repaint();
   273                 window.snippets.StatusBarChromeId.repaint();
   270         }
   274         }
   271         
   275 
   272         //! Gets the appropriate image tag HTML string for the current network 
   276         //! Gets the appropriate image tag HTML string for the current network
   273         //! signal strength.
   277         //! signal strength.
   274         this.getInitialStrengthImgTag = function()
   278         this.getInitialStrengthImgTag = function()
   275         {
   279         {
   276             var strength = window.deviceDelegate.networkSignalStrength;
   280            var strength = window.networkDelegate.networkSignalStrength;
   277             
   281 
   278             currentState = convertStrengthToState(strength);
   282            currentState = convertStrengthToState(strength);
   279             return (networkIconSrc[currentState]);
   283            return (networkIconSrc[currentState]);
   280         }
   284         }
   281         
   285 
   282         //! Displays the initial network name.
   286         //! Displays the initial network name.
   283         this.showInitialNetworkName = function()
   287         this.showInitialNetworkName = function()
   284         {
   288         {
   285             // if we went offline, set the provider name to "offline"
   289             // if we went offline, set the provider name to "offline"
   286             if (currentState == enumNetworkStrengths.state.Offline)
   290             if (currentState == enumNetworkStrengths.state.Offline)
   287                 changeName(window.localeDelegate.translateText("offline"));
   291                 changeName(window.localeDelegate.translateText("txt_browser_offline"));
   288             else
   292             else
   289                 changeName(window.deviceDelegate.networkName);
   293                 changeName(window.networkDelegate.networkName);
   290         }
   294         }
   291         
   295 
   292         //! Handles the signal strength change signal.
   296         //! Handles the signal strength change signal.
   293         /*!
   297         /*!
   294           \param strength new signal strength
   298           \param strength new signal strength
   295         */
   299         */
   296         this.handleSignalStrengthChange = function(strength)
   300         this.handleSignalStrengthChange = function(strength)
   297         {
   301         {
   298             var state = convertStrengthToState(strength);
   302             var state = convertStrengthToState(strength);
   299             
   303 
   300             // only interested in state changes
   304             // only interested in state changes
   301             if (currentState != state) {
   305             if (currentState != state) {
   302                 lastState = currentState; // save former state
   306                 lastState = currentState; // save former state
   303                 // update current state and network icon
   307                 // update current state and network icon
   304                 currentState = state;
   308                 currentState = state;
   305                 document.getElementById('strength').innerHTML = 
   309                 document.getElementById('strength').innerHTML =
   306                     networkIconSrc[currentState];
   310                     networkIconSrc[currentState];
   307                 window.snippets.StatusBarChromeId.repaint();
   311                 window.snippets.StatusBarChromeId.repaint();
   308                 
   312 
   309                 // if we went offline, change the provider name to "offline"
   313                 // if we went offline, change the provider name to "offline"
   310                 if (currentState == enumNetworkStrengths.state.Offline)
   314                 if (currentState == enumNetworkStrengths.state.Offline)
   311                     changeName(window.localeDelegate.translateText("offline"));
   315                     changeName(window.localeDelegate.translateText("txt_browser_offline"));
   312                 // if we just came online, get and update provider name
   316                 // if we just came online, get and update provider name
   313                 else if (lastState == enumNetworkStrengths.state.Offline)
   317                 else if (lastState == enumNetworkStrengths.state.Offline)
   314                     changeName(window.deviceDelegate.networkName);
   318                     changeName(window.networkDelegate.networkName);
   315             }
   319             }
   316         }
   320         }
   317         
   321 
   318         //! Handles the network name change signal.
   322         //! Handles the network name change signal.
   319         /*!
   323         /*!
   320           \param networkName new network name
   324           \param networkName new network name
   321         */
   325         */
   322         this.handleNameChange = function(networkName)
   326         this.handleNameChange = function(networkName)
   324             // Offline network name is hard coded.
   328             // Offline network name is hard coded.
   325             if (currentState != enumNetworkStrengths.state.Offline)
   329             if (currentState != enumNetworkStrengths.state.Offline)
   326                 changeName(networkName);
   330                 changeName(networkName);
   327         }
   331         }
   328     }
   332     }
   329     
   333 
   330     // class property (i.e. property of the class constructor function)
   334     // class property (i.e. property of the class constructor function)
   331     NetworkStatus.MAX_NAME_LEN = 20; // max length of provider name
   335     NetworkStatus.MAX_NAME_LEN = 20; // max length of provider name
   332     
   336 
   333     /*!
   337     /*!
   334       Class to handle updating the battery level. Only 1 BatteryStatus object 
   338       Class to handle updating the battery level. Only 1 BatteryStatus object
   335       should be created for the browser status bar. This class is not designed 
   339       should be created for the browser status bar. This class is not designed
   336       to be code space efficient for creating multiple objects.
   340       to be code space efficient for creating multiple objects.
   337     */
   341     */
   338     function BatteryStatus()
   342     function BatteryStatus()
   339     {
   343     {
   340         // Private Member Variables
   344         // Private Member Variables
   341         var batteryIconSrc = new Array(
   345         var batteryIconSrc = new Array(
   342             "<img src=\"statusbar.snippet/icons/battery/batt10.png\" alt=\"\">", 
   346             "<img src=\"statusbar.snippet/icons/battery/batt10.png\" alt=\"\">",
   343             "<img src=\"statusbar.snippet/icons/battery/batt20.png\" alt=\"\">", 
   347             "<img src=\"statusbar.snippet/icons/battery/batt20.png\" alt=\"\">",
   344             "<img src=\"statusbar.snippet/icons/battery/batt30.png\" alt=\"\">", 
   348             "<img src=\"statusbar.snippet/icons/battery/batt30.png\" alt=\"\">",
   345             "<img src=\"statusbar.snippet/icons/battery/batt40.png\" alt=\"\">", 
   349             "<img src=\"statusbar.snippet/icons/battery/batt40.png\" alt=\"\">",
   346             "<img src=\"statusbar.snippet/icons/battery/batt50.png\" alt=\"\">", 
   350             "<img src=\"statusbar.snippet/icons/battery/batt50.png\" alt=\"\">",
   347             "<img src=\"statusbar.snippet/icons/battery/batt60.png\" alt=\"\">", 
   351             "<img src=\"statusbar.snippet/icons/battery/batt60.png\" alt=\"\">",
   348             "<img src=\"statusbar.snippet/icons/battery/batt70.png\" alt=\"\">", 
   352             "<img src=\"statusbar.snippet/icons/battery/batt70.png\" alt=\"\">",
   349             "<img src=\"statusbar.snippet/icons/battery/batt80.png\" alt=\"\">", 
   353             "<img src=\"statusbar.snippet/icons/battery/batt80.png\" alt=\"\">",
   350             "<img src=\"statusbar.snippet/icons/battery/batt90.png\" alt=\"\">", 
   354             "<img src=\"statusbar.snippet/icons/battery/batt90.png\" alt=\"\">",
   351             "<img src=\"statusbar.snippet/icons/battery/batt100.png\" alt=\"\">",
   355             "<img src=\"statusbar.snippet/icons/battery/batt100.png\" alt=\"\">",
   352             "<img src=\"statusbar.snippet/icons/battery/batt100_charging.png\" alt=\"\">");
   356             "<img src=\"statusbar.snippet/icons/battery/batt100_charging.png\" alt=\"\">");
   353         var enumBatteryLevels = new Object();
   357         var enumBatteryLevels = new Object();
   354         
   358 
   355         enumBatteryLevels.state = {Level10:0, Level20:1, Level30:2, Level40:3, 
   359         enumBatteryLevels.state = {Level10:0, Level20:1, Level30:2, Level40:3,
   356             Level50:4, Level60:5, Level70:6, Level80:7, Level90:8, Level100:9, 
   360             Level50:4, Level60:5, Level70:6, Level80:7, Level90:8, Level100:9,
   357             LevelCharging:10}
   361             LevelCharging:10}
   358         
   362 
   359         //! Converts the specified battery level (1 to 100) to a battery state.
   363         //! Converts the specified battery level (1 to 100) to a battery state.
   360         /*!
   364         /*!
   361           \param level battery level (1 to 100)
   365           \param level battery level (1 to 100)
   362         */
   366         */
   363         function convertLevelToState(level)
   367         function convertLevelToState(level)
   364         {
   368         {
   365             var state;
   369             var state;
   366             
   370 
   367             // Don't report battery level as being any higher than it actually is.
   371             // Don't report battery level as being any higher than it actually is.
   368             // Unless it is under 10% in which case user story specifies one bar be displayed.
   372             // Unless it is under 10% in which case user story specifies one bar be displayed.
   369             if (window.deviceDelegate.batteryCharging)
   373             if (window.deviceDelegate.batteryCharging)
   370                 state = enumBatteryLevels.state.LevelCharging;
   374                 state = enumBatteryLevels.state.LevelCharging;
   371             else if (level < 20) // less than 20% full
   375             else if (level < 20) // less than 20% full
   386                 state = enumBatteryLevels.state.Level80;
   390                 state = enumBatteryLevels.state.Level80;
   387             else if (level < 100) // less than 100% full
   391             else if (level < 100) // less than 100% full
   388                 state = enumBatteryLevels.state.Level90;
   392                 state = enumBatteryLevels.state.Level90;
   389             else // 100% full
   393             else // 100% full
   390                 state = enumBatteryLevels.state.Level100;
   394                 state = enumBatteryLevels.state.Level100;
   391             
   395 
   392             return (state);
   396             return (state);
   393         }
   397         }
   394         
   398 
   395         //! Gets the initial battery level image tag HTML string.
   399         //! Gets the initial battery level image tag HTML string.
   396         this.getInitialLevelImgTag = function()
   400         this.getInitialLevelImgTag = function()
   397         {
   401         {
   398             return (batteryIconSrc[convertLevelToState(
   402             return (batteryIconSrc[convertLevelToState(
   399                 window.deviceDelegate.batteryLevel)]);
   403                 window.deviceDelegate.batteryLevel)]);
   400         }
   404         }
   401         
   405 
   402         //! Handles battery level change signal.
   406         //! Handles battery level change signal.
   403         /*!
   407         /*!
   404           \param level new battery level
   408           \param level new battery level
   405         */
   409         */
   406         this.handleLevelChange = function(level)
   410         this.handleLevelChange = function(level)
   407         {
   411         {
   408             document.getElementById('battery').innerHTML = 
   412             document.getElementById('battery').innerHTML =
   409                 batteryIconSrc[convertLevelToState(level)];
   413                 batteryIconSrc[convertLevelToState(level)];
   410             window.snippets.StatusBarChromeId.repaint();
   414             window.snippets.StatusBarChromeId.repaint();
   411         }
   415         }
   412     }
   416     }
   413 
   417 
   446     var sbLockStatus = new LockStatus(); //!< status bar lock status
   450     var sbLockStatus = new LockStatus(); //!< status bar lock status
   447     var sbClock = new Clock(); //!< status bar clock
   451     var sbClock = new Clock(); //!< status bar clock
   448     var sbNetworkStatus = new NetworkStatus(); //!< status bar network status
   452     var sbNetworkStatus = new NetworkStatus(); //!< status bar network status
   449     var sbBatteryStatus = new BatteryStatus(); //!< status bar battery status
   453     var sbBatteryStatus = new BatteryStatus(); //!< status bar battery status
   450     var sbDownloadStatus = new DownloadStatus(); //!< status bar download status
   454     var sbDownloadStatus = new DownloadStatus(); //!< status bar download status
   451     
   455 
   452     // Private Methods
   456     // Private Methods
   453     //! Write status bar HTML code to document.
   457     //! Write status bar HTML code to document.
   454     function _statusbar_write()
   458     function _statusbar_write()
   455     {
   459     {
   456         var downloadHTML = '';
   460         var downloadHTML = '';
   469               '<td class="centeralign" id="clock">time: &nbsp;</td>' +
   473               '<td class="centeralign" id="clock">time: &nbsp;</td>' +
   470               '<td class="rightalign" id="battery">' + sbBatteryStatus.getInitialLevelImgTag() + '</td>'+
   474               '<td class="rightalign" id="battery">' + sbBatteryStatus.getInitialLevelImgTag() + '</td>'+
   471             '</tr>'+
   475             '</tr>'+
   472             '</table>'+
   476             '</table>'+
   473             // ruler span used for getting the width of network name
   477             // ruler span used for getting the width of network name
   474             // style included here because style sheet not applied early 
   478             // style included here because style sheet not applied early
   475             // enough for sbNetworkStatus.showInitialNetworkName call below 
   479             // enough for sbNetworkStatus.showInitialNetworkName call below
   476             // which needs text width which depends on font
   480             // which needs text width which depends on font
   477             '<span id="sbruler" style="font-size:12px;font-weight:bold;visibility:hidden;"></span>';
   481             '<span id="sbruler" style="font-size:12px;font-weight:bold;visibility:hidden;"></span>';
   478         document.write(html);
   482         document.write(html);
   479         
   483 
   480         sbNetworkStatus.showInitialNetworkName();
   484         sbNetworkStatus.showInitialNetworkName();
   481     }
   485     }
   482 
   486 
   483     // StatusBar Constructor
   487     // StatusBar Constructor
   484     _statusbar_write(); // write status bar HTML code to document
   488     _statusbar_write(); // write status bar HTML code to document
   485     sbClock.showtime(); // display current time on status bar
   489     sbClock.showtime(); // display current time on status bar
   486     // Update displayed time every 30 seconds.
   490     // Update displayed time every 30 seconds.
   487     setInterval(function() {sbClock.showtime();}, 30000);
   491     setInterval(function() {sbClock.showtime();}, 30000);
   488     
   492 
   489     // Note that in the slots below the "this" object is never used directly.
   493     // Note that in the slots below the "this" object is never used directly.
   490     // This is because they don't have access to "this" as they are invoked 
   494     // This is because they don't have access to "this" as they are invoked
   491     // as functions rather than as methods.
   495     // as functions rather than as methods.
   492     
   496 
   493     // Connect page controller signals to slots.
   497     // Connect page controller signals to slots.
   494     window.pageController.titleChanged.connect(
   498     window.pageController.titleChanged.connect(
   495         function(title) {sbTitle.handleTitleChange(title);});
   499         function(title) {sbTitle.handleTitleChange(title);});
   496     window.pageController.partialUrlChanged.connect(
   500     window.pageController.partialUrlChanged.connect(
   497         function(partialUrl) {sbTitle.handlePartialUrlChange(partialUrl);});
   501         function(partialUrl) {sbTitle.handlePartialUrlChange(partialUrl);});
   498     window.pageController.hideSecureIcon.connect(
   502     window.pageController.hideSecureIcon.connect(
   499         function() {sbLockStatus.removeLockIcon();});
   503         function() {sbLockStatus.removeLockIcon();});
   500     window.pageController.showSecureIcon.connect(
   504     window.pageController.showSecureIcon.connect(
   501         function() {sbLockStatus.showLockIcon();});
   505         function() {sbLockStatus.showLockIcon();});
   502     
   506 
   503     // Connect view manager signals to slots.
   507     // Connect view manager signals to slots.
   504     window.views.currentViewChanged.connect(
   508     window.views.currentViewChanged.connect(
   505         function() {
   509         function() {
   506             sbTitle.handleCurrentViewChange();
   510             sbTitle.handleCurrentViewChange();
   507             sbLockStatus.handleCurrentViewChange();
   511             sbLockStatus.handleCurrentViewChange();
   508         }
   512         }
   509     );
   513     );
   510     
   514 
   511     window.ViewStack.currentViewChanged.connect(
   515     window.ViewStack.currentViewChanged.connect(
   512         function() {
   516         function() {
   513             sbTitle.handleCurrentViewChange();
   517             sbTitle.handleCurrentViewChange();
   514             sbLockStatus.handleCurrentViewChange();
   518             sbLockStatus.handleCurrentViewChange();
   515         }
   519         }
   516     );
   520     );
   517     
   521 
   518     // Connect device delegate signals to slots.
   522     // Connect device delegate signals to slots.
   519     window.deviceDelegate.batteryLevelChanged.connect(
   523     window.deviceDelegate.batteryLevelChanged.connect(
   520         function(level) {sbBatteryStatus.handleLevelChange(level);});
   524        function(level) {sbBatteryStatus.handleLevelChange(level);});
   521     window.deviceDelegate.networkSignalStrengthChanged.connect(
   525     window.networkDelegate.networkSignalStrengthChanged.connect(
   522         function(strength) {sbNetworkStatus.handleSignalStrengthChange(strength);});
   526         function(strength) {sbNetworkStatus.handleSignalStrengthChange(strength);});
   523     window.deviceDelegate.networkNameChanged.connect(
   527     window.networkDelegate.networkNameChanged.connect(
   524         function(networkName) {sbNetworkStatus.handleNameChange(networkName);});
   528         function(networkName) {sbNetworkStatus.handleNameChange(networkName);});
       
   529 
       
   530     var mydiv = document.getElementById("StatusBarChromeId");
       
   531     mydiv.addEventListener("mouseup", handleMouseUp, true);
       
   532     mydiv.addEventListener("keyup", handleMouseUp, true);
       
   533 
       
   534     function handleMouseUp() {
       
   535         if (window.views.current().type == "webView" &&
       
   536             !window.views.WebView.currentPageIsSuperPage()) {
       
   537             window.chrome.slideView(100);
       
   538             window.views.WebView.scrollTo(0,0);
       
   539         }
       
   540     }
       
   541 
   525 }
   542 }