Skip to content

Commit

Permalink
Refactored code, created a new EvWebView type
Browse files Browse the repository at this point in the history
Earlier my approach was to replace the atril view directly with a webview. However as it turned out it was extremely difficult to accomplish much tasks without the document-model. So I created an Extension of the WebKitWebView class, EvWebView so that now we can manipulate the webview as desired. Also having a separate file really helps in terms of clarity.

Please note that there are many empty functions and TODO tags right now, I shall aim to fill these up once the display part is done, probably in this week.

I also added some code on the backend to draw thumbnails when with GTK+-3.0, although I have never tested a GTK+-3.0 build.With GTK+-2.0 you won't get any build errors,  however epub backend won't work right now.

That being said, this commit is mostly because there was a lot of code that was lying in the local repository, and it was best to back it up as a failsafe.
I modified ev-window to accomodate this new data structure, and having an equivalent ev_web_view function for every ev_view function, I can achieve most functionality by filling those functions with Webkit modules.

Other than that on the backend

Other than that there were some minor changes to the code.
Although I did the above, currently I am not able to instantiate the EvWebView because of some class and object type definition errors, due to which I can't display the document.
  • Loading branch information
rootAvish committed Jul 7, 2014
1 parent 6f41c20 commit df43418
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 100 deletions.
1 change: 1 addition & 0 deletions atril-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <libview/ev-document-model.h>
#include <libview/ev-print-operation.h>
#include <libview/ev-view.h>
#include <libview/ev-web-view.h>
#include <libview/ev-view-type-builtins.h>
#include <libview/ev-stock-icons.h>

Expand Down
98 changes: 84 additions & 14 deletions backend/epub/epub-document.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/* this file is part of atril, a mate document viewer
*
* Copyright (C) 2014 Avishkar Gupta
*
* Author:
* Avishkar Gupta <[email protected]>
*
* Atril is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Atril is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "ev-file-helpers.h"
#include "epub-document.h"
#include "unzip.h"
Expand All @@ -11,7 +33,12 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>

#include <webkit/webkit.h>
#if GTK_CHECK_VERSION(3, 0, 0)
#include <webkit2/webkit2.h>
#else
#include <webkit/webkit.h>
#endif

#include <gtk/gtk.h>

typedef enum _xmlParseReturnType
Expand Down Expand Up @@ -42,8 +69,6 @@ struct _EpubDocument
gchar* tmp_archive_dir ;
/*Stores the contentlist in a sorted manner*/
GList* contentList ;
/*uri of the current page being displayed in the webview*/
gchar* currentpageuri ;
/* A variable to hold our epubDocument for unzipping*/
unzFile epubDocument ;
};
Expand All @@ -68,10 +93,10 @@ epub_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
cairo_surface_t* surface=NULL;
gchar* uri = (gchar*) rc->page->backend_page;
epub_webkit_render (&surface,uri);
while ( !surface )
;
gint width = cairo_image_surface_get_width (surface);
gint height = cairo_image_surface_get_height (surface);
if ( !surface ) {
return NULL ;
}

if (surface) {
thumbnail = ev_document_misc_pixbuf_from_surface (surface);
cairo_surface_destroy (surface);
Expand Down Expand Up @@ -118,7 +143,7 @@ epub_document_get_n_pages (EvDocument *document)

return g_list_length(epub_document->contentList);
}

#if !GTK_CHECK_VERSION(3, 0, 0)
static void
webkit_render_cb(GtkWidget *web_view,
GParamSpec *specification,
Expand Down Expand Up @@ -148,6 +173,51 @@ epub_webkit_render(cairo_surface_t **surface,
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view),uri);
}

#else /* The webkit2 code for GTK3 */

static void
snapshot_chain_cb(WebKitWebView *web_view,
GAsyncResult* res,
cairo_surface_t **surface)
{
GError * err = NULL ;
*surface = webkit_web_view_get_snapshot_finish(WEBKIT_WEB_VIEW(web_view),res,&err);
if ( err ) {
surface = NULL ;
}
}

static void
webkit_render_cb(WebKitWebView *webview,
WebKitLoadEvent load_status,
cairo_surface_t **surface)
{
if ( load_status != WEBKIT_LOAD_FINISHED )
return ;

webkit_web_view_get_snapshot(webview,
WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING,
NULL,
(GAsyncReadyCallback)snapshot_chain_cb,
surface);
}

