[evolution] EHTMLEditorView - Use HTML keyup event instead of GWidget's key-release-event signal
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorView - Use HTML keyup event instead of GWidget's key-release-event signal
- Date: Wed, 3 Dec 2014 16:13:42 +0000 (UTC)
commit 11c173acdf6e8d01f2a77c6c8f40aec3ead0a000
Author: Tomas Popela <tpopela redhat com>
Date: Wed Dec 3 17:10:43 2014 +0100
EHTMLEditorView - Use HTML keyup event instead of GWidget's key-release-event signal
This is mainly for WebKit2 port.
e-util/e-html-editor-view.c | 247 +++++++++++++++++++++----------------------
1 files changed, 122 insertions(+), 125 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 02822ea..858219e 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -2095,6 +2095,121 @@ register_input_event_listener_on_body (EHTMLEditorView *view)
}
static void
+body_keyup_event_cb (WebKitDOMElement *element,
+ WebKitDOMUIEvent *event,
+ EHTMLEditorView *view)
+{
+ EHTMLEditorSelection *selection;
+ glong key_code;
+
+ register_input_event_listener_on_body (view);
+ selection = e_html_editor_view_get_selection (view);
+ if (!e_html_editor_selection_is_collapsed (selection))
+ return;
+
+ key_code = webkit_dom_ui_event_get_key_code (event);
+ if (key_code == 8 || key_code == 46) {/* BackSpace or Delete */
+ /* This will fix the structure after the situations where some text
+ * inside the quoted content is selected and afterwards deleted with
+ * BackSpace or Delete. */
+ gint level;
+ WebKitDOMElement *selection_start_marker, *selection_end_marker;
+ WebKitDOMElement *element;
+ WebKitDOMDocument *document;
+ WebKitDOMNode *node, *parent;
+
+ document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
+
+ e_html_editor_selection_save (selection);
+ selection_start_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ selection_end_marker = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+
+ level = get_citation_level (
+ WEBKIT_DOM_NODE (selection_start_marker), FALSE);
+ if (level == 0)
+ goto restore;
+
+ node = webkit_dom_node_get_previous_sibling (
+ WEBKIT_DOM_NODE (selection_start_marker));
+
+ if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (node))
+ node = webkit_dom_node_get_previous_sibling (node);
+
+ if (node)
+ goto restore;
+
+ parent = get_parent_block_node_from_child (
+ WEBKIT_DOM_NODE (selection_start_marker));
+
+ node = webkit_dom_node_get_previous_sibling (parent);
+ if (!node) {
+ /* Situation where the start of the selection was in the
+ * multiple quoted content and that start on the beginning
+ * of the citation.
+ *
+ * >
+ * >> |
+ * >> xx|x
+ * */
+ node = webkit_dom_node_get_parent_node (parent);
+ if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
+ goto restore;
+ node = webkit_dom_node_get_previous_sibling (node);
+ if (!node)
+ goto restore;
+ if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (webkit_dom_node_get_parent_node (node)))
+ goto restore;
+ }
+
+ element = webkit_dom_element_query_selector (
+ WEBKIT_DOM_ELEMENT (node), "span.-x-evo-quote-character > br", NULL);
+ if (element) {
+ WebKitDOMNode *tmp;
+
+ if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node)) {
+ /* We have to select the right block when the selection
+ * started on the end of the citation that is
+ * inside another citation.
+ *
+ * >>|
+ * > xx|x
+ */
+ /* <span class="-x-evo-quote-character"> */
+ node = webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (element));
+ /* <span class="-x-evo-quoted"> */
+ node = webkit_dom_node_get_parent_node (node);
+ /* right block */
+ node = webkit_dom_node_get_parent_node (node);
+ }
+
+ webkit_dom_node_append_child (
+ node, WEBKIT_DOM_NODE (selection_start_marker), NULL);
+
+ while ((tmp = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE
(selection_end_marker))))
+ webkit_dom_node_append_child (node, tmp, NULL);
+
+ webkit_dom_node_insert_before (
+ node,
+ WEBKIT_DOM_NODE (selection_end_marker),
+ webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (selection_start_marker)),
+ NULL);
+
+ webkit_dom_node_append_child (
+ node, WEBKIT_DOM_NODE (element), NULL);
+ remove_node (parent);
+ }
+ restore:
+ e_html_editor_selection_restore (selection);
+ }
+ else if (key_code == 17) /* Control */
+ html_editor_view_set_links_active (view, FALSE);
+}
+
+static void
clipboard_text_received_for_paste_as_text (GtkClipboard *clipboard,
const gchar *text,
EHTMLEditorView *view)
@@ -2773,130 +2888,6 @@ html_editor_view_key_press_event (GtkWidget *widget,
key_press_event (widget, event);
}
-static gboolean
-html_editor_view_key_release_event (GtkWidget *widget,
- GdkEventKey *event)
-{
- EHTMLEditorView *view;
- EHTMLEditorSelection *selection;
-
- view = E_HTML_EDITOR_VIEW (widget);
- register_input_event_listener_on_body (view);
-
- selection = e_html_editor_view_get_selection (view);
- if (!e_html_editor_selection_is_collapsed (selection))
- goto out;
-
- /* This will fix the structure after the situations where some text
- * inside the quoted content is selected and afterwards deleted with
- * BackSpace or Delete. */
- if ((event->keyval == GDK_KEY_BackSpace) ||
- (event->keyval == GDK_KEY_Delete)) {
- gint level;
- WebKitDOMElement *selection_start_marker, *selection_end_marker;
- WebKitDOMElement *element;
- WebKitDOMDocument *document;
- WebKitDOMNode *node, *parent;
-
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
-
- e_html_editor_selection_save (selection);
- selection_start_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-start-marker");
- selection_end_marker = webkit_dom_document_get_element_by_id (
- document, "-x-evo-selection-end-marker");
-
- level = get_citation_level (
- WEBKIT_DOM_NODE (selection_start_marker), FALSE);
- if (level == 0)
- goto restore;
-
- node = webkit_dom_node_get_previous_sibling (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (node))
- node = webkit_dom_node_get_previous_sibling (node);
-
- if (node)
- goto restore;
-
- parent = get_parent_block_node_from_child (
- WEBKIT_DOM_NODE (selection_start_marker));
-
- node = webkit_dom_node_get_previous_sibling (parent);
- if (!node) {
- /* Situation where the start of the selection was in the
- * multiple quoted content and that start on the beginning
- * of the citation.
- *
- * >
- * >> |
- * >> xx|x
- * */
- node = webkit_dom_node_get_parent_node (parent);
- if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
- goto restore;
- node = webkit_dom_node_get_previous_sibling (node);
- if (!node)
- goto restore;
- if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (webkit_dom_node_get_parent_node (node)))
- goto restore;
- }
-
- element = webkit_dom_element_query_selector (
- WEBKIT_DOM_ELEMENT (node), "span.-x-evo-quote-character > br", NULL);
- if (element) {
- WebKitDOMNode *tmp;
-
- if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node)) {
- /* We have to select the right block when the selection
- * started on the end of the citation that is
- * inside another citation.
- *
- * >>|
- * > xx|x
- */
- /* <span class="-x-evo-quote-character"> */
- node = webkit_dom_node_get_parent_node (
- WEBKIT_DOM_NODE (element));
- /* <span class="-x-evo-quoted"> */
- node = webkit_dom_node_get_parent_node (node);
- /* right block */
- node = webkit_dom_node_get_parent_node (node);
- }
-
- webkit_dom_node_append_child (
- node, WEBKIT_DOM_NODE (selection_start_marker), NULL);
-
- while ((tmp = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE
(selection_end_marker))))
- webkit_dom_node_append_child (node, tmp, NULL);
-
- webkit_dom_node_insert_before (
- node,
- WEBKIT_DOM_NODE (selection_end_marker),
- webkit_dom_node_get_next_sibling (
- WEBKIT_DOM_NODE (selection_start_marker)),
- NULL);
-
- webkit_dom_node_append_child (
- node, WEBKIT_DOM_NODE (element), NULL);
- remove_node (parent);
- }
- restore:
- e_html_editor_selection_restore (selection);
- }
-
- if ((event->keyval == GDK_KEY_Control_L) ||
- (event->keyval == GDK_KEY_Control_R)) {
-
- html_editor_view_set_links_active (view, FALSE);
- }
- out:
- /* Chain up to parent's key_release_event() method. */
- return GTK_WIDGET_CLASS (e_html_editor_view_parent_class)->
- key_release_event (widget, event);
-}
-
static void
html_editor_view_paste_as_text (EHTMLEditorView *view)
{
@@ -3041,7 +3032,6 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
widget_class->button_press_event = html_editor_view_button_press_event;
widget_class->button_release_event = html_editor_view_button_release_event;
widget_class->key_press_event = html_editor_view_key_press_event;
- widget_class->key_release_event = html_editor_view_key_release_event;
class->paste_clipboard_quoted = html_editor_view_paste_clipboard_quoted;
@@ -4805,6 +4795,13 @@ html_editor_convert_view_content (EHTMLEditorView *view,
FALSE,
view);
+ webkit_dom_event_target_add_event_listener (
+ WEBKIT_DOM_EVENT_TARGET (body),
+ "keyup",
+ G_CALLBACK (body_keyup_event_cb),
+ FALSE,
+ view);
+
g_free (inner_html);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]