import { ContainerLayer, TransformLayer } from '../compositing'; import { SyntheticEvent, SyntheticEventDispatcher, SyntheticEventListener, SyntheticEventTarget, SyntheticPointerEvent, SyntheticWheelEvent } from '../events'; import { AbstractNode } from '../foundation'; import { Matrix, MutableMatrix, Point, Rect, Size } from '../math'; import { HitTestResult } from './hit-test'; import { PaintingContext } from './painting-context'; import { RenderPipeline } from './render-pipeline'; import { StyleMap } from './style-map'; import { Yoga, YogaMeasure } from './yoga'; /** * 储存所有由父对象管理的数据 */ export declare class ParentData { /** * RenderObject 被从 parent 移除时调用 */ detach(): void; } export type Visitor = { bivarianceHack(child: T): void; }['bivarianceHack']; export interface RenderObject { onPointerMove?: SyntheticEventListener>; onPointerOver?: SyntheticEventListener>; onPointerEnter?: SyntheticEventListener>; onPointerDown?: SyntheticEventListener>; onPointerUp?: SyntheticEventListener>; onPointerOut?: SyntheticEventListener>; onPointerLeave?: SyntheticEventListener>; onWheel?: SyntheticEventListener>; onPointerMoveCapture?: SyntheticEventListener>; onPointerOverCapture?: SyntheticEventListener>; onPointerEnterCapture?: SyntheticEventListener>; onPointerDownCapture?: SyntheticEventListener>; onPointerUpCapture?: SyntheticEventListener>; onPointerOutCapture?: SyntheticEventListener>; onPointerLeaveCapture?: SyntheticEventListener>; onWheelCapture?: SyntheticEventListener>; onPaint?: (offset: Point) => void; } /** * RenderObject 是场景树中所有对象的基类 * */ export declare abstract class RenderObject extends AbstractNode implements SyntheticEventTarget { /** * `RenderObject` 的 parent,如果没有 parent,则为 undefined */ get parent(): RenderObject | undefined; /** * 唯一 id */ id?: string | number; /** * 样式 */ readonly style: StyleMap; protected trackStyle(): void; /** * 从样式更新 bounds */ protected updateOffsetAndSizeFromStyle(): void; /** * 父节点使用的信息,比如说保存一些布局相关信息,偏移量等等 * 对于子节点来说是不透明的 */ parentData?: ParentDataType; protected setupParentData(child: RenderObject): void; adoptChild(child: RenderObject): void; protected allocChildYogaNode(child: RenderObject): void; protected allocChildrenYogaNode(): void; dropChild(child: RenderObject): void; protected deallocYogaNode(child: RenderObject): void; protected deallocYogaNodeChildren(): void; abstract visitChildren(visitor: Visitor): void; /** * 我们使用 Yoga 进行 Flex 布局,yogaNode 表示 RenderObject 的**伴生 yoga 节点** */ get yogaNode(): Yoga.YogaNode | undefined; set yogaNode(value: Yoga.YogaNode | undefined); _yogaNode?: Yoga.YogaNode; /** * 节点是否总是持有 YogaNode */ get alwaysHoldYogaNode(): boolean; /** * 初始化 yogaNode */ protected setupYogaNode(): void; protected disposeYogaNode(): void; protected handleFlexBasisChange(value?: StyleMap['flexBasis']): void; protected handleFlexGrowChange(value?: StyleMap['flexGrow']): void; protected handleFlexShrinkChange(value?: StyleMap['flexShrink']): void; protected handleWidthChange(value?: StyleMap['width']): void; protected handleHeightChange(value?: StyleMap['height']): void; protected handleMinWidthChange(value?: StyleMap['minWidth']): void; protected handleMinHeightChange(value?: StyleMap['minHeight']): void; protected handleMaxWidthChange(value?: StyleMap['maxWidth']): void; protected handleMaxHeightChange(value?: StyleMap['maxHeight']): void; protected handlePaddingTopChange(value?: StyleMap['paddingTop']): void; protected handlePaddingRightChange(value?: StyleMap['paddingRight']): void; protected handlePaddingBottomChange(value?: StyleMap['paddingBottom']): void; protected handlePaddingLeftChange(value?: StyleMap['paddingLeft']): void; protected handleMarginTopChange(value?: StyleMap['marginTop']): void; protected handleMarginRightChange(value?: StyleMap['marginRight']): void; protected handleMarginBottomChange(value?: StyleMap['marginBottom']): void; protected handleMarginLeftChange(value?: StyleMap['marginLeft']): void; protected handleDisplayChange(value: StyleMap['display']): void; protected handleVisibilityChange(value: StyleMap['visibility']): void; protected handleLeftChange(value?: StyleMap['left']): void; protected handleTopChange(value?: StyleMap['top']): void; protected handleRightChange(value?: StyleMap['right']): void; protected handleBottomChange(value?: StyleMap['bottom']): void; protected handlePositionChange(value: StyleMap['position']): void; protected updateOffsetAndSizeFromYogaNode(): void; attach(owner: RenderPipeline): void; detach(): void; /** * 设置或获取节节点的逻辑 size * * 默认情况下 `paintBounds` 返回该值,作为参考指示你不可以超出画面进行绘制 * * 设置该属性不会导致重新布局,但是会导致重新绘制 * */ get size(): Size; set size(value: Size); protected setSize(value: Size): boolean; /** * @internal */ _size: Size; /** * 设置或获取节点相对于 parent 的偏移 * * 设置该属性不会导致重新布局,但是会导致重新绘制 */ get offset(): Point; set offset(value: Point); protected setOffset(value: Point): boolean; /** * @internal */ _offset: Point; /** * 设置或获取节点的视口 * * 视口描述了一组裁剪区域和绘制偏移 * * 组件在实现 `paint` 时应读取该属性执行不可见区域的剔除和绘制偏移 * * 在实现 `hitTest` 系列方法时也需要应用偏移和裁剪 * */ get viewport(): Rect; set viewport(value: Rect); protected _viewport: Rect; get viewportOffset(): Point; /** * 标记当前节点已离屏 */ offstage: boolean; /** * 标记当前节点已隐藏 */ get hidden(): boolean; set hidden(value: boolean); protected _hidden: boolean; /** * 如果设置了 yogaMeasure yogaNode 为 dirty */ protected markYogaNodeDirty(): void; protected readonly yogaMeasure?: YogaMeasure; /** friend of RenderPipeline */ _layoutDirty: boolean; _relayoutBoundary?: RenderObject; /** * 标记需要重新布局 * * @param cause 指示本次标记产生的子节点 * */ markLayoutDirty(cause?: RenderObject): void; /** * 寻找布局边界并标记为 dirty */ protected markSelfAndParentLayoutDirty(): void; /** * 调度首次布局 */ scheduleInitialLayout(): void; layoutAsChild(parentUsesSize: boolean, force: boolean): void; private cleanRelayoutBoundary; layoutAsBoundary(): void; private static cleanChildRelayoutBoundary; /** * 子类实现的布局逻辑 */ performLayout(): void; /** * 节点调度了 enterFrame 时调用 */ enterFrame(): void; /** * 标记节点需要调度 enterFrame */ markEnterFrame(): void; /** * 更新 offset 和 size */ protected updateOffsetAndSize(): void; /** * 当前对象是否是重绘边界 */ get repaintBoundary(): boolean; set repaintBoundary(value: boolean); protected _repaintBoundary: boolean; protected _repaintBoundaryLocked: boolean; /** * 指示是否总是需要合成 */ get alwaysNeedsCompositing(): boolean; protected get layer(): ContainerLayer | undefined; protected set layer(value: ContainerLayer | undefined); _layer?: ContainerLayer; _needsCompositingDirty: boolean; markNeedsCompositingDirty(): void; protected _needsCompositing: boolean; /** * 当前及子节点是否需要合成 */ get needsCompositing(): boolean; updateNeedsCompositing(): void; _paintDirty: boolean; /** * 标记节点需要重新绘制 * * @param cause 指示本次标记产生的子节点 */ markPaintDirty(cause?: RenderObject): void; /** * RenderPipeline.flushPaint 重绘 RenderObject,但所在图层还没有 attached * * 为了保证子树在图层被 attached 时最终可以得到重绘,我们标记所有祖先 paintDirty */ skipPaint(): void; scheduleInitialPaint(rootLayer: ContainerLayer): void; replaceRootLayer(rootLayer: TransformLayer): void; /** * 绘制边界,指示了当前节点的绘制区域 * * 你可以绘制超出该区域 * */ get paintBounds(): Rect; /** * 对象的边界,用于离屏检测 */ get bounds(): Rect; _debugDoingThisPaint: boolean; static _debugActivePaint?: RenderObject; paintWithContext(context: PaintingContext, offset: Point): void; abstract paint(context: PaintingContext, offset: Point): void; debugPaint(context: PaintingContext, offset: Point): void; protected debugPaintSize(context: PaintingContext, offset: Point): void; protected debugPaintId(context: PaintingContext, offset: Point): void; applyPaintTransform(child: RenderObject, transform: MutableMatrix): void; localToGlobal(point: Point, ancestor?: RenderObject): Point; globalToLocal(point: Point, ancestor?: RenderObject): Point; getBoundingClientRect(ancestor?: RenderObject): Rect; getTransformTo(ancestor?: RenderObject): Matrix; protected get dispatcher(): SyntheticEventDispatcher; protected _dispatcher?: SyntheticEventDispatcher; addEventListener(type: string, listener: SyntheticEventListener, options?: boolean | AddEventListenerOptions): void; dispatchEvent(event: SyntheticEvent): boolean; removeEventListener(type: string, listener: SyntheticEventListener, options?: boolean | EventListenerOptions): void; getDispatcher(): SyntheticEventDispatcher | undefined; hitTestDisabled: boolean; hitTestSelfDisabled: boolean; hitTest(result: HitTestResult, position: Point): boolean; protected hitTestSelf(_position: Point): boolean; protected hitTestChildren(_result: HitTestResult, _position: Point): boolean; }