これは、Chromeの内部を調べ、コードを解析してWebサイトをレンダリングする方法を探る4投稿シリーズの最後の投稿です。前回の投稿では、レンダラープロセスを見て、コンポジタースレッドについて学びました。この投稿では、* composeフローがユーザー入力に流動的なエクスペリエンスを提供する方法を見ていきます。

- , , .. () . — , - . : *-, *-. , , , , , .
- , , , , . "" , .
" ", , , . — , .
, , , *- — , . *- , , *-. *- *- ( touchstart) . *- , , .

1: *- *-
*-
, *- , . , *- -, . , ? *- , ?
2: Viewport
*-
JavaScript , *- , "Non-Fast Scrollable Region" (*-). , *- , , . - , *- , .

3: *-
=
- . , . , , .
document.body.addEventListener('touchstart', event => {
if (event.target === area) {
event.preventDefault();
}
});
, . , , *-. , , *- , . , .

4: *-
, , passive:true . , , *- .
document.body.addEventListener('touchstart', event => {
if (event.target === area) {
event.preventDefault()
}
}, {passive: true});
cancelable
, , .
passive: true , , , preventDefault . , event.cancelable.
5: -
document.body.addEventListener('pointermove', event => {
if (event.cancelable) {
event.preventDefault(); //
/*
*
*/
}
}, {passive: true});
, CSS-, touch-action, .
#area {
touch-action: pan-x;
}
*- , . *- (paint records), , , , .

6: *- x.y
, 60 . 60-120 , 100 . , .
, , 120 , JavaScript , .

7:
, Chrome (coalesces, *) ( wheel, mousewheel, mousemove, pointermove, touchmove) , requestAnimationFrame.

8: *
, keydown, keyup, mouseup, mousedown, touchstart touchchend .
getCoalescedEvents
-, * , . , , touchmove, . getCoalescedEvents , * .

9: , - *
window.addEventListener('pointermove', event => {
const events = event.getCoalescedEvents();
for (let event of events) {
const x = event.pageX;
const y = event.pageY;
/* x y */
}
});
-. , DevTools {passive: true} async , , , .
= Lighthouse
, , , , Lighthouse — , , . , , .
=
= Feature Policy
, Feature Policy — -, , . Feature Policy . , , , . sync-script: 'none', JavaScript- . , , .
, , . , , , . , -. , , , . , !

含め、このシリーズでは、早期のプロジェクトをレビュー(これらに限定されない)すべての人に感謝アレックス・ラッセル、ポール・アイリッシュ、Megginカーニー、エリックBidelman、マティアスBynens、アディOsmani、絹子安田、Nasko Oskov、そしてチャーリー・レイス。
このエピソードは気に入りましたか?今後の投稿について質問や提案があれば、下のコメントセクションで、またはtwitter @ kosamariで私から聞いてみたいと思います。