From: Daniel Carl Date: Sun, 16 Dec 2012 18:13:21 +0000 (+0100) Subject: Use mouse event to open hint instead of c logic. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=f2625d51516f96efc5ae88ae3ac57431320ace14;p=vimb.git Use mouse event to open hint instead of c logic. --- diff --git a/src/dom.c b/src/dom.c index 986d708..71ad4a6 100644 --- a/src/dom.c +++ b/src/dom.c @@ -93,6 +93,24 @@ DomBoundingRect dom_elemen_get_bounding_rect(Element* element) return rect; } +void dom_dispatch_mouse_event(Document* doc, Element* element, gchar* type, gushort button) +{ + Event* event = webkit_dom_document_create_event(doc, "MouseEvents", NULL); + webkit_dom_mouse_event_init_mouse_event( + WEBKIT_DOM_MOUSE_EVENT(event), + type, + TRUE, + TRUE, + webkit_dom_document_get_default_view(doc), + 1, 0, 0, 0, 0, + FALSE, FALSE, FALSE, FALSE, + button, + WEBKIT_DOM_EVENT_TARGET(element) + ); + + webkit_dom_node_dispatch_event(WEBKIT_DOM_NODE(element), event, NULL); +} + static gboolean dom_auto_insert(Element* element) { if (dom_is_editable(element)) { diff --git a/src/dom.h b/src/dom.h index f3ca21a..ce41bc0 100644 --- a/src/dom.h +++ b/src/dom.h @@ -51,5 +51,6 @@ void dom_element_set_style(Element* element, const gchar* format, ...); void dom_element_style_set_property(Element* element, const gchar* property, const gchar* style); gboolean dom_element_is_visible(Window* win, Element* element); DomBoundingRect dom_elemen_get_bounding_rect(Element* element); +void dom_dispatch_mouse_event(Document* doc, Element* element, gchar* type, gushort button); #endif /* end of include guard: DOM_H */ diff --git a/src/hints.c b/src/hints.c index 35ed56d..e241cfc 100644 --- a/src/hints.c +++ b/src/hints.c @@ -310,19 +310,14 @@ static void hints_fire(const gulong num) { Hint* hint = hints_get_hint_by_number(num); if (hint) { - Element* element = hint->elem; /* TODO * if the elemt has a target attribute - remove it temporary * fire mousedown and click events on the element - * if it is an form element focus it and return - * get the src or href attribute and call vp_fired_hint */ - - Arg a; - a.i = currentMode; - a.s = webkit_dom_html_anchor_element_get_href(WEBKIT_DOM_HTML_ANCHOR_ELEMENT(element)); - vp_fired_hint(&a); - + * if it is an form element focus it and return */ + Document* doc = webkit_web_view_get_dom_document(vp.gui.webview); + dom_dispatch_mouse_event(doc, hint->elem, "click", 0); hints_clear(); + vp_clean_input(); } } diff --git a/src/main.c b/src/main.c index cfc74df..c9f19c6 100644 --- a/src/main.c +++ b/src/main.c @@ -229,7 +229,7 @@ gboolean vp_load_uri(const Arg* arg) g_free(uri); /* change state to normal mode */ - vp_set_mode(VP_MODE_NORMAL, TRUE); + vp_set_mode(VP_MODE_NORMAL, FALSE); return TRUE; } @@ -276,6 +276,13 @@ void vp_clean_up(void) completion_clean(); } +void vp_clean_input(void) +{ + /* move focus from input box to clean it */ + gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview)); + vp_echo(VP_MSG_NORMAL, FALSE, ""); +} + static gboolean vp_hide_message(void) { vp_echo(VP_MSG_NORMAL, FALSE, ""); @@ -390,11 +397,6 @@ void vp_echo(const MessageType type, gboolean hide, const char *error, ...) } } -void vp_fired_hint(const Arg* arg) -{ - vp_load_uri(arg); -} - static void vp_print_version(void) { fprintf(stderr, "%s/%s (build %s %s)\n", VERSION, PROJECT, __DATE__, __TIME__); diff --git a/src/main.h b/src/main.h index 6017965..422357e 100644 --- a/src/main.h +++ b/src/main.h @@ -240,10 +240,10 @@ extern VpCore vp; void vp_update_statusbar(void); void vp_update_urlbar(const gchar* uri); void vp_echo(const MessageType type, gboolean hide, const char *error, ...); -void vp_fired_hint(const Arg* arg); gboolean vp_set_mode(Mode mode, gboolean clean); void vp_set_widget_font(GtkWidget* widget, const VpColor* fg, const VpColor* bg, PangoFontDescription* font); gboolean vp_load_uri(const Arg* arg); void vp_clean_up(void); +void vp_clean_input(void); #endif /* end of include guard: MAIN_H */