Skip to content

Commit

Permalink
Merge pull request #746 from codebrainz/markdown-webkit2gtk
Browse files Browse the repository at this point in the history
Markdown: add support for webkit2gtk
  • Loading branch information
frlan authored Jun 3, 2018
2 parents fb82de4 + 4039a13 commit 6705c54
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build/markdown.m4
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ AC_DEFUN([GP_CHECK_MARKDOWN],
GTK_VERSION=2.16
WEBKIT_VERSION=1.1.13
GP_CHECK_GTK3([webkit_package=webkitgtk-3.0],
GP_CHECK_GTK3([webkit_package=webkit2gtk-4.0],
[webkit_package=webkit-1.0])
GP_CHECK_PLUGIN_DEPS([markdown], [MARKDOWN],
[$GP_GTK_PACKAGE >= ${GTK_VERSION}
$webkit_package >= ${WEBKIT_VERSION}
gthread-2.0])
AM_CONDITIONAL([MARKDOWN_WEBKIT2], [test "$webkit_package" = webkit2gtk-4.0])
GP_COMMIT_PLUGIN_STATUS([Markdown])
Expand Down
4 changes: 4 additions & 0 deletions markdown/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ markdown_la_CFLAGS += $(LIBMARKDOWN_CFLAGS)
markdown_la_LIBADD += $(LIBMARKDOWN_LIBS)
endif

if MARKDOWN_WEBKIT2
markdown_la_CFLAGS += -DMARKDOWN_WEBKIT2
endif

include $(top_srcdir)/build/cppcheck.mk
29 changes: 28 additions & 1 deletion markdown/src/viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <webkit/webkitwebview.h>
#ifdef MARKDOWN_WEBKIT2
# include <webkit2/webkit2.h>
#else
# include <webkit/webkitwebview.h>
#endif
#include <geanyplugin.h>
#ifndef FULL_PRICE
# include <mkdio.h>
Expand Down Expand Up @@ -296,6 +300,18 @@ pop_scroll_pos(MarkdownViewer *self)
return popped;
}

#ifdef MARKDOWN_WEBKIT2
static void
on_webview_load_changed(MarkdownViewer *self,
WebKitLoadEvent load_event,
WebKitWebView *web_view)
{
/* When the webkit is done loading, reset the scroll position. */
if (load_event == WEBKIT_LOAD_FINISHED) {
pop_scroll_pos(self);
}
}
#else
static void
on_webview_load_status_notify(WebKitWebView *view, GParamSpec *pspec,
MarkdownViewer *self)
Expand All @@ -309,6 +325,7 @@ on_webview_load_status_notify(WebKitWebView *view, GParamSpec *pspec,
pop_scroll_pos(self);
}
}
#endif

gchar *
markdown_viewer_get_html(MarkdownViewer *self)
Expand Down Expand Up @@ -388,13 +405,23 @@ markdown_viewer_update_view(MarkdownViewer *self)
/* Connect a signal handler (only needed once) to restore the scroll
* position once the webview is reloaded. */
if (self->priv->load_handle == 0) {
#ifdef MARKDOWN_WEBKIT2
self->priv->load_handle =
g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "load-changed",
G_CALLBACK(on_webview_load_changed), self);
#else
self->priv->load_handle =
g_signal_connect_swapped(WEBKIT_WEB_VIEW(self), "notify::load-status",
G_CALLBACK(on_webview_load_status_notify), self);
#endif
}

#ifdef MARKDOWN_WEBKIT2
webkit_web_view_load_html(WEBKIT_WEB_VIEW(self), html, base_uri);
#else
webkit_web_view_load_string(WEBKIT_WEB_VIEW(self), html, "text/html",
self->priv->enc, base_uri);
#endif

g_free(base_uri);
g_free(html);
Expand Down
6 changes: 5 additions & 1 deletion markdown/src/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#define MARKDOWN_VIEWER_H 1

#include <gtk/gtk.h>
#include <webkit/webkitwebview.h>
#ifdef MARKDOWN_WEBKIT2
# include <webkit2/webkit2.h>
#else
# include <webkit/webkitwebview.h>
#endif

G_BEGIN_DECLS

Expand Down

0 comments on commit 6705c54

Please sign in to comment.