ginebra/chrome/bedrockchrome/toolbar.snippet/toolbar.js
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 
       
     2 
       
     3 /* create all functions with toolbar.* */
       
     4 //
       
     5 // INIT the webView Toolbar
       
     6 //
       
     7 
       
     8 function WebViewToolbar()
       
     9 {
       
    10     //Private methods
       
    11     //write webview toolbar HTML code to document
       
    12     function _writeWebViewToolbar() {
       
    13         var html = ''+
       
    14             '<table class="toolBarTable">' +
       
    15             '<tr>' +
       
    16             '<td class="toolBarBtnCell" style="width=15%;"><img class="toolBarBtn" id="backButton"></td>'+
       
    17             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
    18             '<td class="toolBarBtnCell" style="width=15%;"><img class="toolBarBtn" id="zoomIn"></td>'+
       
    19             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
    20             '<td class="toolBarBtnCell" style="width=15%;"><img class="toolBarBtn" id="zoomOut"></td>'+
       
    21             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
    22             '<td class="toolBarBtnCell" style="width=15%;"><img class="toolBarBtn" id="winButton"></td>'+
       
    23             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
    24              '<td class="toolBarBtnCell" style="width=15%;"><img class="toolBarBtn" id="contextMenuButton"></td>'+
       
    25 
       
    26             '</tr>'+
       
    27             '</table>';
       
    28 
       
    29         document.write(html);
       
    30 
       
    31         // We can immediately set up the simple buttons
       
    32         // ActionButtons have to wait until the page is loaded
       
    33         var index = window.pageController.pageCount();
       
    34         var base = "toolbar.snippet/icons/windows" + index;
       
    35         new SimpleButton("winButton",
       
    36                          base + ".png",
       
    37                          base + "_pushed.png",
       
    38                          base + ".png",
       
    39                          _goToWindowView);
       
    40 
       
    41 
       
    42         new SimpleButton("contextMenuButton",
       
    43                           "toolbar.snippet/icons/go-anywhere.png",
       
    44                           "toolbar.snippet/icons/go-anywhere_pushed.png",
       
    45                           "toolbar.snippet/icons/go-anywhere.png",
       
    46                           _contextMenuF);
       
    47 
       
    48    }
       
    49 
       
    50     /* Adds the back action button  using ActionButton from ../../js/ActionButton.js */
       
    51     function _setActions () {
       
    52         new ActionButton("backButton",
       
    53                      "toolbar.snippet/icons/back.png",
       
    54                      "toolbar.snippet/icons/back_pushed.png",
       
    55                      "toolbar.snippet/icons/back_disabled.png",
       
    56                      window.pageController.actions.back);
       
    57 
       
    58         new ActionButton("zoomIn",
       
    59                      "toolbar.snippet/icons/zoom+.png",
       
    60                      "toolbar.snippet/icons/zoom+_pushed.png",
       
    61                      "toolbar.snippet/icons/zoom+_disabled.png",
       
    62                      window.webView.actions.zoomIn);
       
    63 
       
    64 
       
    65         new ActionButton("zoomOut",
       
    66                      "toolbar.snippet/icons/zoom-.png",
       
    67                      "toolbar.snippet/icons/zoom-_pushed.png",
       
    68                      "toolbar.snippet/icons/zoom-_disabled.png",
       
    69                      window.webView.actions.zoomOut);
       
    70 
       
    71         /* Add 'addWindow' action */
       
    72         new ActionButton("addWindow",
       
    73                          "toolbar.snippet/icons/addwindow.png",
       
    74                          "toolbar.snippet/icons/addwindow_pushed.png",
       
    75                          "toolbar.snippet/icons/addwindow_disabled.png",
       
    76                          window.viewManager.windowView.actions.addWindow);
       
    77     }
       
    78 
       
    79     var timeoutId = 0;
       
    80    
       
    81     function _contextMenuF ()
       
    82     {
       
    83     	     var hideFlag = 0;
       
    84     	    
       
    85     	  	 hideFlag = window.snippets.ContextMenuId.getContextMenuFlag();
       
    86     	     
       
    87     	  	 if(hideFlag == 1)
       
    88     	  	 {
       
    89     	     	 window.snippets.ContextMenuBgId.hide();
       
    90     	     	 window.snippets.ContextMenuId.hide();
       
    91     	       return;
       
    92     	  	 }
       
    93     	     
       
    94     	     clearTimeout(timeoutId); 	
       
    95     	     
       
    96     	     window.snippets.ContextMenuBgId.setPosition(0,20);
       
    97            window.snippets.ContextMenuBgId.show();
       
    98            window.snippets.ContextMenuBgId.zValue = 1;
       
    99     	
       
   100     		   window.snippets.ContextMenuId.repaint();
       
   101     	     if (window.snippets.ContextMenuId.getDisplayMode() == "portrait")
       
   102     	       window.snippets.ContextMenuId.setPosition(90,200);
       
   103     	     else //landscape
       
   104     	     	 window.snippets.ContextMenuId.setPosition(250,100); 
       
   105     	
       
   106            
       
   107            window.snippets.ContextMenuId.show();
       
   108            window.snippets.ContextMenuId.zValue = 10;
       
   109           
       
   110            timeoutId = setTimeout ( 'window.snippets.ContextMenuId.hide(); window.snippets.ContextMenuBgId.hide()', 6000 ); // close the menu after 6 secs
       
   111 
       
   112     }
       
   113 
       
   114     /* Update the windows icon based on the number of windows open */
       
   115     function _changeWindowIcon () {
       
   116         var index = window.pageController.pageCount();
       
   117         var base = "toolbar.snippet/icons/windows" + index;
       
   118 
       
   119         document.getElementById('winButton').button.updateImages(base + ".png",
       
   120                                                                  base + "_pushed.png",
       
   121                                                                  base + ".png");
       
   122     }
       
   123 
       
   124     function _goToWindowView () {
       
   125         //window.chrome.alert("goToWindowView");
       
   126         window.viewStack.switchView("windowView", "webView");
       
   127     }
       
   128 
       
   129     function _goToGoAnywhereView () {
       
   130         /* Change to history view */
       
   131         window.viewStack.switchView("goAnywhereView", "webView");
       
   132     }
       
   133 
       
   134     function _goToBookmarkView () {
       
   135         /* Change to Bookmark view */
       
   136         window.viewStack.switchView("bookmarkTreeView", "webView");
       
   137     }
       
   138 
       
   139     function _goToRecentUrlView () {
       
   140          window.viewStack.switchView("bookmarkHistoryView", "webView");
       
   141     }
       
   142 
       
   143     function _chromeLoadComplete () {
       
   144         _setActions();
       
   145         _changeWindowIcon();
       
   146 
       
   147         /* Connect to pageCreated signal */
       
   148         window.pageController.pageCreated.connect(_changeWindowIcon);
       
   149     }
       
   150 
       
   151     function _activateBookmark () {
       
   152         window.chrome.toggleVisibility("BookmarkViewToolbarId");
       
   153     }
       
   154 
       
   155     function _deActivateBookmark () {
       
   156         window.chrome.toggleVisibility("BookmarkViewToolbarId");
       
   157     }
       
   158 
       
   159     function _activateHistory () {
       
   160         window.chrome.toggleVisibility("HistoryViewToolbarId");
       
   161     }
       
   162 
       
   163     function _deActivateHistory () {
       
   164         window.chrome.toggleVisibility("HistoryViewToolbarId");
       
   165     }
       
   166 
       
   167     function _activateBookMarkHistory () {
       
   168         window.chrome.toggleVisibility("BookmarkHistoryViewToolbarId");
       
   169     }
       
   170 
       
   171     function _deActivateBookMarkHistory () {
       
   172         window.chrome.toggleVisibility("BookmarkHistoryViewToolbarId");
       
   173     }
       
   174 
       
   175     function _activateWebView () {
       
   176         window.chrome.toggleVisibility("WebViewToolbarId");
       
   177     }
       
   178 
       
   179     function _deActivateWebView () {
       
   180         window.chrome.toggleVisibility("WebViewToolbarId");
       
   181     }
       
   182 
       
   183     function _activateWindowView () {
       
   184 
       
   185         window.chrome.alert("_activateWindowView");
       
   186 
       
   187         /* Show the window count snippet */
       
   188         document.getElementById('WindowCountBarId').wcChrome.wcUpdateWindowHtml();
       
   189         window.chrome.toggleVisibility("WindowCountBarId");
       
   190 
       
   191         window.chrome.toggleVisibility("WindowViewToolbarId");
       
   192     }
       
   193 
       
   194     function _deActivateWindowView () {
       
   195 
       
   196         window.chrome.toggleVisibility("WindowCountBarId");
       
   197         window.chrome.toggleVisibility("WindowViewToolbarId");
       
   198 
       
   199         /* Set the windows icon based on the number of windows */
       
   200         _changeWindowIcon();
       
   201     }
       
   202 
       
   203     function _pageChanged() {
       
   204         window.chrome.alert("_pageChanged");
       
   205         document.getElementById('WindowCountBarId').wcChrome.wcUpdateWindowHtml();
       
   206     }
       
   207 
       
   208 
       
   209     _writeWebViewToolbar();
       
   210     window.chrome.loadComplete.connect(_chromeLoadComplete);
       
   211     window.viewStack.activateBookmark.connect(_activateBookmark);
       
   212     window.viewStack.deActivateBookmark.connect(_deActivateBookmark);
       
   213     window.viewStack.activateHistory.connect(_activateHistory);
       
   214     window.viewStack.deActivateHistory.connect(_deActivateHistory);
       
   215     window.viewStack.activateBookMarkHistory.connect(_activateBookMarkHistory);
       
   216     window.viewStack.deActivateBookMarkHistory.connect(_deActivateBookMarkHistory);
       
   217     window.viewStack.activateWebView.connect(_activateWebView);
       
   218     window.viewStack.deActivateWebView.connect(_deActivateWebView);
       
   219     window.viewStack.activateWindowView.connect(_activateWindowView);
       
   220     window.viewStack.deActivateWindowView.connect(_deActivateWindowView);
       
   221     window.viewStack.pageChanged.connect(_pageChanged);
       
   222 
       
   223 } //end of class webViewToolbar
       
   224 
       
   225 
       
   226 // INIT the History View Toolbar
       
   227 function HistoryViewToolbar()
       
   228 {
       
   229     //Private methods
       
   230     //write historyview toolbar HTML code to document
       
   231     function _writeHistoryViewToolbar() {
       
   232         var tbhtml = ''+
       
   233         //'<span id="historyRow" style="width:100%">'+
       
   234         //'<img class="toolBarBtn firstButton" id="goBacktoWebViewHist">'+
       
   235         //'</span>';
       
   236 
       
   237         '<table class="toolBarTable">' +
       
   238         '<tr>' +
       
   239         '<td class="toolBarBtnCell" style="width=100%;"><img class="toolBarBtn" id="goBacktoWebViewHist"></td>'+
       
   240         '</tr>' +
       
   241         '</table>';
       
   242          document.write(tbhtml);
       
   243 
       
   244          /* add back button as a simple button */
       
   245          new SimpleButton("goBacktoWebViewHist",
       
   246                           "toolbar.snippet/icons/back.png",
       
   247                           "toolbar.snippet/icons/back_pushed.png",
       
   248                           "toolbar.snippet/icons/back.png",
       
   249                           _goBackFromGoAnywhereView);
       
   250 
       
   251     }
       
   252 
       
   253     _goBackFromGoAnywhereView = function() {
       
   254         window.viewStack.switchView("webView", "goAnywhereView");
       
   255     }
       
   256 
       
   257     _writeHistoryViewToolbar();
       
   258 
       
   259 } //end of class HistoryViewToolbar
       
   260 
       
   261 // INIT the bookmark View Toolbar
       
   262 function BookmarkViewToolbar()
       
   263 {
       
   264     //Private methods
       
   265     //write webview toolbar HTML code to document
       
   266     function _writeBookmarkViewToolbar() {
       
   267         var tbhtml = ''+
       
   268         //'<span id="bookmarkRow" style="width:100%">'+
       
   269         //'<img class="toolBarBtn firstButton" id="goBacktoWebViewBM">'+
       
   270         //'<img class="toolBarBtn lastButton"  id="addToBookMark">'+
       
   271         //'</span>';
       
   272         '<table class="toolBarTable">' +
       
   273             '<tr>' +
       
   274             '<td class="toolBarBtnCell" style="width=50%;"><img class="toolBarBtn" id="goBacktoWebViewBM"></td>'+
       
   275             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
   276             '<td class="toolBarBtnCell" style="width=50%;"><img class="toolBarBtn" id="addToBookMark"></td>'+
       
   277             '</tr>'+
       
   278             '</table>';
       
   279 
       
   280          document.write(tbhtml);
       
   281 
       
   282 
       
   283          /* add back button as a simple button */
       
   284          new SimpleButton("goBacktoWebViewBM",
       
   285                           "toolbar.snippet/icons/back.png",
       
   286                           "toolbar.snippet/icons/back_pushed.png",
       
   287                           "toolbar.snippet/icons/back.png",
       
   288                           _goBackFromBookmarkView);
       
   289 
       
   290          /* add bookmark button as a simple button */
       
   291          new SimpleButton("addToBookMark",
       
   292                          "toolbar.snippet/icons/addwindow.png",
       
   293                          "toolbar.snippet/icons/addwindow_pushed.png",
       
   294                          "toolbar.snippet/icons/addwindow.png",
       
   295                          _addCurrentPageToBookMark);
       
   296 
       
   297     }
       
   298 
       
   299     function _goBackFromBookmarkView () {
       
   300         window.viewStack.switchView("webView", "bookmarkTreeView");
       
   301     }
       
   302 
       
   303     function _addCurrentPageToBookMark () {
       
   304         /* Change to history view */
       
   305         window.chrome.addCurrentPageToBookMark();
       
   306     }
       
   307 
       
   308 
       
   309     _writeBookmarkViewToolbar();
       
   310 
       
   311 }
       
   312 
       
   313 // INIT the Bookmark History View Toolbar
       
   314 function BookmarkHistoryViewToolbar()
       
   315 {
       
   316     /* BookmarkHist View Toolbar */
       
   317     function _writeBookmarkHistoryViewToolbar() {
       
   318         var tbhtml = ''+
       
   319         //'<span id="bookmarkHistoryRow" style="width:100%">'+
       
   320         //'<img class="toolBarBtn firstButton" id="goBacktoWebViewBMH">'+
       
   321         //'</span>';
       
   322         '<table class="toolBarTable">' +
       
   323             '<tr>' +
       
   324             '<td class="toolBarBtnCell" style="width=100%;"><img class="toolBarBtn" id="goBacktoWebViewBMH"></td>'+
       
   325             '</tr>'+
       
   326             '</table>';
       
   327          document.write(tbhtml);
       
   328 
       
   329          /* add back button as a simple button */
       
   330          new SimpleButton("goBacktoWebViewBMH",
       
   331                           "toolbar.snippet/icons/back.png",
       
   332                           "toolbar.snippet/icons/back_pushed.png",
       
   333                           "toolbar.snippet/icons/back.png",
       
   334                           _goBackFromRecentUrlView);
       
   335     }
       
   336 
       
   337     /* This function changes the view to webView and updates the layout correspondingly */
       
   338     _goBackFromRecentUrlView = function()
       
   339     {
       
   340         window.viewStack.switchView("webView", "bookmarkHistoryView");
       
   341     }
       
   342 
       
   343     _writeBookmarkHistoryViewToolbar();
       
   344 
       
   345 }
       
   346 
       
   347 
       
   348 // INIT the Window View Toolbar
       
   349 function WindowViewToolbar()
       
   350 {
       
   351     /* Window View Toolbar */
       
   352     function _writeWindowToolbar() {
       
   353         var tbhtml = ''+
       
   354             //    '<span id="windowRow" style="width:100%">'+
       
   355             //    '<img class="toolBarBtn firstButton" id="goBacktoWebViewWin">'+
       
   356             //    '<img class="toolBarBtn" id="addWindow">'+
       
   357             //    '</span>';
       
   358             '<table class="toolBarTable">' +
       
   359             '<tr>' +
       
   360             '<td class="toolBarBtnCell" style="width=50%;"><img class="toolBarBtn" id="goBacktoWebViewWin"></td>'+
       
   361             '<td><img src="toolbar.snippet/icons/btnBorder.png"></td>'+
       
   362             '<td class="toolBarBtnCell" style="width=50%;"><img class="toolBarBtn" id="addWindow"></td>'+
       
   363             '</tr>'+
       
   364             '</table>';
       
   365 
       
   366 
       
   367          document.write(tbhtml);
       
   368 
       
   369          /* add back as simple button, add window is an action button */
       
   370          new SimpleButton("goBacktoWebViewWin",
       
   371                           "toolbar.snippet/icons/back.png",
       
   372                           "toolbar.snippet/icons/back_pushed.png",
       
   373                           "toolbar.snippet/icons/back.png",
       
   374                           _goBackFromWindowView);
       
   375 
       
   376        }
       
   377 
       
   378     _goBackFromWindowView = function() {
       
   379         window.viewStack.switchView("webView", "windowView");
       
   380     }
       
   381     _writeWindowToolbar();
       
   382 }
       
   383 
       
   384 
       
   385