[Commits] [SCM] claws branch, master, updated. 3.17.3-144-g1efbdb3

ticho at claws-mail.org ticho at claws-mail.org
Wed Apr 10 19:38:39 CEST 2019


The branch, master has been updated
       via  1efbdb3d9beea0137aeb304865dd061752a1e46f (commit)
      from  0c0a3c773b657bb80f4af3b7dbfd9646766bb526 (commit)

Summary of changes:
 src/plugins/litehtml_viewer/lh_widget.cpp |   81 +++++++++++++++++++----------
 src/plugins/litehtml_viewer/lh_widget.h   |    6 ++-
 2 files changed, 57 insertions(+), 30 deletions(-)


- Log -----------------------------------------------------------------
commit 1efbdb3d9beea0137aeb304865dd061752a1e46f
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Wed Apr 10 19:37:38 2019 +0200

    Make cursor and statusbar URL display smarter in litehtml plugin

diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp
index 64fdbdd..4e6d785 100644
--- a/src/plugins/litehtml_viewer/lh_widget.cpp
+++ b/src/plugins/litehtml_viewer/lh_widget.cpp
@@ -106,6 +106,8 @@ lh_widget::lh_widget()
 
 	m_partinfo = NULL;
 
+	m_showing_url = FALSE;
+
 	gtk_widget_set_events(m_drawing_area,
 			        GDK_BUTTON_RELEASE_MASK
 			      | GDK_BUTTON_PRESS_MASK
@@ -293,23 +295,35 @@ void lh_widget::clear()
 
 void lh_widget::set_cursor(const litehtml::tchar_t* cursor)
 {
-	if (cursor) {
-		if (m_cursor != cursor) {
-			m_cursor = cursor;
-			update_cursor();
+	litehtml::element::ptr over_el;
+	gint x, y;
+	GdkWindow *w = gdk_display_get_window_at_pointer(gdk_display_get_default(),
+			&x, &y);
+
+	if (w != gtk_widget_get_window(m_drawing_area))
+		return;
+
+	over_el = m_html->root()->get_element_by_point(x, y, x, y);
+
+	if (!over_el) {
+		m_over_element = NULL;
+		return;
+	}
+
+	if (cursor && over_el) {
+		if (over_el != m_over_element) {
+			m_over_element = over_el;
+			update_cursor(cursor);
 		}
 	}
 }
 
-void lh_widget::update_cursor()
+void lh_widget::update_cursor(const litehtml::tchar_t* cursor)
 {
-	gint x, y;
 	const litehtml::tchar_t *href;
-	GdkWindow *w = gdk_display_get_window_at_pointer(gdk_display_get_default(),
-			&x, &y);
 	GdkCursorType cursType = GDK_ARROW;
 
-	if (m_cursor == _t("pointer")) {
+	if (cursor == _t("pointer")) {
 		cursType = GDK_HAND2;
 	}
 
@@ -319,47 +333,58 @@ void lh_widget::update_cursor()
 		gdk_window_set_cursor(gtk_widget_get_window(m_drawing_area), gdk_cursor_new(cursType));
 	}
 
-	if (w != gtk_widget_get_window(m_drawing_area))
-		return;
-
 	/* 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(fullurl(href).c_str());
-	} else {
+	if (m_showing_url) {
 		lh_widget_statusbar_pop();
+		m_showing_url = FALSE;
+	}
+
+	if ((href = get_href_at(m_over_element)) != NULL) {
+		lh_widget_statusbar_push(fullurl(href).c_str());
+		m_showing_url = TRUE;
 	}
 }
 
-const litehtml::tchar_t *lh_widget::get_href_at(const gint x, const gint y) const
+const litehtml::tchar_t *lh_widget::get_href_at(litehtml::element::ptr element) const
 {
-	litehtml::element::ptr over_el, el;
+	litehtml::element::ptr el;
 
-	if (m_html == NULL)
-		return NULL;
-
-	over_el = m_html->root()->get_element_by_point(x, y, x, y);
-	if (over_el == NULL)
+	if (element == 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();
+	if (strcmp(element->get_tagName(), "a") && element->parent()) {
+		el = element->parent();
 		while (el && el != m_html->root() && strcmp(el->get_tagName(), "a")) {
 			el = el->parent();
 		}
 
-		if (el && el != m_html->root())
-			over_el = el;
-		else
+		if (!el || el == m_html->root())
 			return NULL;
+	} else {
+		el = element;
 	}
 
 	/* 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"));
+	return el->get_attr(_t("href"));
+}
+
+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;
+
+	return get_href_at(over_el);
 }
 
 void lh_widget::print()
diff --git a/src/plugins/litehtml_viewer/lh_widget.h b/src/plugins/litehtml_viewer/lh_widget.h
index e6b784a..9b95ef8 100644
--- a/src/plugins/litehtml_viewer/lh_widget.h
+++ b/src/plugins/litehtml_viewer/lh_widget.h
@@ -57,10 +57,11 @@ class lh_widget : public container_linux
 		void redraw(gboolean force_render);
 		void open_html(const gchar *contents);
 		void clear();
-		void update_cursor();
+		void update_cursor(const litehtml::tchar_t* cursor);
 		void update_font();
 		void print();
 
+		const litehtml::tchar_t *get_href_at(litehtml::element::ptr element) const;
 		const litehtml::tchar_t *get_href_at(const gint x, const gint y) const;
 		void popup_context_menu(const litehtml::tchar_t *url, GdkEventButton *event);
 		const litehtml::tstring fullurl(const litehtml::tchar_t *url) const;
@@ -82,7 +83,8 @@ class lh_widget : public container_linux
 		GtkWidget *m_context_menu;
 		litehtml::context m_context;
 		gint m_height;
-		litehtml::tstring m_cursor;
+		litehtml::element::ptr m_over_element;
+		gboolean m_showing_url;
 		MimeInfo *m_partinfo;
 
 		litehtml::tchar_t *m_font_name;

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list