blob: cf919022d02274bfb449b9b2c2dd1b5e6501150e [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
19import android.provider.Browser;
20import android.webkit.WebView;
21import android.view.ActionMode;
22import android.view.Menu;
23import android.view.MenuItem;
24import android.view.View;
25
26class SelectActionModeCallback implements ActionMode.Callback {
27 private WebView mWebView;
28 private View mTitleBar;
29 private ActionMode mActionMode;
30
31 void setWebView(WebView webView) {
32 mWebView = webView;
33 }
34
35 void setTitleBar(View v) { mTitleBar = v; }
36
37 void finish() {
38 mActionMode.finish();
39 }
40
41 // ActionMode.Callback implementation
42
43 @Override
44 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
45 mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy,
46 menu);
47 mode.setTitle(com.android.internal.R.string.textSelectionCABTitle);
48 mActionMode = mode;
49 return true;
50 }
51
52 @Override
53 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
54 return true;
55 }
56
57 @Override
58 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
59 switch(item.getItemId()) {
60 case android.R.id.copy:
61 mWebView.copySelection();
62 mode.finish();
63 break;
64
65 case com.android.internal.R.id.share:
66 String selection = mWebView.getSelection();
67 Browser.sendString(mWebView.getContext(), selection);
68 mode.finish();
69 break;
70
71 case com.android.internal.R.id.select_all:
72 mWebView.selectAll();
73 break;
74
75 case com.android.internal.R.id.find:
76 String sel= mWebView.getSelection();
77 mode.finish();
78 mWebView.showFindDialog(sel);
79 break;
80
81 default:
82 return false;
83 }
84 return true;
85 }
86
87 @Override
88 public void onDestroyActionMode(ActionMode mode) {
89 if (mTitleBar != null) mWebView.setEmbeddedTitleBar(mTitleBar);
90 mWebView.selectionDone();
91 }
92}