[sushi] html: add an HTML plugin using WebKitGTK



commit 57c3c68cb388da8eb110be3a2a54cf4654f18b58
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed May 11 14:58:21 2011 -0400

    html: add an HTML plugin using WebKitGTK

 src/Makefile-js.am     |    3 +-
 src/js/ui/utils.js     |   18 +++++++++++
 src/js/viewers/html.js |   75 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 4ac381a..9d8500e 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -15,7 +15,8 @@ dist_jsviewers_DATA = \
     js/viewers/audio.js \
     js/viewers/evince.js \
     js/viewers/folder.js \
-    js/viewers/font.js
+    js/viewers/font.js \
+    js/viewers/html.js
 
 jsutildir = $(pkgdatadir)/js/util
 dist_jsutil_DATA = \
diff --git a/src/js/ui/utils.js b/src/js/ui/utils.js
index 8101e9d..f1f6640 100644
--- a/src/js/ui/utils.js
+++ b/src/js/ui/utils.js
@@ -76,3 +76,21 @@ function createFullScreenButton(mainWindow) {
 
     return toolbarZoom;
 }
+
+function createRunButton(file) {
+    let toolbarRun = new Gtk.ToolButton({ expand: false,
+                                          "icon-name": "system-run-symbolic" });
+    toolbarRun.show();
+    toolbarRun.connect("clicked",
+                       function () {
+                           let timestamp = Gtk.get_current_event_time();
+                           try {
+                               Gtk.show_uri(toolbarRun.get_screen(),
+                                            file.get_uri(),
+                                            timestamp);
+                           } catch (e) {
+                           }
+                       });
+
+    return toolbarRun;
+}
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
new file mode 100644
index 0000000..9d6a286
--- /dev/null
+++ b/src/js/viewers/html.js
@@ -0,0 +1,75 @@
+let MimeHandler = imports.ui.mimeHandler;
+let GtkClutter = imports.gi.GtkClutter;
+let Gtk = imports.gi.Gtk;
+let GLib = imports.gi.GLib;
+let WebKit = imports.gi.WebKit;
+
+let Sushi = imports.gi.Sushi;
+
+let Utils = imports.ui.utils;
+
+function HTMLRenderer(args) {
+    this._init(args);
+}
+
+HTMLRenderer.prototype = {
+    _init : function(args) {
+        this.moveOnClick = false;
+        this.canFullScreen = true;
+    },
+
+    render : function(file, mainWindow) {
+        this._mainWindow = mainWindow;
+        this._file = file;
+
+        this._webView = WebKit.WebView.new();
+        this._scrolledWin = Gtk.ScrolledWindow.new (null, null);
+        this._scrolledWin.add(this._webView);
+        this._scrolledWin.show_all();
+
+        /* disable the default context menu of the web view */
+        let settings = this._webView.settings;
+        settings["enable-default-context-menu"] = false;
+
+        this._webView.load_uri(file.get_uri());
+
+        this._actor = new GtkClutter.Actor({ contents: this._scrolledWin });
+        this._actor.set_reactive(true);
+
+        return this._actor;
+    },
+
+    getSizeForAllocation : function(allocation) {
+        return allocation;
+    },
+
+    createToolbar : function() {
+        this._mainToolbar = new Gtk.Toolbar({ "icon-size": Gtk.IconSize.MENU });
+        this._mainToolbar.get_style_context().add_class("np-toolbar");
+        this._mainToolbar.set_show_arrow(false);
+        this._mainToolbar.show();
+
+        this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
+
+        this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
+        this._mainToolbar.insert(this._toolbarZoom, 0);
+
+        let separator = new Gtk.SeparatorToolItem();
+        separator.show();
+        this._mainToolbar.insert(separator, 1);
+
+        this._toolbarRun = Utils.createRunButton(this._file);
+        this._mainToolbar.insert(this._toolbarRun, 2);
+
+        return this._toolbarActor;
+    }
+}
+
+let handler = new MimeHandler.MimeHandler();
+let renderer = new HTMLRenderer();
+
+let mimeTypes = [
+    "text/html",
+];
+
+handler.registerMimeTypes(mimeTypes, renderer);
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]