* Calculates the task's score. A task with the lowest score will be dequeued * from the queue the first. * * There are three components of the score: element's priority, operation or * offset priority and viewport priority. * * Element's priority is constant of the element's name.
(task)
| 1397 | * @private |
| 1398 | */ |
| 1399 | calcTaskScore_(task) { |
| 1400 | // TODO(jridgewell): these should be taking into account the active |
| 1401 | // scroller, which may not be the root scroller. Maybe a weighted average |
| 1402 | // of "scroller scrolls necessary" to see the element. |
| 1403 | // Demo at https://output.jsbin.com/hicigom/quiet |
| 1404 | const viewport = this.viewport_.getRect(); |
| 1405 | const box = task.resource.getLayoutBox(); |
| 1406 | let posPriority = Math.floor((box.top - viewport.top) / viewport.height); |
| 1407 | if (Math.sign(posPriority) != this.getScrollDirection()) { |
| 1408 | posPriority *= 2; |
| 1409 | } |
| 1410 | posPriority = Math.abs(posPriority); |
| 1411 | return task.priority * PRIORITY_BASE_ + posPriority; |
| 1412 | } |
| 1413 | |
| 1414 | /** |
| 1415 | * Calculates the timeout of a task. The timeout depends on two main factors: |
no test coverage detected