【发布时间】:2014-06-14 15:34:57
【问题描述】:
手头的任务是为用 Dart 编写的 WebGL 应用程序添加对全屏模式的支持。
canvas.requestFullscreen() 适用于简单的测试用例,但在整个应用程序上失败。
请指出阻止浏览器切换到全屏的原因。
代码是:
void trapFullscreenError() {
document.onFullscreenError.listen((e) {
log("fullscreenerror: $e");
});
}
void toggleFullscreen(CanvasElement c) {
log(
"fullscreenSupport=${document.fullscreenEnabled} fullscreenElement=${document.fullscreenElement}"
);
if (document.fullscreenElement != null) {
log("exiting fullscreen");
document.exitFullscreen();
} else {
log("requesting fullscreen");
c.requestFullscreen();
}
}
在 Chrome 中该代码导致:
fullscreenSupport=true fullscreenElement=null
requesting fullscreen
fullscreenerror: Instance of 'Event'
Dartium 调试器显示以下字段:
Event [id=4]
_selector null
bubbles true
cancelable false
clipboardData null
currentTarget #document [id=5]
defaultPrevented false
eventPhase 3
hashCode 234642739
path NodeList[6] [id=6]
target canvas#main_canvas [id=7]
timeStamp 1398779450832
type "webkitfullscreenerror"
【问题讨论】:
-
log("fullscreenerror: ${e.detail}");的输出是什么? -
它抛出异常:未捕获类型错误:未定义不是函数 J.get$detail$x trapFullscreenError_closure.call$1 fullscreen.dart:9 invokeClosure_closure0.call$0 js_helper.dart:1842 _IsolateContext.eval$1 isolate_helper.dart:392 _callInIsolate isolate_helper.dart:30 invokeClosure js_helper.dart:1842(匿名函数)
-
这是仅在 JavaScript 中还是在 Dart 中。您尝试过哪些浏览器?
-
能否尝试在事件处理程序中设置断点并检查参数
e的类型?我错误地假设了 Event 类型而不是 Error 类型。您能否调查一下参数e是否包含一些包含附加信息的字段。 -
你检查过这个吗:stackoverflow.com/questions/9454125(只能从鼠标或键盘事件中调用)
标签: canvas html5-canvas dart webgl fullscreen