SOFT_INPUT_ADJUST_PAN does not work for input fields in WebView |
|
Issue description
Expected behavior:
A WebView is hosted on a Window that has SOFT_INPUT_ADJUST_PAN, then contents will not be shifted up as it implies.
Actual behavior:
I guess this has never worked in practice.
Repro code:
----
package com.google.corp.b.bug115528561;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
final StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append(" <form>");
for (int i = 0; i < 100; ++i) {
sb.append("<input type=\"text\" style=\"font-size:xx-large\" name=\"input")
.append(i).append("\"><br>");
}
sb.append(" </form>");
sb.append("</html>");
final String html = sb.toString();
final WebView webView = new WebView(this);
webView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
webView.loadData(html, "text/html; charset=UTF-8", null);
setContentView(webView);
}
}
By comparison, the following works on EditText:
package com.google.corp.b.bug115528561expected;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
final EditText editText = new EditText(this);
final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(Gravity.BOTTOM);
layout.addView(editText);
setContentView(layout);
}
}
Internally SOFT_INPUT_ADJUST_PAN is implemented in ViewRootImpl.java with an assumption that the focused View directly or indirectly triggers ViewRootImpl#requestChildRectangleOnScreen(). EditText/TextView does this by internally calling TextView#bringPointIntoView() from TextView#{onPreDraw(), onLayout(), updateAfterEdit()}. WebView, however, does not have things like TextView#bringPointIntoView(). As a result, SOFT_INPUT_ADJUST_PAN will be ignored while interacting with WebView.
Making this a feature request as it never worked in practice.
Originally filed as b/115528561
,
Dec 18
See b/27133109 internally also which is a similar/same issue about not using requestRectangleOnScreen when we probably should. |
|
►
Sign in to add a comment |
|
Comment 1 by changwan@chromium.org
, Dec 6Status: Assigned (was: Available)