LayerTreeBase.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export class Layer{id(){}
  2. parentId(){}
  3. parent(){}
  4. isRoot(){}
  5. children(){}
  6. addChild(child){}
  7. node(){}
  8. nodeForSelfOrAncestor(){}
  9. offsetX(){}
  10. offsetY(){}
  11. width(){}
  12. height(){}
  13. transform(){}
  14. quad(){}
  15. anchorPoint(){}
  16. invisible(){}
  17. paintCount(){}
  18. lastPaintRect(){}
  19. scrollRects(){}
  20. stickyPositionConstraint(){}
  21. gpuMemoryUsage(){}
  22. requestCompositingReasons(){}
  23. drawsContent(){}
  24. snapshots(){}}
  25. Layer.ScrollRectType={NonFastScrollable:'NonFastScrollable',TouchEventHandler:'TouchEventHandler',WheelEventHandler:'WheelEventHandler',RepaintsOnScroll:'RepaintsOnScroll',MainThreadScrollingReason:'MainThreadScrollingReason'};export class StickyPositionConstraint{constructor(layerTree,constraint){this._stickyBoxRect=constraint.stickyBoxRect;this._containingBlockRect=constraint.containingBlockRect;this._nearestLayerShiftingStickyBox=null;if(layerTree&&constraint.nearestLayerShiftingStickyBox){this._nearestLayerShiftingStickyBox=layerTree.layerById(constraint.nearestLayerShiftingStickyBox);}
  26. this._nearestLayerShiftingContainingBlock=null;if(layerTree&&constraint.nearestLayerShiftingContainingBlock){this._nearestLayerShiftingContainingBlock=layerTree.layerById(constraint.nearestLayerShiftingContainingBlock);}}
  27. stickyBoxRect(){return this._stickyBoxRect;}
  28. containingBlockRect(){return this._containingBlockRect;}
  29. nearestLayerShiftingStickyBox(){return this._nearestLayerShiftingStickyBox;}
  30. nearestLayerShiftingContainingBlock(){return this._nearestLayerShiftingContainingBlock;}}
  31. export default class LayerTreeBase{constructor(target){this._target=target;this._domModel=target?target.model(SDK.DOMModel):null;this._layersById={};this._root=null;this._contentRoot=null;this._backendNodeIdToNode=new Map();}
  32. target(){return this._target;}
  33. root(){return this._root;}
  34. setRoot(root){this._root=root;}
  35. contentRoot(){return this._contentRoot;}
  36. setContentRoot(contentRoot){this._contentRoot=contentRoot;}
  37. forEachLayer(callback,root){if(!root){root=this.root();if(!root){return false;}}
  38. return callback(root)||root.children().some(this.forEachLayer.bind(this,callback));}
  39. layerById(id){return this._layersById[id]||null;}
  40. async resolveBackendNodeIds(requestedNodeIds){if(!requestedNodeIds.size||!this._domModel){return;}
  41. const nodesMap=await this._domModel.pushNodesByBackendIdsToFrontend(requestedNodeIds);if(!nodesMap){return;}
  42. for(const nodeId of nodesMap.keysArray()){this._backendNodeIdToNode.set(nodeId,nodesMap.get(nodeId)||null);}}
  43. backendNodeIdToNode(){return this._backendNodeIdToNode;}
  44. setViewportSize(viewportSize){this._viewportSize=viewportSize;}
  45. viewportSize(){return this._viewportSize;}
  46. _nodeForId(id){return this._domModel?this._domModel.nodeForId(id):null;}}
  47. self.SDK=self.SDK||{};SDK=SDK||{};SDK.Layer=Layer;SDK.LayerTreeBase=LayerTreeBase;SDK.Layer.StickyPositionConstraint=StickyPositionConstraint;SDK.SnapshotWithRect;