talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 6e437d475fdf79fad55ff6c45b074b62cc2db8d5
parent a300f65525e509204fd133292badb6836b32dc11
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Fri,  1 Feb 2019 16:55:15 +0100

Add lh_widget::get_href_at()

Diffstat:
Msrc/plugins/litehtml_viewer/lh_widget.cpp | 42+++++++++++++++++++++++++++---------------
Msrc/plugins/litehtml_viewer/lh_widget.h | 2++
2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp @@ -319,7 +319,7 @@ void lh_widget::set_cursor(const litehtml::tchar_t* cursor) void lh_widget::update_cursor() { gint x, y; - litehtml::element::ptr root_el, over_el, el; + const litehtml::tchar_t *href; GdkWindow *w = gdk_display_get_window_at_pointer(gdk_display_get_default(), &x, &y); GdkCursorType cursType = GDK_ARROW; @@ -337,32 +337,44 @@ void lh_widget::update_cursor() if (w != gtk_widget_get_window(m_drawing_area)) return; - /* Find the element we are hovering over */ - root_el = m_html->root(); - g_return_if_fail(root_el != NULL); - over_el = root_el->get_element_by_point(x, y, x, y); - g_return_if_fail(over_el != NULL); + /* If it's an anchor, show its "href" attribute in statusbar, + * otherwise clear statusbar. */ + if ((href = get_href_at(x, y)) != NULL) { + lh_widget_statusbar_push(href); + } else { + lh_widget_statusbar_pop(); + } +} + +const litehtml::tchar_t *lh_widget::get_href_at(const gint x, const gint y) const +{ + litehtml::element::ptr over_el, el; + + if (m_html == NULL) + return NULL; + + over_el = m_html->root()->get_element_by_point(x, y, x, y); + if (over_el == NULL) + return NULL; /* If it's not an anchor, check if it has a parent anchor * (e.g. it's an image within an anchor) and grab a pointer * to that. */ if (strcmp(over_el->get_tagName(), "a") && over_el->parent()) { el = over_el->parent(); - while (el && el != root_el && strcmp(el->get_tagName(), "a")) { + while (el && el != m_html->root() && strcmp(el->get_tagName(), "a")) { el = el->parent(); } - if (el && el != root_el) + if (el && el != m_html->root()) over_el = el; + else + return NULL; } - /* If it's an anchor, show its "href" attribute in statusbar, - * otherwise clear statusbar. */ - if (!strcmp(over_el->get_tagName(), "a")) { - lh_widget_statusbar_push(over_el->get_attr(_t("href"))); - } else { - lh_widget_statusbar_pop(); - } + /* At this point, over_el is pointing at an anchor tag, so let's + * grab its href attribute. */ + return over_el->get_attr(_t("href")); } void lh_widget::print() diff --git a/src/plugins/litehtml_viewer/lh_widget.h b/src/plugins/litehtml_viewer/lh_widget.h @@ -29,6 +29,8 @@ class lh_widget : public container_linux void update_cursor(); void print(); + const litehtml::tchar_t *get_href_at(const gint x, const gint y) const; + litehtml::document::ptr m_html; litehtml::tstring m_clicked_url;