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