[evolution/wip/webkit2] Report element position in clicked callback with scrollbar positions accounted



commit ac7548185f7b36f5b15c16df84015baa0c820482
Author: Milan Crha <mcrha redhat com>
Date:   Thu May 19 10:05:56 2016 +0200

    Report element position in clicked callback with scrollbar positions accounted
    
    Thus basically the place in the EWebView, rather than the position inside
    the whole page, which is misleading when the page is scrolled in any direction.

 e-util/e-web-view.c              |    3 ++-
 web-extensions/e-web-extension.c |   15 +++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index d734403..6058ce3 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -4275,7 +4275,8 @@ e_web_view_set_document_iframe_src (EWebView *web_view,
  *
  * The callback is called whenever an element of class @element_class is clicked.
  * The @element_value is a content of the 'value' attribute of the clicked element.
- * The @element_location is the place of the element within the web page.
+ * The @element_position is the place of the element within the web page, already
+ * accounting scrollbar positions.
  *
  * See: e_web_view_register_element_clicked, e_web_view_unregister_element_clicked
  *
diff --git a/web-extensions/e-web-extension.c b/web-extensions/e-web-extension.c
index 54aaa52..34ada13 100644
--- a/web-extensions/e-web-extension.c
+++ b/web-extensions/e-web-extension.c
@@ -180,9 +180,11 @@ element_clicked_cb (WebKitDOMElement *element,
 {
        EWebExtension *extension = user_data;
        WebKitDOMElement *offset_parent;
+       WebKitDOMDOMWindow *dom_window;
        gchar *attr_class, *attr_value;
        const guint64 *ppage_id;
        gdouble with_parents_left, with_parents_top;
+       glong scroll_x = 0, scroll_y = 0;
        GError *error = NULL;
 
        g_return_if_fail (E_IS_WEB_EXTENSION (extension));
@@ -200,6 +202,15 @@ element_clicked_cb (WebKitDOMElement *element,
                with_parents_top += webkit_dom_element_get_offset_top (offset_parent);
        }
 
+       dom_window = webkit_dom_document_get_default_view (webkit_dom_node_get_owner_document 
(WEBKIT_DOM_NODE (element)));
+       if (WEBKIT_DOM_IS_DOM_WINDOW (dom_window)) {
+               g_object_get (G_OBJECT (dom_window),
+                       "scroll-x", &scroll_x,
+                       "scroll-y", &scroll_y,
+                       NULL);
+       }
+       g_clear_object (&dom_window);
+
        attr_class = webkit_dom_element_get_class_name (element);
        attr_value = webkit_dom_element_get_attribute (element, "value");
 
@@ -210,8 +221,8 @@ element_clicked_cb (WebKitDOMElement *element,
                E_WEB_EXTENSION_INTERFACE,
                "ElementClicked",
                g_variant_new ("(tssiiii)", *ppage_id, attr_class ? attr_class : "", attr_value ? attr_value 
: "",
-                       (gint) with_parents_left,
-                       (gint) with_parents_top,
+                       (gint) (with_parents_left - scroll_x),
+                       (gint) (with_parents_top - scroll_y),
                        (gint) webkit_dom_element_get_offset_width (element),
                        (gint) webkit_dom_element_get_offset_height (element)),
                &error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]