Bug 696319 - Scroll window as needed when soft keyboard is up [r=mfinkle]

This commit is contained in:
Kartikaya Gupta 2011-10-26 14:30:48 -04:00
parent 8d499eecc0
commit ee3e74b6ae
2 changed files with 19 additions and 0 deletions

View File

@ -295,6 +295,13 @@ class GeckoSurfaceView
GeckoAppShell.scheduleRedraw();
GeckoAppShell.geckoEventSync();
}
// if the surface changed size and we have the soft keyboard up, make sure
// the focused input field is still in view or it might get hidden behind the
// keyboard and be really hard to use
if (mIMEState == IME_STATE_ENABLED) {
GeckoAppShell.sendEventToGecko(new GeckoEvent("ScrollTo:FocusedInput", null));
}
}
public void surfaceCreated(SurfaceHolder holder) {

View File

@ -131,6 +131,7 @@ var BrowserApp = {
Services.obs.addObserver(this, "SaveAs:PDF", false);
Services.obs.addObserver(this, "Preferences:Get", false);
Services.obs.addObserver(this, "Preferences:Set", false);
Services.obs.addObserver(this, "ScrollTo:FocusedInput", false);
Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(XPInstallObserver, "addon-install-started", false);
@ -435,6 +436,15 @@ var BrowserApp = {
}
},
scrollToFocusedInput: function(aBrowser) {
let doc = aBrowser.contentDocument;
if (!doc)
return;
let focused = doc.activeElement;
if ((focused instanceof HTMLInputElement && focused.mozIsTextField(false)) || (focused instanceof HTMLTextAreaElement))
focused.scrollIntoView(false);
},
observe: function(aSubject, aTopic, aData) {
let browser = this.selectedBrowser;
if (!browser)
@ -461,6 +471,8 @@ var BrowserApp = {
this.getPreferences(aData);
} else if (aTopic == "Preferences:Set") {
this.setPreferences(aData);
} else if (aTopic == "ScrollTo:FocusedInput") {
this.scrollToFocusedInput(browser);
}
}
}