blob: 54c9d9a182c4792cfe780d3165fcc18f0992ce5d [file] [log] [blame]
Leon Scrogginsfe026bd2010-08-24 14:16:09 -04001/*
2 * Copyright (C) 2010 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
17package android.webkit;
18
Ben Murdoch0fa484a2010-12-09 19:48:13 +000019import android.app.SearchManager;
20import android.content.Intent;
Leon Scrogginsfe026bd2010-08-24 14:16:09 -040021import android.provider.Browser;
22import android.webkit.WebView;
23import android.view.ActionMode;
24import android.view.Menu;
25import android.view.MenuItem;
26import android.view.View;
27
28class SelectActionModeCallback implements ActionMode.Callback {
29 private WebView mWebView;
Leon Scrogginsfe026bd2010-08-24 14:16:09 -040030 private ActionMode mActionMode;
31
32 void setWebView(WebView webView) {
33 mWebView = webView;
34 }
35
Leon Scrogginsfe026bd2010-08-24 14:16:09 -040036 void finish() {
37 mActionMode.finish();
38 }
39
40 // ActionMode.Callback implementation
41
42 @Override
43 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
44 mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy,
45 menu);
46 mode.setTitle(com.android.internal.R.string.textSelectionCABTitle);
47 mActionMode = mode;
48 return true;
49 }
50
51 @Override
52 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
53 return true;
54 }
55
56 @Override
57 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
58 switch(item.getItemId()) {
59 case android.R.id.copy:
60 mWebView.copySelection();
61 mode.finish();
62 break;
63
64 case com.android.internal.R.id.share:
65 String selection = mWebView.getSelection();
66 Browser.sendString(mWebView.getContext(), selection);
67 mode.finish();
68 break;
69
70 case com.android.internal.R.id.select_all:
71 mWebView.selectAll();
72 break;
73
74 case com.android.internal.R.id.find:
75 String sel= mWebView.getSelection();
76 mode.finish();
77 mWebView.showFindDialog(sel);
78 break;
Ben Murdoch0fa484a2010-12-09 19:48:13 +000079 case com.android.internal.R.id.websearch:
80 mode.finish();
81 Intent i = new Intent(Intent.ACTION_WEB_SEARCH);
82 i.putExtra(SearchManager.QUERY, mWebView.getSelection());
83 mWebView.getContext().startActivity(i);
84 break;
Leon Scrogginsfe026bd2010-08-24 14:16:09 -040085
86 default:
87 return false;
88 }
89 return true;
90 }
91
92 @Override
93 public void onDestroyActionMode(ActionMode mode) {
Leon Scrogginsfe026bd2010-08-24 14:16:09 -040094 mWebView.selectionDone();
95 }
96}