author | hgs |
Fri, 06 Aug 2010 17:23:08 -0400 | |
changeset 9 | b39122337a00 |
parent 3 | 0954f5dd2cd0 |
child 12 | afcd8e6d025b |
permissions | -rw-r--r-- |
3 | 1 |
var preLoadBookmarksDone=0; |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
function calcToolbarPopAnchorOffset(anchoredSnippet, |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
anchorToSnippet, |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
xCenterOffset, |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
yBotGap) |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
{ |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
// For popup-chrome (menu, zoomBtn) they are aligned by default |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
// to the upper left-hand corners. |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
// This will calculate the offset needed to center the popup above the |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
// button, or make it slightly off-center |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
// xCenterOffset = make x param this much off center |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
// yBotGap = how much gap should there be between top of anchorTo, |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
// and bottom of anchored |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
// |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
anchorToGeom = anchorToSnippet.getGeometry(); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
anchoredGeom = anchoredSnippet.getGeometry(); |
3 | 20 |
xOffset = -(0.5 * anchoredGeom.width) + |
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
(0.5 * anchorToGeom.width) + |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
xCenterOffset; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
yOffset = -anchoredGeom.height - yBotGap; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
return([xOffset,yOffset]); |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
} |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
|
3 | 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++; |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
129 |
|
3 | 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 |
||
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); |
|
162 |
window.snippets.UrlSearchChromeId.anchorToView("top"); |
|
163 |
window.snippets.WebViewToolbarId.menuButtonCanceled.connect(chrome_cancelMenu); |
|
164 |
||
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
165 |
//window.snippets.ButtonContainer.setVisibilityAnimator("G_VISIBILITY_FADE_ANIMATOR"); |
3 | 166 |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
167 |
result = new Array; |
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
168 |
result = calcToolbarPopAnchorOffset(window.snippets.ZoomBarId, |
3 | 169 |
window.snippets.ZoomButtonSnippet, |
170 |
0,10); |
|
171 |
window.snippets.ZoomBarId.anchorTo("ZoomButtonSnippet",result[0],result[1]); |
|
172 |
||
173 |
snippets.SuggestsChromeId.url = chrome.baseDirectory + "suggests.snippet/suggests.html"; |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
174 |
|
3 | 175 |
window.ViewStack.activateBookmark.connect(onActivateBookmarkView); |
176 |
||
177 |
chrome.popupShown.connect(onPopupShown); |
|
178 |
chrome.popupHidden.connect(onPopupHidden); |
|
179 |
window.pageController.loadFinished.connect(_updateHistory); |
|
9 | 180 |
window.pageController.loadFinishedForBackgroundWindow.connect(_updateHistory); |
3 | 181 |
window.bookmarksManager.bookmarksCleared.connect(_updateBookmarks); |
182 |
window.bookmarksManager.historyCleared.connect(_updateHistory); |
|
0
1450b09d0cfd
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
183 |
} |
3 | 184 |
|
185 |
// For debugging: prints all properties and functions attached to a given object. |
|
186 |
function printProp(x) { |
|
187 |
var str = "-------------\n" + x + " properties:\n"; |
|
188 |
for (property in x) { |
|
189 |
str += ("\t" + property + ": " + x[property] + "\n"); |
|
190 |
} |
|
191 |
app.debug(str); |
|
192 |
} |