aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-06-03 21:42:34 +0800
committerChristian Persch <chpe@src.gnome.org>2005-06-03 21:42:34 +0800
commiteeac7e657d86802e904337ffef1bf5a0341a8cd0 (patch)
tree414d9a2cf8df822765357a4524283061b4c9d6dd
parent822d2a28ff4c437e23043dc03adbb00ddde36e4d (diff)
downloadgsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.gz
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.bz2
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.lz
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.xz
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.zst
gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.zip
Don't open search toolbar on / or ' over formfields:
2005-06-03 Christian Persch <chpe@cvs.gnome.org> Don't open search toolbar on / or ' over formfields: * embed/ephy-embed.c: (ephy_embed_base_init): * embed/ephy-embed.h: New signal for searchable key presses. * embed/mozilla/EventContext.cpp: * embed/mozilla/EventContext.h: Add static function to check if a keypress should be forwarded to the search toolbar. * embed/mozilla/mozilla-embed.cpp: Emit the signal here. * lib/ephy-marshal.list: * src/ephy-find-toolbar.c: (tab_search_key_press_cb), (ephy_find_toolbar_set_embed): Use the new signal instead of dom-key-press.
-rw-r--r--ChangeLog25
-rw-r--r--embed/ephy-embed.c18
-rw-r--r--embed/ephy-embed.h2
-rw-r--r--embed/mozilla/EventContext.cpp68
-rw-r--r--embed/mozilla/EventContext.h2
-rw-r--r--embed/mozilla/mozilla-embed.cpp33
-rw-r--r--lib/ephy-marshal.list1
-rw-r--r--src/ephy-find-toolbar.c42
8 files changed, 164 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index d37fcfa64..13ced7a56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2005-06-03 Christian Persch <chpe@cvs.gnome.org>
+
+ Don't open search toolbar on / or ' over formfields:
+
+ * embed/ephy-embed.c: (ephy_embed_base_init):
+ * embed/ephy-embed.h:
+
+ New signal for searchable key presses.
+
+ * embed/mozilla/EventContext.cpp:
+ * embed/mozilla/EventContext.h:
+
+ Add static function to check if a keypress should be forwarded
+ to the search toolbar.
+
+ * embed/mozilla/mozilla-embed.cpp:
+
+ Emit the signal here.
+
+ * lib/ephy-marshal.list:
+ * src/ephy-find-toolbar.c: (tab_search_key_press_cb),
+ (ephy_find_toolbar_set_embed):
+
+ Use the new signal instead of dom-key-press.
+
2005-06-02 Jean-François Rameau <jframeau@cvs.gnome.org>
* embed/mozilla/EventContext.cpp: (EventContext::GetEventContext):
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 79d95e51b..eb9785b29 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -350,6 +350,24 @@ ephy_embed_base_init (gpointer g_class)
1,
G_TYPE_POINTER);
+/**
+ * EphyEmbed::ge-search-key-press:
+ * @embed:
+ * @event: the #GdkEventKey which triggered this signal
+ *
+ * The ::ge-search-key-press signal is emitted for keypresses which
+ * should be used for find implementations.
+ **/
+ g_signal_new ("ge-search-key-press",
+ EPHY_TYPE_EMBED,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyEmbedIface, context_menu),
+ g_signal_accumulator_true_handled, NULL,
+ ephy_marshal_BOOLEAN__BOXED,
+ G_TYPE_BOOLEAN,
+ 1,
+ GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
initialized = TRUE;
}
}
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index c3dff5b33..7da209684 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -146,6 +146,8 @@ struct _EphyEmbedIface
EphyEmbedDocumentType type);
void (* new_window) (EphyEmbed *embed,
EphyEmbed *new_embed);
+ gboolean (* search_key_press) (EphyEmbed *embed,
+ GdkEventKey *event);
/* Methods */
void (* load_url) (EphyEmbed *embed,
diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp
index 6211b36a8..f4b998129 100644
--- a/embed/mozilla/EventContext.cpp
+++ b/embed/mozilla/EventContext.cpp
@@ -56,6 +56,8 @@
#include <nsIDOMNodeList.h>
#include <nsIDOMDocumentView.h>
#include <nsIDOMAbstractView.h>
+#include <nsIDOMNSHTMLDocument.h>
+#include <nsIDOMNSUIEvent.h>
#ifdef ALLOW_PRIVATE_API
#include <nsITextToSubURI.h>
@@ -1003,3 +1005,69 @@ nsresult EventContext::SetURIProperty (nsIDOMNode *node, const char *name, const
NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue);
return SetURIProperty (node, name, cValue);
}
+
+/* static */
+PRBool
+EventContext::CheckKeyPress (nsIDOMKeyEvent *aEvent)
+{
+ PRBool retval = PR_FALSE;
+
+ /* check for alt/ctrl */
+ PRBool isCtrl = PR_FALSE, isAlt = PR_FALSE;
+ aEvent->GetCtrlKey (&isCtrl);
+ aEvent->GetAltKey (&isAlt);
+ if (isCtrl || isAlt) return retval;
+
+ nsCOMPtr<nsIDOMNSUIEvent> uiEvent (do_QueryInterface (aEvent));
+ NS_ENSURE_TRUE (uiEvent, retval);
+
+ /* check for already handled event */
+ PRBool isPrevented = PR_FALSE;
+ uiEvent->GetPreventDefault (&isPrevented);
+ if (isPrevented) return retval;
+
+ /* check for form controls */
+ nsresult rv;
+ nsCOMPtr<nsIDOMEventTarget> target;
+ rv = aEvent->GetTarget (getter_AddRefs (target));
+ NS_ENSURE_SUCCESS (rv, retval);
+
+ nsCOMPtr<nsIDOMHTMLElement> element (do_QueryInterface (target, &rv));
+ NS_ENSURE_SUCCESS (rv, retval);
+
+ PRUint16 type = 0;
+ element->GetNodeType(&type);
+ if (nsIDOMNode::ELEMENT_NODE != type) return retval;
+
+ nsEmbedString uTag;
+ rv = element->GetLocalName(uTag);
+ NS_ENSURE_SUCCESS (rv, retval);
+
+ nsEmbedCString tag;
+ NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag);
+
+ if (g_ascii_strcasecmp (tag.get(), "input") == 0 ||
+ g_ascii_strcasecmp (tag.get(), "textaread") == 0 ||
+ g_ascii_strcasecmp (tag.get(), "select") == 0 ||
+ g_ascii_strcasecmp (tag.get(), "button") == 0 ||
+ g_ascii_strcasecmp (tag.get(), "isindex") == 0) return retval;
+
+ /* check for design mode */
+ nsCOMPtr<nsIDOMDocument> doc;
+ rv = element->GetOwnerDocument (getter_AddRefs (doc));
+ NS_ENSURE_SUCCESS (rv, retval);
+
+ nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc (do_QueryInterface (doc, &rv));
+ if (NS_FAILED (rv)) return retval; /* it's okay not to be a HTML document */
+
+ nsEmbedString uDesign;
+ rv = htmlDoc->GetDesignMode (uDesign);
+ NS_ENSURE_SUCCESS (rv, retval);
+
+ nsEmbedCString design;
+ NS_UTF16ToCString (uDesign, NS_CSTRING_ENCODING_UTF8, design);
+
+ retval = g_ascii_strcasecmp (design.get(), "on") != 0;
+
+ return retval;
+}
diff --git a/embed/mozilla/EventContext.h b/embed/mozilla/EventContext.h
index c982b9722..97e190437 100644
--- a/embed/mozilla/EventContext.h
+++ b/embed/mozilla/EventContext.h
@@ -55,6 +55,8 @@ public:
nsresult GetKeyEventInfo (nsIDOMKeyEvent *event, MozillaEmbedEvent *info);
nsresult GetTargetDocument (nsIDOMDocument **domDoc);
+ static PRBool CheckKeyPress (nsIDOMKeyEvent *aEvent);
+
private:
EphyBrowser *mBrowser;
MozillaEmbedEvent *mEmbedEvent;
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index 1d87d77ab..e9fc2aab9 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -64,6 +64,9 @@ static gboolean mozilla_embed_dom_mouse_click_cb(GtkMozEmbed *embed,
static gboolean mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed,
gpointer dom_event,
MozillaEmbed *membed);
+static gboolean mozilla_embed_dom_key_press_cb (GtkMozEmbed *embed,
+ gpointer dom_event,
+ MozillaEmbed *membed);
static void mozilla_embed_new_window_cb (GtkMozEmbed *embed,
GtkMozEmbed **newEmbed,
guint chrome_mask,
@@ -242,6 +245,9 @@ mozilla_embed_init (MozillaEmbed *embed)
g_signal_connect_object (G_OBJECT (embed), "dom_mouse_down",
G_CALLBACK (mozilla_embed_dom_mouse_down_cb),
embed, (GConnectFlags) 0);
+ g_signal_connect_object (G_OBJECT (embed), "dom-key-press",
+ G_CALLBACK (mozilla_embed_dom_key_press_cb),
+ embed, (GConnectFlags) 0);
g_signal_connect_object (G_OBJECT (embed), "new_window",
G_CALLBACK (mozilla_embed_new_window_cb),
embed, (GConnectFlags) 0);
@@ -910,6 +916,33 @@ mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event,
"ge_dom_mouse_down");
}
+static gint
+mozilla_embed_dom_key_press_cb (GtkMozEmbed *embed,
+ gpointer dom_event,
+ MozillaEmbed *membed)
+{
+ MozillaEmbedPrivate *mpriv = membed->priv;
+ gint retval = FALSE;
+
+ if (dom_event == NULL) return FALSE;
+
+ nsCOMPtr<nsIDOMKeyEvent> ev = static_cast<nsIDOMKeyEvent*>(dom_event);
+ NS_ENSURE_TRUE (ev, FALSE);
+
+ if (!EventContext::CheckKeyPress (ev)) return FALSE;
+
+ GdkEvent *event = gtk_get_current_event ();
+ if (event == NULL) return FALSE; /* shouldn't happen! */
+
+ g_return_val_if_fail (GDK_KEY_PRESS == event->type, FALSE);
+
+ g_signal_emit_by_name (embed, "ge-search-key-press", event, &retval);
+
+ gdk_event_free (event);
+
+ return retval;
+}
+
EphyEmbedChrome
_mozilla_embed_translate_chrome (GtkMozEmbedChromeFlags flags)
{
diff --git a/lib/ephy-marshal.list b/lib/ephy-marshal.list
index f915fe517..7294c6b84 100644
--- a/lib/ephy-marshal.list
+++ b/lib/ephy-marshal.list
@@ -1,3 +1,4 @@
+BOOLEAN:BOXED
BOOLEAN:ENUM,STRING,STRING,STRING
BOOLEAN:OBJECT
BOOLEAN:STRING,STRING
diff --git a/src/ephy-find-toolbar.c b/src/ephy-find-toolbar.c
index 6de388c91..041a4f85c 100644
--- a/src/ephy-find-toolbar.c
+++ b/src/ephy-find-toolbar.c
@@ -154,71 +154,59 @@ send_focus_change (GtkWidget *widget,
* gtk_tree_view_real_start_interactive_seach()
*/
static gboolean
-tab_dom_key_press_cb (EphyEmbed *embed,
- gpointer dom_event,
- EphyFindToolbar *toolbar)
+tab_search_key_press_cb (EphyEmbed *embed,
+ GdkEventKey *event,
+ EphyFindToolbar *toolbar)
{
EphyFindToolbarPrivate *priv = toolbar->priv;
GtkWidget *widget = (GtkWidget *) toolbar;
GtkEntry *entry = (GtkEntry *) priv->entry;
GdkWindow *event_window;
- GdkEvent *event;
- GdkEventKey *event_key;
gboolean retval = FALSE;
guint oldhash, newhash;
+ g_return_val_if_fail (event != NULL, FALSE);
+
/* don't do anything in PPV mode */
if (ephy_window_get_is_print_preview (priv->window)) return FALSE;
- event = gtk_get_current_event ();
- if (event == NULL) return FALSE; /* shouldn't happen! */
-
- g_return_val_if_fail (GDK_KEY_PRESS == event->type, FALSE);
-
- event_key = (GdkEventKey *) event;
-
/* check for / and ' which open the find toolbar in text resp. link mode */
if (GTK_WIDGET_VISIBLE (widget) == FALSE)
{
- if (event_key->keyval == GDK_slash)
+ if (event->keyval == GDK_slash)
{
ephy_find_toolbar_open (toolbar, FALSE, TRUE);
- gdk_event_free (event);
return TRUE;
}
- else if (event_key->keyval == GDK_apostrophe)
+ else if (event->keyval == GDK_apostrophe)
{
ephy_find_toolbar_open (toolbar, TRUE, TRUE);
- gdk_event_free (event);
return TRUE;
}
}
/* don't do anything if the find toolbar is hidden */
if (GTK_WIDGET_VISIBLE (widget) == FALSE ||
- event_key->keyval == GDK_Return ||
- event_key->keyval == GDK_KP_Enter)
+ event->keyval == GDK_Return ||
+ event->keyval == GDK_KP_Enter)
{
- gdk_event_free (event);
return FALSE;
}
oldhash = g_str_hash (gtk_entry_get_text (entry));
- event_window = event_key->window;
- event_key->window = priv->entry->window;
+ event_window = event->window;
+ event->window = priv->entry->window;
/* Send the event to the window. If the preedit_changed signal is emitted
* during this event, we will set priv->imcontext_changed */
priv->preedit_changed = priv->activated = FALSE;
priv->prevent_activate = TRUE;
- retval = gtk_widget_event (priv->entry, event);
+ retval = gtk_widget_event (priv->entry, (GdkEvent*) event);
priv->prevent_activate = FALSE;
/* restore event window, else gdk_event_free below will crash */
- event_key->window = event_window;
-
- gdk_event_free (event);
+ event->window = event_window;
newhash = g_str_hash (gtk_entry_get_text (entry));
@@ -607,8 +595,8 @@ ephy_find_toolbar_set_embed (EphyFindToolbar *toolbar,
G_CALLBACK (tab_content_changed_cb),
toolbar, G_CONNECT_AFTER);
#ifdef HAVE_TYPEAHEADFIND
- g_signal_connect_object (embed, "dom-key-press",
- G_CALLBACK (tab_dom_key_press_cb),
+ g_signal_connect_object (embed, "ge-search-key-press",
+ G_CALLBACK (tab_search_key_press_cb),
toolbar, 0);
#endif