ginebra2/chrome/bedrockchrome/zoombar.snippet/zoombar.js
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 16 3c88a81ff781
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     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   
     9   and on timer maintained by native code
    10   \param webtb web toolbar needed to set state of zoom button
       
    11 */
    10 */
    12 function ZoomBar(webtb)
    11 function ZoomBar()
    13 {
    12 {
    14     var timeoutId = 0; // inactivity timer ID
       
    15     var ZB_TIMEOUT = 5000; // hide zoombar after 5 secs
       
    16     var zooming = false; // true when in the process of zooming
       
    17     var enabled = true; // zooming enabled flag - initially enabled
    13     var enabled = true; // zooming enabled flag - initially enabled
    18     
    14 
    19     // Private Methods
    15     // Private Methods
    20     //! Write zoom bar HTML code to document.
    16     //! Write zoom bar HTML code to document.
    21     function _zoombar_write() {
    17     function _zoombar_write() {
    22         var html = ''+
    18         var html = ''+
    23             '<div id="zoomBarDiv">'+
    19             '<div id="zoomBarDiv">'+
    24             '<img class="zoomBarBtn" id="zoomBarBtnIn">'+
    20             '<div class = "GinebraSnippet zoomBarBtn" id="zoomBarBtnIn" data-GinebraVisible="false" data-GinebraHidesContent="true"   data-GinebraNativeClass="ActionButton"> </div>'+
    25             '<img class="zoomBarBtn" id="zoomBarBtnOut">'+
    21             '<div class = "GinebraSnippet zoomBarBtn" id="zoomBarBtnOut" data-GinebraVisible="false" data-GinebraHidesContent="true"   data-GinebraNativeClass="ActionButton"> </div>'+
       
    22 
    26             '</div>';
    23             '</div>';
    27         document.write(html);
    24         document.write(html);
    28     }
    25     }
    29 
    26 
    30     //! Create zoom in & out buttons.
    27     //! Create zoom in & out buttons.
    31     function _setActions() {
    28     function _setActions() {
    32         new ActionButton("zoomBarBtnIn",
    29         snippets.zoomBarBtnIn.connectAction("zoomIn", "WebView", true, true);
    33                          "zoombar.snippet/icons/icon_zoom+.png",
    30         snippets.zoomBarBtnOut.connectAction("zoomOut", "WebView",  true, true);
    34                          "zoombar.snippet/icons/icon_zoom+_pressed.png",
    31         snippets.zoomBarBtnIn.setIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom+.png");
    35                          "zoombar.snippet/icons/icon_zoom+_disabled.png",
    32         snippets.zoomBarBtnIn.setActiveIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom+_pressed.png");
    36                          window.views.WebView.actions.zoomIn,
    33         snippets.zoomBarBtnIn.setDisabledIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom+_disabled.png");
    37                          true,true,true);
    34         snippets.zoomBarBtnOut.setIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom-.png");
       
    35         snippets.zoomBarBtnOut.setActiveIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom-_pressed.png");
       
    36         snippets.zoomBarBtnOut.setDisabledIcon(":/chrome/bedrockchrome/zoombar.snippet/icons/icon_zoom-_disabled.png");
    38 
    37 
    39         new ActionButton("zoomBarBtnOut",
       
    40                          "zoombar.snippet/icons/icon_zoom-.png",
       
    41                          "zoombar.snippet/icons/icon_zoom-_pressed.png",
       
    42                          "zoombar.snippet/icons/icon_zoom-_disabled.png",
       
    43                          window.views.WebView.actions.zoomOut,
       
    44                          true,true,true);
       
    45         
       
    46         // reset toolbar timeout each time a zoom is triggered
       
    47 //        window.views.WebView.actions.zoomIn.triggered.connect(
       
    48 //            function(checked) {handleZoom();});
       
    49 //        window.views.WebView.actions.zoomOut.triggered.connect(
       
    50 //            function(checked) {handleZoom();});
       
    51         // Connect to each action's "changed" signal.
    38         // Connect to each action's "changed" signal.
    52         window.views.WebView.actions.zoomIn.changed.connect(
    39         window.views.WebView.actions.zoomIn.changed.connect(
    53             createDelegate(this, handleChange));
    40             createDelegate(this, handleChange));
    54         window.views.WebView.actions.zoomOut.changed.connect(
    41         window.views.WebView.actions.zoomOut.changed.connect(
    55             createDelegate(this, handleChange));
    42             createDelegate(this, handleChange));
       
    43 
    56     }
    44     }
    57     
    45 
    58     //! Set inactivity timer when not zooming.
       
    59     function handleZoom()
       
    60     {
       
    61         // zoom activation toggles zoom on/off
       
    62         zooming = !zooming; // toggle zoom state
       
    63         clearTimeout(timeoutId);
       
    64         if (!zooming) {
       
    65             // close zoom after 5 secs
       
    66             timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT);
       
    67         }
       
    68     }
       
    69     
       
    70     //! Start inactivity timer when zoom bar is shown.
       
    71     function handleShow()
       
    72     {
       
    73         timeoutId = setTimeout('window.snippets.ZoomBarId.hide()', ZB_TIMEOUT); // close zoom after 5 secs
       
    74     }
       
    75     
       
    76     //! Clear inactivity timer when zoom bar is hidden.
       
    77     function handleHide()
       
    78     {
       
    79         clearTimeout(timeoutId);
       
    80         zooming = false; // ensure zooming state doesn't get out of sync
       
    81     }
       
    82     
       
    83     //! Handle action object changes. In particular we are interested in
    46     //! Handle action object changes. In particular we are interested in
    84     //! changes to the enabled state of the object.
    47     //! changes to the enabled state of the object.
    85     function handleChange() {
    48     function handleChange() {
    86         var saveEnabled = enabled;
    49         var saveEnabled = enabled;
    87         
    50 
    88         // enable zoom button if either zoom-in or zoom-out action enabled
    51         // enable zoom button if either zoom-in or zoom-out action enabled
    89         if (window.views.WebView.actions.zoomIn.enabled
    52         if (window.views.WebView.actions.zoomIn.enabled
    90             || window.views.WebView.actions.zoomOut.enabled) {
    53             || window.views.WebView.actions.zoomOut.enabled) {
    91             enabled = true;
    54             enabled = true;
    92         } else {
    55         } else {
    93             enabled = false;
    56             enabled = false;
    94         }
    57         }
    95         
    58 
    96         // if state changed update web toolbar zoom button state
    59         // if state changed update web toolbar zoom button state
    97         if (saveEnabled != enabled) {
    60         if (saveEnabled != enabled) {
    98             // enabled state changed
    61             // enabled state changed
    99             webtb.setZoomEnabled(enabled);
    62             window.snippets.ZoomButtonSnippet.setEnabled(enabled);
   100         }
    63         }
   101     }
    64     }
   102     function handleLoadStarted() {
       
   103         window.snippets.ZoomBarId.hide()
       
   104     }
       
   105 
    65 
   106     //! After chrome is loaded, create zoombar buttons and setup show/hide 
    66     //! After chrome is loaded, create zoombar buttons and setup show/hide
   107     //! handlers.
    67     //! handlers.
   108     function _chromeLoadComplete() {
    68     function _chromeLoadComplete() {
   109         _setActions();
    69         _setActions();
   110         window.pageController.loadStarted.connect(handleLoadStarted);
       
   111 //        window.snippets.ZoomBarId.shown.connect(handleShow);
       
   112 //        window.snippets.ZoomBarId.hidden.connect(handleHide);
       
   113     }
    70     }
   114 
    71 
   115     _zoombar_write();
    72     _zoombar_write();
   116 
    73 
   117     window.chrome.chromeComplete.connect(_chromeLoadComplete);
    74     window.chrome.chromeComplete.connect(_chromeLoadComplete);
   118 }
    75 }
   119 
    76 
   120 
    77 
   121 
    78 
   122  
    79