[Commits] [SCM] claws branch, litehtml, updated. 3.17.3-107-g9487b83
ticho at claws-mail.org
ticho at claws-mail.org
Fri Feb 1 20:27:17 CET 2019
The branch, litehtml has been updated
via 9487b830a25c71f384bdfac2e10526dd61eb0a2f (commit)
via c336805e99da44968f0e8849e1479cd99d4a2b5e (commit)
from 37178c5d20f3a156904b51109295fcc868d09366 (commit)
Summary of changes:
src/plugins/litehtml_viewer/lh_widget.cpp | 166 +++++++++++++++++++++--------
src/plugins/litehtml_viewer/lh_widget.h | 4 +
2 files changed, 125 insertions(+), 45 deletions(-)
- Log -----------------------------------------------------------------
commit 9487b830a25c71f384bdfac2e10526dd61eb0a2f
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Fri Feb 1 16:55:48 2019 +0100
Implement link context menu in Litehtml
diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp
index 1cc93e9..a92735a 100644
--- a/src/plugins/litehtml_viewer/lh_widget.cpp
+++ b/src/plugins/litehtml_viewer/lh_widget.cpp
@@ -23,6 +23,7 @@
#endif
#include <glib.h>
+#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <fcntl.h>
#include <sys/types.h>
@@ -57,9 +58,13 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventButton *event,
gpointer user_data);
static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
gpointer user_data);
+static void open_link_cb(GtkMenuItem *item, gpointer user_data);
+static void copy_link_cb(GtkMenuItem *item, gpointer user_data);
lh_widget::lh_widget()
{
+ GtkWidget *item;
+
/* scrolled window */
m_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_scrolled_window),
@@ -88,6 +93,17 @@ lh_widget::lh_widget()
gtk_widget_show_all(m_scrolled_window);
+ /* context menu */
+ m_context_menu = gtk_menu_new();
+
+ item = gtk_menu_item_new_with_label(_("Open Link"));
+ g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(open_link_cb), this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_context_menu), item);
+
+ item = gtk_menu_item_new_with_label(_("Copy Link Location"));
+ g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(copy_link_cb), this);
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_context_menu), item);
+
m_html = NULL;
m_rendered_width = 0;
m_context.load_master_stylesheet(master_css);
@@ -383,6 +399,20 @@ void lh_widget::print()
gtk_widget_realize(GTK_WIDGET(m_drawing_area));
}
+void lh_widget::popup_context_menu(const litehtml::tchar_t *url,
+ GdkEventButton *event)
+{
+ cm_return_if_fail(url != NULL);
+ cm_return_if_fail(event != NULL);
+
+ debug_print("lh_widget showing context menu for '%s'\n", url);
+
+ m_clicked_url = url;
+ gtk_widget_show_all(m_context_menu);
+ gtk_menu_popup(GTK_MENU(m_context_menu), NULL, NULL, NULL, NULL,
+ event->button, event->time);
+}
+
static gboolean expose_event_cb(GtkWidget *widget, GdkEvent *event,
gpointer user_data)
{
@@ -406,21 +436,34 @@ static void size_allocate_cb(GtkWidget *widget, GdkRectangle *allocation,
static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
gpointer user_data)
{
- litehtml::position::vector redraw_boxes;
- lh_widget *w = (lh_widget *)user_data;
-
- debug_print("lh_widget on_button_press_event\n");
+ litehtml::position::vector redraw_boxes;
+ lh_widget *w = (lh_widget *)user_data;
- if(w->m_html)
- {
- if(w->m_html->on_lbutton_down((int) event->x, (int) event->y, (int) event->x, (int) event->y, redraw_boxes))
- {
- for(auto& pos : redraw_boxes)
- {
- debug_print("x: %d y:%d w: %d h: %d\n", pos.x, pos.y, pos.width, pos.height);
- gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
- }
- }
+ if (w->m_html == NULL)
+ return false;
+
+ debug_print("lh_widget on_button_press_event\n");
+
+ if (event->type == GDK_2BUTTON_PRESS ||
+ event->type == GDK_3BUTTON_PRESS)
+ return true;
+
+ /* Right-click */
+ if (event->button == 3) {
+ const litehtml::tchar_t *url = w->get_href_at((gint)event->x, (gint)event->y);
+
+ if (url != NULL)
+ w->popup_context_menu(url, event);
+
+ return true;
+ }
+
+ if(w->m_html->on_lbutton_down((int) event->x, (int) event->y,
+ (int) event->x, (int) event->y, redraw_boxes)) {
+ for(auto& pos : redraw_boxes) {
+ debug_print("x: %d y:%d w: %d h: %d\n", pos.x, pos.y, pos.width, pos.height);
+ gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
+ }
}
return true;
@@ -457,30 +500,51 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
lh_widget *w = (lh_widget *)user_data;
GError* error = NULL;
+ if (w->m_html == NULL)
+ return false;
+
debug_print("lh_widget on_button_release_event\n");
-
- if(w->m_html)
- {
- w->m_clicked_url.clear();
- if(w->m_html->on_lbutton_up((int) event->x, (int) event->y, (int) event->x, (int) event->y, redraw_boxes))
- {
- for (auto& pos : redraw_boxes)
- {
- debug_print("x: %d y:%d w: %d h: %d\n", pos.x, pos.y, pos.width, pos.height);
- gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
- }
- }
-
- if (!w->m_clicked_url.empty())
+
+ if (event->type == GDK_2BUTTON_PRESS ||
+ event->type == GDK_3BUTTON_PRESS)
+ return true;
+
+ /* Right-click */
+ if (event->button == 3)
+ return true;
+
+ w->m_clicked_url.clear();
+
+ if(w->m_html->on_lbutton_up((int) event->x, (int) event->y, (int) event->x, (int) event->y, redraw_boxes))
+ {
+ for (auto& pos : redraw_boxes)
{
- debug_print("Open in browser: %s\n", w->m_clicked_url.c_str());
- open_uri(w->m_clicked_url.c_str(), prefs_common_get_uri_cmd());
+ debug_print("x: %d y:%d w: %d h: %d\n", pos.x, pos.y, pos.width, pos.height);
+ gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
}
}
+ if (!w->m_clicked_url.empty())
+ {
+ debug_print("Open in browser: %s\n", w->m_clicked_url.c_str());
+ open_uri(w->m_clicked_url.c_str(), prefs_common_get_uri_cmd());
+ }
+
return true;
}
+static void open_link_cb(GtkMenuItem *item, gpointer user_data)
+{
+ lh_widget_wrapped *w = (lh_widget_wrapped *)user_data;
+
+ open_uri(w->m_clicked_url.c_str(), prefs_common_get_uri_cmd());
+}
+
+static void copy_link_cb(GtkMenuItem *item, gpointer user_data)
+{
+// lh_widget_wrapped *w = (lh_widget_wrapped *)user_data;
+}
+
///////////////////////////////////////////////////////////
extern "C" {
diff --git a/src/plugins/litehtml_viewer/lh_widget.h b/src/plugins/litehtml_viewer/lh_widget.h
index 8f80d95..f4060d5 100644
--- a/src/plugins/litehtml_viewer/lh_widget.h
+++ b/src/plugins/litehtml_viewer/lh_widget.h
@@ -30,6 +30,7 @@ class lh_widget : public container_linux
void print();
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);
litehtml::document::ptr m_html;
litehtml::tstring m_clicked_url;
@@ -41,6 +42,7 @@ class lh_widget : public container_linux
GtkWidget *m_drawing_area;
GtkWidget *m_scrolled_window;
GtkWidget *m_viewport;
+ GtkWidget *m_context_menu;
litehtml::context m_context;
gint m_height;
litehtml::tstring m_cursor;
commit c336805e99da44968f0e8849e1479cd99d4a2b5e
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Fri Feb 1 16:55:15 2019 +0100
Add lh_widget::get_href_at()
diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp
index fd74a3b..1cc93e9 100644
--- 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
index daffcac..8f80d95 100644
--- 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;
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list