diff options
-rw-r--r-- | backend/epub/epub-document.c | 5 | ||||
-rw-r--r-- | libview/ev-jobs.c | 53 | ||||
-rw-r--r-- | libview/ev-web-view.c | 235 | ||||
-rw-r--r-- | shell/ev-window.c | 35 |
4 files changed, 289 insertions, 39 deletions
diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c index 3a574151..d0dce118 100644 --- a/backend/epub/epub-document.c +++ b/backend/epub/epub-document.c @@ -1198,6 +1198,7 @@ epub_document_get_info(EvDocument *document) EV_DOCUMENT_INFO_LAYOUT | EV_DOCUMENT_INFO_CREATOR | EV_DOCUMENT_INFO_LINEARIZED | + EV_DOCUMENT_INFO_PERMISSIONS | EV_DOCUMENT_INFO_N_PAGES ; infofile = g_filename_from_uri(uri,NULL,&error); @@ -1242,7 +1243,9 @@ epub_document_get_info(EvDocument *document) /* number of pages */ epubinfo->n_pages = epub_document_get_n_pages(document); - + + /*Copying*/ + epubinfo->permissions = EV_DOCUMENT_PERMISSIONS_OK_TO_COPY; /*TODO : Add a function to get date*/ g_free(uri); g_string_free(containerpath,TRUE); diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c index e7f0ba35..b5a147f1 100644 --- a/libview/ev-jobs.c +++ b/libview/ev-jobs.c @@ -790,6 +790,7 @@ ev_job_thumbnail_dispose (GObject *object) (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object); } +#if !GTK_CHECK_VERSION(3, 0, 0) static void web_thumbnail_get_screenshot_cb(WebKitWebView *webview, WebKitWebFrame *webframe, @@ -815,6 +816,50 @@ web_thumbnail_get_screenshot_cb(WebKitWebView *webview, ev_document_doc_mutex_unlock(); ev_job_succeeded(EV_JOB(job_thumb)); } +#else + +static void +snapshot_callback(WebKitWebView *webview, + GAsyncResult *results, + EvJobThumbnail *job_thumb) +{ + EvPage *page = ev_document_get_page (EV_JOB(job_thumb)->document, job_thumb->page); + job_thumb->surface = webkit_web_view_get_snapshot_finish (webview, + results, + NULL); + EvRenderContext *rc = ev_render_context_new (page, job_thumb->rotation, job_thumb->scale); + EvPage *screenshotpage; + screenshotpage = ev_page_new(job_thumb->page); + screenshotpage->backend_page = (EvBackendPage)job_thumb->surface; + screenshotpage->backend_destroy_func = (EvBackendPageDestroyFunc)cairo_surface_destroy ; + ev_render_context_set_page(rc,screenshotpage); + + job_thumb->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB(job_thumb)->document), + rc, TRUE); + g_object_unref(screenshotpage); + g_object_unref(rc); + + ev_document_doc_mutex_unlock(); + ev_job_succeeded(EV_JOB(job_thumb)); +} + +static void +web_thumbnail_get_screenshot_cb (WebKitWebView *webview, + WebKitLoadEvent event, + EvJobThumbnail *job_thumb) +{ + if (event != WEBKIT_LOAD_FINISHED) { + return; + } + + webkit_web_view_get_snapshot (webview, + WEBKIT_SNAPSHOT_REGION_VISIBLE, + WEBKIT_SNAPSHOT_OPTIONS_NONE, + NULL, + (GAsyncReadyCallback)snapshot_callback, + g_object_ref(job_thumb)); +} +#endif static gboolean ev_job_thumbnail_run (EvJob *job) @@ -859,9 +904,17 @@ ev_job_thumbnail_run (EvJob *job) } webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)rc->page->backend_page); +#if !GTK_CHECK_VERSION (3, 0, 0) g_signal_connect(WEBKIT_WEB_VIEW(webview),"notify::load-status", G_CALLBACK(web_thumbnail_get_screenshot_cb), g_object_ref(job_thumb)); +#else + g_signal_connect(WEBKIT_WEB_VIEW(webview),"load-changed", + G_CALLBACK(web_thumbnail_get_screenshot_cb), + g_object_ref(job_thumb)); + +#endif + g_object_unref(job_thumb); } else { job_thumb->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (job->document), diff --git a/libview/ev-web-view.c b/libview/ev-web-view.c index e6bef75a..f88dd84a 100644 --- a/libview/ev-web-view.c +++ b/libview/ev-web-view.c @@ -44,12 +44,11 @@ typedef struct _SearchParams { gboolean case_sensitive; - gboolean search_jump; gchar* search_string; + EvWebViewFindDirection direction; + gboolean search_jump; gint on_result; - guint n_results; guint *results; - EvWebViewFindDirection direction; }SearchParams; struct _EvWebView @@ -61,6 +60,11 @@ struct _EvWebView gboolean inverted_colors ; gboolean fullscreen; SearchParams *search; +#if GTK_CHECK_VERSION (3, 0, 0) + WebKitFindController *findcontroller; + WebKitFindOptions findoptions; + gdouble zoom_level; +#endif gchar *hlink; }; @@ -141,16 +145,16 @@ ev_web_view_init (EvWebView *webview) gtk_widget_set_can_focus (GTK_WIDGET (webview), TRUE); gtk_widget_set_has_window (GTK_WIDGET (webview), TRUE); - + webview->current_page = 0; webview->search = g_new0(SearchParams, 1); webview->search->search_string = NULL; + webview->search->on_result = -1 ; - webview->search->n_results = 0; webview->search->results = NULL; webview->search->search_jump = TRUE ; - + webview->fullscreen = FALSE; webview->hlink = NULL; @@ -174,8 +178,11 @@ ev_web_view_change_page (EvWebView *webview, webview->current_page = new_page; ev_document_model_set_page(webview->model,new_page); - +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_find_controller_search_finish(webview->findcontroller); +#else webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW(webview)); +#endif if (webview->hlink) { webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webview->hlink); g_free(webview->hlink); @@ -209,7 +216,16 @@ ev_web_view_new (void) GtkWidget *webview; webview = g_object_new (EV_TYPE_WEB_VIEW, NULL); - + + #if GTK_CHECK_VERSION (3, 0, 0) + EV_WEB_VIEW(webview)->findcontroller = webkit_web_view_get_find_controller (WEBKIT_WEB_VIEW(webview)); + EV_WEB_VIEW(webview)->findoptions = webkit_find_controller_get_options (EV_WEB_VIEW(webview)->findcontroller); + + EV_WEB_VIEW(webview)->zoom_level = 1.0; + + EV_WEB_VIEW(webview)->findoptions |= WEBKIT_FIND_OPTIONS_NONE; + #endif + return webview; } @@ -417,8 +433,10 @@ ev_web_view_handle_link(EvWebView *webview,EvLink *link) /* Searching */ +#if !GTK_CHECK_VERSION (3, 0, 0) static void -jump_to_find_result_on_page(EvWebView *webview,EvWebViewFindDirection direction) +jump_to_find_result_on_page(EvWebView *webview, + EvWebViewFindDirection direction) { gboolean forward,wrap; @@ -431,6 +449,9 @@ jump_to_find_result_on_page(EvWebView *webview,EvWebViewFindDirection direction) wrap = FALSE; } + if (webview->search->search_jump) { + wrap = TRUE; + } webkit_web_view_search_text (WEBKIT_WEB_VIEW(webview), webview->search->search_string, webview->search->case_sensitive, @@ -439,24 +460,70 @@ jump_to_find_result_on_page(EvWebView *webview,EvWebViewFindDirection direction) webview->search->search_jump = FALSE; } +#endif +#if GTK_CHECK_VERSION (3, 0, 0) +static void +results_counted_cb(WebKitFindController *findcontroller, + guint match_count, + EvWebView *webview) +{ + if (match_count > 0 && webview->search->on_result < match_count) { + webkit_find_controller_search(findcontroller, + webview->search->search_string, + webview->findoptions, + match_count); + webview->search->search_jump = FALSE; + } +} +#endif +/* + * Jump to find results once we have changed the page in the webview. + */ +#if GTK_CHECK_VERSION (3, 0, 0) +static void +jump_to_find_results(EvWebView *webview, + WebKitLoadEvent load_event, + gpointer data) +#else static void jump_to_find_results(EvWebView *webview, GParamSpec *pspec, gpointer data) +#endif { + #if !GTK_CHECK_VERSION (3, 0, 0) gint n_results; gboolean forward ; gboolean wrap ; - + if (webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(webview)) != WEBKIT_LOAD_FINISHED) { return; } - +#else + if ( load_event != WEBKIT_LOAD_FINISHED) { + return; + } +#endif if (!webview->search->search_string) { return; } +#if GTK_CHECK_VERSION (3, 0, 0) + if (webview->search->direction == EV_WEB_VIEW_FIND_NEXT) { + webview->findoptions &= ~WEBKIT_FIND_OPTIONS_BACKWARDS; + webview->findoptions &= ~WEBKIT_FIND_OPTIONS_WRAP_AROUND; + } + else { + webview->findoptions |= WEBKIT_FIND_OPTIONS_BACKWARDS; + webview->findoptions |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + } + + webkit_find_controller_count_matches (webview->findcontroller, + webview->search->search_string, + webview->findoptions, + G_MAXUINT); +#else n_results = webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW(webview), webview->search->search_string, webview->search->case_sensitive, @@ -482,6 +549,8 @@ jump_to_find_results(EvWebView *webview, webview->search->search_jump = FALSE; } +#endif + webview->search->search_jump = FALSE; } static gint @@ -520,15 +589,41 @@ jump_to_find_page (EvWebView *webview, EvWebViewFindDirection direction, gint sh } else if (page < 0) page = page + n_pages; - if (page == webview->current_page && ev_web_view_find_get_n_results(webview,page) > 0) { + if (page == webview->current_page && ev_web_view_find_get_n_results(webview,page) > 0) { +#if !GTK_CHECK_VERSION (3, 0, 0) jump_to_find_result_on_page(webview,EV_WEB_VIEW_FIND_NEXT); +#else + if (direction == EV_WEB_VIEW_FIND_PREV) { + webview->findoptions |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + webview->findoptions |= WEBKIT_FIND_OPTIONS_BACKWARDS; + } + else { + if (webview->search->search_jump) + webview->findoptions |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + else + webview->findoptions &= ~WEBKIT_FIND_OPTIONS_WRAP_AROUND; + + webview->findoptions &= ~WEBKIT_FIND_OPTIONS_BACKWARDS; + } + + webkit_find_controller_search (webview->findcontroller, + webview->search->search_string, + webview->findoptions, + /*Highlight all the results.*/ + G_MAXUINT); + webview->search->search_jump = FALSE; +#endif break; } if (ev_web_view_find_get_n_results (webview, page) > 0) { + webview->search->direction = direction; +#if !GTK_CHECK_VERSION (3, 0, 0) webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW(webview)); +#else + webkit_find_controller_search_finish(webview->findcontroller); +#endif ev_document_model_set_page (webview->model, page); - webview->search->direction = direction; break; } } @@ -537,11 +632,19 @@ jump_to_find_page (EvWebView *webview, EvWebViewFindDirection direction, gint sh void ev_web_view_find_changed (EvWebView *webview, guint *results, gchar *text,gboolean case_sensitive) { - webview->search->results = results; + webview->search->results = results; + webview->search->on_result = 0; webview->search->search_string = g_strdup(text); webview->search->case_sensitive = case_sensitive; - webview->search->on_result = 0; - if (webview->search->search_jump == TRUE) { + if (webview->search->search_jump == TRUE) { +#if GTK_CHECK_VERSION (3, 0, 0) + if (!case_sensitive) { + webview->findoptions |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; + } + else { + webview->findoptions &= ~WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; + } +#endif jump_to_find_page (webview, EV_WEB_VIEW_FIND_NEXT, 0); } } @@ -559,7 +662,11 @@ ev_web_view_find_next (EvWebView *webview) jump_to_find_page (webview, EV_WEB_VIEW_FIND_NEXT, 1); } else { +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_find_controller_search_next(webview->findcontroller); +#else jump_to_find_result_on_page (webview, EV_WEB_VIEW_FIND_NEXT); +#endif } } @@ -572,7 +679,11 @@ ev_web_view_find_previous (EvWebView *webview) jump_to_find_page (webview, EV_WEB_VIEW_FIND_PREV, -1); webview->search->on_result = MAX (0, ev_web_view_find_get_n_results (webview, webview->current_page) - 1); } else { +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_find_controller_search_previous(webview->findcontroller); +#else jump_to_find_result_on_page (webview,EV_WEB_VIEW_FIND_PREV); +#endif } } @@ -580,68 +691,127 @@ void ev_web_view_find_search_changed (EvWebView *webview) { /* search string has changed, focus on new search result */ +#if !GTK_CHECK_VERSION(3, 0, 0) webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webview)); - - webview->search->search_jump = TRUE; - +#endif if (webview->search->search_string) { g_free(webview->search->search_string); webview->search->search_string = NULL; } +#if GTK_CHECK_VERSION(3, 0, 0) + webkit_find_controller_search_finish(webview->findcontroller); +#endif + + webview->search->search_jump = TRUE; } +#if !GTK_CHECK_VERSION (3, 0, 0) void ev_web_view_find_set_highlight_search (EvWebView *webview, gboolean value) { webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW(webview),value); } +#endif void ev_web_view_find_cancel (EvWebView *webview) { +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_find_controller_search_finish (webview->findcontroller); +#else webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webview)); ev_web_view_find_set_highlight_search(webview,FALSE); +#endif } + void ev_web_view_set_handler(EvWebView *webview,gboolean visible) { if (visible) { g_signal_connect(webview, +#if GTK_CHECK_VERSION (3, 0, 0) + "load-changed", +#else "notify::load-status", +#endif G_CALLBACK(jump_to_find_results), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_connect(webview->findcontroller, + "counted-matches", + G_CALLBACK(results_counted_cb), + webview); +#endif } else { g_signal_handlers_disconnect_by_func(webview, jump_to_find_results, NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_handlers_disconnect_by_func(webview, + results_counted_cb, + NULL); +#endif } } -/* Selection */ +/* Selection and copying*/ +#if !GTK_CHECK_VERSION (3, 0, 0) gboolean ev_web_view_get_has_selection(EvWebView *webview) { return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(webview)); } +#endif void ev_web_view_select_all(EvWebView *webview) { +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_web_view_execute_editing_command(WEBKIT_WEB_VIEW(webview), + WEBKIT_EDITING_COMMAND_SELECT_ALL); +#else webkit_web_view_select_all(WEBKIT_WEB_VIEW(webview)); +#endif +} + +#if GTK_CHECK_VERSION (3, 0, 0) +static void +copy_text_cb(WebKitWebView *webview, + GAsyncResult *res, + gpointer data) +{ + gboolean okay_to_copy = webkit_web_view_can_execute_editing_command_finish (WEBKIT_WEB_VIEW(webview), + res, + NULL); + + if (okay_to_copy) { + webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW(webview), + WEBKIT_EDITING_COMMAND_COPY); + } } +#endif void ev_web_view_copy(EvWebView *webview) { - /* If for some reason we don't have a selection any longer,best to be safe*/ - if (ev_web_view_get_has_selection(webview) == FALSE) - return; - if (webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(webview))) { - webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(webview)); - } +#if !GTK_CHECK_VERSION (3, 0, 0) + /* If for some reason we don't have a selection any longer,best to be safe */ + if (ev_web_view_get_has_selection(webview) == FALSE) + return; + if (webkit_web_view_can_copy_clipboard(WEBKIT_WEB_VIEW(webview))) { + webkit_web_view_copy_clipboard(WEBKIT_WEB_VIEW(webview)); + } +#else + webkit_web_view_can_execute_editing_command(WEBKIT_WEB_VIEW(webview), + WEBKIT_EDITING_COMMAND_COPY, + NULL, + (GAsyncReadyCallback)copy_text_cb, + NULL); + +#endif } @@ -649,13 +819,26 @@ ev_web_view_copy(EvWebView *webview) gboolean ev_web_view_zoom_in(EvWebView *webview) { +#if GTK_CHECK_VERSION (3, 0, 0) + webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(webview), + (webview->zoom_level+= 0.1)); +#else webkit_web_view_zoom_in(WEBKIT_WEB_VIEW(webview)); +#endif return TRUE; } gboolean ev_web_view_zoom_out(EvWebView *webview) { +#if GTK_CHECK_VERSION (3, 0, 0) + if (webview->zoom_level == 1) + return FALSE; + + webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW(webview), + (webview->zoom_level -= 0.1)); +#else webkit_web_view_zoom_out(WEBKIT_WEB_VIEW(webview)); +#endif return TRUE; }
\ No newline at end of file diff --git a/shell/ev-window.c b/shell/ev-window.c index aab14229..bb870976 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -504,11 +504,23 @@ ev_window_update_actions (EvWindow *ev_window) has_pages && ev_view_get_has_selection (view)); } +#if GTK_CHECK_VERSION (3, 0, 0) + else if (webview) { + /* + * The webkit2 function for this is an asynchronous call, + * so our only option is to set this to always on, and we'll take care of whether we can copy + * or not when this command is actually given. + */ + ev_window_set_action_sensitive (ev_window,"EditCopy", + has_pages); + } +#else else if(webview) { ev_window_set_action_sensitive (ev_window, "EditCopy", has_pages && ev_web_view_get_has_selection (webview)); } +#endif ev_window_set_action_sensitive (ev_window, "EditFindNext", has_pages && can_find_in_page); ev_window_set_action_sensitive (ev_window, "EditFindPrevious", @@ -928,7 +940,7 @@ view_selection_changed_cb (EvView *view, ev_window_set_action_sensitive (window, "EditCopy", ev_view_get_has_selection (view)); } - +#if !GTK_CHECK_VERSION (3, 0, 0) static void web_view_selection_changed_cb(EvWebView *webview, EvWindow *window) @@ -936,6 +948,7 @@ web_view_selection_changed_cb(EvWebView *webview, ev_window_set_action_sensitive (window,"EditCopy", ev_web_view_get_has_selection(webview)); } +#endif static void ev_window_page_changed_cb (EvWindow *ev_window, @@ -1489,6 +1502,7 @@ ev_window_set_document (EvWindow *ev_window, EvDocument *document) /*We have encountered a web document, replace the atril view with a web view, if the web view is not already loaded.*/ gtk_container_remove (GTK_CONTAINER(ev_window->priv->scrolled_window), ev_window->priv->view); + g_object_unref(ev_window->priv->view); ev_window->priv->view = NULL; gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window), @@ -5201,7 +5215,9 @@ find_bar_visibility_changed_cb (EggFindBar *find_bar, ev_view_find_search_changed (EV_VIEW (ev_window->priv->view)); } else { +#if !GTK_CHECK_VERSION(3, 0, 0) ev_web_view_find_set_highlight_search(EV_WEB_VIEW(ev_window->priv->webview),visible); +#endif ev_web_view_find_search_changed(EV_WEB_VIEW(ev_window->priv->webview)); ev_web_view_set_handler(EV_WEB_VIEW(ev_window->priv->webview),visible); } @@ -5593,15 +5609,7 @@ ev_window_key_press_event (GtkWidget *widget, * It's needed to be able to type in * annot popups windows */ - if (priv->webview && priv->document && priv->document->iswebdocument == TRUE) { - g_object_ref (priv->webview); - if (gtk_widget_is_sensitive (priv->webview)) - handled = gtk_widget_event (priv->webview, (GdkEvent*) event); - g_object_unref (priv->webview); - - } - - else if ( priv->view) { + if ( priv->view) { g_object_ref (priv->view); if (gtk_widget_is_sensitive (priv->view)) handled = gtk_widget_event (priv->view, (GdkEvent*) event); @@ -5871,7 +5879,9 @@ sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, Ev if (window->priv->document->iswebdocument == FALSE ) { ev_view_handle_link (EV_VIEW (window->priv->view), link); } - ev_web_view_handle_link(EV_WEB_VIEW(window->priv->webview), link); + else { + ev_web_view_handle_link(EV_WEB_VIEW(window->priv->webview), link); + } } static void @@ -7229,11 +7239,12 @@ ev_window_init (EvWindow *ev_window) #ifdef ENABLE_EPUB /*The webview, we won't add it now but it will replace the atril-view if a web(epub) document is encountered.*/ ev_window->priv->webview = ev_web_view_new(); ev_web_view_set_model(EV_WEB_VIEW(ev_window->priv->webview),ev_window->priv->model); - +#if !GTK_CHECK_VERSION (3, 0, 0) g_signal_connect_object (ev_window->priv->webview,"selection-changed", G_CALLBACK(web_view_selection_changed_cb), ev_window, 0); #endif +#endif ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE); ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model); |