无法从 mousemove 事件获取鼠标指针信息

Cannot get mouse pointer information from mousemove event

在普通的 JS Polymer 中,我可以做类似 this:

<dom-module id="my-module">
  <template>
    <div on-mousemove="mousemove">Text here!</div>
  </template>
  <script>
    Polymer({
      is: 'my-module',

      mousemove: function (event) {
        console.log(event);
      }
    });
  </script>
</dom-module>

这将打印包含鼠标指针坐标的鼠标移动事件。

但是,请考虑以下 Dart 项目:

pubspec.yaml

name: example
description: "stuff here"
version: 0.1.0
dependencies:
  polymer: ^1.0.0-rc.18
  web_components: ^0.12.0
  browser: ^0.10.0
transformers:
- polymer:
    entry_points:
    - web/index.html

web/index.飞镖

library photon.index;

import 'package:example/test.dart';

export 'package:polymer/init.dart';
import 'package:polymer/polymer.dart';

web/index.html

<head>
  <script src="packages/web_components/webcomponents-lite.min.js"></script>
  <script src="packages/web_components/dart_support.js"></script>
</head>
<body unresolved>
  <my-module></my-module>

  <script type="application/dart" src="index.dart"></script>
  <script src="packages/browser/dart.js"></script>
</body>

lib/test.飞镖

@HtmlImport('test.html')
library example.test;

import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart' show HtmlImport;

@PolymerRegister('my-module')
class MyModule extends PolymerElement {
  MyModule.created() : super.created();

  @reflectable
  void mousemove(event, [_]) {
    print(event);
  }
}

lib/test.html

<dom-module id="my-module">
  <template>
    <div on-mousemove="mousemove" id="target">Text here!</div>
  </template>
</dom-module>

这大致相当于 JavaScript 版本。但是,这将打印 CustomEventWrapper 的实例,它缺少有关光标所在位置的信息。有什么方法可以访问鼠标指针信息吗?

这应该有效

  @reflectable
  void mousemove(CustomEventWrapper event, [_]) {
    MouseEvent mouseEvent = event.original;
    print('x: ${mouseEvent.client.x}');
    print('y: ${mouseEvent.client.y}');
  }