no route to host Chromium网页输入事件捕捉和手势检测过程分析(14)

电脑杂谈  发布时间:2018-02-16 22:46:44  来源:网络整理

这个函数定义在文件external/chromium_org/ui/events/gesture_detection/scale_gesture_detector.cc中。

ScaleGestureDetector类的成员函数OnTouchEvent首先计算网页被捏合的大小span。这是依据网页在X轴和Y轴上的捏合大小span_x和span_y计算得到的。

ScaleGestureDetector类的成员函数OnTouchEvent接下来推断网页被捏合的大小span是否大于等于预设的阀值。

假设大于等于,而且网页是刚开始被捏合,那么就会调用成员变量listener_指向的一个ScaleGestureListenerImpl对象的成员函数OnScaleBegin。用来询问是否同意产生一个捏合手势操作。假设同意的话,ScaleGestureDetector类的成员变量in_progress_就会被设置为true。

上述ScaleGestureListenerImpl对象就是前面分析的GestureProvider类的成员变量scale_gesture_listener_所指向的ScaleGestureListenerImpl对象。它的成员函数OnScaleBegin的实现例如以下所看到的:

class GestureProvider::ScaleGestureListenerImpl
    : public ScaleGestureDetector::ScaleGestureListener {
 public:
  ......

  virtual bool OnScaleBegin(const ScaleGestureDetector& detector,
                            const MotionEvent& e) OVERRIDE {
    if (ignore_multitouch_events_ && !detector.InDoubleTapMode())
      return false;
    ......
    return true;
  }

  ......
};
这个函数定义在文件external/chromium_org/ui/events/gesture_detection/gesture_provider.cc中。

ScaleGestureListenerImpl类的成员函数OnScaleBegin在两种情况下的返回值为true。第一种情况是当它的成员变量ignore_multitouch_events_的值等于false时。

这表示当网页被多点触摸时,有可能须要对网页进行缩放,也就是要产生一个捏合手势操作。

另外一种情况是网页被Double Tap时。

回到ScaleGestureDetector类的成员函数OnTouchEvent中。综合起来,我们就能够知道,当网页被多点触摸移动或者Double Tap后移动,而且移动的距离或者两次Tap的距离大于等于预设值时。那么就会产生捏合手势操作。

这个捏合手势操作将会交给ScaleGestureDetector类的成员变量listener_指向的ScaleGestureListenerImpl对象的成员函数OnScale处理。例如以下所看到的:

class GestureProvider::ScaleGestureListenerImpl
    : public ScaleGestureDetector::ScaleGestureListener {
 public:
  ......

  virtual bool OnScale(const ScaleGestureDetector& detector,
                       const MotionEvent& e) OVERRIDE {
    ......

    if (!pinch_event_sent_) {
      pinch_event_sent_ = true;
      provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN,
                                    e.GetId(),
                                    detector.GetEventTime(),
                                    detector.GetFocusX(),
                                    detector.GetFocusY(),
                                    detector.GetFocusX() + e.GetRawOffsetX(),
                                    detector.GetFocusY() + e.GetRawOffsetY(),
                                    e.GetPointerCount(),
                                    GetBoundingBox(e)));
    }

    ......

    float scale = detector.GetScaleFactor();
    ......

    GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0);
    provider_->Send(CreateGesture(pinch_details,
                                  e.GetId(),
                                  detector.GetEventTime(),
                                  detector.GetFocusX(),
                                  detector.GetFocusY(),
                                  detector.GetFocusX() + e.GetRawOffsetX(),
                                  detector.GetFocusY() + e.GetRawOffsetY(),
                                  e.GetPointerCount(),
                                  GetBoundingBox(e)));
    return true;
  }

  ......
};
这个函数定义在文件external/chromium_org/ui/events/gesture_detection/gesture_provider.cc中。


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-81055-14.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 林志颖
      林志颖

      想要彻底的政商分离有可能吗

    • 李慧芳
      李慧芳

      让那些光棍跟你爸合伙用你妈

    • 万彤云
      万彤云

      毛主席语录

    热点图片
    拼命载入中...