зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1041604 - Update query in search bar when user navigates to new results page. r=wesj
This commit is contained in:
Родитель
40b848e7e5
Коммит
fa2c67d7dc
|
@ -32,6 +32,13 @@ public interface AcceptsSearchQuery {
|
|||
*/
|
||||
void onSearch(String query, SuggestionAnimation suggestionAnimation);
|
||||
|
||||
/**
|
||||
* Handles a change to the current search query.
|
||||
*
|
||||
* @param query
|
||||
*/
|
||||
void onQueryChange(String query);
|
||||
|
||||
/**
|
||||
* Interface to specify search suggestion animation details.
|
||||
*/
|
||||
|
|
|
@ -95,8 +95,18 @@ public class PostSearchFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
// We keep URLs in the webview that are either about:blank or a search engine result page.
|
||||
if (TextUtils.equals(url, Constants.ABOUT_BLANK) || engine.isSearchResultsPage(url)) {
|
||||
// Ignore about:blank URL loads.
|
||||
if (TextUtils.equals(url, Constants.ABOUT_BLANK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the URL is a results page, don't override the URL load, but
|
||||
// do update the query in the search bar if possible.
|
||||
if (engine.isSearchResultsPage(url)) {
|
||||
final String query = engine.queryForResultsUrl(url);
|
||||
if (!TextUtils.isEmpty(query)) {
|
||||
((AcceptsSearchQuery) getActivity()).onQueryChange(query);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -247,6 +247,11 @@ public class SearchActivity extends LocaleAware.LocaleAwareFragmentActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueryChange(String query) {
|
||||
searchBar.setText(query);
|
||||
}
|
||||
|
||||
private void startSearch(final String query) {
|
||||
if (engine != null) {
|
||||
postSearchFragment.startSearch(engine, query);
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Extend this class to add a new search engine to
|
||||
|
@ -202,6 +203,22 @@ public class SearchEngine {
|
|||
return resultsUri.getAuthority().equalsIgnoreCase(Uri.parse(url).getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the search query encoded in a given results URL.
|
||||
*
|
||||
* @param url Current results URL.
|
||||
* @return The search query, or an empty string if a query couldn't be found.
|
||||
*/
|
||||
public String queryForResultsUrl(String url) {
|
||||
final Set<String> names = resultsUri.getQueryParameterNames();
|
||||
for (String name : names) {
|
||||
if (resultsUri.getQueryParameter(name).matches(OS_PARAM_USER_DEFINED)) {
|
||||
return Uri.parse(url).getQueryParameter(name);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a uri string that can be used to fetch the results page.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче