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
Родитель 055734f08f
Коммит 1832cfaea1
2 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -295,6 +295,13 @@ class GeckoSurfaceView
GeckoAppShell.scheduleRedraw(); GeckoAppShell.scheduleRedraw();
GeckoAppShell.geckoEventSync(); 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) { public void surfaceCreated(SurfaceHolder holder) {

Просмотреть файл

@ -131,6 +131,7 @@ var BrowserApp = {
Services.obs.addObserver(this, "SaveAs:PDF", false); Services.obs.addObserver(this, "SaveAs:PDF", false);
Services.obs.addObserver(this, "Preferences:Get", false); Services.obs.addObserver(this, "Preferences:Get", false);
Services.obs.addObserver(this, "Preferences:Set", 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-blocked", false);
Services.obs.addObserver(XPInstallObserver, "addon-install-started", 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) { observe: function(aSubject, aTopic, aData) {
let browser = this.selectedBrowser; let browser = this.selectedBrowser;
if (!browser) if (!browser)
@ -461,6 +471,8 @@ var BrowserApp = {
this.getPreferences(aData); this.getPreferences(aData);
} else if (aTopic == "Preferences:Set") { } else if (aTopic == "Preferences:Set") {
this.setPreferences(aData); this.setPreferences(aData);
} else if (aTopic == "ScrollTo:FocusedInput") {
this.scrollToFocusedInput(browser);
} }
} }
} }