事件捕获

In computer graphics programming, hit-testing (hit detection, picking, or pick correlation) is the process of determining whether a user-controlled cursor (such as a mouse cursor or touch-point on a touch-screen interface) intersects a given graphical object (such as a shape, line, or curve) drawn on the screen.Hit-testing may be performed on the movement or activation

举个例子,在大家看来,点击一个HTML的<a>标签链接打开一个新页面,看起来非常理所当然的一件事情,在WebKit内核里面,却做了非常多的事情,首先,要获取当前点击的位置,带着这个位置坐标信息,去做一个HitTest。所谓的HitTest就是探测下当前的点击的内容是什么,怎么才能知道当前点击的是什么呢?HitTest会遍历整个DomTree, LayerTree,看看当前的坐标位置是什么内容,是空白?还是文字?还是图片,还是链接?这些信息都可以通过遍历DomTree, LayerTree来实现,最终将遍历的探测结果以HitTestResult的形式返回,最终通过返回的类型来判断,如果是一个链接,则回调对应的回调函数,最终实现通过点击打开一个新的页面。

作者:三旬叔

链接:https://www.zhihu.com/question/22799206/answer/148330651

来源:知乎

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/11712441.html