Narayan Kamath | 9497c5f | 2011-02-22 12:05:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | package android.webkit; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | /** |
| 23 | * Defines the interaction between the browser/renderer and the page running on |
| 24 | * a given WebView frame, if the page supports the chromium SearchBox API. |
| 25 | * |
| 26 | * http://dev.chromium.org/searchbox |
| 27 | * |
| 28 | * The browser or container app can query the page for search results using |
| 29 | * SearchBox.query() and receive suggestions by registering a listener on the |
| 30 | * SearchBox object. |
| 31 | * |
| 32 | * @hide pending API council approval. |
| 33 | */ |
| 34 | public interface SearchBox { |
| 35 | /** |
| 36 | * Sets the current searchbox query. Note that the caller must call |
| 37 | * onchange() to ensure that the search page processes this query. |
| 38 | */ |
| 39 | void setQuery(String query); |
| 40 | |
| 41 | /** |
| 42 | * Verbatim is true if the caller suggests that the search page |
| 43 | * treat the current query as a verbatim search query (as opposed to a |
| 44 | * partially typed search query). As with setQuery, onchange() must be |
| 45 | * called to ensure that the search page processes the query. |
| 46 | */ |
| 47 | void setVerbatim(boolean verbatim); |
| 48 | |
| 49 | /** |
| 50 | * These attributes must contain the offset to the characters that immediately |
| 51 | * follow the start and end of the selection in the search box. If there is |
| 52 | * no such selection, then both selectionStart and selectionEnd must be the offset |
| 53 | * to the character that immediately follows the text entry cursor. In the case |
| 54 | * that there is no explicit text entry cursor, the cursor is |
| 55 | * implicitly at the end of the input. |
| 56 | */ |
| 57 | void setSelection(int selectionStart, int selectionEnd); |
| 58 | |
| 59 | /** |
| 60 | * Sets the dimensions of the view (if any) that overlaps the current |
| 61 | * window object. This is to ensure that the page renders results in |
| 62 | * a manner that allows them to not be obscured by such a view. Note |
| 63 | * that a call to onresize() is required if these dimensions change. |
| 64 | */ |
| 65 | void setDimensions(int x, int y, int width, int height); |
| 66 | |
| 67 | /** |
| 68 | * Notify the search page of any changes to the searchbox. Such as |
| 69 | * a change in the typed query (onchange), the user commiting a given query |
| 70 | * (onsubmit), or a change in size of a suggestions dropdown (onresize). |
| 71 | */ |
| 72 | void onchange(); |
| 73 | void onsubmit(); |
| 74 | void onresize(); |
| 75 | void oncancel(); |
| 76 | |
| 77 | /** |
| 78 | * Add and remove listeners to the given Searchbox. Listeners are notified |
| 79 | * of any suggestions to the query that the underlying search engine might |
| 80 | * provide. |
| 81 | */ |
| 82 | void addSearchBoxListener(SearchBoxListener l); |
| 83 | void removeSearchBoxListener(SearchBoxListener l); |
| 84 | |
| 85 | /** |
| 86 | * Listeners (if any) will be called on the thread that created the |
| 87 | * webview. |
| 88 | */ |
| 89 | interface SearchBoxListener { |
| 90 | void onSuggestionsReceived(String query, List<String> suggestions); |
| 91 | } |
| 92 | } |