browser-next-form-field: skip non-visible elements
[conkeror.git] / modules / history.js
blob639f53671d48d95177cd39bd021bc69b768bf3b9
1 /**
2  * (C) Copyright 2008 Eli Naeher
3  * (C) Copyright 2008 Jeremy Maitin-Shepard
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 const nav_history_service = Cc["@mozilla.org/browser/nav-history-service;1"]
10     .getService(Ci.nsINavHistoryService);
12 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks");
13 function history_completer() {
14     keywords(arguments);
15     var use_history = arguments.$use_history;
16     var use_bookmarks = arguments.$use_bookmarks;
17     return function (input, pos, conservative) {
18         if (conservative && input.length == 0)
19             return null;
20         var query = nav_history_service.getNewQuery();
21         query.searchTerms = input;
22         if (!use_history)
23             query.onlyBookmarked = true;
24         var options = nav_history_service.getNewQueryOptions();
25         options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
26         if (use_bookmarks && !use_history)
27             options.queryType = options.QUERY_TYPE_BOOKMARKS;
28         else if (use_history && !use_bookmarks)
29             options.queryType = options.QUERY_TYPE_HISTORY;
30         else
31             options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
32         var root = nav_history_service.executeQuery(query, options).root;
33         root.containerOpen = true;
34         var history_count = root.childCount;
35         return {count: history_count,
36                 get_string: function (i) root.getChild(i).uri,
37                 get_description: function (i) root.getChild(i).title,
38                 get_input_state: function (i) [root.getChild(i).uri],
39                 destroy: function () { root.containerOpen = false; }
40                };
41     }
44 function url_completer() {
45     keywords(arguments);
46     var use_webjumps = arguments.$use_webjumps;
47     var use_history = arguments.$use_history;
48     var use_bookmarks = arguments.$use_bookmarks;
49     var completers = [];
50     completers.push(file_path_completer());
51     if(use_webjumps) {
52         completers.push(webjump_completer());
53     }
54     if(use_history || use_bookmarks) {
55         completers.push(history_completer($use_history = use_history,
56                                           $use_bookmarks = use_bookmarks));
57     }
58     return merge_completers(completers);
61 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
63 function add_bookmark(url, title) {
64     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
65                                          makeURL(url), -1, title);