{"complete", command_complete, {0}},
{"complete-back", command_complete, {1}},
{"inspect", command_inspect, {0}},
- {"hint-link", command_hints, {HINTS_TYPE_LINK, "."}},
- {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK, ","}},
- {"hint-input-open", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";o"}},
- {"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";t"}},
- {"hint-yank", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_YANK, ";y"}},
- {"hint-image-open", command_hints, {HINTS_TYPE_IMAGE, ";i"}},
- {"hint-image-tabopen", command_hints, {HINTS_TYPE_IMAGE | HINTS_TARGET_BLANK, ";I"}},
+ {"hint-link", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_OPEN, "."}},
+ {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_OPEN | HINTS_OPEN_NEW, ","}},
+ {"hint-input-open", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_INPUT, ";o"}},
+ {"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_INPUT | HINTS_OPEN_NEW, ";t"}},
+ {"hint-yank", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS_YANK, ";y"}},
+ {"hint-image-open", command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN, ";i"}},
+ {"hint-image-tabopen", command_hints, {HINTS_TYPE_IMAGE | HINTS_PROCESS_OPEN | HINTS_OPEN_NEW, ";I"}},
{"hint-focus-next", command_hints_focus, {0}},
{"hint-focus-prev", command_hints_focus, {1}},
{"yank-uri", command_yank, {COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY | COMMAND_YANK_URI}},
}
/* convert the mode into the type chare used in the hint script */
- if (mode & HINTS_PROCESS) {
- type = 'd';
- } else if (mode & HINTS_TYPE_IMAGE) {
- type = (HINTS_TARGET_BLANK & mode) ? 'I' : 'i';
- } else {
- type = (HINTS_TARGET_BLANK & mode) ? 'F' : 'f';
+ if (mode & HINTS_TYPE_LINK) {
+ type = 'l';
+ } else if (HINTS_TYPE_IMAGE) {
+ type = 'i';
}
js = g_strdup_printf("%s.create('%s', '%c');", HINT_VAR, input ? input : "", type);
} else if (!strncmp(value, "DATA:", 5)) {
hints_observe_input(FALSE);
Arg a = {0};
- if (mode & HINTS_TYPE_IMAGE) {
- a.s = (value + 5);
- a.i = (mode & HINTS_TARGET_BLANK) ? VP_TARGET_NEW : VP_TARGET_CURRENT;
+ char* v = (value + 5);
+ if (mode & HINTS_PROCESS_OPEN) {
+ a.s = v;
+ a.i = (mode & HINTS_OPEN_NEW) ? VP_TARGET_NEW : VP_TARGET_CURRENT;
command_open(&a);
+ } else if (mode & HINTS_PROCESS_INPUT) {
+ a.s = g_strconcat((mode & HINTS_OPEN_NEW) ? ":tabopen " : ":open ", v, NULL);
+ command_input(&a);
+ g_free(a.s);
} else {
- HintsProcess type = HINTS_GET_PROCESSING(mode);
- if (type == HINTS_PROCESS_INPUT) {
- a.s = g_strconcat((mode & HINTS_TARGET_BLANK) ? ":tabopen " : ":open ", (value + 5), NULL);
- command_input(&a);
- g_free(a.s);
- } else if (type == HINTS_PROCESS_YANK) {
- a.i = COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY;
- a.s = (value + 5);
- command_yank(&a);
- }
+ a.i = COMMAND_YANK_PRIMARY | COMMAND_YANK_SECONDARY;
+ a.s = v;
+ command_yank(&a);
}
}
g_free(value);
g_signal_handler_disconnect(G_OBJECT(vp.gui.inputbox), keypressHandler);
changeHandler = 0;
keypressHandler = 0;
+
+ /* clear the input box - TODO move this to a better place */
+ gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview));
+ gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), "");
}
}
#include "main.h"
-#define HINTS_GET_PROCESSING(type) ((type) & ~(HINTS_TYPE_LINK | HINTS_TYPE_IMAGE | HINTS_PROCESS | HINTS_TARGET_BLANK))
-
-typedef enum {
- HINTS_TYPE_LINK = (1 << 1),
- HINTS_TYPE_IMAGE = (1 << 2),
- HINTS_TYPE_LAST = HINTS_TYPE_IMAGE,
-} HintsType;
+#define HINTS_GET_TYPE(n) ((n) & (HINTS_TYPE_LINK | HINTS_TYPE_IMAGE))
enum {
- HINTS_PROCESS = (1 << 3),
- HINTS_TARGET_BLANK = (1 << 4)
+ HINTS_TYPE_LINK = 1,
+ HINTS_TYPE_IMAGE = 2,
+ HINTS_PROCESS_INPUT = (1 << 2),
+ HINTS_PROCESS_YANK = (1 << 3),
+ HINTS_PROCESS_OPEN = (1 << 4),
+ HINTS_OPEN_NEW = (1 << 5),
};
-typedef enum {
- HINTS_PROCESS_INPUT = (1 << 5),
- HINTS_PROCESS_YANK = (1 << 6),
-} HintsProcess;
-
void hints_init(WebKitWebFrame* frame);
void hints_create(const char* input, guint mode, const guint prefixLength);
void hints_update(const gulong num);
var hintCount = 0;
this.clear();
- function _helper (win, offsetX, offsetY) {
+ function _helper (win, offsetX, offsetY)
+ {
var doc = win.document;
var win_height = win.height;
hCont = doc.createElement("div");
hCont.id = "hint_container";
- xpath_expr = _getXpathXpression(inputText);
+ xpath_expr = _getXpath(inputText);
- var res = doc.evaluate(xpath_expr, doc,
- function (p) {
- return "http://www.w3.org/1999/xhtml";
- }, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+ var res = doc.evaluate(
+ xpath_expr, doc,
+ function (p) {return "http://www.w3.org/1999/xhtml";},
+ XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
+ );
/* generate basic hint element which will be cloned and updated later */
var hintSpan = doc.createElement("span");
}
var style = topwin.getComputedStyle(elem, "");
- if (style.display == "none" || style.visibility != "visible") {
+ if (style.display === "none" || style.visibility !== "visible") {
continue;
}
if (typeof(hints[index + 1]) !== "undefined") {
return _focus(hints[index + 1].number);
- } else {
- return _focus(hints[0].number);
}
+ return _focus(hints[0].number);
};
/* set focus to previous avaiable hint */
var index = _getHintIdByNumber(curFocusNum);
if (index !== 0 && typeof(hints[index - 1].number) !== "undefined") {
return _focus(hints[index - 1].number);
- } else {
- return _focus(hints[hints.length - 1].number);
}
+ return _focus(hints[hints.length - 1].number);
};
/* filters hints matching given number */
this.fire = function(n)
{
n = n ? n : curFocusNum;
- var result = "DONE:";
var hint = _getHintByNumber(n);
if (!hint || typeof(hint.elem) == "undefined") {
- return result;
+ return "DONE:";
}
var el = hint.elem;
this.clear();
if (tag === "iframe" || tag === "frame" || tag === "textarea" || tag === "select" || tag === "input"
- && (el.type != "image" && el.type != "submit")
+ && (el.type !== "image" && el.type !== "submit")
) {
el.focus();
if (tag === "input" || tag === "textarea") {
return "DONE:";
}
- switch (mode) {
- case "f":
- _open(el);
- break;
- case "F":
- _openNewWindow(el);
- break;
- default:
- result = "DATA:" + _getElemtSource(el);
- break;
- }
-
- return result;
+ return "DATA:" + _getSrc(el);;
};
/* set focus on hint with given number */
hint.elem.className = hint.elem.className.replace(config.hintClass, config.hintClassFocus);
hint.elem.style.background = config.eBgf;
_mouseEvent(hint.elem, "mouseover");
- var source = _getElemtSource(hint.elem);
- return "OVER:" + (source ? source : "");
- }
- }
+ var source = _getSrc(hint.elem);
- /* retrieves text content fro given element */
- function _getTextFromElement(el)
- {
- var text;
- if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
- text = el.value;
- } else if (el instanceof HTMLSelectElement) {
- if (el.selectedIndex >= 0) {
- text = el.item(el.selectedIndex).text;
- } else{
- text = "";
- }
- } else {
- text = el.textContent;
+ return "OVER:" + (source ? source : "");
}
- return text.toLowerCase();
}
/* retrieves the hint for given hint number */
}
}
- /* opens given element */
- function _open(elem)
- {
- if (elem.target == "_blank") {
- elem.removeAttribute("target");
- }
- _mouseEvent(elem, "moudedown");
- _mouseEvent(elem, "click");
- }
-
- /* opens given element into new window */
- function _openNewWindow(elem)
- {
- var oldTarget = elem.target;
-
- /* set target to open in new window */
- elem.target = "_blank";
- _mouseEvent(elem, "moudedown");
- _mouseEvent(elem, "click");
- elem.target = oldTarget;
- }
-
function _mouseEvent(elem, name)
{
var doc = elem.ownerDocument;
}
/* retrieves the url of given element */
- function _getElemtSource(elem)
+ function _getSrc(elem)
{
- var url = elem.href || elem.src;
- return url;
+ return elem.href || elem.src;
}
/* retrieves the xpath expression according to mode */
- function _getXpathXpression(text)
+ function _getXpath(s)
{
var expr;
- if (typeof(text) === "undefined") {
- text = "";
+ if (typeof(s) === "undefined") {
+ s = "";
}
switch (mode) {
- case "f":
- case "F":
- if (text === "") {
+ case "l":
+ if (s === "") {
expr = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href] | //input[not(@type='hidden')] | //a[href] | //area | //textarea | //button | //select";
} else {
- expr = "//*[(@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href) and contains(., '" + text + "')] | //input[not(@type='hidden') and contains(., '" + text + "')] | //a[@href and contains(., '" + text + "')] | //area[contains(., '" + text + "')] | //textarea[contains(., '" + text + "')] | //button[contains(@value, '" + text + "')] | //select[contains(., '" + text + "')]";
+ expr = "//*[(@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href) and contains(., '" + s + "')] | //input[not(@type='hidden') and contains(., '" + s + "')] | //a[@href and contains(., '" + s + "')] | //area[contains(., '" + s + "')] | //textarea[contains(., '" + s + "')] | //button[contains(@value, '" + s + "')] | //select[contains(., '" + s + "')]";
}
break;
case "i":
- case "I":
- if (text === "") {
+ if (s === "") {
expr = "//img[@src]";
} else {
- expr = "//img[@src and contains(., '" + text + "')]";
+ expr = "//img[@src and contains(., '" + s + "')]";
}
break;
default:
- if (text === "") {
+ if (s === "") {
expr = "//*[@role='link' or @href] | //a[href] | //area | //img[not(ancestor::a)]";
} else {
- expr = "//*[(@role='link' or @href) and contains(., '" + text + "')] | //a[@href and contains(., '" + text + "')] | //area[contains(., '" + text + "')] | //img[not(ancestor::a) and contains(., '" + text + "')]";
+ expr = "//*[(@role='link' or @href) and contains(., '" + s + "')] | //a[@href and contains(., '" + s + "')] | //area[contains(., '" + s + "')] | //img[not(ancestor::a) and contains(., '" + s + "')]";
}
break;
}