diff options
-rw-r--r-- | modules/mail/e-mail-shell-view-private.c | 93 |
1 files changed, 66 insertions, 27 deletions
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c index 6cf83b98a8..53da2bc288 100644 --- a/modules/mail/e-mail-shell-view-private.c +++ b/modules/mail/e-mail-shell-view-private.c @@ -257,6 +257,37 @@ mail_shell_view_folder_tree_popup_event_cb (EShellView *shell_view, } static gboolean +mail_shell_view_mail_display_needs_key (EMailDisplay *mail_display, + gboolean with_input) +{ + gboolean needs_key = FALSE; + + if (gtk_widget_has_focus (GTK_WIDGET (mail_display))) { + WebKitWebFrame *frame; + WebKitDOMDocument *dom; + WebKitDOMElement *element; + gchar *name = NULL; + + frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display)); + dom = webkit_web_frame_get_dom_document (frame); + /* intentionally used "static_cast" */ + element = webkit_dom_html_document_get_active_element ((WebKitDOMHTMLDocument *) dom); + + if (element) + name = webkit_dom_node_get_node_name (WEBKIT_DOM_NODE (element)); + + /* if INPUT or TEXTAREA has focus, then any key press should go there */ + if (name && ((with_input && g_ascii_strcasecmp (name, "INPUT") == 0) || g_ascii_strcasecmp (name, "TEXTAREA") == 0)) { + needs_key = TRUE; + } + + g_free (name); + } + + return needs_key; +} + +static gboolean mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view, GdkEventKey *event) { @@ -274,6 +305,11 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view, if ((event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)) != 0) return FALSE; + shell_content = e_shell_view_get_shell_content (shell_view); + mail_view = e_mail_shell_content_get_mail_view (E_MAIL_SHELL_CONTENT (shell_content)); + reader = E_MAIL_READER (mail_view); + mail_display = e_mail_reader_get_mail_display (reader); + switch (event->keyval) { case GDK_KEY_space: action = ACTION (MAIL_SMART_FORWARD); @@ -283,37 +319,40 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view, action = ACTION (MAIL_SMART_BACKWARD); break; + case GDK_KEY_Home: + case GDK_KEY_Left: + case GDK_KEY_Up: + case GDK_KEY_Right: + case GDK_KEY_Down: + case GDK_KEY_Prior: + case GDK_KEY_Next: + case GDK_KEY_End: + case GDK_KEY_Begin: + if (!mail_shell_view_mail_display_needs_key (mail_display, FALSE) && + webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (mail_display)) != + webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display))) { + WebKitDOMDocument *document; + WebKitDOMDOMWindow *window; + + document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (mail_display)); + window = webkit_dom_document_get_default_view (document); + + /* Workaround WebKit bug for key navigation, when inner IFRAME is focused. + EMailView's inner IFRAMEs have disabled scrolling, but WebKit doesn't post + key navigation events to parent's frame, thus the view doesn't scroll. + This is a poor workaround for this issue, the main frame is focused, + which has scrolling enabled. + */ + webkit_dom_dom_window_focus (window); + } + + return FALSE; default: return FALSE; } - shell_content = e_shell_view_get_shell_content (shell_view); - mail_view = e_mail_shell_content_get_mail_view (E_MAIL_SHELL_CONTENT (shell_content)); - reader = E_MAIL_READER (mail_view); - mail_display = e_mail_reader_get_mail_display (reader); - - if (gtk_widget_has_focus (GTK_WIDGET (mail_display))) { - WebKitWebFrame *frame; - WebKitDOMDocument *dom; - WebKitDOMElement *element; - gchar *name = NULL; - - frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display)); - dom = webkit_web_frame_get_dom_document (frame); - /* intentionally used "static_cast" */ - element = webkit_dom_html_document_get_active_element ((WebKitDOMHTMLDocument *) dom); - - if (element) - name = webkit_dom_node_get_node_name (WEBKIT_DOM_NODE (element)); - - /* if INPUT or TEXTAREA has focus, then any key press should go there */ - if (name && (g_ascii_strcasecmp (name, "INPUT") == 0 || g_ascii_strcasecmp (name, "TEXTAREA") == 0)) { - g_free (name); - return FALSE; - } - - g_free (name); - } + if (mail_shell_view_mail_display_needs_key (mail_display, TRUE)) + return FALSE; gtk_action_activate (action); |