#include "hints.h"
static CommandInfo cmd_list[] = {
- /* command function arg mode */
- {"open", command_open, {VP_TARGET_CURRENT, ""}, VP_MODE_NORMAL},
- {"tabopen", command_open, {VP_TARGET_NEW, ""}, VP_MODE_NORMAL},
- {"input", command_input, {0, ":"}, VP_MODE_COMMAND},
- {"inputopen", command_input, {0, ":open "}, VP_MODE_COMMAND},
- {"inputtabopen", command_input, {0, ":tabopen "}, VP_MODE_COMMAND},
- {"inputopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":open "}, VP_MODE_COMMAND},
- {"inputtabopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":tabopen "}, VP_MODE_COMMAND},
- {"quit", command_close, {0}, VP_MODE_NORMAL},
- {"source", command_view_source, {0}, VP_MODE_NORMAL},
- {"back", command_navigate, {VP_NAVIG_BACK}, VP_MODE_NORMAL},
- {"forward", command_navigate, {VP_NAVIG_FORWARD}, VP_MODE_NORMAL},
- {"reload", command_navigate, {VP_NAVIG_RELOAD}, VP_MODE_NORMAL},
- {"reload!", command_navigate, {VP_NAVIG_RELOAD_FORCE}, VP_MODE_NORMAL},
- {"stop", command_navigate, {VP_NAVIG_STOP_LOADING}, VP_MODE_NORMAL},
- {"jumpleft", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}, VP_MODE_NORMAL},
- {"jumpright", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}, VP_MODE_NORMAL},
- {"jumptop", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}, VP_MODE_NORMAL},
- {"jumpbottom", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}, VP_MODE_NORMAL},
- {"pageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL},
- {"pagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL},
- {"halfpageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL},
- {"halfpagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL},
- {"scrollleft", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
- {"scrollright", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
- {"scrollup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
- {"scrolldown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
- {"nmap", command_map, {VP_MODE_NORMAL}, VP_MODE_NORMAL},
- {"imap", command_map, {VP_MODE_INSERT}, VP_MODE_NORMAL},
- {"cmap", command_map, {VP_MODE_COMMAND}, VP_MODE_NORMAL},
- {"hmap", command_map, {VP_MODE_HINTING}, VP_MODE_NORMAL},
- {"nunmap", command_unmap, {VP_MODE_NORMAL}, VP_MODE_NORMAL},
- {"iunmap", command_unmap, {VP_MODE_INSERT}, VP_MODE_NORMAL},
- {"cunmap", command_unmap, {VP_MODE_COMMAND}, VP_MODE_NORMAL},
- {"hunmap", command_unmap, {VP_MODE_HINTING}, VP_MODE_NORMAL},
- {"set", command_set, {0}, VP_MODE_NORMAL},
- {"complete", command_complete, {0}, VP_MODE_COMMAND | VP_MODE_COMPLETE},
- {"complete-back", command_complete, {1}, VP_MODE_COMMAND | VP_MODE_COMPLETE},
- {"inspect", command_inspect, {0}, VP_MODE_NORMAL},
- {"hint-link", command_hints, {HINTS_TYPE_LINK, "."}, VP_MODE_HINTING},
- {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_CLICK_BLANK, ","}, VP_MODE_HINTING},
- {"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING},
- {"hint-focus-prev", command_hints_focus, {1}, VP_MODE_HINTING},
+ /* command function arg mode */
+ {"open", command_open, {VP_TARGET_CURRENT, ""}, VP_MODE_NORMAL},
+ {"tabopen", command_open, {VP_TARGET_NEW, ""}, VP_MODE_NORMAL},
+ {"input", command_input, {0, ":"}, VP_MODE_COMMAND},
+ {"inputopen", command_input, {0, ":open "}, VP_MODE_COMMAND},
+ {"inputtabopen", command_input, {0, ":tabopen "}, VP_MODE_COMMAND},
+ {"inputopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":open "}, VP_MODE_COMMAND},
+ {"inputtabopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":tabopen "}, VP_MODE_COMMAND},
+ {"quit", command_close, {0}, VP_MODE_NORMAL},
+ {"source", command_view_source, {0}, VP_MODE_NORMAL},
+ {"back", command_navigate, {VP_NAVIG_BACK}, VP_MODE_NORMAL},
+ {"forward", command_navigate, {VP_NAVIG_FORWARD}, VP_MODE_NORMAL},
+ {"reload", command_navigate, {VP_NAVIG_RELOAD}, VP_MODE_NORMAL},
+ {"reload!", command_navigate, {VP_NAVIG_RELOAD_FORCE}, VP_MODE_NORMAL},
+ {"stop", command_navigate, {VP_NAVIG_STOP_LOADING}, VP_MODE_NORMAL},
+ {"jumpleft", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}, VP_MODE_NORMAL},
+ {"jumpright", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}, VP_MODE_NORMAL},
+ {"jumptop", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}, VP_MODE_NORMAL},
+ {"jumpbottom", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}, VP_MODE_NORMAL},
+ {"pageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL},
+ {"pagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL},
+ {"halfpageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL},
+ {"halfpagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL},
+ {"scrollleft", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
+ {"scrollright", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
+ {"scrollup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
+ {"scrolldown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL},
+ {"nmap", command_map, {VP_MODE_NORMAL}, VP_MODE_NORMAL},
+ {"imap", command_map, {VP_MODE_INSERT}, VP_MODE_NORMAL},
+ {"cmap", command_map, {VP_MODE_COMMAND}, VP_MODE_NORMAL},
+ {"hmap", command_map, {VP_MODE_HINTING}, VP_MODE_NORMAL},
+ {"nunmap", command_unmap, {VP_MODE_NORMAL}, VP_MODE_NORMAL},
+ {"iunmap", command_unmap, {VP_MODE_INSERT}, VP_MODE_NORMAL},
+ {"cunmap", command_unmap, {VP_MODE_COMMAND}, VP_MODE_NORMAL},
+ {"hunmap", command_unmap, {VP_MODE_HINTING}, VP_MODE_NORMAL},
+ {"set", command_set, {0}, VP_MODE_NORMAL},
+ {"complete", command_complete, {0}, VP_MODE_COMMAND | VP_MODE_COMPLETE},
+ {"complete-back", command_complete, {1}, VP_MODE_COMMAND | VP_MODE_COMPLETE},
+ {"inspect", command_inspect, {0}, VP_MODE_NORMAL},
+ {"hint-link", command_hints, {HINTS_TYPE_LINK, "."}, VP_MODE_HINTING},
+ {"hint-link-new", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK, ","}, VP_MODE_HINTING},
+ {"hint-input-open", command_hints, {HINTS_TYPE_LINK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";o"}, VP_MODE_HINTING},
+ {"hint-input-tabopen", command_hints, {HINTS_TYPE_LINK | HINTS_TARGET_BLANK | HINTS_PROCESS | HINTS_PROCESS_INPUT, ";t"}, VP_MODE_HINTING},
+ {"hint-focus-next", command_hints_focus, {0}, VP_MODE_HINTING},
+ {"hint-focus-prev", command_hints_focus, {1}, VP_MODE_HINTING},
};
static void command_write_input(const gchar* str);
#include <gdk/gdkkeysyms-compat.h>
#include "hints.h"
#include "dom.h"
-#include "main.h"
+#include "command.h"
#define MAX_HINTS 200
#define HINT_CONTAINER_ID "__hint_container"
gulong top_height, gulong offsetX, gulong offsetY);
static void hints_focus(const gulong num);
static void hints_fire(const gulong num);
+static void hints_click_fired_hint(guint mode, Element* elem);
+static void hints_process_fired_hint(guint mode, const gchar* uri);
static Hint* hints_get_hint_by_number(const gulong num);
static GList* hints_get_hint_list_by_number(const gulong num);
static gchar* hints_get_xpath(const gchar* input);
gulong top_width, top_height, offsetX, offsetY;
currentMode = mode;
-
hints_clear();
doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(vp.gui.webview));
dom_element_style_set_property(hint->elem, "background-color", ELEM_BACKGROUND_FOCUS);
dom_dispatch_mouse_event(doc, hint->elem, "mouseover", 0);
+ webkit_dom_element_blur(hint->elem);
}
currentFocusNum = num;
webkit_dom_element_focus(hint->elem);
vp_set_mode(VP_MODE_INSERT, FALSE);
} else {
- if (currentMode & HINTS_OPEN_USE) {
- /* get the elements source or href attribute */
-
+ if (currentMode & HINTS_PROCESS) {
+ hints_process_fired_hint(currentMode, dom_element_get_source(hint->elem));
} else {
- /* TODO I don't get the mouse click event dispatched here to
- * invoce the gtk events for button press wich might be the better
- * way hanlding to open new windows that setting temporary target
- * attribute here */
- gchar* target = webkit_dom_element_get_attribute(hint->elem, "target");
- if (currentMode & HINTS_CLICK_BLANK) { /* open in new window */
- webkit_dom_element_set_attribute(hint->elem, "target", "_blank", NULL);
- } else if (g_strcmp0(target, "_blank") == 0) { /* remove possible target attribute */
- webkit_dom_element_remove_attribute(hint->elem, "target");
- }
-
- /* dispatch click event */
- Document* doc = webkit_web_view_get_dom_document(vp.gui.webview);
- dom_dispatch_mouse_event(doc, hint->elem, "click", 0);
+ hints_click_fired_hint(currentMode, hint->elem);
- /* reset previous target attribute */
- if (target && strlen(target)) {
- webkit_dom_element_set_attribute(hint->elem, "target", target, NULL);
- } else {
- webkit_dom_element_remove_attribute(hint->elem, "target");
- }
+ /* remove the hint filter input and witch to normal mode */
+ vp_set_mode(VP_MODE_NORMAL, TRUE);
}
-
- /* remove the hint filter input and witch to normal mode */
- vp_set_mode(VP_MODE_NORMAL, TRUE);
}
hints_clear();
}
+/**
+ * Perform a mouse click to given element.
+ */
+static void hints_click_fired_hint(guint mode, Element* elem)
+{
+ /* TODO I don't get the mouse click event dispatched here to
+ * invoke the gtk events for button press wich might be the better
+ * way hanlding to open new windows than setting temporary target
+ * attribute here */
+ gchar* target = webkit_dom_element_get_attribute(elem, "target");
+ if (mode & HINTS_TARGET_BLANK) { /* open in new window */
+ webkit_dom_element_set_attribute(elem, "target", "_blank", NULL);
+ } else if (g_strcmp0(target, "_blank") == 0) { /* remove possible target attribute */
+ webkit_dom_element_remove_attribute(elem, "target");
+ }
+
+ /* dispatch click event */
+ /* TODO use document of the hint an not the default one, but this is only
+ * required if we hint also into frames and iframes */
+ Document* doc = webkit_web_view_get_dom_document(vp.gui.webview);
+ dom_dispatch_mouse_event(doc, elem, "click", 0);
+
+ /* reset previous target attribute */
+ if (target && strlen(target)) {
+ webkit_dom_element_set_attribute(elem, "target", target, NULL);
+ } else {
+ webkit_dom_element_remove_attribute(elem, "target");
+ }
+}
+
+/**
+ * Handle fired hints that are not opened via simulated mouse click.
+ */
+static void hints_process_fired_hint(guint mode, const gchar* uri)
+{
+ HintsProcess type = HINTS_GET_PROCESSING(mode);
+ Arg a = {0};
+ switch (type) {
+ case HINTS_PROCESS_INPUT:
+ a.s = g_strconcat((mode & HINTS_TARGET_BLANK) ? ":tabopen " : ":open ", uri, NULL);
+ command_input(&a);
+ g_free(a.s);
+ break;
+
+ case HINTS_PROCESS_YANK:
+ /* TODO not implemented */
+ break;
+ }
+}
+
static Hint* hints_get_hint_by_number(const gulong num)
{
GList* list = hints_get_hint_list_by_number(num);
{
gchar* xpath = NULL;
- switch (CLEAN_HINTS_TYPE(currentMode)) {
+ switch (HINTS_GET_TYPE(currentMode)) {
case HINTS_TYPE_LINK:
if (input == NULL) {
xpath = g_strdup(
{
const gchar* text = GET_TEXT();
- if (text[0] == '.' || text[0] == ',') {
- hints_create(text + 1, currentMode);
- }
+ /* skip hinting prefixes like '. ', ', ', ';y' ... */
+ hints_create(text + 2, currentMode);
return TRUE;
}