Commit 65a4411e authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Consolidate LocationBar keyboard handling.

This CL deduplicates and consolidates Phone and Tablet behavior.

Bug: 1050813
Change-Id: I6bf10f973c1b569570bc56fa821e53a0d69924fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086552
Commit-Queue: Ender <ender@google.com>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747417}
parent 5a3894e0
...@@ -19,6 +19,7 @@ import android.view.LayoutInflater; ...@@ -19,6 +19,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
...@@ -82,6 +83,8 @@ import java.util.List; ...@@ -82,6 +83,8 @@ import java.util.List;
public class LocationBarLayout extends FrameLayout public class LocationBarLayout extends FrameLayout
implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate, implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate,
VoiceRecognitionHandler.Delegate, AssistantVoiceSearchService.Observer { VoiceRecognitionHandler.Delegate, AssistantVoiceSearchService.Observer {
private static final int KEYBOARD_HIDE_DELAY_MS = 150;
private static final int KEYBOARD_MODE_CHANGE_DELAY_MS = 300;
protected ImageButton mDeleteButton; protected ImageButton mDeleteButton;
protected ImageButton mMicButton; protected ImageButton mMicButton;
...@@ -121,6 +124,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -121,6 +124,7 @@ public class LocationBarLayout extends FrameLayout
protected CompositeTouchDelegate mCompositeTouchDelegate; protected CompositeTouchDelegate mCompositeTouchDelegate;
private AssistantVoiceSearchService mAssistantVoiceSearchService; private AssistantVoiceSearchService mAssistantVoiceSearchService;
private Runnable mKeyboardResizeModeTask;
/** /**
* Class to handle input from a hardware keyboard when the focus is on the URL bar. In * Class to handle input from a hardware keyboard when the focus is on the URL bar. In
...@@ -174,28 +178,27 @@ public class LocationBarLayout extends FrameLayout ...@@ -174,28 +178,27 @@ public class LocationBarLayout extends FrameLayout
mUrlCoordinator = new UrlBarCoordinator((UrlBar) mUrlBar); mUrlCoordinator = new UrlBarCoordinator((UrlBar) mUrlBar);
mUrlCoordinator.setDelegate(this); mUrlCoordinator.setDelegate(this);
OmniboxSuggestionListEmbedder embedder = OmniboxSuggestionListEmbedder embedder = new OmniboxSuggestionListEmbedder() {
new OmniboxSuggestionListEmbedder() { @Override
@Override public boolean isTablet() {
public boolean isTablet() { return mIsTablet;
return mIsTablet; }
}
@Override @Override
public WindowDelegate getWindowDelegate() { public WindowDelegate getWindowDelegate() {
return mWindowDelegate; return mWindowDelegate;
} }
@Override @Override
public View getAnchorView() { public View getAnchorView() {
return getRootView().findViewById(R.id.toolbar); return getRootView().findViewById(R.id.toolbar);
} }
@Override @Override
public View getAlignmentView() { public View getAlignmentView() {
return mIsTablet ? LocationBarLayout.this : null; return mIsTablet ? LocationBarLayout.this : null;
} }
}; };
mAutocompleteCoordinator = AutocompleteCoordinatorFactory.createAutocompleteCoordinator( mAutocompleteCoordinator = AutocompleteCoordinatorFactory.createAutocompleteCoordinator(
this, this, embedder, mUrlCoordinator); this, this, embedder, mUrlCoordinator);
addUrlFocusChangeListener(mAutocompleteCoordinator); addUrlFocusChangeListener(mAutocompleteCoordinator);
...@@ -293,14 +296,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -293,14 +296,6 @@ public class LocationBarLayout extends FrameLayout
mUrlCoordinator.setAllowFocus(focusable); mUrlCoordinator.setAllowFocus(focusable);
} }
/**
* @return The WindowDelegate for the LocationBar. This should be used for all Window related
* state queries.
*/
protected WindowDelegate getWindowDelegate() {
return mWindowDelegate;
}
@Override @Override
public AutocompleteCoordinator getAutocompleteCoordinator() { public AutocompleteCoordinator getAutocompleteCoordinator() {
return mAutocompleteCoordinator; return mAutocompleteCoordinator;
...@@ -522,6 +517,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -522,6 +517,7 @@ public class LocationBarLayout extends FrameLayout
* @param hasFocus Whether focus was gained. * @param hasFocus Whether focus was gained.
*/ */
protected void handleUrlFocusAnimation(boolean hasFocus) { protected void handleUrlFocusAnimation(boolean hasFocus) {
removeCallbacks(mKeyboardResizeModeTask);
if (hasFocus) mUrlFocusedWithoutAnimations = false; if (hasFocus) mUrlFocusedWithoutAnimations = false;
for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) { for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) {
listener.onUrlFocusChange(hasFocus); listener.onUrlFocusChange(hasFocus);
...@@ -1182,4 +1178,53 @@ public class LocationBarLayout extends FrameLayout ...@@ -1182,4 +1178,53 @@ public class LocationBarLayout extends FrameLayout
mAssistantVoiceSearchService.getMicButtonColorStateList(primaryColor, getContext()); mAssistantVoiceSearchService.getMicButtonColorStateList(primaryColor, getContext());
ApiCompatibilityUtils.setImageTintList(mMicButton, colorStateList); ApiCompatibilityUtils.setImageTintList(mMicButton, colorStateList);
} }
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
* @param hasFocus Whether the URL field has gained focus.
*/
protected void finishUrlFocusChange(boolean hasFocus) {
if (!hasFocus) {
// The animation rendering may not yet be 100% complete and hiding the keyboard makes
// the animation quite choppy.
postDelayed(() -> getWindowAndroid().getKeyboardDelegate().hideKeyboard(mUrlBar),
KEYBOARD_HIDE_DELAY_MS);
// Convert the keyboard back to resize mode (delay the change for an arbitrary amount
// of time in hopes the keyboard will be completely hidden before making this change).
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, true);
} else {
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, false);
getWindowAndroid().getKeyboardDelegate().showKeyboard(mUrlBar);
}
mStatusViewCoordinator.onUrlAnimationFinished(hasFocus);
setUrlFocusChangeInProgress(false);
updateShouldAnimateIconChanges();
}
/**
* @param softInputMode The software input resize mode.
* @param delay Delay the change in input mode.
*/
private void setSoftInputMode(final int softInputMode, boolean delay) {
if (mKeyboardResizeModeTask != null) {
removeCallbacks(mKeyboardResizeModeTask);
mKeyboardResizeModeTask = null;
}
if (mWindowDelegate == null || mWindowDelegate.getWindowSoftInputMode() == softInputMode) {
return;
}
if (delay) {
mKeyboardResizeModeTask = () -> {
mWindowDelegate.setWindowSoftInputMode(softInputMode);
mKeyboardResizeModeTask = null;
};
postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
} else {
mWindowDelegate.setWindowSoftInputMode(softInputMode);
}
}
} }
...@@ -12,10 +12,8 @@ import android.graphics.Rect; ...@@ -12,10 +12,8 @@ import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.TouchDelegate; import android.view.TouchDelegate;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.status.StatusView; import org.chromium.chrome.browser.omnibox.status.StatusView;
...@@ -27,17 +25,12 @@ import java.util.List; ...@@ -27,17 +25,12 @@ import java.util.List;
* A location bar implementation specific for smaller/phone screens. * A location bar implementation specific for smaller/phone screens.
*/ */
public class LocationBarPhone extends LocationBarLayout { public class LocationBarPhone extends LocationBarLayout {
private static final int KEYBOARD_MODE_CHANGE_DELAY_MS = 300;
private static final int KEYBOARD_HIDE_DELAY_MS = 150;
private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15; private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15;
private View mFirstVisibleFocusedView; private View mFirstVisibleFocusedView;
private View mUrlBar; private View mUrlBar;
private StatusView mStatusView; private StatusView mStatusView;
private Runnable mKeyboardResizeModeTask;
/** /**
* Constructor used to inflate from XML. * Constructor used to inflate from XML.
*/ */
...@@ -305,34 +298,13 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -305,34 +298,13 @@ public class LocationBarPhone extends LocationBarLayout {
return retVal; return retVal;
} }
/** @Override
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
* @param hasFocus Whether the URL field has gained focus.
*/
public void finishUrlFocusChange(boolean hasFocus) { public void finishUrlFocusChange(boolean hasFocus) {
super.finishUrlFocusChange(hasFocus);
if (!hasFocus) { if (!hasFocus) {
// The animation rendering may not yet be 100% complete and hiding the keyboard makes
// the animation quite choppy.
postDelayed(new Runnable() {
@Override
public void run() {
getWindowAndroid().getKeyboardDelegate().hideKeyboard(mUrlBar);
}
}, KEYBOARD_HIDE_DELAY_MS);
// Convert the keyboard back to resize mode (delay the change for an arbitrary amount
// of time in hopes the keyboard will be completely hidden before making this change).
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, true);
mUrlActionContainer.setVisibility(GONE); mUrlActionContainer.setVisibility(GONE);
} else {
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, false);
getWindowAndroid().getKeyboardDelegate().showKeyboard(mUrlBar);
} }
updateUrlBarPaddingForSearchEngineIcon(); updateUrlBarPaddingForSearchEngineIcon();
mStatusViewCoordinator.onUrlAnimationFinished(hasFocus);
setUrlFocusChangeInProgress(false);
updateShouldAnimateIconChanges();
} }
@Override @Override
...@@ -352,34 +324,6 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -352,34 +324,6 @@ public class LocationBarPhone extends LocationBarLayout {
mStatusViewCoordinator.setShowIconsWhenUrlFocused(showIcon); mStatusViewCoordinator.setShowIconsWhenUrlFocused(showIcon);
} }
/**
* @param softInputMode The software input resize mode.
* @param delay Delay the change in input mode.
*/
private void setSoftInputMode(final int softInputMode, boolean delay) {
final WindowDelegate delegate = getWindowDelegate();
if (mKeyboardResizeModeTask != null) {
removeCallbacks(mKeyboardResizeModeTask);
mKeyboardResizeModeTask = null;
}
if (delegate == null || delegate.getWindowSoftInputMode() == softInputMode) return;
if (delay) {
mKeyboardResizeModeTask = new Runnable() {
@Override
public void run() {
delegate.setWindowSoftInputMode(softInputMode);
mKeyboardResizeModeTask = null;
}
};
postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
} else {
delegate.setWindowSoftInputMode(softInputMode);
}
}
private int getAdditionalOffsetForNTP() { private int getAdditionalOffsetForNTP() {
return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding) return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding)
- getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding); - getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding);
......
...@@ -13,7 +13,6 @@ import android.util.AttributeSet; ...@@ -13,7 +13,6 @@ import android.util.AttributeSet;
import android.util.Property; import android.util.Property;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DownloadUtils; import org.chromium.chrome.browser.download.DownloadUtils;
...@@ -31,7 +30,6 @@ import java.util.List; ...@@ -31,7 +30,6 @@ import java.util.List;
* Location bar for tablet form factors. * Location bar for tablet form factors.
*/ */
public class LocationBarTablet extends LocationBarLayout { public class LocationBarTablet extends LocationBarLayout {
private static final int KEYBOARD_MODE_CHANGE_DELAY_MS = 300;
private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200; private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200;
private static final int ICON_FADE_ANIMATION_DURATION_MS = 150; private static final int ICON_FADE_ANIMATION_DURATION_MS = 150;
...@@ -65,14 +63,6 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -65,14 +63,6 @@ public class LocationBarTablet extends LocationBarLayout {
} }
}; };
private final Runnable mKeyboardResizeModeTask = new Runnable() {
@Override
public void run() {
getWindowDelegate().setWindowSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
};
private View mLocationBarIcon; private View mLocationBarIcon;
private View mBookmarkButton; private View mBookmarkButton;
private View mSaveOfflineButton; private View mSaveOfflineButton;
...@@ -160,8 +150,6 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -160,8 +150,6 @@ public class LocationBarTablet extends LocationBarLayout {
public void handleUrlFocusAnimation(final boolean hasFocus) { public void handleUrlFocusAnimation(final boolean hasFocus) {
super.handleUrlFocusAnimation(hasFocus); super.handleUrlFocusAnimation(hasFocus);
removeCallbacks(mKeyboardResizeModeTask);
if (mUrlFocusChangeAnimator != null && mUrlFocusChangeAnimator.isRunning()) { if (mUrlFocusChangeAnimator != null && mUrlFocusChangeAnimator.isRunning()) {
mUrlFocusChangeAnimator.cancel(); mUrlFocusChangeAnimator.cancel();
mUrlFocusChangeAnimator = null; mUrlFocusChangeAnimator = null;
...@@ -195,29 +183,6 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -195,29 +183,6 @@ public class LocationBarTablet extends LocationBarLayout {
mUrlFocusChangeAnimator.start(); mUrlFocusChangeAnimator.start();
} }
private void finishUrlFocusChange(boolean hasFocus) {
// Report focus change early to trigger animations.
mStatusViewCoordinator.onUrlFocusChange(hasFocus);
if (hasFocus) {
if (getWindowDelegate().getWindowSoftInputMode()
!= WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
getWindowDelegate().setWindowSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
getWindowAndroid().getKeyboardDelegate().showKeyboard(mUrlBar);
} else {
getWindowAndroid().getKeyboardDelegate().hideKeyboard(mUrlBar);
// Convert the keyboard back to resize mode (delay the change for an arbitrary
// amount of time in hopes the keyboard will be completely hidden before making
// this change).
if (getWindowDelegate().getWindowSoftInputMode()
!= WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
}
}
setUrlFocusChangeInProgress(false);
}
/** /**
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not * @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused. * focused.
......
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