Bug 701374 - Show go or search icon in awesomescreen field, as appropriate [r=lucasr a=android-only]

This commit is contained in:
Mark Finkle 2011-12-13 11:31:35 -05:00
parent 87dfc08a7a
commit 923ec728e3
7 changed files with 49 additions and 52 deletions

View File

@ -84,7 +84,7 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs);
mAwesomeTabs.setOnUrlOpenListener(new AwesomeBarTabs.OnUrlOpenListener() {
public void onUrlOpen(String url) {
openUrlAndFinish(url);
submitAndFinish(url);
}
public void onSearch(String engine) {
@ -95,7 +95,7 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
mGoButton = (ImageButton) findViewById(R.id.awesomebar_button);
mGoButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
openUrlAndFinish(mText.getText().toString());
submitAndFinish(mText.getText().toString());
}
});
@ -166,7 +166,7 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
if (event.getAction() != KeyEvent.ACTION_DOWN)
return true;
openUrlAndFinish(mText.getText().toString());
submitAndFinish(mText.getText().toString());
return true;
} else {
return false;
@ -209,6 +209,34 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
return true;
}
/*
* This method tries to guess if the given string could be a search query or URL
* Search examples:
* foo
* foo bar.com
* foo http://bar.com
*
* URL examples
* foo.com
* foo.c
* :foo
* http://foo.com bar
*/
private boolean isSearchUrl(String text) {
text = text.trim();
if (text.length() == 0)
return false;
int colon = text.indexOf(':');
int dot = text.indexOf('.');
int space = text.indexOf(' ');
// If a space is found before any dot or colon, we assume this is a search query
boolean spacedOut = space > -1 && (space < colon || space < dot);
return spacedOut || (dot == -1);
}
private void updateGoButton(String text) {
if (text.length() == 0) {
mGoButton.setVisibility(View.GONE);
@ -218,13 +246,19 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
mGoButton.setVisibility(View.VISIBLE);
int imageResource = R.drawable.ic_awesomebar_go;
if (!GeckoAppShell.canCreateFixupURI(text)) {
if (isSearchUrl(text))
imageResource = R.drawable.ic_awesomebar_search;
}
mGoButton.setImageResource(imageResource);
}
private void submitAndFinish(String url) {
if (isSearchUrl(url))
openSearchAndFinish(url, "__default__");
else
openUrlAndFinish(url);
}
private void cancelAndFinish() {
setResult(Activity.RESULT_CANCELED);
finish();

View File

@ -130,7 +130,6 @@ public class GeckoAppShell
public static native void onChangeNetworkLinkStatus(String status);
public static native void reportJavaCrash(String stack);
public static native void notifyUriVisited(String uri);
public static native boolean canCreateFixupURI(String text);
public static native void processNextNativeEvent();

View File

@ -540,10 +540,17 @@ var BrowserApp = {
let args = JSON.parse(aData);
let uri;
if (args.engine) {
let engine = Services.search.getEngineByName(args.engine);
uri = engine.getSubmission(args.url).uri;
} else
let engine;
if (args.engine == "__default__")
engine = Services.search.currentEngine || Services.search.defaultEngine;
else
engine = Services.search.getEngineByName(args.engine);
if (engine)
uri = engine.getSubmission(args.url).uri;
} else {
uri = URIFixup.createFixupURI(args.url, Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP);
}
return uri ? uri.spec : args.url;
},

View File

@ -298,7 +298,6 @@ SHELL_WRAPPER0(executeNextRunnable)
SHELL_WRAPPER1(cameraCallbackBridge, jbyteArray)
SHELL_WRAPPER1(notifyUriVisited, jstring)
SHELL_WRAPPER3(notifyBatteryChange, jdouble, jboolean, jdouble);
SHELL_WRAPPER1_WITH_RETURN(canCreateFixupURI, bool, jstring);
SHELL_WRAPPER3(notifySmsReceived, jstring, jstring, jlong);
static void * xul_handle = NULL;
@ -704,7 +703,6 @@ loadLibs(const char *apkName)
GETFUNC(cameraCallbackBridge);
GETFUNC(notifyUriVisited);
GETFUNC(notifyBatteryChange);
GETFUNC(canCreateFixupURI);
GETFUNC(notifySmsReceived);
#undef GETFUNC
sStartupTimeline = (uint64_t *)__wrap_dlsym(xul_handle, "_ZN7mozilla15StartupTimeline16sStartupTimelineE");

View File

@ -50,9 +50,6 @@
#include "nsWindow.h"
#include "mozilla/Preferences.h"
#include "nsThreadUtils.h"
#include "nsIURIFixup.h"
#include "nsCDefaultURIFixup.h"
#include "nsComponentManagerUtils.h"
#ifdef DEBUG
#define ALOG_BRIDGE(args...) ALOG(args)
@ -578,25 +575,6 @@ AndroidBridge::ClipboardHasText()
return true;
}
bool
AndroidBridge::CanCreateFixupURI(const nsACString& aURIText)
{
ALOG_BRIDGE("AndroidBridge::CanCreateFixupURI");
if (!mURIFixup) {
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
if (!mURIFixup) return false;
}
nsCOMPtr<nsIURI> targetURI;
mURIFixup->CreateFixupURI(aURIText,
nsIURIFixup::FIXUP_FLAG_NONE,
getter_AddRefs(targetURI));
return (targetURI != nsnull);
}
void
AndroidBridge::EmptyClipboard()
{

View File

@ -52,7 +52,6 @@
#include "nsIMutableArray.h"
#include "nsIMIMEInfo.h"
#include "nsColor.h"
#include "nsIURIFixup.h"
#include "nsIAndroidBridge.h"
@ -184,8 +183,6 @@ public:
bool ClipboardHasText();
bool CanCreateFixupURI(const nsACString& aURIText);
void ShowAlertNotification(const nsAString& aImageUrl,
const nsAString& aAlertTitle,
const nsAString& aAlertText,
@ -434,9 +431,6 @@ protected:
jclass jEGLContextClass;
jclass jEGL10Class;
// Needed for canCreateFixupURI()
nsCOMPtr<nsIURIFixup> mURIFixup;
// calls we've dlopened from libjnigraphics.so
int (* AndroidBitmap_getInfo)(JNIEnv *env, jobject bitmap, void *info);
int (* AndroidBitmap_lockPixels)(JNIEnv *env, jobject bitmap, void **buffer);

View File

@ -87,7 +87,6 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_executeNextRunnable(JNIEnv *, jclass);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyUriVisited(JNIEnv *, jclass, jstring uri);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass, jdouble, jboolean, jdouble);
NS_EXPORT bool JNICALL Java_org_mozilla_gecko_GeckoAppShell_canCreateFixupURI(JNIEnv* jenv, jclass, jstring text);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass, jstring, jstring, jlong);
}
@ -246,18 +245,6 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass,
NS_DispatchToMainThread(runnable);
}
NS_EXPORT bool JNICALL
Java_org_mozilla_gecko_GeckoAppShell_canCreateFixupURI(JNIEnv* jenv, jclass, jstring text)
{
__android_log_print(ANDROID_LOG_INFO, "GeckoJNI", "%s", __PRETTY_FUNCTION__);
const jchar *textChars = jenv->GetStringChars(text, NULL);
NS_ConvertUTF16toUTF8 uriString(textChars);
jenv->ReleaseStringChars(text, textChars);
return AndroidBridge::Bridge()->CanCreateFixupURI(uriString);
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass,
jstring aSender,