Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1468)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java

Issue 2831233002: [Home] Set soft input mode based on sheet state (Closed)
Patch Set: address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java
index cfcfc1df4727d77ce16466f8fdc7227b3edf93f6..184e34abce28733cc37c81afd67a1519dfda4d21 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java
@@ -24,6 +24,8 @@ import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.MathUtils;
+import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
+import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.ui.UiUtils;
/**
@@ -153,7 +155,6 @@ public class LocationBarPhone extends LocationBarLayout {
* @param hasFocus Whether the URL field has gained focus.
*/
public void finishUrlFocusChange(boolean hasFocus) {
- final WindowDelegate windowDelegate = getWindowDelegate();
if (!hasFocus) {
// Remove the selection from the url text. The ending selection position
// will determine the scroll position when the url field is restored. If
@@ -183,32 +184,15 @@ public class LocationBarPhone extends LocationBarLayout {
}, 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).
- if (mKeyboardResizeModeTask == null
- && windowDelegate.getWindowSoftInputMode()
- != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
- mKeyboardResizeModeTask = new Runnable() {
- @Override
- public void run() {
- windowDelegate.setWindowSoftInputMode(
- WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- mKeyboardResizeModeTask = null;
- }
- };
- postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
+ // If Chrome Home is enabled, it will handle its own mode changes.
+ if (mBottomSheet == null) {
+ setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, true);
}
mUrlActionsContainer.setVisibility(GONE);
} else {
- if (mKeyboardResizeModeTask != null) {
- removeCallbacks(mKeyboardResizeModeTask);
- mKeyboardResizeModeTask = null;
- }
- // TODO(mdjones): SOFT_INPUT_ADJUST_NOTHING breaks omnibox suggestions but fixes a
- // content jumping bug in Chrome Home. See https://crbug.com/706918
- int softInputMode = mBottomSheet != null
- ? WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
- : WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
- if (windowDelegate.getWindowSoftInputMode() != softInputMode) {
- windowDelegate.setWindowSoftInputMode(softInputMode);
+ // If Chrome Home is enabled, it will handle its own mode changes.
+ if (mBottomSheet == null) {
+ setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, false);
}
UiUtils.showKeyboard(mUrlBar);
// As the position of the navigation icon has changed, ensure the suggestions are
@@ -310,4 +294,54 @@ public class LocationBarPhone extends LocationBarLayout {
super.setLayoutDirection(layoutDirection);
updateIncognitoBadgePadding();
}
+
+ /**
+ * @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);
+ }
+ }
+
+ @Override
+ public void setBottomSheet(BottomSheet sheet) {
+ super.setBottomSheet(sheet);
+
+ sheet.addObserver(new EmptyBottomSheetObserver() {
+ @Override
+ public void onSheetStateChanged(int state) {
+ switch (state) {
+ case BottomSheet.SHEET_STATE_FULL:
+ setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN, false);
+ break;
+ case BottomSheet.SHEET_STATE_PEEK:
+ setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE, true);
+ break;
+ default:
+ setSoftInputMode(
+ WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING, false);
+ }
+ }
+ });
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698