Bug 1419463 - Add onFocusRequest to ContentListener API. r=snorp

This listens for "DOMWindowFocus" and calls onFocusRequest in the GeckoSession ContentListener whenever it is received, and implements onFocusRequest for custom tabs and PWAs.
This commit is contained in:
Dylan Roeh 2018-01-29 10:38:46 -06:00
Родитель a191f435d6
Коммит c8a5a694f9
6 изменённых файлов: 40 добавлений и 0 удалений

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

@ -844,6 +844,10 @@ public abstract class GeckoApp extends GeckoActivity
public void onTitleChange(final GeckoSession session, final String title) {
}
@Override // GeckoSession.ContentListener
public void onFocusRequest(final GeckoSession session) {
}
@Override // GeckoSession.ContentListener
public void onFullScreen(final GeckoSession session, final boolean fullScreen) {
if (fullScreen) {

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

@ -678,6 +678,13 @@ public class CustomTabsActivity extends AppCompatActivity
updateActionBar();
}
@Override
public void onFocusRequest(GeckoSession session) {
Intent intent = new Intent(getIntent());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
@Override
public void onFullScreen(GeckoSession session, boolean fullScreen) {
ActivityUtils.setFullScreen(this, fullScreen);

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

@ -351,6 +351,13 @@ public class WebAppActivity extends AppCompatActivity
public void onTitleChange(GeckoSession session, String title) {
}
@Override // GeckoSession.ContentListener
public void onFocusRequest(GeckoSession session) {
Intent intent = new Intent(getIntent());
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
@Override // GeckoSession.ContentListener
public void onContextMenu(GeckoSession session, int screenX, int screenY,
String uri, String elementSrc) {

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

@ -25,6 +25,7 @@ class GeckoViewContent extends GeckoViewContentModule {
debug("register");
addEventListener("DOMTitleChanged", this, false);
addEventListener("DOMWindowFocus", this, false);
addEventListener("MozDOMFullscreen:Entered", this, false);
addEventListener("MozDOMFullscreen:Exit", this, false);
addEventListener("MozDOMFullscreen:Exited", this, false);
@ -43,6 +44,7 @@ class GeckoViewContent extends GeckoViewContentModule {
debug("unregister");
removeEventListener("DOMTitleChanged", this);
removeEventListener("DOMWindowFocus", this);
removeEventListener("MozDOMFullscreen:Entered", this);
removeEventListener("MozDOMFullscreen:Exit", this);
removeEventListener("MozDOMFullscreen:Exited", this);
@ -173,6 +175,11 @@ class GeckoViewContent extends GeckoViewContentModule {
title: content.document.title
});
break;
case "DOMWindowFocus":
this.eventDispatcher.sendRequest({
type: "GeckoView:DOMWindowFocus"
});
break;
}
}
}

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

@ -75,6 +75,7 @@ public class GeckoSession extends LayerSession
new String[]{
"GeckoView:ContextMenu",
"GeckoView:DOMTitleChanged",
"GeckoView:DOMWindowFocus",
"GeckoView:FullScreenEnter",
"GeckoView:FullScreenExit"
}
@ -94,6 +95,8 @@ public class GeckoSession extends LayerSession
} else if ("GeckoView:DOMTitleChanged".equals(event)) {
listener.onTitleChange(GeckoSession.this,
message.getString("title"));
} else if ("GeckoView:DOMWindowFocus".equals(event)) {
listener.onFocusRequest(GeckoSession.this);
} else if ("GeckoView:FullScreenEnter".equals(event)) {
listener.onFullScreen(GeckoSession.this, true);
} else if ("GeckoView:FullScreenExit".equals(event)) {
@ -1197,6 +1200,13 @@ public class GeckoSession extends LayerSession
*/
void onTitleChange(GeckoSession session, String title);
/**
* A page has requested focus. Note that window.focus() in content will not result
* in this being called.
* @param session The GeckoSession that initiated the callback.
*/
void onFocusRequest(GeckoSession session);
/**
* A page has entered or exited full screen mode. Typically, the implementation
* would set the Activity containing the GeckoSession to full screen when the page is

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

@ -162,6 +162,11 @@ public class GeckoViewActivity extends Activity {
Log.i(LOGTAG, "Content title changed to " + title);
}
@Override
public void onFocusRequest(GeckoSession session) {
Log.i(LOGTAG, "Content requesting focus");
}
@Override
public void onFullScreen(final GeckoSession session, final boolean fullScreen) {
getWindow().setFlags(fullScreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,