Merge "Fix bugs around overlay action modes."
This commit is contained in:
@ -152,6 +152,18 @@ public abstract class ActionMode {
|
|||||||
*/
|
*/
|
||||||
public abstract MenuInflater getMenuInflater();
|
public abstract MenuInflater getMenuInflater();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the UI presenting this action mode can take focus or not.
|
||||||
|
* This is used by internal components within the framework that would otherwise
|
||||||
|
* present an action mode UI that requires focus, such as an EditText as a custom view.
|
||||||
|
*
|
||||||
|
* @return true if the UI used to show this action mode can take focus
|
||||||
|
* @hide Internal use only
|
||||||
|
*/
|
||||||
|
public boolean isUiFocusable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface for action modes. Supplied to
|
* Callback interface for action modes. Supplied to
|
||||||
* {@link View#startActionMode(Callback)}, a Callback
|
* {@link View#startActionMode(Callback)}, a Callback
|
||||||
|
@ -180,6 +180,14 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
if (!mode.isUiFocusable()) {
|
||||||
|
// If the action mode we're running in is not focusable the user
|
||||||
|
// will not be able to type into the find on page field. This
|
||||||
|
// should only come up when we're running in a dialog which is
|
||||||
|
// already less than ideal; disable the option for now.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mode.setCustomView(mCustomView);
|
mode.setCustomView(mCustomView);
|
||||||
mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find,
|
mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find,
|
||||||
menu);
|
menu);
|
||||||
|
@ -17,13 +17,12 @@
|
|||||||
package android.webkit;
|
package android.webkit;
|
||||||
|
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
class SelectActionModeCallback implements ActionMode.Callback {
|
class SelectActionModeCallback implements ActionMode.Callback {
|
||||||
private WebView mWebView;
|
private WebView mWebView;
|
||||||
@ -45,9 +44,25 @@ class SelectActionModeCallback implements ActionMode.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy,
|
mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy, menu);
|
||||||
menu);
|
|
||||||
mode.setTitle(com.android.internal.R.string.textSelectionCABTitle);
|
final Context context = mWebView.getContext();
|
||||||
|
boolean allowText = context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon);
|
||||||
|
mode.setTitle(allowText ?
|
||||||
|
context.getString(com.android.internal.R.string.textSelectionCABTitle) : null);
|
||||||
|
|
||||||
|
if (!mode.isUiFocusable()) {
|
||||||
|
// If the action mode UI we're running in isn't capable of taking window focus
|
||||||
|
// the user won't be able to type into the find on page UI. Disable this functionality.
|
||||||
|
// (Note that this should only happen in floating dialog windows.)
|
||||||
|
// This can be removed once we can handle multiple focusable windows at a time
|
||||||
|
// in a better way.
|
||||||
|
final MenuItem findOnPageItem = menu.findItem(com.android.internal.R.id.find);
|
||||||
|
if (findOnPageItem != null) {
|
||||||
|
findOnPageItem.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
mActionMode = mode;
|
mActionMode = mode;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,17 +36,19 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call
|
|||||||
private ActionMode.Callback mCallback;
|
private ActionMode.Callback mCallback;
|
||||||
private WeakReference<View> mCustomView;
|
private WeakReference<View> mCustomView;
|
||||||
private boolean mFinished;
|
private boolean mFinished;
|
||||||
|
private boolean mFocusable;
|
||||||
|
|
||||||
private MenuBuilder mMenu;
|
private MenuBuilder mMenu;
|
||||||
|
|
||||||
public StandaloneActionMode(Context context, ActionBarContextView view,
|
public StandaloneActionMode(Context context, ActionBarContextView view,
|
||||||
ActionMode.Callback callback) {
|
ActionMode.Callback callback, boolean isFocusable) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mContextView = view;
|
mContextView = view;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
|
||||||
mMenu = new MenuBuilder(context).setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
mMenu = new MenuBuilder(context).setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
mMenu.setCallback(this);
|
mMenu.setCallback(this);
|
||||||
|
mFocusable = isFocusable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,4 +141,8 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call
|
|||||||
invalidate();
|
invalidate();
|
||||||
mContextView.showOverflowMenu();
|
mContextView.showOverflowMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUiFocusable() {
|
||||||
|
return mFocusable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
37
core/res/res/layout/screen_simple_overlay_action_mode.xml
Normal file
37
core/res/res/layout/screen_simple_overlay_action_mode.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
/*
|
||||||
|
** Copyright 2011, The Android Open Source Project
|
||||||
|
**
|
||||||
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
** you may not use this file except in compliance with the License.
|
||||||
|
** You may obtain a copy of the License at
|
||||||
|
**
|
||||||
|
** http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
**
|
||||||
|
** Unless required by applicable law or agreed to in writing, software
|
||||||
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
** See the License for the specific language governing permissions and
|
||||||
|
** limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
This is an optimized layout for a screen, with the minimum set of features
|
||||||
|
enabled.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@android:id/content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:foregroundInsidePadding="false"
|
||||||
|
android:foregroundGravity="fill_horizontal|top"
|
||||||
|
android:foreground="?android:attr/windowContentOverlay" />
|
||||||
|
<ViewStub android:id="@+id/action_mode_bar_stub"
|
||||||
|
android:inflatedId="@+id/action_mode_bar"
|
||||||
|
android:layout="@layout/action_mode_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</FrameLayout>
|
@ -2147,15 +2147,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
mActionMode = mode;
|
mActionMode = mode;
|
||||||
} else {
|
} else {
|
||||||
if (mActionModeView == null) {
|
if (mActionModeView == null) {
|
||||||
if (hasFeature(FEATURE_ACTION_MODE_OVERLAY)) {
|
if (isFloating()) {
|
||||||
mActionModeView = new ActionBarContextView(mContext);
|
mActionModeView = new ActionBarContextView(mContext);
|
||||||
mActionModePopup = new PopupWindow(mContext, null,
|
mActionModePopup = new PopupWindow(mContext, null,
|
||||||
com.android.internal.R.attr.actionModePopupWindowStyle);
|
com.android.internal.R.attr.actionModePopupWindowStyle);
|
||||||
mActionModePopup.setLayoutInScreenEnabled(true);
|
mActionModePopup.setLayoutInScreenEnabled(true);
|
||||||
mActionModePopup.setLayoutInsetDecor(true);
|
mActionModePopup.setLayoutInsetDecor(true);
|
||||||
mActionModePopup.setFocusable(true);
|
|
||||||
mActionModePopup.setOutsideTouchable(false);
|
|
||||||
mActionModePopup.setTouchModal(false);
|
|
||||||
mActionModePopup.setWindowLayoutType(
|
mActionModePopup.setWindowLayoutType(
|
||||||
WindowManager.LayoutParams.TYPE_APPLICATION);
|
WindowManager.LayoutParams.TYPE_APPLICATION);
|
||||||
mActionModePopup.setContentView(mActionModeView);
|
mActionModePopup.setContentView(mActionModeView);
|
||||||
@ -2186,7 +2183,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
|
|
||||||
if (mActionModeView != null) {
|
if (mActionModeView != null) {
|
||||||
mActionModeView.killMode();
|
mActionModeView.killMode();
|
||||||
mode = new StandaloneActionMode(getContext(), mActionModeView, wrappedCallback);
|
mode = new StandaloneActionMode(getContext(), mActionModeView, wrappedCallback,
|
||||||
|
mActionModePopup == null);
|
||||||
if (callback.onCreateActionMode(mode, mode.getMenu())) {
|
if (callback.onCreateActionMode(mode, mode.getMenu())) {
|
||||||
mode.invalidate();
|
mode.invalidate();
|
||||||
mActionModeView.initForMode(mode);
|
mActionModeView.initForMode(mode);
|
||||||
@ -2664,6 +2662,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
layoutResource = com.android.internal.R.layout.screen_title;
|
layoutResource = com.android.internal.R.layout.screen_title;
|
||||||
}
|
}
|
||||||
// System.out.println("Title!");
|
// System.out.println("Title!");
|
||||||
|
} else if ((features & (1 << FEATURE_ACTION_MODE_OVERLAY)) != 0) {
|
||||||
|
layoutResource = com.android.internal.R.layout.screen_simple_overlay_action_mode;
|
||||||
} else {
|
} else {
|
||||||
// Embedded, so no decoration is needed.
|
// Embedded, so no decoration is needed.
|
||||||
layoutResource = com.android.internal.R.layout.screen_simple;
|
layoutResource = com.android.internal.R.layout.screen_simple;
|
||||||
|
Reference in New Issue
Block a user