diff -r b0dd75e285d2 -r 0f2326c2a325 ginebra2/chrome/bedrockchrome/suggests.snippet/suggests.js
--- a/ginebra2/chrome/bedrockchrome/suggests.snippet/suggests.js Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/chrome/bedrockchrome/suggests.snippet/suggests.js Wed Jun 23 17:59:43 2010 +0300
@@ -1,69 +1,250 @@
+/*!
+ \file suggests.js This module contains the Suggests class.
+*/
+
+/*!
+ Class to handle displaying URL suggestions from history and bookmarks.
+*/
function Suggests()
{
- // attach internal funcs
- this.write = writeSuggests;
+ // "Private" member variables
+ var suggestsXOffset = 20;
+ var inputTimeoutId = null;
+ var inputTimeoutDelay = _getTimeoutDelaySetting();
+ var maxHeight = 0; // maximum height of suggest list
+ var urlSearchHeight = 0;
- // do setup
- this.write();
+ // "Private" methods
- this.showSuggests = function() {
- window.chrome.alert("showSuggests");
- //window.snippets.updateGeometry();
- window.snippets.SuggestsId.repaint();
+ //! Calculates the maximum height for the suggest list.
+ //! If not all suggest items can fit in list, only half an item should be
+ //! visible the end when scrolled to the top. This is to indicate more items.
+ function _setMaxHeight()
+ {
+ // Calculate height of available space for suggest list.
+ var statusbarSz = snippets.StatusBarChromeId.getGeometry();
+ var urlSearchSz = snippets.UrlSearchChromeId.getGeometry();
+ var toolbarSz = snippets.WebViewToolbarId.getGeometry();
+ // leave some space between suggest and toolbar (~10% of display height)
+ var bufferHeight = Math.ceil(chrome.displaySize.height / 10);
+ var availableHeight = chrome.displaySize.height -
+ (statusbarSz.height + urlSearchSz.height + toolbarSz.height + bufferHeight);
+ // Calculate number of elements that can fit in available space.
+ var elementHeight = 70; // set in suggests.css
+ var numElements = Math.floor(availableHeight / elementHeight);
- var curPos = window.snippets.SuggestsId.getPosition();
- window.chrome.alert(curPos.x);
- if (curPos.y == 0)
- window.snippets.SuggestsId.setPosition(5,68);
- window.snippets.SuggestsId.show();
- window.snippets.SuggestsId.zValue = 10;
+ // in order to make room for 1/2 entry at end of list we may
+ // need to sacrifice 1 full element.
+ if ((availableHeight % elementHeight) < (elementHeight / 2)) {
+ numElements -= 1;
+ }
+ numElements += 0.5; // half of final visible entry
+ // max suggest list height in pixels
+ maxHeight = Math.floor(numElements * elementHeight);
}
- this.hideSuggests = function() {
- window.snippets.SuggestsId.hide();
+ //! Temporary substitute for settings function to get the delay for
+ //! displaying the URL suggests list.
+ function _getTimeoutDelaySetting()
+ {
+ // no setting stored for this currently
+ return (1000); // 1 second
+ }
+
+ //! Displays and updates suggest list.
+ function _showSuggests()
+ {
+ // make sure the input is the latest
+ var input = window.snippets.UrlSearchChromeId.url;
+
+ // only display suggestions if there is input
+ if (input.length != 0) {
+ _updateSuggestList(input);
+ this.updateSuggestsSize();
+
+ if (!snippets.SuggestsChromeId.visible
+ && (pageController.loadState == Suggests.GotoModeEditing)) {
+ window.scrollTo(0, 0);
+ // Disable the content view, leave the URL serach bar and status bar enabled.
+ views.WebView.enabled = false;
+ views.WebView.freeze();
+ snippets.SuggestsChromeId.show(false);
+ }
+ } else {
+ // no user input so hide suggestions
+ _hideSuggests();
+ }
}
- this.setWidth = function(width) {
- document.getElementById("SuggestsId").style.width = width;
- //window.chrome.alert("set width:" + document.getElementById("SuggestsId").offsetWidth);
+ //! Updates the suggestion list based on the specified input.
+ /*!
+ \param input the current URL box text
+ */
+ function _updateSuggestList(input)
+ {
+ var recenturl;
+ var recenttitle = window.localeDelegate.translateText(
+ "txt_browser_url_bar_drop_down_search_for");
+ var snippetId = document.getElementById('SuggestsId');
+ var suggests = window.pageController.fetchSuggestions(input);
+ var suggestUL = document.createElement('ul');
+ var suggestLI = document.createElement('li');
+ var pattern = new RegExp(input, "ig");
+
+ snippetId.innerHTML = ""; // clear previous results
+ suggestUL.id = 'suggestUlId';
+ suggestLI.id = "searchLiId";
+
+ // always provide an option to search for user entry
+ recenttitle = recenttitle.replace(/%1/, "" + input + "");
+
+ suggestLI.innerHTML = ''+
+ '
'+
+ ''+recenturl+'