GWT 2.5 Canvas toDataURL()在MouseUp处理程序中工作,但不在TouchEnd Handler中工作

时间:2013-11-16 16:28:12

标签: events gwt canvas touch

我使用GWT 2.5 Canvas实现了一个数字签名小部件,它可以很好地处理鼠标事件。不幸的是,触摸事件失败了,我不明白为什么。在触摸屏上绘制了签名,但canvas.toDataURL()总是不返回任何内容(实际上是“data:”)。代码片段是:

  _canvas.addMouseMoveHandler(new MouseMoveHandler() {
  public void onMouseMove(MouseMoveEvent event) {
      int thisX = event.getRelativeX(_canvas.getElement());
      int thisY = event.getRelativeY(_canvas.getElement());
      if (_lastX >= 0 && _lastY >= 0) {
    _exists = true;
    _context.moveTo(_lastX, _lastY);
    _context.lineTo(thisX, thisY);
    _context.stroke();
      }
      _lastX = thisX;
      _lastY = thisY;
  }
});
  _canvas.addMouseUpHandler(new MouseUpHandler() {
  public void onMouseUp(MouseUpEvent event) { 
     _lastX = -1;
    _lastY = -1;
   _drawing = false; 
    if (_exists) _handler.sigChanged(_canvas.toDataUrl());
  }
});

  _canvas.addTouchMoveHandler(new TouchMoveHandler() {
  public void onTouchMove(TouchMoveEvent event) {
    if (event.getTouches().length() > 0) {
      Touch touch = event.getTouches().get(0);
      int thisX = touch.getRelativeX(_canvas.getElement());
      int thisY = touch.getRelativeY(_canvas.getElement());
      if (_lastX >= 0 && _lastY >= 0) {
    _context.moveTo(_lastX, _lastY);
    _context.lineTo(thisX, thisY);
    _context.stroke();
    //_handler.sigChanged(_canvas.toDataUrl());
      }
      _lastX = thisX;
      _lastY = thisY;
    }
    event.preventDefault();
    event.stopPropagation();
  }
});
  _canvas.addTouchEndHandler(new TouchEndHandler() {
  public void onTouchEnd(TouchEndEvent event) {
    _handler.sigChanged(_canvas.toDataUrl());
    com.google.gwt.user.client.Window.alert("onTouchEnd1: " + _canvas.toDataUrl());
  }
  event.preventDefault();
});

同样,toDataURL()适用于鼠标事件但在触摸事件中始终不返回任何内容,即使您从触摸移动处理程序中调用它也是如此。任何帮助或建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

我借了一个运行更新版本的朋友安卓手机(4.1 vs 2.3)并且它有效。我不明白,但我认为它是GWT 2.5的一个错误,我正在继续。

詹姆斯