• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      */
setQuery(String query)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      */
setVerbatim(boolean verbatim)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      */
setSelection(int selectionStart, int selectionEnd)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      */
setDimensions(int x, int y, int width, int height)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      * @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.
75      */
onchange(SearchBoxListener listener)76     void onchange(SearchBoxListener listener);
onsubmit(SearchBoxListener listener)77     void onsubmit(SearchBoxListener listener);
onresize(SearchBoxListener listener)78     void onresize(SearchBoxListener listener);
oncancel(SearchBoxListener listener)79     void oncancel(SearchBoxListener listener);
80 
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      */
addSearchBoxListener(SearchBoxListener l)86     void addSearchBoxListener(SearchBoxListener l);
removeSearchBoxListener(SearchBoxListener l)87     void removeSearchBoxListener(SearchBoxListener l);
88 
89     /**
90      * Indicates if the searchbox API is supported in the current page.
91      */
isSupported(IsSupportedCallback callback)92     void isSupported(IsSupportedCallback callback);
93 
94     /**
95      * Listeners (if any) will be called on the thread that created the
96      * webview.
97      */
98     public abstract class SearchBoxListener {
onSuggestionsReceived(String query, List<String> suggestions)99         public void onSuggestionsReceived(String query, List<String> suggestions) {}
onChangeComplete(boolean called)100         public void onChangeComplete(boolean called) {}
onSubmitComplete(boolean called)101         public void onSubmitComplete(boolean called) {}
onResizeComplete(boolean called)102         public void onResizeComplete(boolean called) {}
onCancelComplete(boolean called)103         public void onCancelComplete(boolean called) {}
104     }
105 
106     interface IsSupportedCallback {
searchBoxIsSupported(boolean supported)107         void searchBoxIsSupported(boolean supported);
108     }
109 }
110