diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-06-03 21:42:34 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-06-03 21:42:34 +0800 |
commit | eeac7e657d86802e904337ffef1bf5a0341a8cd0 (patch) | |
tree | 414d9a2cf8df822765357a4524283061b4c9d6dd /embed/mozilla/EventContext.cpp | |
parent | 822d2a28ff4c437e23043dc03adbb00ddde36e4d (diff) | |
download | gsoc2013-epiphany-eeac7e657d86802e904337ffef1bf5a0341a8cd0.tar.gz 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.
Diffstat (limited to 'embed/mozilla/EventContext.cpp')
-rw-r--r-- | embed/mozilla/EventContext.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
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; +} |