ginebra2/chrome/bedrockchrome/windowcount.snippet/windowcount.js
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 16 3c88a81ff781
--- a/ginebra2/chrome/bedrockchrome/windowcount.snippet/windowcount.js	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/chrome/bedrockchrome/windowcount.snippet/windowcount.js	Tue Jun 29 00:46:29 2010 -0400
@@ -5,7 +5,7 @@
  * Note: When overlaying the snippet there were some issues repainting when the background was set to none
  * and hence a table with three cells are being used - the width of first and last cells match the
  * area we need to see from the status bar and their backgrounds are set to none. The middle cell is
- * used to display the circles and its bakground changes between black and white based 
+ * used to display the circles and its bakground changes between black and white based
  * on the display mode.
  */
 
@@ -14,23 +14,23 @@
 //
 function WindowCountBar(id)
 {
-   
+
     this.id = id;
 
-    this.begin = 
+    this.begin =
         '<table id="wcrow" align=center   >'+
         '<tr>'+
         '<td id="wcfirst" style="background-color: transparent;">'+
         '</td>'+
         '<td  id="wccontent">';
 
-    this.filledimg = 
+    this.filledimg =
         '<img class="wcicon" src="windowcount.snippet/icons/filledcircle.png" >' ;
 
-    this.emptyimg = 
+    this.emptyimg =
         '<img class="wcicon" src="windowcount.snippet/icons/emptycircle.png" >' ;
 
-    this.end = 
+    this.end =
         '</td>'+
         '<td id="wclast" style="background-color: transparent;">'+
         '</td>'+
@@ -57,10 +57,18 @@
 
     this.wcUpdateWindowHtml = function() {
 
-        window.app.debug("WC: wcUpdateWindowHtml "+ window.pageController.pageCount());
+        //window.app.debug("WC: wcUpdateWindowHtml "+ window.pageController.pageCount());
+        //If we are in webview get page count from pageController
+        if (window.views.current().type == "webView" ) {
+            count = window.pageController.pageCount();
+        }
+        else  if (window.views.current().type == "WindowView" ){
+            count = window.views.WindowView.pageCount();
+        }
 
+        //app.debug("wcUpdateWindowHtml: View " + window.views.current().type  + " Count : " + count);
         /* Generate html based on the number of windows open */
-        switch(window.pageController.pageCount()) {
+        switch (count) {
             case 1:
                 this.wcOneWindow();
                 break;
@@ -86,10 +94,10 @@
     this.wcOneWindow = function() {
         var htmlText = '' +
                 this.begin + this.filledimg + this.end;
- 
+
         var el = document.getElementById("wcrow");
         if (el) {
-            el.innerHTML = htmlText; 
+            el.innerHTML = htmlText;
         }
         else {
             document.write(htmlText);
@@ -121,7 +129,7 @@
     this.wcFiveWindows = function() {
         var htmlText = '' +
                 this.begin + this.emptyimg + this.emptyimg + this.emptyimg + this.emptyimg + this.emptyimg + this.end;
-    
+
         this.setHtmlText(htmlText)
     }
 
@@ -129,7 +137,7 @@
 
         var el = document.getElementById("wcrow");
         if (el) {
-            el.innerHTML = htmlText; 
+            el.innerHTML = htmlText;
         }
         else {
             document.write(htmlText);
@@ -140,13 +148,21 @@
     this.setCurrentIndex  = function(){
         var el = document.getElementById("wcrow");
         Icons = el.getElementsByTagName("img");
- 
-        Icons[window.pageController.currentPageIndex].setAttribute('src', "windowcount.snippet/icons/filledcircle.png");
+
+        if (window.views.current().type == "webView" ) {
+            index = window.pageController.currentPageIndex();
+        }
+        else  if (window.views.current().type == "WindowView" ){
+            index = window.views.WindowView.currentPageIndex();
+        }
+
+        //app.debug("setCurrentIndex: View " + window.views.current().type  + " Index : " + index);
+        Icons[index].setAttribute('src', "windowcount.snippet/icons/filledcircle.png");
     }
 
 
     this.setSnippetPosition = function() {
-    
+
         if (window.snippets.WindowCountBarId ) {
             mode = window.chrome.displayMode;
             if (mode == "portrait") {
@@ -166,14 +182,14 @@
      * display mode
      */
     this.setProps = function() {
-    
+
         var leftW = document.getElementById("strength").offsetWidth +
                     document.getElementById("provider").offsetWidth +
                     document.getElementById("title").offsetWidth;
 
         var rightW = document.getElementById("clock").offsetWidth +
                     document.getElementById("battery").offsetWidth;
-   
+
         if (window.snippets.WindowCountBarId) {
             if (window.chrome.displayMode == "portrait" ) {
                 // for some reason setting width to 0 doesn't work
@@ -186,13 +202,20 @@
             }
         }
     }
-    
+
     function updateWCSnippet(mode) {
         el = document.getElementById('WindowCountBarId').wcChrome;
         el.setSnippetPosition();
         el.setProps();
     }
 
+    function onPageAdded() {
+
+        //app.debug("onPageAdded: Count " + window.views.WindowView.pageCount());
+        document.getElementById('WindowCountBarId').wcChrome.wcUpdateWindowHtml();
+        //app.debug("Leave onPageAdded ");
+    }
+
     /* Initialize */
     this.InitWCBar();
 
@@ -201,8 +224,9 @@
         function() {
           el = document.getElementById('WindowCountBarId').wcChrome;
           el.setSnippetPosition();
-          el.wcUpdateWindowHtml();
+          //el.wcUpdateWindowHtml();
           window.chrome.aspectChanged.connect(updateWCSnippet);
+          window.views.WindowView.pageAdded.connect(onPageAdded);
         }
     );