Skip to content

Commit

Permalink
Fix 2D virtual keyboard shows up after navigate from recent tabs in VR
Browse files Browse the repository at this point in the history
This CL makes sure that a VR version ImeAdapter is used when WebContent
for current tab swapped.


Bug: 841607
Change-Id: I751221684c17101ae80c4ebeff5684f5f5b7f8c5
Reviewed-on: https://chromium-review.googlesource.com/1057827
Reviewed-by: Amirhossein Simjour <asimjour@chromium.org>
Commit-Queue: Biao She <bshe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558745}
  • Loading branch information
Biao She authored and Commit Bot committed May 15, 2018
1 parent 2f7f86f commit 87a5c00
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.chromium.content_public.browser.ContentViewCore;
import org.chromium.content_public.browser.ImeAdapter;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.common.BrowserControlsState;
import org.chromium.ui.base.PermissionCallback;
import org.chromium.ui.base.WindowAndroid;
Expand Down Expand Up @@ -216,6 +217,9 @@ public void onContentChanged(Tab tab) {
@Override
public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) {
onContentChanged(tab);
// It is not needed to restore IME for old web contents as it is going away and
// replaced by the new web contents.
configWebContentsImeForVr(tab.getWebContents());
}

@Override
Expand Down Expand Up @@ -426,41 +430,41 @@ private void swapToTab(Tab tab) {
mTabObserver.onContentChanged(mTab);
}

private void configWebContentsImeForVr(WebContents webContents) {
if (webContents == null) return;

ImeAdapter imeAdapter = ImeAdapter.fromWebContents(webContents);
if (imeAdapter == null) return;

mInputMethodManagerWrapper = new VrInputMethodManagerWrapper(mActivity, this);
imeAdapter.setInputMethodManagerWrapper(mInputMethodManagerWrapper);
}

private void restoreWebContentsImeFromVr(WebContents webContents) {
if (webContents == null) return;

ImeAdapter imeAdapter = ImeAdapter.fromWebContents(webContents);
if (imeAdapter == null) return;

imeAdapter.setInputMethodManagerWrapper(
ImeAdapter.createDefaultInputMethodManagerWrapper(mActivity));
mInputMethodManagerWrapper = null;
}

private void initializeTabForVR() {
if (mTab == null) return;
// Make sure we are not redirecting to another app, i.e. out of VR mode.
mNonVrTabRedirectHandler = mTab.getTabRedirectHandler();
mTab.setTabRedirectHandler(mTabRedirectHandler);
assert mTab.getWindowAndroid() == mContentVrWindowAndroid;
initializeImeForVr();
}

private void initializeImeForVr() {
assert mTab != null;
if (mTab.getWebContents() == null) return;
ImeAdapter imeAdapter = ImeAdapter.fromWebContents(mTab.getWebContents());
if (imeAdapter != null) {
mInputMethodManagerWrapper = new VrInputMethodManagerWrapper(mActivity, this);
imeAdapter.setInputMethodManagerWrapper(mInputMethodManagerWrapper);
}
}

private void uninitializeImeForVr() {
assert mTab != null;
if (mTab.getWebContents() == null) return;
ImeAdapter imeAdapter = ImeAdapter.fromWebContents(mTab.getWebContents());
if (imeAdapter != null) {
imeAdapter.setInputMethodManagerWrapper(
ImeAdapter.createDefaultInputMethodManagerWrapper(mActivity));
}
mInputMethodManagerWrapper = null;
configWebContentsImeForVr(mTab.getWebContents());
}

private void restoreTabFromVR() {
if (mTab == null) return;
mTab.setTabRedirectHandler(mNonVrTabRedirectHandler);
mNonVrTabRedirectHandler = null;
uninitializeImeForVr();
restoreWebContentsImeFromVr(mTab.getWebContents());
}

private void reparentAllTabs(WindowAndroid window) {
Expand Down Expand Up @@ -717,7 +721,7 @@ public void shutdown() {
if (mTab != null) {
mTab.removeObserver(mTabObserver);
restoreTabFromVR();
uninitializeImeForVr();
restoreWebContentsImeFromVr(mTab.getWebContents());
if (mTab.getContentViewCore() != null) {
View parent = mTab.getContentView();
mTab.getWebContents().setSize(parent.getWidth(), parent.getHeight());
Expand Down

0 comments on commit 87a5c00

Please sign in to comment.