From 9497c5f8c4bc7c47789e5ccde01179abc31ffeb2 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Tue, 22 Feb 2011 12:05:34 +0000 Subject: A Java implementation of the SearchBox API. Implemented as a Java bridge object and a JS adapter. Works on both V8 and JSC. Change-Id: I8a4268fb3c6688b5ece9e27c11724c0776017255 --- core/java/android/webkit/SearchBox.java | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 core/java/android/webkit/SearchBox.java (limited to 'core/java/android/webkit/SearchBox.java') diff --git a/core/java/android/webkit/SearchBox.java b/core/java/android/webkit/SearchBox.java new file mode 100644 index 000000000000..57c7b035efad --- /dev/null +++ b/core/java/android/webkit/SearchBox.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package android.webkit; + +import java.util.List; + +/** + * Defines the interaction between the browser/renderer and the page running on + * a given WebView frame, if the page supports the chromium SearchBox API. + * + * http://dev.chromium.org/searchbox + * + * The browser or container app can query the page for search results using + * SearchBox.query() and receive suggestions by registering a listener on the + * SearchBox object. + * + * @hide pending API council approval. + */ +public interface SearchBox { + /** + * Sets the current searchbox query. Note that the caller must call + * onchange() to ensure that the search page processes this query. + */ + void setQuery(String query); + + /** + * Verbatim is true if the caller suggests that the search page + * treat the current query as a verbatim search query (as opposed to a + * partially typed search query). As with setQuery, onchange() must be + * called to ensure that the search page processes the query. + */ + void setVerbatim(boolean verbatim); + + /** + * These attributes must contain the offset to the characters that immediately + * follow the start and end of the selection in the search box. If there is + * no such selection, then both selectionStart and selectionEnd must be the offset + * to the character that immediately follows the text entry cursor. In the case + * that there is no explicit text entry cursor, the cursor is + * implicitly at the end of the input. + */ + void setSelection(int selectionStart, int selectionEnd); + + /** + * Sets the dimensions of the view (if any) that overlaps the current + * window object. This is to ensure that the page renders results in + * a manner that allows them to not be obscured by such a view. Note + * that a call to onresize() is required if these dimensions change. + */ + void setDimensions(int x, int y, int width, int height); + + /** + * Notify the search page of any changes to the searchbox. Such as + * a change in the typed query (onchange), the user commiting a given query + * (onsubmit), or a change in size of a suggestions dropdown (onresize). + */ + void onchange(); + void onsubmit(); + void onresize(); + void oncancel(); + + /** + * Add and remove listeners to the given Searchbox. Listeners are notified + * of any suggestions to the query that the underlying search engine might + * provide. + */ + void addSearchBoxListener(SearchBoxListener l); + void removeSearchBoxListener(SearchBoxListener l); + + /** + * Listeners (if any) will be called on the thread that created the + * webview. + */ + interface SearchBoxListener { + void onSuggestionsReceived(String query, List suggestions); + } +} -- cgit v1.2.3