ginebra2/chrome/bedrockchrome/chrome.js
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 var _backEnabled = false;
     1 var preLoadBookmarksDone=0;
     2 
       
     3 function onBackEnabled(enabled) 
       
     4 {
       
     5     _backEnabled = enabled;
       
     6 }
       
     7 
       
     8 var _forwardEnabled = false;
       
     9 
       
    10 function onForwardEnabled(enabled)  
       
    11 {
       
    12     _forwardEnabled = enabled;
       
    13 }
       
    14 
       
    15 function calcToolbarPopAnchorOffset(anchoredSnippet,
     2 function calcToolbarPopAnchorOffset(anchoredSnippet,
    16                                     anchorToSnippet,
     3                                     anchorToSnippet,
    17                                     xCenterOffset,
     4                                     xCenterOffset,
    18                                     yBotGap)
     5                                     yBotGap)
    19 {
     6 {
    28     // yBotGap = how much gap should there be between top of anchorTo,
    15     // yBotGap = how much gap should there be between top of anchorTo,
    29     //           and bottom of anchored
    16     //           and bottom of anchored
    30     //
    17     //
    31     anchorToGeom = anchorToSnippet.getGeometry();
    18     anchorToGeom = anchorToSnippet.getGeometry();
    32     anchoredGeom = anchoredSnippet.getGeometry();
    19     anchoredGeom = anchoredSnippet.getGeometry();
    33     xOffset = -(0.5 * anchoredGeom.width) + 
    20     xOffset = -(0.5 * anchoredGeom.width) +
    34         (0.5 * anchorToGeom.width) +
    21         (0.5 * anchorToGeom.width) +
    35         xCenterOffset;
    22         xCenterOffset;
    36     yOffset = -anchoredGeom.height - yBotGap;
    23     yOffset = -anchoredGeom.height - yBotGap;
    37     return([xOffset,yOffset]);
    24     return([xOffset,yOffset]);
    38 }
    25 }
    39 
    26 
       
    27 // Display the super-page with the given name and path.
       
    28 function showSuperPage(pageName, path) {
       
    29 
       
    30     if (window.views.WebView[pageName] == undefined) {
       
    31         window.views.WebView.createSuperPage(pageName, true);
       
    32     		window.views.WebView[pageName].load(chrome.baseDirectory + path);
       
    33     }
       
    34 	
       
    35     if (!window.views.WebView.bedrockTiledBackingStoreEnabled())
       
    36         window.views.WebView.zoomFactor = 1.0;
       
    37     //window.views.WebView.showSuperPage(pageName);
       
    38     window.ViewStack.switchView(pageName, "WebView");
       
    39     if (!window.views.WebView.bedrockTiledBackingStoreEnabled())
       
    40         window.views.WebView.touchNav.doubleClickEnabled = false;
       
    41 }
       
    42 
       
    43 function chrome_showBookmarksView() {
       
    44     showSuperPage("BookmarkTreeView", "bookmarkview.superpage/BookmarkView.html");
       
    45 }
       
    46 
       
    47 function chrome_showHistoryView() {
       
    48     showSuperPage("BookmarkHistoryView", "historyview.superpage/historyView.html");
       
    49 }
       
    50 
       
    51 function chrome_showWindowsView() {
       
    52     window.snippets.ZoomBarId.hide(); // hide Zoom Bar while showing windows view
       
    53     window.snippets.MostVisitedViewId.hide();
       
    54     window.ViewStack.switchView("WindowView", "WebView");
       
    55 }
       
    56 
       
    57 function chrome_showSettingsView() {
       
    58     showSuperPage("SettingsView", "settingsview.superpage/SettingsView.html");
       
    59 }
       
    60 
       
    61 function chrome_showBasicMenu() {
       
    62 
       
    63     cm_TheContextMenu.show(viewMenu_getWebViewContextMenuData());
       
    64 
       
    65 }
       
    66 
       
    67 function chrome_addBookmark() {
       
    68     launchBookmarkDialog(window.pageController.currentDocTitle,window.pageController.currentDocUrl,0);
       
    69 }
       
    70 
       
    71 function chrome_cancelMenu() {
       
    72 
       
    73     cm_TheContextMenu.cancel();
       
    74 }
       
    75 
       
    76 // Center the given snippet on-screen.
       
    77 function centerSnippet(snippet) {
       
    78     var x = (chrome.displaySize.width - snippet.geometry.width) / 2;
       
    79     var y = (chrome.displaySize.height - snippet.geometry.height) / 2;
       
    80     snippet.setPosition(x, y);
       
    81 }
       
    82 
       
    83 function getChildById(el, childId) {
       
    84     var children = el.getElementsByTagName("*");
       
    85     for (var i = 0; i < children.length; i++) {
       
    86         var child = children[i];
       
    87         if (child.id == childId)
       
    88             return child;
       
    89     }
       
    90     return undefined;
       
    91 }
       
    92 
       
    93 function onActivateBookmarkView() {
       
    94     window.bookmarksManager.launchBookmarkEditDailog.connect(showBookmarkEditDialog);
       
    95 }
       
    96 function preLoad()
       
    97 {   
       
    98     preloadSuperPage("BookmarkTreeView", "bookmarkview.superpage/BookmarkView.html");
       
    99     preloadSuperPage("SettingsView", "settingsview.superpage/SettingsView.html"); 
       
   100     preLoadBookmarksDone=1;
       
   101 }
       
   102 function _updateHistory()
       
   103 {
       
   104 	preloadSuperPage("BookmarkHistoryView", "historyview.superpage/historyView.html");
       
   105 
       
   106 }
       
   107 
       
   108 function _updateBookmarks()
       
   109 {
       
   110     preloadSuperPage("BookmarkTreeView", "bookmarkview.superpage/BookmarkView.html");
       
   111 }
       
   112 
       
   113 // chrome_popupShownCount keeps a count of how many popups are currently being shown so that
       
   114 // we can re-enable the appropriate UI elements only when the last one is hidden.
       
   115 var chrome_popupShownCount = 0;
       
   116 
       
   117 // Called when a PopupChromeItem is displayed.
       
   118 function onPopupShown(id) {
       
   119     if(chrome_popupShownCount == 0) {
       
   120         // Disable snippets etc. that should be greyed-out while the popup is shown. 
       
   121         snippets.UrlSearchChromeId.enabled = false;
       
   122         views.WebView.enabled = false;
       
   123         views.WebView.freeze();
       
   124         
       
   125         // Note: this can be expanded as needed.  We may want to disable all snippets except
       
   126         // for the status bar and the one who's id was passed in.
       
   127     }
       
   128     chrome_popupShownCount++;
       
   129     
       
   130     if(preLoadBookmarksDone==0)
       
   131     {
       
   132     	preLoad();
       
   133     }
       
   134 }
       
   135 
       
   136 // Called when a PopupChromeItem is hidden.
       
   137 function onPopupHidden(id) {
       
   138     chrome_popupShownCount--;
       
   139     if(chrome_popupShownCount == 0) {
       
   140         // Re-enable snippets etc. that were greyed-out while popups were being shown.
       
   141         snippets.UrlSearchChromeId.enabled = true;
       
   142         views.WebView.enabled = true;
       
   143         views.WebView.unfreeze();
       
   144     }
       
   145     if(chrome_popupShownCount < 0) app.debug("onPopupHidden: error, chrome_popupShownCount invalid");
       
   146 }
       
   147 
       
   148 function preloadSuperPage(pageName, path) {
       
   149     if (window.views.WebView[pageName] == undefined) {
       
   150         window.views.WebView.createSuperPage(pageName, true);
       
   151     }
       
   152     window.views.WebView[pageName].load(chrome.baseDirectory + path);
       
   153 }
       
   154 
    40 function onChromeComplete(){
   155 function onChromeComplete(){
       
   156     if (app.ui() == "orbit_ui") {
       
   157         snippets.StatusBarChromeId.hide();
       
   158     }
       
   159 
       
   160     window.snippets.WebViewToolbarId.menuButtonSelected.connect(chrome_showBasicMenu);
       
   161     window.snippets.BookmarkViewToolbarId.addBookmarkSelected.connect(chrome_addBookmark);
    41     window.snippets.UrlSearchChromeId.anchorToView("top");
   162     window.snippets.UrlSearchChromeId.anchorToView("top");
    42     
   163     window.snippets.WebViewToolbarId.menuButtonCanceled.connect(chrome_cancelMenu);
    43     window.views.WebView.backEnabled(onBackEnabled);
   164 
    44     window.views.WebView.forwardEnabled(onForwardEnabled);
       
    45     //window.snippets.ButtonContainer.setVisibilityAnimator("G_VISIBILITY_FADE_ANIMATOR");
   165     //window.snippets.ButtonContainer.setVisibilityAnimator("G_VISIBILITY_FADE_ANIMATOR");
    46     
   166 
    47     result = new Array;
   167     result = new Array;
    48     result = calcToolbarPopAnchorOffset(window.snippets.ZoomBarId,
   168     result = calcToolbarPopAnchorOffset(window.snippets.ZoomBarId,
    49                                         window.snippets.ZooomButtonSnippet,
   169                                         window.snippets.ZoomButtonSnippet,
    50                                         0,10);       
   170                                         0,10);
    51     window.snippets.ZoomBarId.anchorTo("ZooomButtonSnippet",result[0],result[1]);
   171     window.snippets.ZoomBarId.anchorTo("ZoomButtonSnippet",result[0],result[1]);
       
   172 
       
   173     snippets.SuggestsChromeId.url = chrome.baseDirectory + "suggests.snippet/suggests.html";
    52     
   174     
    53     result = calcToolbarPopAnchorOffset(window.snippets.ContextMenuId,
   175     window.ViewStack.activateBookmark.connect(onActivateBookmarkView);
    54                                         window.snippets.MenuButtonSnippet,
   176 
    55                                         0,10); 
   177     chrome.popupShown.connect(onPopupShown);
    56     
   178     chrome.popupHidden.connect(onPopupHidden);
    57     window.snippets.ContextMenuId.anchorTo("MenuButtonSnippet",result[0],result[1]);
   179     window.pageController.loadFinished.connect(_updateHistory);
       
   180     window.bookmarksManager.bookmarksCleared.connect(_updateBookmarks);
       
   181     window.bookmarksManager.historyCleared.connect(_updateHistory);
    58 }
   182 }
       
   183 
       
   184 // For debugging: prints all properties and functions attached to a given object.
       
   185 function printProp(x) {
       
   186     var str = "-------------\n" + x + " properties:\n";
       
   187     for (property in x) {
       
   188         str += ("\t" + property + ": " + x[property] + "\n");
       
   189     }
       
   190     app.debug(str);
       
   191 }