ginebra2/chrome/bedrockchrome/zoombar.snippet/zoombar.js
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*!
     1 /*!
     2   \file zoombar.js This module contains the ZoomBar class.
     2   \file zoombar.js This module contains the ZoomBar class.
     3 */
     3 */
     4 
     4 
     5 /*!
     5 /*!
     6   Class to handle displaying the zoom bar. The zoom bar is displayed when the 
     6   Class to handle displaying the zoom bar. The zoom bar is displayed when the
     7   user presses the zoom button on the toolbar. It provides access to the zoom
     7   user presses the zoom button on the toolbar. It provides access to the zoom
     8   in and out functions. It is hidden when the main toolbar is hidden on user inactivity
     8   in and out functions. It is hidden when the main toolbar is hidden on user inactivity
     9   
       
    10   \param webtb web toolbar needed to set state of zoom button
       
    11 */
     9 */
    12 function ZoomBar(webtb)
    10 function ZoomBar()
    13 {
    11 {
    14     var timeoutId = 0; // inactivity timer ID
    12     var timeoutId = 0; // inactivity timer ID
    15     var ZB_TIMEOUT = 5000; // hide zoombar after 5 secs
    13     var ZB_TIMEOUT = 5000; // hide zoombar after 5 secs
    16     var zooming = false; // true when in the process of zooming
    14     var zooming = false; // true when in the process of zooming
    17     var enabled = true; // zooming enabled flag - initially enabled
    15     var enabled = true; // zooming enabled flag - initially enabled
    18     
    16 
    19     // Private Methods
    17     // Private Methods
    20     //! Write zoom bar HTML code to document.
    18     //! Write zoom bar HTML code to document.
    21     function _zoombar_write() {
    19     function _zoombar_write() {
    22         var html = ''+
    20         var html = ''+
    23             '<div id="zoomBarDiv">'+
    21             '<div id="zoomBarDiv">'+
    40                          "zoombar.snippet/icons/icon_zoom-.png",
    38                          "zoombar.snippet/icons/icon_zoom-.png",
    41                          "zoombar.snippet/icons/icon_zoom-_pressed.png",
    39                          "zoombar.snippet/icons/icon_zoom-_pressed.png",
    42                          "zoombar.snippet/icons/icon_zoom-_disabled.png",
    40                          "zoombar.snippet/icons/icon_zoom-_disabled.png",
    43                          window.views.WebView.actions.zoomOut,
    41                          window.views.WebView.actions.zoomOut,
    44                          true,true,true);
    42                          true,true,true);
    45         
    43 
    46         // reset toolbar timeout each time a zoom is triggered
    44         // reset toolbar timeout each time a zoom is triggered
    47 //        window.views.WebView.actions.zoomIn.triggered.connect(
    45 //        window.views.WebView.actions.zoomIn.triggered.connect(
    48 //            function(checked) {handleZoom();});
    46 //            function(checked) {handleZoom();});
    49 //        window.views.WebView.actions.zoomOut.triggered.connect(
    47 //        window.views.WebView.actions.zoomOut.triggered.connect(
    50 //            function(checked) {handleZoom();});
    48 //            function(checked) {handleZoom();});
    52         window.views.WebView.actions.zoomIn.changed.connect(
    50         window.views.WebView.actions.zoomIn.changed.connect(
    53             createDelegate(this, handleChange));
    51             createDelegate(this, handleChange));
    54         window.views.WebView.actions.zoomOut.changed.connect(
    52         window.views.WebView.actions.zoomOut.changed.connect(
    55             createDelegate(this, handleChange));
    53             createDelegate(this, handleChange));
    56     }
    54     }
    57     
    55 
    58     //! Set inactivity timer when not zooming.
    56     //! Set inactivity timer when not zooming.
    59     function handleZoom()
    57     function handleZoom()
    60     {
    58     {
    61         // zoom activation toggles zoom on/off
    59         // zoom activation toggles zoom on/off
    62         zooming = !zooming; // toggle zoom state
    60         zooming = !zooming; // toggle zoom state
    64         if (!zooming) {
    62         if (!zooming) {
    65             // close zoom after 5 secs
    63             // close zoom after 5 secs
    66             timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT);
    64             timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT);
    67         }
    65         }
    68     }
    66     }
    69     
    67 
    70     //! Start inactivity timer when zoom bar is shown.
    68     //! Start inactivity timer when zoom bar is shown.
    71     function handleShow()
    69     function handleShow()
    72     {
    70     {
    73         timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT); // close zoom after 5 secs
    71         timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT); // close zoom after 5 secs
    74     }
    72     }
    75     
    73 
    76     //! Clear inactivity timer when zoom bar is hidden.
    74     //! Clear inactivity timer when zoom bar is hidden.
    77     function handleHide()
    75     function handleHide()
    78     {
    76     {
    79         clearTimeout(timeoutId);
    77         clearTimeout(timeoutId);
    80         zooming = false; // ensure zooming state doesn't get out of sync
    78         zooming = false; // ensure zooming state doesn't get out of sync
    81     }
    79     }
    82     
    80 
    83     //! Handle action object changes. In particular we are interested in
    81     //! Handle action object changes. In particular we are interested in
    84     //! changes to the enabled state of the object.
    82     //! changes to the enabled state of the object.
    85     function handleChange() {
    83     function handleChange() {
    86         var saveEnabled = enabled;
    84         var saveEnabled = enabled;
    87         
    85 
    88         // enable zoom button if either zoom-in or zoom-out action enabled
    86         // enable zoom button if either zoom-in or zoom-out action enabled
    89         if (window.views.WebView.actions.zoomIn.enabled
    87         if (window.views.WebView.actions.zoomIn.enabled
    90             || window.views.WebView.actions.zoomOut.enabled) {
    88             || window.views.WebView.actions.zoomOut.enabled) {
    91             enabled = true;
    89             enabled = true;
    92         } else {
    90         } else {
    93             enabled = false;
    91             enabled = false;
    94         }
    92         }
    95         
    93 
    96         // if state changed update web toolbar zoom button state
    94         // if state changed update web toolbar zoom button state
    97         if (saveEnabled != enabled) {
    95         if (saveEnabled != enabled) {
    98             // enabled state changed
    96             // enabled state changed
    99             webtb.setZoomEnabled(enabled);
    97             window.snippets.ZoomButtonSnippet.setEnabled(enabled);
   100         }
    98         }
   101     }
    99     }
   102     function handleLoadStarted() {
   100     function handleLoadStarted() {
   103         window.snippets.ZoomBarId.hide()
   101         window.snippets.ZoomBarId.hide()
   104     }
   102     }
   105 
   103 
   106     //! After chrome is loaded, create zoombar buttons and setup show/hide 
   104     //! After chrome is loaded, create zoombar buttons and setup show/hide
   107     //! handlers.
   105     //! handlers.
   108     function _chromeLoadComplete() {
   106     function _chromeLoadComplete() {
   109         _setActions();
   107         _setActions();
   110         window.pageController.loadStarted.connect(handleLoadStarted);
   108         window.pageController.loadStarted.connect(handleLoadStarted);
   111 //        window.snippets.ZoomBarId.shown.connect(handleShow);
   109 //        window.snippets.ZoomBarId.shown.connect(handleShow);
   117     window.chrome.chromeComplete.connect(_chromeLoadComplete);
   115     window.chrome.chromeComplete.connect(_chromeLoadComplete);
   118 }
   116 }
   119 
   117 
   120 
   118 
   121 
   119 
   122  
   120