ginebra2/chrome/bedrockchrome/chrome.js
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 var _backEnabled = false;
       
     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 
     1 
    15 function calcToolbarPopAnchorOffset(anchoredSnippet,
     2 function calcToolbarPopAnchorOffset(anchoredSnippet,
    16                                     anchorToSnippet,
     3                                     anchorToSnippet,
    17                                     xCenterOffset,
     4                                     xCenterOffset,
    18                                     yBotGap)
     5                                     yBotGap)
    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     if (window.views.WebView[pageName] == undefined) {
       
    30         window.views.WebView.createSuperPage(pageName, true);
       
    31     }
       
    32     window.views.WebView[pageName].load(chrome.baseDirectory + path);
       
    33 
       
    34     // Show it.
       
    35     window.views.WebView.zoomFactor = 1.0;
       
    36     window.views.WebView.showSuperPage(pageName);
       
    37     window.ViewStack.switchView(pageName, "WebView");
       
    38 }
       
    39 
       
    40 function chrome_showBookmarksView() {
       
    41     app.debug("chrome_showBookmarksView");
       
    42     showSuperPage("BookmarkTreeView", "bookmarkview.superpage/BookmarkView.html");
       
    43 }
       
    44 
       
    45 function chrome_showHistoryView() {
       
    46     app.debug("chrome_showHistoryView");
       
    47     showSuperPage("BookmarkHistoryView", "historyview.superpage/historyView.html");
       
    48 //    showHistoryView();
       
    49 }
       
    50 
       
    51 function chrome_showWindowsView() {
       
    52     app.debug("chrome_showWindowsView");
       
    53     window.snippets.ZoomBarId.hide(); // hide Zoom Bar while showing windows view
       
    54     window.snippets.MostVisitedViewId.hide();
       
    55     window.ViewStack.switchView("WindowView", "WebView");
       
    56 }
       
    57 
       
    58 function chrome_showSettingsView() {
       
    59     app.debug("chrome_showSettingsView");
       
    60     showSuperPage("SettingsView", "settingsview.superpage/SettingsView.html");
       
    61 }
       
    62 
       
    63 function chrome_showBasicMenu() {
       
    64     if (!snippets.ContextMenuId.dontShow) {
       
    65         cm_TheContextMenu.show(viewMenu_getWebViewContextMenuData());
       
    66     }
       
    67 }
       
    68 
       
    69 function chrome_addBookmark() {
       
    70     launchBookmarkDialog(window.pageController.currentDocTitle,window.pageController.currentDocUrl,0);
       
    71 }
       
    72 
       
    73 function chrome_cancelMenu() {
       
    74 
       
    75     cm_TheContextMenu.cancel();
       
    76 }
       
    77 
       
    78 // Center the given snippet on-screen.
       
    79 function centerSnippet(snippet) {
       
    80     var x = (chrome.displaySize.width - snippet.geometry.width) / 2;
       
    81     var y = (chrome.displaySize.height - snippet.geometry.height) / 2;
       
    82     snippet.setPosition(x, y);
       
    83 }
       
    84 
       
    85 function getChildById(el, childId) {
       
    86     var children = el.getElementsByTagName("*");
       
    87     for (var i = 0; i < children.length; i++) {
       
    88         var child = children[i];
       
    89         if (child.id == childId)
       
    90             return child;
       
    91     }
       
    92     return undefined;
       
    93 }
       
    94 
       
    95 function onActivateBookmarkView() {
       
    96     window.bookmarksManager.launchBookmarkEditDailog.connect(showBookmarkEditDialog);
       
    97 }
       
    98 
       
    99 // Called when a PopupChromeItem is displayed.
       
   100 function onPopupShown(id) {
       
   101     // Disable snippets etc. that should be greyed-out while the popup is shown. 
       
   102     snippets.UrlSearchChromeId.enabled = false;
       
   103     views.WebView.enabled = false;
       
   104     views.WebView.freeze();
       
   105     
       
   106     // Note: this can be expanded as needed.  We may want to disable all snippets except
       
   107     // for the urlSearchBar and the one who's id was passed in.
       
   108 }
       
   109 
       
   110 // Called when a PopupChromeItem is hidden.
       
   111 function onPopupHidden(id) {
       
   112     // Re-enable snippets etc. that were greyed-out while the popup is shown.
       
   113     snippets.UrlSearchChromeId.enabled = true;
       
   114     views.WebView.enabled = true;
       
   115     views.WebView.unfreeze();
       
   116 }
       
   117 
    40 function onChromeComplete(){
   118 function onChromeComplete(){
       
   119     if (app.ui() != "orbit_ui") {
       
   120         snippets.StatusBarChromeId.show();
       
   121     }
       
   122 
       
   123     window.snippets.WebViewToolbarId.menuButtonSelected.connect(chrome_showBasicMenu);
       
   124     window.snippets.BookmarkViewToolbarId.addBookmarkSelected.connect(chrome_addBookmark);
    41     window.snippets.UrlSearchChromeId.anchorToView("top");
   125     window.snippets.UrlSearchChromeId.anchorToView("top");
    42     
   126     window.snippets.WebViewToolbarId.menuButtonCanceled.connect(chrome_cancelMenu);
    43     window.views.WebView.backEnabled(onBackEnabled);
   127 
    44     window.views.WebView.forwardEnabled(onForwardEnabled);
       
    45     //window.snippets.ButtonContainer.setVisibilityAnimator("G_VISIBILITY_FADE_ANIMATOR");
   128     //window.snippets.ButtonContainer.setVisibilityAnimator("G_VISIBILITY_FADE_ANIMATOR");
    46     
   129 
    47     result = new Array;
   130     result = new Array;
    48     result = calcToolbarPopAnchorOffset(window.snippets.ZoomBarId,
   131     result = calcToolbarPopAnchorOffset(window.snippets.ZoomBarId,
    49                                         window.snippets.ZooomButtonSnippet,
   132                                         window.snippets.ZoomButtonSnippet,
    50                                         0,10);       
   133                                         0,10);
    51     window.snippets.ZoomBarId.anchorTo("ZooomButtonSnippet",result[0],result[1]);
   134     window.snippets.ZoomBarId.anchorTo("ZoomButtonSnippet",result[0],result[1]);
       
   135 
       
   136     snippets.SuggestsChromeId.url = chrome.baseDirectory + "suggests.snippet/suggests.html";
    52     
   137     
    53     result = calcToolbarPopAnchorOffset(window.snippets.ContextMenuId,
   138     window.ViewStack.activateBookmark.connect(onActivateBookmarkView);
    54                                         window.snippets.MenuButtonSnippet,
   139 
    55                                         0,10); 
   140     chrome.popupShown.connect(onPopupShown);
    56     
   141     chrome.popupHidden.connect(onPopupHidden);
    57     window.snippets.ContextMenuId.anchorTo("MenuButtonSnippet",result[0],result[1]);
       
    58 }
   142 }
       
   143 
       
   144 // For debugging: prints all properties and functions attached to a given object.
       
   145 function printProp(x) {
       
   146     var str = "-------------\n" + x + " properties:\n";
       
   147     for (property in x) {
       
   148         str += ("\t" + property + ": " + x[property] + "\n");
       
   149     }
       
   150     app.debug(str);
       
   151 }