blob: 38a1740aefa7e9ec2657d5b7ece6fcae86de5ce6 [file] [log] [blame]
Narayan Kamath9497c5f2011-02-22 12:05:34 +00001/*
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
18package android.webkit;
19
20import 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 *
Jonathan Dixon4cde13a2011-12-16 18:36:20 +000032 * @hide
Narayan Kamath9497c5f2011-02-22 12:05:34 +000033 */
34public 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).
Mathew Inwoode7821cd2011-07-08 17:26:46 +010071 *
72 * @param listener an optional listener to notify of the success of the operation,
73 * indicating if the javascript function existed and could be called or not.
74 * It will be called on the UI thread.
Narayan Kamath9497c5f2011-02-22 12:05:34 +000075 */
Mathew Inwoode7821cd2011-07-08 17:26:46 +010076 void onchange(SearchBoxListener listener);
77 void onsubmit(SearchBoxListener listener);
78 void onresize(SearchBoxListener listener);
79 void oncancel(SearchBoxListener listener);
Narayan Kamath9497c5f2011-02-22 12:05:34 +000080
81 /**
82 * Add and remove listeners to the given Searchbox. Listeners are notified
83 * of any suggestions to the query that the underlying search engine might
84 * provide.
85 */
86 void addSearchBoxListener(SearchBoxListener l);
87 void removeSearchBoxListener(SearchBoxListener l);
88
89 /**
Mathew Inwoodbdaa1aa2011-07-04 15:15:27 +010090 * Indicates if the searchbox API is supported in the current page.
91 */
92 void isSupported(IsSupportedCallback callback);
93
94 /**
Narayan Kamath9497c5f2011-02-22 12:05:34 +000095 * Listeners (if any) will be called on the thread that created the
96 * webview.
97 */
Mathew Inwoode7821cd2011-07-08 17:26:46 +010098 public abstract class SearchBoxListener {
99 public void onSuggestionsReceived(String query, List<String> suggestions) {}
100 public void onChangeComplete(boolean called) {}
101 public void onSubmitComplete(boolean called) {}
102 public void onResizeComplete(boolean called) {}
103 public void onCancelComplete(boolean called) {}
Narayan Kamath9497c5f2011-02-22 12:05:34 +0000104 }
Mathew Inwoodbdaa1aa2011-07-04 15:15:27 +0100105
106 interface IsSupportedCallback {
107 void searchBoxIsSupported(boolean supported);
108 }
Narayan Kamath9497c5f2011-02-22 12:05:34 +0000109}