Use mouse event to open hint instead of c logic.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 16 Dec 2012 18:13:21 +0000 (19:13 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 16 Dec 2012 18:14:19 +0000 (19:14 +0100)
src/dom.c
src/dom.h
src/hints.c
src/main.c
src/main.h

index 986d708..71ad4a6 100644 (file)
--- 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)) {
index f3ca21a..ce41bc0 100644 (file)
--- 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 */
index 35ed56d..e241cfc 100644 (file)
@@ -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();
     }
 }
 
index cfc74df..c9f19c6 100644 (file)
@@ -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__);
index 6017965..422357e 100644 (file)
@@ -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 */