From bb1073fa828ebe2f0043ee52f33eafbb652d896b Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Fri, 21 Dec 2012 14:22:37 +0100 Subject: [PATCH] Use a bitmap for the hints type and open modes. --- src/command.c | 4 ++-- src/hints.c | 42 ++++++++++++++++++++++-------------------- src/hints.h | 25 +++++++++++++++++++------ 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/command.c b/src/command.c index 570fd99..6242fe8 100644 --- a/src/command.c +++ b/src/command.c @@ -64,8 +64,8 @@ static CommandInfo cmd_list[] = { {"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_MODE_LINK, "."}, VP_MODE_HINTING}, - {"hint-link-new", command_hints, {HINTS_MODE_LINK_NEW, ","}, VP_MODE_HINTING}, + {"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}, }; diff --git a/src/hints.c b/src/hints.c index a2b6ba3..382bdee 100644 --- a/src/hints.c +++ b/src/hints.c @@ -71,7 +71,7 @@ static GList* hints = NULL; static gulong currentFocusNum = 0; static gulong hintCount = 0; static gulong hintNum = 0; -static HintMode currentMode = HINTS_MODE_LINK; +static guint currentMode = HINTS_TYPE_LINK; static Element* hintContainer = NULL; void hints_clear(void) @@ -103,16 +103,13 @@ void hints_clear(void) hints_observe_input(FALSE); } -void hints_create(const gchar* input, HintMode mode) +void hints_create(const gchar* input, guint mode) { Document* doc; Window* win; gulong top_width, top_height, offsetX, offsetY; - /* set the current mode only if this was given */ - if (mode) { - currentMode = mode; - } + currentMode = mode; hints_clear(); @@ -150,7 +147,7 @@ void hints_update(const gulong num) if (num == 0) { /* recreate the hints */ - hints_create(NULL, 0); + hints_create(NULL, currentMode); return; } @@ -318,17 +315,23 @@ static void hints_focus(const gulong num) static void hints_fire(const gulong num) { Hint* hint = hints_get_hint_by_number(num); - if (hint) { - if (dom_is_editable(hint->elem)) { - webkit_dom_element_focus(hint->elem); - vp_set_mode(VP_MODE_INSERT, FALSE); + if (!hint) { + return; + } + if (dom_is_editable(hint->elem)) { + 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 */ + } 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_MODE_LINK_NEW) { /* open in new window */ + 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"); @@ -344,12 +347,12 @@ static void hints_fire(const gulong num) } 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); } - hints_clear(); + + /* remove the hint filter input and witch to normal mode */ + vp_set_mode(VP_MODE_NORMAL, TRUE); } + hints_clear(); } static Hint* hints_get_hint_by_number(const gulong num) @@ -387,9 +390,8 @@ static gchar* hints_get_xpath(const gchar* input) { gchar* xpath = NULL; - switch (currentMode) { - case HINTS_MODE_LINK: - case HINTS_MODE_LINK_NEW: + switch (CLEAN_HINTS_TYPE(currentMode)) { + case HINTS_TYPE_LINK: if (input == NULL) { xpath = g_strdup( "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @ role='link'] | " @@ -414,7 +416,7 @@ static gchar* hints_get_xpath(const gchar* input) } break; - case HINTS_MODE_IMAGE: + case HINTS_TYPE_IMAGE: if (input == NULL) { xpath = g_strdup("//img[@src]"); } else { diff --git a/src/hints.h b/src/hints.h index 6a0840f..2e7c4c9 100644 --- a/src/hints.h +++ b/src/hints.h @@ -22,13 +22,26 @@ #include "main.h" -typedef enum { - HINTS_MODE_LINK = 1, - HINTS_MODE_LINK_NEW = 2, - HINTS_MODE_IMAGE = 3, -} HintMode; +#define CLEAN_HINTS_TYPE(type) ((type) & ~(HINTS_OPEN_USE | HINTS_CLICK_BLANK)) -void hints_create(const gchar* input, HintMode mode); +enum { + HINTS_TYPE_LINK, + HINTS_TYPE_IMAGE, + HINTS_TYPE_DEFAULT, + HINTS_TYPE_FORM +} HintsType; + +enum { + HINTS_OPEN_CLICK, + HINTS_OPEN_USE = (1 << 2) +}; + +enum { + HINTS_CLICK_CURRENT, + HINTS_CLICK_BLANK = (1 << 3) +}; + +void hints_create(const gchar* input, guint mode); void hints_update(const gulong num); void hints_clear(void); void hints_clear_focus(void); -- 2.20.1