ginebra2/chrome/bedrockchrome/toolbar.snippet/toolbar.js
changeset 5 0f2326c2a325
parent 1 b0dd75e285d2
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /* create all functions with toolbar */
       
     2 
       
     3 //
       
     4 // INIT the webView Toolbar
       
     5 //
       
     6 
       
     7 function ToolbarSnippet()
       
     8 {
       
     9   this.setContainerWidth = function(leftid, rightid, id) {
       
    10       var lcbWidth = document.getElementById(leftid).offsetWidth;
       
    11       var rcbWidth = document.getElementById(rightid).offsetWidth;
       
    12       var totalW =   window.chrome.displaySize.width;
       
    13       
       
    14       var fcWidth = totalW - lcbWidth - rcbWidth;
       
    15       var fcWidthPercent = (fcWidth/totalW) * 100 ;
       
    16       fcWidthPercent = fcWidthPercent.toFixed(2);
       
    17       
       
    18       el =  document.getElementById(id);
       
    19       el.style.width = fcWidthPercent +"%";
       
    20   }
       
    21 
       
    22   /*
       
    23   ** Main View Buttons
       
    24   */
       
    25   function LeftCornerButton() {
       
    26       this.writeButton = function() {
       
    27           document.write('<img  class="webToolbarBtn"id="backButton" src="toolbar.snippet/icons/icon_back.png">');       
       
    28       }
       
    29   }
       
    30   function RightCornerButton() { 
       
    31       this.writeButton = function() {
       
    32           document.write('<img  class="webToolbarBtn"id="mvButton">');  
       
    33 
       
    34 		  new ToggleButton("mvButton", "MostVisitedViewId",
       
    35                          "toolbar.snippet/icons/icon_mostvisited.png",
       
    36                          "toolbar.snippet/icons/icon_mostvisited_pressed.png",
       
    37                          "toolbar.snippet/icons/icon_mostvisited_disabled.png",
       
    38                          _activateMostVisited);                                       
       
    39       }
       
    40       function _activateMostVisited() {
       
    41           window.snippets.ZoomBarId.hide(); // hide Zoom Bar while showing most visited
       
    42 		  window.snippets.MostVisitedViewId.toggleVisibility();
       
    43       }      
       
    44   }
       
    45 
       
    46   function WinButton() {
       
    47     this.writeButton = function() {
       
    48         document.write('<img class="webToolbarBtn" id="winButton">');        
       
    49         new SimpleButton("winButton",
       
    50                          "toolbar.snippet/icons/icon_windows1.png",
       
    51                          "toolbar.snippet/icons/icon_windows1_pressed.png",
       
    52                          "toolbar.snippet/icons/icon_windows1.png",
       
    53                          _activateWindows);
       
    54     }
       
    55     this.changeWindowIcon = function() {
       
    56         var index = window.pageController.pageCount();
       
    57         var base = "toolbar.snippet/icons/icon_windows" + index;
       
    58         
       
    59         //window.app.debug("BASE "+ base);
       
    60         document.getElementById('winButton').button.updateImages(base + ".png",
       
    61                                                                  base + "_pressed.png",
       
    62                                                                  base + ".png");
       
    63     }
       
    64 
       
    65     function _activateWindows() {
       
    66 	  window.snippets.ZoomBarId.hide(); // hide Zoom Bar while showing windows view
       
    67 	  window.snippets.MostVisitedViewId.hide();
       
    68       window.app.debug("_activateWindows");
       
    69       if(window.views.current().objectName == "WebView") {
       
    70         window.ViewStack.switchView("WindowView", "WebView");
       
    71       }
       
    72       else {
       
    73         window.ViewStack.switchView("WebView", "WindowView");
       
    74       }   
       
    75     }
       
    76   }
       
    77 
       
    78   function MenuButton() {
       
    79     this.writeButton = function() {
       
    80         document.write('<img class="webToolbarBtn" id="contextMenuButton">');
       
    81         new ToggleButton("contextMenuButton", "ContextMenuId",
       
    82                          "toolbar.snippet/icons/icon_menu.png",
       
    83                          "toolbar.snippet/icons/icon_menu_pressed.png",
       
    84                          "toolbar.snippet/icons/icon_menu_disabled.png",
       
    85                          _contextMenuF);
       
    86    }
       
    87 
       
    88    function _contextMenuF () {
       
    89        window.app.debug("_contextMenuF");
       
    90        if(window.snippets.ContextMenuId.dontShow)
       
    91        {
       
    92            window.snippets.ContextMenuId.dontShow = false;
       
    93            return;
       
    94        }
       
    95        
       
    96        window.snippets.ZoomBarId.hide(); // Don't show Zoom Bar while showing Context Menu
       
    97        window.snippets.MostVisitedViewId.hide();
       
    98        window.snippets.ContextMenuId.repaint();
       
    99        window.snippets.ContextMenuId.zValue = 10;
       
   100        window.snippets.ContextMenuId.show();
       
   101    }
       
   102   }
       
   103   
       
   104   /*!
       
   105     Class to handle displaying the zoom button. The zoom button provides access
       
   106     to the zoom bar.
       
   107   */
       
   108   function ZoomButton() {
       
   109       this.writeButton = function() {
       
   110           document.write('<img class="webToolbarBtn" id="zoomBarButton">');
       
   111           
       
   112           // create simple button to access zoom bar
       
   113           this.theButton = new ToggleButton("zoomBarButton", "ZoomBarId",
       
   114                        "toolbar.snippet/icons/icon_zoom.png",
       
   115                        "toolbar.snippet/icons/icon_zoom_pressed.png",
       
   116                        "toolbar.snippet/icons/icon_zoom_disabled.png",
       
   117                        _zoomBarF);
       
   118     }
       
   119     
       
   120     //! Handles zoom button presses.
       
   121     function _zoomBarF()
       
   122     {
       
   123         window.snippets.MostVisitedViewId.hide();
       
   124         // toggle visibility of zoom bar
       
   125         window.snippets.ZoomBarId.toggleVisibility();
       
   126     }
       
   127     
       
   128     //! Set enabled state of zoom button.
       
   129     /*!
       
   130       \param enabled new enabled state of button
       
   131     */
       
   132     this.setEnabled = function(enabled)
       
   133     {
       
   134       this.theButton.setEnabled(enabled);
       
   135     }
       
   136   } //end of class ZoomButton
       
   137 
       
   138   /*
       
   139   ** Windows View Toolbar Buttons
       
   140   */
       
   141   function WinBackButton() {
       
   142       this.writeButton = function() {
       
   143           window.app.debug("WinBackButton:writeButton");
       
   144           document.write('<img class="webToolbarBtn" id="goBacktoWebViewWin">');
       
   145           new SimpleButton("goBacktoWebViewWin",
       
   146                            "toolbar.snippet/icons/icon_back.png",
       
   147                            "toolbar.snippet/icons/icon_back_pressed.png",
       
   148                            "toolbar.snippet/icons/icon_back.png",
       
   149                            _goBackFromWindowView);
       
   150       }
       
   151       _goBackFromWindowView = function() {
       
   152           window.ViewStack.switchView("WebView", "WindowView");
       
   153       }
       
   154   }
       
   155   function WinAddButton() {
       
   156       this.writeButton = function() {
       
   157           document.write('<img class="webToolbarBtn" id="addWindow" src="toolbar.snippet/icons/icon_windowsadd.png">');
       
   158       }
       
   159   }
       
   160   
       
   161   /*
       
   162   ** Bookmarks Toolbar Buttons
       
   163   */
       
   164   function BMBackButton() {
       
   165       this.writeButton = function() {
       
   166           document.write('<img  class="webToolbarBtn" id="goBacktoWebViewBM">');
       
   167           new SimpleButton("goBacktoWebViewBM",
       
   168                            "toolbar.snippet/icons/icon_back.png",
       
   169                            "toolbar.snippet/icons/icon_back_pressed.png",
       
   170                            "toolbar.snippet/icons/icon_back.png",
       
   171                            _goBackFromBookmarkView);
       
   172       }
       
   173       _goBackFromBookmarkView = function() {
       
   174           window.views.WebView.showNormalPage();		
       
   175           window.ViewStack.switchView( "WebView","BookmarkTreeView");
       
   176           views.WebView.gesturesEnabled = true;
       
   177       }
       
   178   }
       
   179   function BMAddButton() { 
       
   180       this.writeButton = function() {
       
   181           document.write('<img  class="webToolbarBtn"id="addToBookMark">');
       
   182           new SimpleButton("addToBookMark",
       
   183 			               "toolbar.snippet/icons/icon_addbookmark.png",
       
   184 			               "toolbar.snippet/icons/icon_addbookmark_pressed.png",
       
   185 			               "toolbar.snippet/icons/icon_addbookmark_disabled.png",
       
   186 			               _showBookmarkAddDialog);
       
   187       }
       
   188       _showBookmarkAddDialog = function() {
       
   189           launchBookmarkAddDialog();
       
   190       }
       
   191   }
       
   192 
       
   193   /*
       
   194   ** Recent URLs Toolbar Buttons
       
   195   */
       
   196   function RecentURLBackButton() {
       
   197       this.writeButton = function() {
       
   198           document.write('<img  class="webToolbarBtn" id="goBacktoWebViewRecent">');
       
   199           new SimpleButton("goBacktoWebViewRecent",
       
   200                            "toolbar.snippet/icons/icon_back.png",
       
   201                            "toolbar.snippet/icons/icon_back_pressed.png",
       
   202                            "toolbar.snippet/icons/icon_back.png",
       
   203                            _goBackFromRecentUrlView);
       
   204       }			                          
       
   205 	  _goBackFromRecentUrlView = function() {
       
   206           window.views.WebView.showNormalPage();
       
   207           window.ViewStack.switchView("WebView", "BookmarkHistoryView");
       
   208       }
       
   209   }
       
   210   function RecentURLClearallButton() {
       
   211       this.writeButton = function() {
       
   212           document.write('<img  class="webToolbarBtn"id="clearHistory">');
       
   213           new SimpleButton("clearHistory",
       
   214                            "toolbar.snippet/icons/icon_clearall.png",
       
   215                            "toolbar.snippet/icons/icon_clearall_pressed.png",
       
   216                            "toolbar.snippet/icons/icon_clearall_disabled.png",
       
   217                            _clearHistory);
       
   218 	  }
       
   219       _clearHistory = function() {
       
   220     	  if(confirm("Are you sure you want to permanently delete your history?"))
       
   221           {
       
   222               window.bookmarksManager.clearHistory();
       
   223               window.views.WebView.reload();
       
   224           }
       
   225       }
       
   226   }
       
   227 
       
   228 	
       
   229 
       
   230   /*
       
   231   ** Settings Toolbar Buttons
       
   232   */
       
   233   function SettingsBackButton() {
       
   234     this.writeButton = function() {
       
   235         document.write('<img  class="webToolbarBtn" id="goBacktoWebViewSettings">');
       
   236         new SimpleButton("goBacktoWebViewSettings",
       
   237                          "toolbar.snippet/icons/icon_back.png",
       
   238                          "toolbar.snippet/icons/icon_back_pressed.png",
       
   239                          "toolbar.snippet/icons/icon_back.png",
       
   240                          _goBackFromSettingsView);
       
   241     }			
       
   242     
       
   243       
       
   244                               
       
   245     _goBackFromSettingsView = function() {
       
   246         window.views.WebView.showNormalPage();
       
   247         window.ViewStack.switchView("WebView", "SettingsView");
       
   248         //window.snippets.UrlSearchChromeId.show(false);  
       
   249         
       
   250     }
       
   251   }
       
   252   function SettingsSaveButton() {
       
   253     this.writeButton = function() {
       
   254         document.write('<img  class="webToolbarBtn" id="SaveSettings">');
       
   255         new SimpleButton("SaveSettings",
       
   256                          "toolbar.snippet/icons/icon_clearall.png",
       
   257                          "toolbar.snippet/icons/icon_clearall_pressed.png",
       
   258                          "toolbar.snippet/icons/icon_clearall_disabled.png",
       
   259                          _SaveSet); 
       
   260     }
       
   261     _SaveSet = function() {
       
   262         window.views.WebView.showNormalPage();
       
   263         window.ViewStack.switchView("WebView", "SettingsView");	
       
   264         //window.snippets.UrlSearchChromeId.show(false);    
       
   265     }
       
   266   }
       
   267 
       
   268   /*
       
   269   ** Utility functions
       
   270   */
       
   271   function _chromeLoadComplete() {
       
   272     _setActions();
       
   273     winbutton.changeWindowIcon();
       
   274     window.pageController.pageChanged.connect(winbutton.changeWindowIcon);
       
   275   }
       
   276 
       
   277   function _chromeAspectChanged() {
       
   278     var lcbWidth = document.getElementById("LCToolbarChromeId").offsetWidth;
       
   279     var rcbWidth = document.getElementById("RCToolbarChromeId").offsetWidth;
       
   280     var totalW =   window.chrome.displaySize.width;
       
   281 
       
   282     var fcWidth = totalW - lcbWidth - rcbWidth;
       
   283     var fcWidthPercent = (fcWidth/totalW) * 100 ;
       
   284     fcWidthPercent = fcWidthPercent.toFixed(2);
       
   285 
       
   286     // Clear popups if aspect ratio changes
       
   287     window.snippets.ContextMenuId.hide();
       
   288     window.snippets.ZoomBarId.hide();
       
   289     
       
   290     el =  document.getElementById("ButtonContainer");
       
   291     el.style.width = fcWidthPercent +"%";
       
   292 
       
   293   }
       
   294 
       
   295   function _setActions() {
       
   296       new ActionButton("backButton",
       
   297                        "toolbar.snippet/icons/icon_back.png",
       
   298                        "toolbar.snippet/icons/icon_back_pressed.png",
       
   299                        "toolbar.snippet/icons/icon_back_disabled.png",
       
   300                        window.pageController.actions.back);
       
   301       
       
   302       /* Add 'addWindow' action */
       
   303       new ActionButton("addWindow",
       
   304                        "toolbar.snippet/icons/icon_windowsadd.png",
       
   305                        "toolbar.snippet/icons/icon_windowsadd_pressed.png",
       
   306                        "toolbar.snippet/icons/icon_windowsadd_disabled.png",
       
   307                        window.views.WindowView.actions.addWindow);
       
   308   }
       
   309  	
       
   310   function _pageLoadComplete(ok) {
       
   311       if(ok) {
       
   312           window.bookmarksManager.addHistory(window.pageController.currentDocUrl,window.pageController.currentDocTitle);
       
   313     }
       
   314   }
       
   315 
       
   316   function _pageLoadStarted() {
       
   317 	  window.snippets.MostVisitedViewId.hide();	
       
   318       //snippets.ButtonContainer.show();
       
   319   }
       
   320   
       
   321   // Main toolbar button instances
       
   322   var lc = new LeftCornerButton();
       
   323   var rc = new RightCornerButton();
       
   324   var menubutton = new MenuButton();
       
   325   var zoombutton = new ZoomButton();
       
   326   var winbutton = new WinButton();
       
   327   
       
   328   // Windows View toolbar instances
       
   329   var winBackButton = new WinBackButton();
       
   330   var winAddButton = new WinAddButton();
       
   331 
       
   332   // Bookmarks View toolbar instances
       
   333   var bmBackButton = new BMBackButton();
       
   334   var bmAddButton = new BMAddButton();
       
   335 
       
   336   // Recent URL View toolbar instances
       
   337   var recentBackButton = new RecentURLBackButton();
       
   338   var recentClearallButton = new RecentURLClearallButton();
       
   339 
       
   340   // Settings View toolbar instances
       
   341   var settingsBackButton = new SettingsBackButton();
       
   342   var settingsSaveButton = new SettingsSaveButton();
       
   343 
       
   344   // Toolbar button write accessor methods
       
   345   this.writeLeftCornerButton = function() { lc.writeButton(); }
       
   346   this.writeRightCornerButton = function() { rc.writeButton(); }
       
   347   this.writeMenuButton = function() { menubutton.writeButton(); } 
       
   348   this.writeWinButton = function() { winbutton.writeButton(); }
       
   349   this.writeZoomButton = function() { zoombutton.writeButton(); }  
       
   350   this.writeWinBackButton = function() { winBackButton.writeButton(); }
       
   351   this.writeWinAddButton = function() { winAddButton.writeButton(); }
       
   352   this.writeBMBackButton = function() { bmBackButton.writeButton(); }
       
   353   this.writeBMAddButton = function() { bmAddButton.writeButton(); }
       
   354   this.writeRecentBackButton = function() { recentBackButton.writeButton(); }
       
   355   this.writeRecentClearallButton = function() { recentClearallButton.writeButton(); }
       
   356   this.writeSettingsBackButton = function() { settingsBackButton.writeButton(); }
       
   357   this.writeSettingsSaveButton = function() { settingsSaveButton.writeButton(); }
       
   358 
       
   359   //! Set enabled state of zoom button.
       
   360   /*!
       
   361     \param enabled new enabled state of button
       
   362   */
       
   363   this.setZoomEnabled = function(enabled)
       
   364   {
       
   365     zoombutton.setEnabled(enabled);
       
   366   }
       
   367  
       
   368   window.chrome.chromeComplete.connect(_chromeLoadComplete);
       
   369   window.chrome.prepareForGeometryChange.connect(_chromeAspectChanged);
       
   370   window.pageController.loadFinished.connect(_pageLoadComplete);
       
   371   window.pageController.loadStarted.connect(_pageLoadStarted);
       
   372 
       
   373 
       
   374   window.ViewStack.activateWebView.connect(_activateWebView);
       
   375   window.ViewStack.deActivateWebView.connect(_deActivateWebView);
       
   376   window.ViewStack.activateWindowView.connect(_activateWindowView);
       
   377   window.ViewStack.deActivateWindowView.connect(_deActivateWindowView);
       
   378   window.ViewStack.activateBookmark.connect(_activateBookmarkView);
       
   379   window.ViewStack.deActivateBookmark.connect(_deActivateBookmarkView);
       
   380   window.ViewStack.activateBookMarkHistory.connect(_activateRecentUrlView);
       
   381   window.ViewStack.deActivateBookMarkHistory.connect(_deActivateRecentUrlView);
       
   382   window.ViewStack.activateSettingsView.connect(_activateSettingsView);
       
   383   window.ViewStack.deActivateSettingsView.connect(_deActivateSettingsView);
       
   384     
       
   385   function _activateWebView () {
       
   386       window.snippets.WebViewToolbarId.show(false);
       
   387   }
       
   388 
       
   389   function _deActivateWebView () {
       
   390       window.snippets.WebViewToolbarId.hide(false);
       
   391   }
       
   392 
       
   393   function _activateWindowView () {
       
   394       window.snippets.WindowViewToolbarId.show();
       
   395   }
       
   396 
       
   397   function _deActivateWindowView () {
       
   398       window.snippets.WindowViewToolbarId.hide();
       
   399       /* Set the windows icon based on the number of windows */
       
   400       winbutton.changeWindowIcon();
       
   401   }
       
   402   
       
   403   function _activateSettingsView () {
       
   404       window.snippets.SettingsViewToolbarId.show();
       
   405   }
       
   406 
       
   407   function _deActivateSettingsView () {
       
   408       window.snippets.SettingsViewToolbarId.hide();
       
   409   }
       
   410 
       
   411   function _activateBookmarkView () {
       
   412       window.snippets.BookmarkViewToolbarId.show();
       
   413   }
       
   414 
       
   415   function _deActivateBookmarkView () {
       
   416       window.snippets.BookmarkViewToolbarId.hide();
       
   417   }
       
   418 
       
   419   function _activateRecentUrlView () {
       
   420       window.snippets.RecentUrlViewToolbarId.show();
       
   421   }
       
   422 
       
   423   function _deActivateRecentUrlView () {
       
   424       window.snippets.RecentUrlViewToolbarId.hide();
       
   425   }
       
   426 
       
   427 } //end of class WebToolbar
       
   428