aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyFind.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-08-16 06:22:31 +0800
committerChristian Persch <chpe@src.gnome.org>2005-08-16 06:22:31 +0800
commit0cba580858576aba1d4f2b4480e91dc3570c8d62 (patch)
tree43678464382a6fe9f188a82f58cb5054d479feac /embed/mozilla/EphyFind.cpp
parent02250ba19947aab8a099d2890649768e90ff3009 (diff)
downloadgsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar.gz
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar.bz2
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar.lz
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar.xz
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.tar.zst
gsoc2013-epiphany-0cba580858576aba1d4f2b4480e91dc3570c8d62.zip
Activate the found link with a faked keypress event.
2005-08-16 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-embed-find.c: (ephy_embed_find_activate_link): * embed/ephy-embed-find.h: * embed/mozilla/EphyFind.cpp: * embed/mozilla/EphyFind.h: * embed/mozilla/mozilla-embed-find.cpp: Activate the found link with a faked keypress event. * src/ephy-find-toolbar.c: (tab_search_key_press_cb), (entry_key_press_event_cb), (entry_activate_cb), (ephy_find_toolbar_set_embed), (ephy_find_toolbar_open), (ephy_find_toolbar_close): On enter, activate the found link instead of finding the next occurrence. Always really give focus to the find bar, instead of faking keypresses in the find bar entry while focusing the embed. Fixes bug #307216, bug #311985, bug #312419.
Diffstat (limited to 'embed/mozilla/EphyFind.cpp')
-rw-r--r--embed/mozilla/EphyFind.cpp86
1 files changed, 81 insertions, 5 deletions
diff --git a/embed/mozilla/EphyFind.cpp b/embed/mozilla/EphyFind.cpp
index ace176b23..224e85081 100644
--- a/embed/mozilla/EphyFind.cpp
+++ b/embed/mozilla/EphyFind.cpp
@@ -37,6 +37,17 @@
#include <nsIInterfaceRequestorUtils.h>
#include <nsIDOMWindow.h>
#include <nsIWebBrowser.h>
+#include <nsIWebBrowserFocus.h>
+#include <nsIDOMNode.h>
+#include <nsIDOMElement.h>
+#include <nsIDOMDocument.h>
+#include <nsIDOMDocumentView.h>
+#include <nsIDOMAbstractView.h>
+#include <nsIDOMDocumentEvent.h>
+#include <nsIDOMEvent.h>
+#include <nsIDOMKeyEvent.h>
+#include <nsIDOMEventTarget.h>
+#include <nsIDOMHTMLAnchorElement.h>
#ifdef HAVE_TYPEAHEADFIND
#include <nsIDocShell.h>
@@ -52,6 +63,9 @@
#define NS_TYPEAHEADFIND_CONTRACTID "@mozilla.org/typeaheadfind;1"
#endif /* HAVE_TYPEAHEADFIND */
+static const PRUnichar kKeyEvents[] = { 'K', 'e', 'y', 'E', 'v', 'e', 'n', 't', 's', '\0' };
+static const PRUnichar kKeyPress[] = { 'k', 'e', 'y', 'p', 'r', 'e', 's', 's', '\0' };
+
EphyFind::EphyFind ()
: mCurrentEmbed(nsnull)
{
@@ -70,15 +84,15 @@ EphyFind::SetEmbed (EphyEmbed *aEmbed)
if (aEmbed == mCurrentEmbed) return rv;
mCurrentEmbed = nsnull;
+ mWebBrowser = nsnull;
rv = NS_ERROR_FAILURE;
- nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED (aEmbed),
- getter_AddRefs (webBrowser));
- NS_ENSURE_TRUE (webBrowser, rv);
+ getter_AddRefs (mWebBrowser));
+ NS_ENSURE_TRUE (mWebBrowser, rv);
#ifdef HAVE_TYPEAHEADFIND
- nsCOMPtr<nsIDocShell> docShell (do_GetInterface (webBrowser, &rv));
+ nsCOMPtr<nsIDocShell> docShell (do_GetInterface (mWebBrowser, &rv));
NS_ENSURE_SUCCESS (rv, rv);
if (!mFinder) {
@@ -97,7 +111,7 @@ EphyFind::SetEmbed (EphyEmbed *aEmbed)
mFinder->GetSearchString (&string);
}
- mFinder = do_GetInterface (webBrowser, &rv);
+ mFinder = do_GetInterface (mWebBrowser, &rv);
NS_ENSURE_SUCCESS (rv, rv);
mFinder->SetWrapFind (PR_TRUE);
@@ -186,3 +200,65 @@ EphyFind::FindAgain (PRBool aForward)
return NS_SUCCEEDED (rv) && didFind;
#endif /* HAVE_TYPEAHEADFIND */
}
+
+PRBool
+EphyFind::ActivateLink (GdkModifierType aMask)
+{
+ nsresult rv;
+ nsCOMPtr<nsIDOMElement> link;
+#if defined(HAVE_TYPEAHEADFIND) && defined(HAVE_GECKO_1_8)
+ rv = mFinder->GetFoundLink (getter_AddRefs (link));
+ NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && link, FALSE);
+#else
+ nsCOMPtr<nsIWebBrowserFocus> focus (do_QueryInterface (mWebBrowser));
+ NS_ENSURE_TRUE (focus, FALSE);
+
+ rv = focus->GetFocusedElement (getter_AddRefs (link));
+ NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && link, FALSE);
+
+ /* ensure this is really a link so we don't accidentally submit if we're on a button or so! */
+ nsCOMPtr<nsIDOMHTMLAnchorElement> anchor (do_QueryInterface (link));
+ if (!anchor) return FALSE;
+#endif /* HAVE_TYPEAHEADFIND && HAVE_GECKO_1_8 */
+
+ nsCOMPtr<nsIDOMDocument> doc;
+ rv = link->GetOwnerDocument (getter_AddRefs (doc));
+ NS_ENSURE_TRUE (doc, FALSE);
+
+ nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (doc));
+ NS_ENSURE_TRUE (docView, FALSE);
+
+ nsCOMPtr<nsIDOMAbstractView> abstractView;
+ docView->GetDefaultView (getter_AddRefs (abstractView));
+ NS_ENSURE_TRUE (abstractView, FALSE);
+
+ nsCOMPtr<nsIDOMDocumentEvent> docEvent (do_QueryInterface (doc));
+ NS_ENSURE_TRUE (docEvent, FALSE);
+
+ nsCOMPtr<nsIDOMEvent> event;
+ rv = docEvent->CreateEvent (nsEmbedString(kKeyEvents), getter_AddRefs (event));
+ NS_ENSURE_SUCCESS (rv, FALSE);
+
+ nsCOMPtr<nsIDOMKeyEvent> keyEvent (do_QueryInterface (event));
+ NS_ENSURE_TRUE (keyEvent, FALSE);
+
+ rv = keyEvent->InitKeyEvent (nsEmbedString (kKeyPress),
+ PR_TRUE /* bubble */,
+ PR_TRUE /* cancelable */,
+ abstractView,
+ (aMask & GDK_CONTROL_MASK) != 0,
+ (aMask & GDK_MOD1_MASK) != 0 /* Alt */,
+ (aMask & GDK_SHIFT_MASK) != 0,
+ PR_FALSE /* Meta */,
+ nsIDOMKeyEvent::DOM_VK_RETURN,
+ 0);
+ NS_ENSURE_SUCCESS (rv, FALSE);
+
+ nsCOMPtr<nsIDOMEventTarget> target (do_QueryInterface (link));
+ NS_ENSURE_TRUE (target, FALSE);
+
+ PRBool defaultPrevented = PR_FALSE;
+ rv = target->DispatchEvent (event, &defaultPrevented);
+
+ return NS_SUCCEEDED (rv);
+}