Commit 4531d6fa authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

Remove actions from keyboard accessory when hiding it

This aims to fix the case in which when moving focus to a different
field (for which the action doesn't apply), the accessory is first
shown and then the action is removed. When this happens, there is
a perceivable delay before the action button disappears.

Bug: 856971
Change-Id: I1dfb63c513d109b74592870d3d63277b8237df25
Reviewed-on: https://chromium-review.googlesource.com/1142150
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarFriedrich Horschig <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579060}
parent 294830ad
...@@ -147,6 +147,9 @@ public class KeyboardAccessoryCoordinator { ...@@ -147,6 +147,9 @@ public class KeyboardAccessoryCoordinator {
/** /**
* Allows any {@link KeyboardAccessoryData.Provider} to communicate with the * Allows any {@link KeyboardAccessoryData.Provider} to communicate with the
* {@link KeyboardAccessoryMediator} of this component. * {@link KeyboardAccessoryMediator} of this component.
*
* Note that the provided actions are removed when the accessory is hidden.
*
* @param provider The object providing action lists to observers in this component. * @param provider The object providing action lists to observers in this component.
*/ */
public void registerActionListProvider( public void registerActionListProvider(
......
...@@ -10,6 +10,7 @@ import android.support.design.widget.TabLayout; ...@@ -10,6 +10,7 @@ import android.support.design.widget.TabLayout;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.autofill.AutofillKeyboardSuggestions; import org.chromium.chrome.browser.autofill.AutofillKeyboardSuggestions;
import org.chromium.chrome.browser.autofill.keyboard_accessory.KeyboardAccessoryCoordinator.VisibilityDelegate; import org.chromium.chrome.browser.autofill.keyboard_accessory.KeyboardAccessoryCoordinator.VisibilityDelegate;
import org.chromium.chrome.browser.autofill.keyboard_accessory.KeyboardAccessoryData.Action;
import org.chromium.chrome.browser.modelutil.ListObservable; import org.chromium.chrome.browser.modelutil.ListObservable;
import org.chromium.chrome.browser.modelutil.PropertyObservable; import org.chromium.chrome.browser.modelutil.PropertyObservable;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -126,6 +127,9 @@ class KeyboardAccessoryMediator ...@@ -126,6 +127,9 @@ class KeyboardAccessoryMediator
if (propertyKey == KeyboardAccessoryModel.PropertyKey.VISIBLE) { if (propertyKey == KeyboardAccessoryModel.PropertyKey.VISIBLE) {
// When the accessory just (dis)appeared, there should be no active tab. // When the accessory just (dis)appeared, there should be no active tab.
mModel.setActiveTab(null); mModel.setActiveTab(null);
if (!mModel.isVisible()) {
mModel.setActions(new Action[0]);
}
return; return;
} }
if (propertyKey == KeyboardAccessoryModel.PropertyKey.ACTIVE_TAB) { if (propertyKey == KeyboardAccessoryModel.PropertyKey.ACTIVE_TAB) {
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.autofill.keyboard_accessory; package org.chromium.chrome.browser.autofill.keyboard_accessory;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.Nullable;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
...@@ -22,7 +21,6 @@ class PasswordAccessoryBridge { ...@@ -22,7 +21,6 @@ class PasswordAccessoryBridge {
new KeyboardAccessoryData.PropertyProvider<>(); new KeyboardAccessoryData.PropertyProvider<>();
private final ManualFillingCoordinator mManualFillingCoordinator; private final ManualFillingCoordinator mManualFillingCoordinator;
private final ChromeActivity mActivity; private final ChromeActivity mActivity;
private @Nullable Action mGenerationAction;
private long mNativeView; private long mNativeView;
private PasswordAccessoryBridge(long nativeView, WindowAndroid windowAndroid) { private PasswordAccessoryBridge(long nativeView, WindowAndroid windowAndroid) {
...@@ -48,9 +46,6 @@ class PasswordAccessoryBridge { ...@@ -48,9 +46,6 @@ class PasswordAccessoryBridge {
private void onAutomaticGenerationStatusChanged(boolean available) { private void onAutomaticGenerationStatusChanged(boolean available) {
final Action[] generationAction; final Action[] generationAction;
if (available) { if (available) {
if (mGenerationAction != null) {
return;
}
// This is meant to suppress the warning that the short string is not used. // This is meant to suppress the warning that the short string is not used.
// TODO(crbug.com/855581): Switch between strings based on whether they fit on the // TODO(crbug.com/855581): Switch between strings based on whether they fit on the
// screen or not. // screen or not.
...@@ -58,16 +53,12 @@ class PasswordAccessoryBridge { ...@@ -58,16 +53,12 @@ class PasswordAccessoryBridge {
String caption = useLongString String caption = useLongString
? mActivity.getString(R.string.password_generation_accessory_button) ? mActivity.getString(R.string.password_generation_accessory_button)
: mActivity.getString(R.string.password_generation_accessory_button_short); : mActivity.getString(R.string.password_generation_accessory_button_short);
generationAction = new Action[] {new Action(caption, (action) -> {
mGenerationAction = new Action(caption, (action) -> {
assert mNativeView assert mNativeView
!= 0 : "Controller has been destroyed but the bridge wasn't cleaned up!"; != 0 : "Controller has been destroyed but the bridge wasn't cleaned up!";
nativeOnGenerationRequested(mNativeView); nativeOnGenerationRequested(mNativeView);
}); })};
generationAction = new Action[] {mGenerationAction};
} else { } else {
if (mGenerationAction == null) return;
mGenerationAction = null;
generationAction = new Action[0]; generationAction = new Action[0];
} }
mActionProvider.notifyObservers(generationAction); mActionProvider.notifyObservers(generationAction);
......
...@@ -203,6 +203,17 @@ public class KeyboardAccessoryControllerTest { ...@@ -203,6 +203,17 @@ public class KeyboardAccessoryControllerTest {
assertThat(mModel.isVisible(), is(true)); assertThat(mModel.isVisible(), is(true));
} }
@Test
public void testActionsRemovedWhenNotVisible() {
// Make the accessory visible and add an action to it.
mMediator.keyboardVisibilityChanged(true);
mModel.getActionList().add(new Action(null, null));
// Hiding the accessory should also remove actions.
mMediator.keyboardVisibilityChanged(false);
assertThat(mModel.getActionList().size(), is(0));
}
@Test @Test
public void testIsVisibleWithTabs() { public void testIsVisibleWithTabs() {
// Without any actions, the accessory should remain invisible. // Without any actions, the accessory should remain invisible.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment