Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTommi Komulainen <tko@litl.com>2009-08-25 16:04:59 (GMT)
committer Marco Pesenti Gritti <marcopg@litl.com>2010-07-27 22:04:22 (GMT)
commit84cc52bd4fd197ec4aad845d9b09bcd5b74453d5 (patch)
tree5ac772b302a3c5bcf38e4212d43e8bb7ee39f71e
parentaded6eb5272ccb4f9b90ee529bdb014ffaa59031 (diff)
browser-plugin: add clipboard copy support
Only supporting copy, evince doesn't support editing (at least the API is lacking cut and paste) Using property access workaround. Example: if (plugin.canCopy) { plugin.canCopy = 42; (workaround) copy selection to clipboard }
-rw-r--r--browser-plugin/plugin.cpp26
-rw-r--r--browser-plugin/plugin.h5
-rw-r--r--browser-plugin/scriptable.cpp15
-rw-r--r--browser-plugin/scriptable.h1
4 files changed, 46 insertions, 1 deletions
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp
index 7d79100..88893c8 100644
--- a/browser-plugin/plugin.cpp
+++ b/browser-plugin/plugin.cpp
@@ -27,7 +27,8 @@ Plugin::Plugin (NPP instance) : mInstance (instance),
mScriptableObject (0),
mWindow (0),
mLoadJob (0),
- mTitle (0)
+ mTitle (0),
+ mHasSelection (false)
{
mScrolledWindow = gtk_scrolled_window_new (NULL, NULL);
@@ -36,6 +37,10 @@ Plugin::Plugin (NPP instance) : mInstance (instance),
"notify::sizing-mode",
G_CALLBACK (Plugin::SizingModeCallback),
reinterpret_cast<void*>(this));
+ g_signal_connect (G_OBJECT (mView),
+ "notify::has-selection",
+ G_CALLBACK (Plugin::HasSelectionCallback),
+ reinterpret_cast<void*>(this));
g_signal_connect (G_OBJECT (mView),
"external-link",
@@ -103,6 +108,12 @@ Plugin::FindPrevious (const char *text)
}
void
+Plugin::CopyClipboard ()
+{
+ ev_view_copy (EV_VIEW (mView));
+}
+
+void
Plugin::SetWindow (GdkNativeWindow window)
{
if (mWindow != 0) {
@@ -226,6 +237,19 @@ Plugin::SizingModeCallback (EvView *view, GParamSpec *pspec, gpointer data)
}
void
+Plugin::HasSelectionCallback (EvView *view, GParamSpec *pspec, gpointer data)
+{
+ Plugin *plugin = reinterpret_cast<Plugin*> (data);
+
+ gboolean has_selection = ev_view_get_has_selection (view);
+
+ if (has_selection != plugin->mHasSelection) {
+ plugin->mHasSelection = has_selection;
+ plugin->CallBrowser ("onClipboardChanged");
+ }
+}
+
+void
Plugin::ExternalLinkCallback (EvView *view, EvLinkAction *action, gpointer data)
{
Plugin *plugin = reinterpret_cast<Plugin*> (data);
diff --git a/browser-plugin/plugin.h b/browser-plugin/plugin.h
index 7ea940e..7da0aa3 100644
--- a/browser-plugin/plugin.h
+++ b/browser-plugin/plugin.h
@@ -39,6 +39,7 @@ class Plugin {
void SetZoom (double);
void FindNext (const char *text);
void FindPrevious (const char *text);
+ void CopyClipboard ();
void ShowLoadingError ();
NPObject *GetScriptableNPObject ();
@@ -51,6 +52,9 @@ class Plugin {
static void SizingModeCallback (EvView *view,
GParamSpec *pspec,
gpointer data);
+ static void HasSelectionCallback (EvView *view,
+ GParamSpec *pspec,
+ gpointer data);
static void ExternalLinkCallback (EvView *view,
EvLinkAction *action,
gpointer data);
@@ -66,6 +70,7 @@ class Plugin {
public:
char *mTitle;
+ bool mHasSelection;
};
void* NPN_MemDup (const void *aMem, uint32 aLen);
diff --git a/browser-plugin/scriptable.cpp b/browser-plugin/scriptable.cpp
index e8fbcb2..81caeb0 100644
--- a/browser-plugin/scriptable.cpp
+++ b/browser-plugin/scriptable.cpp
@@ -198,6 +198,7 @@ ScriptablePluginObject::ScriptablePluginObject (NPP npp) :
{
mTitleID = NPN_GetStringIdentifier ("title");
mZoomID = NPN_GetStringIdentifier ("zoom");
+ mCanCopyID = NPN_GetStringIdentifier ("canCopy");
mMagicWrapperID = NPN_GetStringIdentifier ("magicWrapper");
mZoomInID = NPN_GetStringIdentifier ("zoomIn");
@@ -231,6 +232,7 @@ ScriptablePluginObject::HasProperty (NPIdentifier name)
NPIdentifier properties[] = {
mTitleID,
mZoomID,
+ mCanCopyID,
mMagicWrapperID
};
@@ -261,6 +263,9 @@ ScriptablePluginObject::GetProperty (NPIdentifier name, NPVariant *result)
} else if (name == mZoomID) {
DOUBLE_TO_NPVARIANT (plugin->GetZoom(), *result);
return true;
+ } else if (name == mCanCopyID) {
+ BOOLEAN_TO_NPVARIANT (plugin->mHasSelection, *result);
+ return true;
}
return false;
@@ -310,6 +315,16 @@ ScriptablePluginObject::SetProperty (NPIdentifier name, const NPVariant *value)
plugin->SetZoom (zoom);
return true;
+ } else if (name == mCanCopyID) {
+ // FIXME fix method calls (using write access to a property as
+ // an awful workaround)
+ if (!plugin->mHasSelection) {
+ NPN_SetException (this, "Nothing to copy");
+ return false;
+ }
+
+ plugin->CopyClipboard ();
+ return true;
}
return false;
diff --git a/browser-plugin/scriptable.h b/browser-plugin/scriptable.h
index cc6ac1c..763ead2 100644
--- a/browser-plugin/scriptable.h
+++ b/browser-plugin/scriptable.h
@@ -94,6 +94,7 @@ class ScriptablePluginObject : public ScriptablePluginObjectBase
private:
NPIdentifier mTitleID;
NPIdentifier mZoomID;
+ NPIdentifier mCanCopyID;
NPIdentifier mMagicWrapperID;
NPIdentifier mZoomInID;