#define HINT_VAR "VpHint"
#define HINT_FILE NULL
+extern const unsigned int MAXIMUM_HINTS;
+
static void hints_run_script(Client* c, char* js);
static void hints_fire(Client* c);
static void hints_observe_input(Client* c, gboolean observe);
void hints_create(Client* c, const char* input, guint mode, const guint prefixLength)
{
char* js = NULL;
- char type, usage;
if (CLEAN_MODE(c->state.mode) != VP_MODE_HINTING) {
Style* style = &core.style;
c->hints.prefixLength = prefixLength;
c->hints.mode = mode;
c->hints.num = 0;
+ char type, usage;
+ /* convert the mode into the type chare used in the hint script */
+ type = mode & HINTS_TYPE_LINK ? 'l' : 'i';
+
+ if (mode & HINTS_PROCESS_OPEN) {
+ usage = mode & HINTS_OPEN_NEW ? 'T' : 'O';
+ } else {
+ usage = 'U';
+ }
+
js = g_strdup_printf(
- "%s = new VimpHints('%s', '%s', '%s', '%s');",
- HINT_VAR,
+ "%s = new VimpHints('%c', '%c', '%s', '%s', '%s', '%s', %d);",
+ HINT_VAR, type, usage,
style->hint_bg,
style->hint_bg_focus,
style->hint_fg,
- style->hint_style
+ style->hint_style,
+ MAXIMUM_HINTS
);
hints_run_script(c, js);
g_free(js);
hints_observe_input(c, TRUE);
}
- /* convert the mode into the type chare used in the hint script */
- if (mode & HINTS_TYPE_LINK) {
- type = 'l';
- } else if (HINTS_TYPE_IMAGE) {
- type = 'i';
- }
-
- if (mode & HINTS_PROCESS_OPEN) {
- usage = mode & HINTS_OPEN_NEW ? 'T' : 'O';
- } else {
- usage = 'U';
- }
- js = g_strdup_printf(
- "%s.create('%s', '%c', '%c');",
- HINT_VAR,
- input ? input : "", type,
- usage
- );
+ js = g_strdup_printf("%s.create('%s');", HINT_VAR, input ? input : "");
hints_run_script(c, js);
g_free(js);
}
-VimpHints = function Hints(bg, bgf, fg, style) {
+/* mode: l - links, i - images */
+/* usage: O - open, T - open in new window, U - use source */
+VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) {
"use strict";
- var config = {
- maxHints: 200,
- hintCss: style,
- hintClass: "__hint",
- hintClassFocus: "__hint_container",
- eBg: bg,
- eBgf: bgf,
- eFg: fg
- };
-
+ var hClass = "__hint";
+ var hClassFocus = "__hint_container";
var hCont;
var curFocusNum = 1;
var hints = [];
- var mode;
- /* O - open, T - open in new window, U - use source */
- var usage;
- this.create = function(inputText, hintMode, resultUsage)
+ this.create = function(inputText)
{
- if (hintMode) {
- mode = hintMode;
- }
- if (resultUsage) {
- usage = resultUsage;
- }
-
var topwin = window;
var top_height = topwin.innerHeight;
var top_width = topwin.innerWidth;
/* generate basic hint element which will be cloned and updated later */
var hintSpan = doc.createElement("span");
- hintSpan.setAttribute("class", config.hintClass);
- hintSpan.style.cssText = config.hintCss;
+ hintSpan.setAttribute("class", hClass);
+ hintSpan.style.cssText = style;
/* due to the different XPath result type, we will need two counter variables */
var rect, elem, text, node, show_text;
for (i = 0; i < res.snapshotLength; i++) {
- if (hintCount >= config.maxHints) {
+ if (hintCount >= maxHints) {
break;
}
continue;
}
- var style = topwin.getComputedStyle(elem, "");
- if (style.display === "none" || style.visibility !== "visible") {
+ var cStyle = topwin.getComputedStyle(elem, "");
+ if (cStyle.display === "none" || cStyle.visibility !== "visible") {
continue;
}
);
/* make the link black to ensure it's readable */
- elem.style.color = config.eFg;
- elem.style.background = config.eBg;
+ elem.style.color = fg;
+ elem.style.background = bg;
}
doc.documentElement.appendChild(hCont);
/* reset previous focused hint */
var hint = _getHintByNumber(curFocusNum);
if (hint !== null) {
- hint.elem.className = hint.elem.className.replace(config.hintClassFocus, config.hintClass);
- hint.elem.style.background = config.eBg;
+ hint.elem.className = hint.elem.className.replace(hClassFocus, hClass);
+ hint.elem.style.background = bg;
_mouseEvent(hint.elem, "mouseout");
}
/* mark new hint as focused */
hint = _getHintByNumber(curFocusNum);
if (hint !== null) {
- hint.elem.className = hint.elem.className.replace(config.hintClass, config.hintClassFocus);
- hint.elem.style.background = config.eBgf;
+ hint.elem.className = hint.elem.className.replace(hClass, hClassFocus);
+ hint.elem.style.background = bgf;
_mouseEvent(hint.elem, "mouseover");
var source = _getSrc(hint.elem);
expr = "//img[@src and contains(., '" + s + "')]";
}
break;
- default:
- if (s === "") {
- expr = "//*[@role='link' or @href] | //a[href] | //area | //img[not(ancestor::a)]";
- } else {
- expr = "//*[(@role='link' or @href) and contains(., '" + s + "')] | //a[@href and contains(., '" + s + "')] | //area[contains(., '" + s + "')] | //img[not(ancestor::a) and contains(., '" + s + "')]";
- }
- break;
}
return expr;
}