diff options
author | Tommi Komulainen <tko@litl.com> | 2009-08-25 17:15:03 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marcopg@litl.com> | 2010-07-27 22:04:23 (GMT) |
commit | 5ff761c012fca4cfc925de1511afca90c08d5d74 (patch) | |
tree | 5de65c9e652cf39c304d6deb96f6bb74d0752331 /browser-plugin/plugin.cpp | |
parent | 84cc52bd4fd197ec4aad845d9b09bcd5b74453d5 (diff) |
browser-plugin: implement search
Changed the API to be better match for find as you type. Using property
access workaround.
Example:
plugin.findTerms = "hello"; begin searching and highlights all matches in
the document
plugin.findNext = 42; (workaround) jump to next match
plugin.findPrevious = 42; (workaround) jump to previous match
Diffstat (limited to 'browser-plugin/plugin.cpp')
-rw-r--r-- | browser-plugin/plugin.cpp | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp index 88893c8..541e9d9 100644 --- a/browser-plugin/plugin.cpp +++ b/browser-plugin/plugin.cpp @@ -26,7 +26,9 @@ Plugin::Plugin (NPP instance) : mInstance (instance), mScriptableObject (0), mWindow (0), + mDocument (0), mLoadJob (0), + mFindJob (0), mTitle (0), mHasSelection (false) { @@ -52,6 +54,8 @@ Plugin::Plugin (NPP instance) : mInstance (instance), used only to calculate the minimum and maximux allowed zoom level. */ ev_view_set_screen_dpi (EV_VIEW(mView), 96); + ev_view_find_set_highlight_search (EV_VIEW (mView), TRUE); + gtk_container_add (GTK_CONTAINER(mScrolledWindow), mView); gtk_widget_show (mView); @@ -61,6 +65,7 @@ Plugin::Plugin (NPP instance) : mInstance (instance), Plugin::~Plugin () { ClearLoadJob (); + ClearFindJob (); g_free (mTitle); @@ -98,13 +103,58 @@ Plugin::GetZoom (void) const } void -Plugin::FindNext (const char *text) +Plugin::ClearFindJob () { + if (!mFindJob) + return; + + if (!ev_job_is_finished (mFindJob)) + ev_job_cancel (mFindJob); + + g_signal_handlers_disconnect_by_func (mFindJob, + (gpointer)Plugin::FindJobUpdatedCallback, + reinterpret_cast<void*> (this)); + + g_object_unref (mFindJob); + mFindJob = 0; } void -Plugin::FindPrevious (const char *text) +Plugin::Find (const char *text) { + if (!mDocument || !EV_IS_DOCUMENT_FIND (mDocument)) + return; + + ev_view_find_search_changed (EV_VIEW (mView)); + + ClearFindJob (); + + if (text && text[0]) { + EvPageCache *page_cache = ev_page_cache_get (mDocument); + + mFindJob = ev_job_find_new (mDocument, + ev_page_cache_get_current_page (page_cache), + ev_page_cache_get_n_pages (page_cache), + text, /*case_sensitive=*/ FALSE); + g_signal_connect (mFindJob, "updated", + G_CALLBACK (Plugin::FindJobUpdatedCallback), + reinterpret_cast<void*> (this)); + ev_job_scheduler_push_job (mFindJob, EV_JOB_PRIORITY_NONE); + } else { + gtk_widget_queue_draw (mView); + } +} + +void +Plugin::FindNext () +{ + ev_view_find_next (EV_VIEW (mView)); +} + +void +Plugin::FindPrevious () +{ + ev_view_find_previous (EV_VIEW (mView)); } void @@ -275,10 +325,13 @@ Plugin::LoadJobFinishedCallback (EvJob *job, gpointer data) Plugin *plugin = reinterpret_cast<Plugin*> (data); if (!ev_job_is_failed (job)) { + // let EvView own the document and mDocument have weak ref + plugin->mDocument = EV_JOB (job)->document; + ev_view_set_document (EV_VIEW(plugin->mView), - EV_JOB (job)->document); + plugin->mDocument); - EvDocumentInfo *doc_info = ev_document_get_info (EV_JOB (job)->document); + EvDocumentInfo *doc_info = ev_document_get_info (plugin->mDocument); if (doc_info) { if (doc_info->fields_mask & EV_DOCUMENT_INFO_TITLE) { @@ -290,8 +343,22 @@ Plugin::LoadJobFinishedCallback (EvJob *job, gpointer data) ev_document_info_free (doc_info); } } else { + plugin->mDocument = 0; + plugin->ShowLoadingError (); } plugin->ClearLoadJob (); } + +void +Plugin::FindJobUpdatedCallback (EvJobFind *job, gint page, gpointer data) +{ + Plugin *plugin = reinterpret_cast<Plugin*> (data); + + // FIXME: enable/disable find next/prev actions + + ev_view_find_changed (EV_VIEW (plugin->mView), + ev_job_find_get_results (job), + page); +} |