static void epub_webkit_render(cairo_surface_t **surface,
const char* uri)
{
GtkWidget *offscreen_window = gtk_offscreen_window_new ();
gtk_window_set_default_size(GTK_WINDOW(offscreen_window),800,600);
GtkWidget* scroll_view = gtk_scrolled_window_new (NULL,NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll_view),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
GtkWidget* web_view = webkit_web_view_new ();
gtk_container_add(GTK_CONTAINER(offscreen_window),scroll_view);
gtk_container_add(GTK_CONTAINER(scroll_view),web_view);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view),uri);
gtk_widget_show_all(offscreen_window);
g_signal_connect(web_view,"load-changed",G_CALLBACK(webkit_render_cb),surface);
}
#endif
/**
* epub_remove_temporary_dir : Removes a directory recursively.
* This function is same as comics_remove_temporary_dir
Expand Down Expand Up @@ -793,7 +863,6 @@ epub_document_init (EpubDocument *epub_document)
epub_document->archivename = NULL ;
epub_document->tmp_archive_dir = NULL ;
epub_document->contentList = NULL ;
epub_document->currentpageuri = NULL;
}

static gboolean
Expand Down Expand Up @@ -869,11 +938,12 @@ epub_document_finalize (GObject *object)
if ( epub_document->contentList ) {
g_list_free_full(epub_document->contentList,(GDestroyNotify)free_tree_nodes);
}

g_free (epub_document->tmp_archive_dir);
g_free (epub_document->currentpageuri);
g_free (epub_document->archivename);

if ( epub_document->tmp_archive_dir) {
g_free (epub_document->tmp_archive_dir);
}
if ( epub_document->archivename) {
g_free (epub_document->archivename);
}
G_OBJECT_CLASS (epub_document_parent_class)->finalize (object);
}

Expand Down
7 changes: 0 additions & 7 deletions libdocument/ev-document.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,6 @@ ev_document_render (EvDocument *document,
return klass->render (document, rc);
}

/*gchar*
ev_web_document_render(EvDocument *document)
{
Layout engine takes care of the rendering, so what we are essentially doing is serving pages to the webview
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
klass->webkit_render(document);
}*/
const gchar *
ev_document_get_uri (EvDocument *document)
{
Expand Down
2 changes: 1 addition & 1 deletion libdocument/ev-document.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct _EvDocument
GObject base;

EvDocumentPrivate *priv;
/*
/*
* Since we can only access the members of this structure from the window frontend,
* we need a flag to detemine whether to replace the atril-view with a web-view.
*/
Expand Down
6 changes: 5 additions & 1 deletion libview/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ INST_H_SRC_FILES = \
ev-print-operation.h \
ev-stock-icons.h \
ev-view.h \
ev-web-view.h \
ev-view-presentation.h

INST_H_FILES = \
Expand All @@ -41,6 +42,7 @@ libatrilview_la_SOURCES = \
ev-timeline.c \
ev-transition-animation.c \
ev-view.c \
ev-web-view.c \
ev-view-accessible.c \
ev-view-marshal.c \
ev-view-cursor.c \
Expand All @@ -63,6 +65,7 @@ libatrilview_la_CFLAGS = \
$(LIBVIEW_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(WEBKIT_CFLAGS) \
$(AM_CFLAGS)

libatrilview_la_LDFLAGS = \
Expand All @@ -73,7 +76,8 @@ libatrilview_la_LDFLAGS = \

libatrilview_la_LIBADD = \
$(top_builddir)/libdocument/libatrildocument.la \
$(LIBVIEW_LIBS)
$(LIBVIEW_LIBS) \
$(WEBKIT_CFLAGS)

BUILT_SOURCES = \
ev-view-marshal.h \
Expand Down
6 changes: 4 additions & 2 deletions previewer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ atril_previewer_CFLAGS = \
$(PREVIEWER_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(AM_CFLAGS)
$(AM_CFLAGS) \
$(WEBKIT_CFLAGS)

atril_previewer_LDFLAGS = $(AM_LDFLAGS)

Expand All @@ -33,7 +34,8 @@ atril_previewer_LDADD = \
$(top_builddir)/libdocument/libatrildocument.la \
$(top_builddir)/libview/libatrilview.la \
$(top_builddir)/libmisc/libevmisc.la \
$(PREVIEWER_LIBS)
$(PREVIEWER_LIBS) \
$(WEBKIT_LIBS)

EXTRA_DIST = $(man_MANS)

Expand Down
Loading

0 comments on commit df43418

Please sign in to comment.