import { IReferenceCountable, WeakList, Bounds, IndentingWriter } from "../../base/utilities"; import { EventDispatcher } from "../events/EventDispatcher"; import { Event } from "../events/Event"; import { DisplaySymbol } from "../symbol"; import { Matrix } from "../geom/Matrix"; import { PerspectiveProjection } from "../geom/PerspectiveProjection"; import { Point } from "../geom/Point"; import { Transform } from "../geom/Transform"; import { ColorTransform } from "../geom/ColorTransform"; import { Rectangle } from "../geom/Rectangle"; import { Vector3D } from "../geom/Vector3D"; import { ASArray } from "../../avm2/nat/ASArray"; import { ASObject } from "../../avm2/nat/ASObject"; import { IBitmapDrawable } from "./IBitmapDrawable"; import { IRemotable } from "../../base/remoting"; import { PlaceObjectTag } from "../../../parsers/utils/SWFTags"; import { Stage } from "./Stage"; import { DisplayObjectContainer } from "./DisplayObjectContainer"; import { LoaderInfo } from "./LoaderInfo"; import { AccessibilityProperties } from "../accessibility/AccessibilityProperties"; import { Matrix3D } from "../geom/Matrix3D"; import { Graphics } from "./Graphics"; import { AXClass } from '../../avm2/run/AXClass'; /** * Copyright 2014 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Flash bugs to keep in mind: * * http://aaronhardy.com/flex/displayobject-quirks-and-tips/ * http://blog.anselmbradford.com/2009/02/12/flash-movie-clip-transformational-properties-explorer-x-y-width-height-more/ * http://gskinner.com/blog/archives/2007/08/annoying_as3_bu.html * http://blog.dennisrobinson.name/getbounds-getrect-unexpected-results/ * */ /** * Invalid Bits: * * Invalid bits are used to mark path dependent properties of display objects as stale. To compute these properties we either have to * walk the tree all the way the root, or visit all children. * * +---+ * | A | * +---+ * / \ * +---+ +---+ * | B | | C | * +---+ +---+ * / \ * +---+ +---+ * | D | | E | * +---+ +---+ * * We use a combination of eager invalid bit propagation and lazy property evaluation. If a node becomes invalid because one of its * local properties has changed, we mark all of its valid descendents as invalid. When computing dependent properties, we walk up * the tree until we find a valid node and propagate the computation lazily downwards, marking all the nodes along the path as * valid. * * Suppose we mark A as invalid, this causes nodes B, C, D, and E to become invalid. We then compute a path dependent property * on E, causing A, and C to become valid. If we mark A as invalid again, A and C become invalid again. We don't need to mark * parts of the tree that are already invalid. * * * Dirty Bits: * * These are used to mark properties as having been changed. */ export declare const enum DisplayObjectFlags { None = 0, /** * Display object is visible. */ Visible = 1, /** * Display object has invalid line bounds. */ InvalidLineBounds = 2, /** * Display object has invalid fill bounds. */ InvalidFillBounds = 4, /** * Display object has an invalid matrix because one of its local properties: x, y, scaleX, ... * has been mutated. */ InvalidMatrix = 8, /** * Display object has an invalid inverted matrix because its matrix has been mutated. */ InvalidInvertedMatrix = 16, /** * Display object has an invalid concatenated matrix because its matrix or one of its * ancestor's matrices has been mutated. */ InvalidConcatenatedMatrix = 32, /** * Display object has an invalid inverted concatenated matrix because its matrix or one of its * ancestor's matrices has been mutated. We don't always need to compute the inverted matrix. * This is why we use a sepearete invalid flag for it and don't roll it under the * |InvalidConcatenatedMatrix| flag. */ InvalidInvertedConcatenatedMatrix = 64, /** * Display object has an invalid concatenated color transform because its color transform or * one of its ancestor's color transforms has been mutated. */ InvalidConcatenatedColorTransform = 128, /** * The display object's constructor has been executed or any of the derived class constructors * have executed. It may be that the derived class doesn't call super, in such cases this flag * must be set manually elsewhere. */ Constructed = 256, /** * Display object has been removed by the timeline but it no longer recieves any event. */ Destroyed = 512, /** * Indicates wether an AVM1 load event needs to be dispatched on this display object. */ NeedsLoadEvent = 1024, /** * Display object is owned by the timeline, meaning that it is under the control of the * timeline and that a reference to this object has not leaked into AS3 code via the * DisplayObjectContainer methods |getChildAt|, |getChildByName| or through the execution of * the symbol class constructor. */ OwnedByTimeline = 2048, /** * Display object is animated by the timeline. It may no longer be owned by the timeline * (|OwnedByTimeline|) but it is still animated by it. If AS3 code mutates any property on the * display object, this flag is cleared and further timeline mutations are ignored. */ AnimatedByTimeline = 4096, /** * MovieClip object has reached a frame with a frame script or ran a frame script that attached * a new one to the current frame. To run the script, it has to be appended to the queue of * scripts. */ HasFrameScriptPending = 8192, /** * DisplayObjectContainer contains at least one descendant with the HasFrameScriptPending flag * set. */ ContainsFrameScriptPendingChildren = 16384, /** * Indicates whether this display object is a MorphShape or contains at least one descendant * that is. */ ContainsMorph = 32768, /** * Indicates whether this display object should be cached as a bitmap. The display object may * be cached as bitmap even if this flag is not set, depending on whether any filters are * applied or if the bitmap is too large or we've run out of memory. */ CacheAsBitmap = 65536, /** * Indicates whether an AVM1 timeline needs to initialize an object after place object * occurred. */ HasPlaceObjectInitPending = 131072, /** * Indicates whether a transform.perspectiveProjection was set. */ HasPerspectiveProjection = 262144, /** * Indicates whether this display object has dirty descendents. If this flag is set then the * subtree need to be synchronized. */ DirtyDescendents = 536870912, /** * Masks flags that need to be propagated up when this display object gets added to a parent. */ Bubbling = 536920064 } export declare const enum DisplayObjectDirtyFlags { /** * Indicates whether this display object's matrix has changed since the last time it was * synchronized. */ DirtyMatrix = 1, /** * Indicates whether this display object's children list is dirty. */ DirtyChildren = 2, /** * Indicates whether this display object's graphics has changed since the last time it was * synchronized. */ DirtyGraphics = 4, /** * Indicates whether this display object's text content has changed since the last time it was * synchronized. */ DirtyTextContent = 8, /** * Indicates whether this display object's bitmap data has changed since the last time it was * synchronized. */ DirtyBitmapData = 16, /** * Indicates whether this display object's bitmap data has changed since the last time it was * synchronized. */ DirtyNetStream = 32, /** * Indicates whether this display object's color transform has changed since the last time it * was synchronized. */ DirtyColorTransform = 64, /** * Indicates whether this display object's mask has changed since the last time it was * synchronized. */ DirtyMask = 128, /** * Indicates whether this display object's clip depth has changed since the last time it was * synchronized. */ DirtyClipDepth = 256, /** * Indicates whether this display object's other properties have changed. We need to split this * up in multiple bits so we don't serialize as much: * * So far we only mark these properties here: * * blendMode, * scale9Grid, * cacheAsBitmap, * filters, * visible, */ DirtyMiscellaneousProperties = 512, /** * All synchronizable properties are dirty. */ Dirty = 1023 } /** * Controls how the visitor walks the display tree. */ export declare const enum VisitorFlags { /** * None */ None = 0, /** * Continue with normal traversal. */ Continue = 0, /** * Not used yet, should probably just stop the visitor. */ Stop = 1, /** * Skip processing current node. */ Skip = 2, /** * Visit front to back. */ FrontToBack = 8, /** * Only visit the nodes matching a certain flag set. */ Filter = 16 } export declare const enum HitTestingType { HitTestBounds = 0, HitTestBoundsAndMask = 1, HitTestShape = 2, Mouse = 3, ObjectsUnderPoint = 4, Drop = 5 } export declare const enum HitTestingResult { None = 0, Bounds = 1, Shape = 2 } export interface IAdvancable extends IReferenceCountable { _initFrame(advance: boolean): void; _constructFrame(): void; } export declare class DisplayObject extends EventDispatcher implements IBitmapDrawable, IRemotable { static axClass: typeof DisplayObject & AXClass; /** * Every displayObject is assigned an unique integer ID. */ static getNextSyncID(): number; /** * DisplayObject#name is set to an initial value of 'instanceN', where N is auto-incremented. * This is true for all DisplayObjects except for Stage, so it happens in an overrideable * method. */ static _instanceID: number; static _advancableInstances: WeakList; static classInitializer(): void; static reset(): void; static classSymbols: string[]; static instanceSymbols: string[]; /** * Creates a new display object from a symbol and initializes its animated display properties. * Calling its constructor is optional at this point, since that can happen in a later frame * phase. */ createAnimatedDisplayObject(symbol: DisplaySymbol, placeObjectTag: PlaceObjectTag, callConstructor: boolean): DisplayObject; private static _runScripts; static _stage: Stage; /** * Runs one full turn of the frame events cycle. * * Frame navigation methods on MovieClip can trigger nested frame events cycles. These nested * cycles do everything the outermost cycle does, except for broadcasting the ENTER_FRAME * event. * * If runScripts is true, no events are dispatched and Movieclip frame scripts are run. This * is true for nested cycles, too. (We keep static state for that.) */ static performFrameNavigation(mainLoop: boolean, runScripts: boolean): void; /** * Dispatches a frame event on all instances of DisplayObjects. */ static _broadcastFrameEvent(type: string): void; constructor(); protected _initializeFields(): void; /** * Sets the object's initial name to adhere to the 'instanceN' naming scheme. */ _setInitialName(): void; _setParent(parent: DisplayObjectContainer, depth: number): void; _setDepth(value: number): void; _setFillAndLineBoundsFromWidthAndHeight(width: number, height: number): void; _setFillAndLineBoundsFromSymbol(symbol: DisplaySymbol): void; _setFlags(flags: DisplayObjectFlags): void; /** * Use this to set dirty flags so that we can also propagate the dirty child bit. */ _setDirtyFlags(flags: DisplayObjectDirtyFlags): void; _removeDirtyFlags(flags: DisplayObjectDirtyFlags): void; _hasDirtyFlags(flags: DisplayObjectDirtyFlags): boolean; _hasAnyDirtyFlags(flags: DisplayObjectDirtyFlags): boolean; _toggleFlags(flags: DisplayObjectFlags, on: boolean): void; _removeFlags(flags: DisplayObjectFlags): void; _hasFlags(flags: DisplayObjectFlags): boolean; _hasAnyFlags(flags: DisplayObjectFlags): boolean; /** * Propagates flags up the display list. Propagation stops if all flags are already set. */ _propagateFlagsUp(flags: DisplayObjectFlags): void; /** * Propagates flags down the display list. Non-containers just set the flags on themselves. * * Overridden in DisplayObjectContainer. */ _propagateFlagsDown(flags: DisplayObjectFlags): void; _id: number; private _flags; private _dirtyFlags; _root: DisplayObject; _stage: Stage; _name: string; _parent: DisplayObjectContainer; _mask: DisplayObject; /** * These are always the most up to date properties. The |_matrix| is kept in sync with * these values. This is only true when |_matrix3D| is null. */ _scaleX: number; _scaleY: number; _skewX: number; _skewY: number; _z: number; _scaleZ: number; _rotation: number; _rotationX: number; _rotationY: number; _rotationZ: number; _mouseX: number; _mouseY: number; _width: number; _height: number; _opaqueBackground: ASObject; _scrollRect: Rectangle; _filters: any[]; _blendMode: string; _scale9Grid: Bounds; _loaderInfo: LoaderInfo; _accessibilityProperties: AccessibilityProperties; /** * Bounding box excluding strokes. */ _fillBounds: Bounds; /** * Bounding box including strokes. */ _lineBounds: Bounds; _clipDepth: number; /** * The a, b, c, d components of the matrix are only valid if the InvalidMatrix flag * is not set. Don't access this directly unless you can be sure that its components * are valid. */ _matrix: Matrix; _invertedMatrix: Matrix; _concatenatedMatrix: Matrix; _invertedConcatenatedMatrix: Matrix; _colorTransform: ColorTransform; _concatenatedColorTransform: ColorTransform; _matrix3D: Matrix3D; _perspectiveProjectionFOV: number; _perspectiveProjectionCenterX: number; _perspectiveProjectionCenterY: number; _perspectiveProjection: PerspectiveProjection; _depth: number; _ratio: number; /** * Index of this display object within its container's children */ _index: number; _isContainer: boolean; _maskedObject: DisplayObject; _mouseOver: boolean; _mouseDown: boolean; _symbol: DisplaySymbol; _placeObjectTag: PlaceObjectTag; _graphics: Graphics; /** * This is only ever used in classes that can have children, like |DisplayObjectContainer| or * |SimpleButton|. */ _children: DisplayObject[]; /** * */ _referenceCount: number; /** * Finds the nearest ancestor with a given set of flags that are either turned on or off. */ private _findNearestAncestor; _findFurthestAncestorOrSelf(): DisplayObject; /** * Tests if this display object is an ancestor of the specified display object. */ _isAncestor(child: DisplayObject): boolean; /** * Clamps the rotation value to the range (-180, 180). */ private static _clampRotation; /** * Used as a temporary array to avoid allocations. */ private static _path; /** * Return's a list of ancestors excluding the |last|, the return list is reused. */ private static _getAncestors; /** * Computes the combined transformation matrixes of this display object and all of its parents. * It is not the same as |transform.concatenatedMatrix|, the latter also includes the screen * space matrix. */ _getConcatenatedMatrix(): Matrix; _getInvertedConcatenatedMatrix(): Matrix; _setMatrix(matrix: Matrix, toTwips: boolean): void; /** * Returns an updated matrix if the current one is invalid. */ _getMatrix(): Matrix; _getInvertedMatrix(): Matrix; /** * Computes the combined transformation color matrixes of this display object and all of its * ancestors. */ _getConcatenatedColorTransform(): ColorTransform; _setColorTransform(colorTransform: ColorTransform): void; /** * Invalidates the fill- and lineBounds of this display object along with all of its ancestors. */ _invalidateFillAndLineBounds(fill: boolean, line: boolean): void; _invalidateParentFillAndLineBounds(fill: boolean, line: boolean): void; /** * Computes the bounding box for all of this display object's content, its graphics and all of * its children. */ _getContentBounds(includeStrokes?: boolean): Bounds; /** * Empty base case: DisplayObject cannot have children, but several distinct subclasses can. * Overridden in DisplayObjectContainer, SimpleButton, and AVM1Movie. */ _getChildBounds(bounds: Bounds, includeStrokes: boolean): void; /** * Gets the bounds of this display object relative to another coordinate space. The * transformation matrix from the local coordinate space to the target coordinate space is * computed using: * * this.concatenatedMatrix * inverse(target.concatenatedMatrix) * * If the |targetCoordinateSpace| is |null| then assume the identity coordinate space. */ _getTransformedBounds(targetCoordinateSpace: DisplayObject, includeStroke: boolean): Bounds; /** * Detaches this object from being animated by the timeline. This happens whenever a display * property of this object is changed by user code. */ private _stopTimelineAnimation; /** * Marks this object as having its matrix changed. * * Propagates flags both up- and (via invalidatePosition) downwards, so is quite costly. * TODO: check if we can usefully combine all upwards-propagated flags here. */ private _invalidateMatrix; /** * Marks this object as having been moved in its parent display object. */ _invalidatePosition(): void; /** * Animates this object's display properties. */ _animate(placeObjectTag: PlaceObjectTag): void; /** * Dispatches an event on this object and all its descendants. */ _propagateEvent(event: Event): void; get x(): number; _getX(): number; set x(value: number); get y(): number; _getY(): number; set y(value: number); /** * In Flash player, this always returns a positive number for some reason. This however, is not * the case for scaleY. */ get scaleX(): number; set scaleX(value: number); get scaleY(): number; set scaleY(value: number); get scaleZ(): number; set scaleZ(value: number); get rotation(): number; set rotation(value: number); get rotationX(): number; set rotationX(value: number); get rotationY(): number; set rotationY(value: number); get rotationZ(): number; set rotationZ(value: number); /** * The width of this display object in its parent coordinate space. */ get width(): number; _getWidth(): any; /** * Attempts to change the width of this display object by changing its scaleX / scaleY * properties. The scaleX property is set to the specified |width| value / baseWidth * of the object in its parent cooridnate space with rotation applied. */ set width(value: number); _setWidth(value: number): void; /** * The height of this display object in its parent coordinate space. */ get height(): number; _getHeight(): number; /** * Attempts to change the height of this display object by changing its scaleY / scaleX * properties. The scaleY property is set to the specified |height| value / baseHeight * of the object in its parent cooridnate space with rotation applied. */ set height(value: number); _setHeight(value: number): void; get mask(): DisplayObject; /** * Sets the mask for this display object. This does not affect the bounds. */ set mask(value: DisplayObject); get transform(): Transform; _getTransform(): Transform; set transform(value: Transform); private destroy; /** * Walks up the tree to find this display object's root. An object is classified * as a root if its _root property points to itself. Root objects are the Stage, * the main timeline object and a Loader's content. */ get root(): DisplayObject; /** * Walks up the tree to find this display object's stage, the first object whose * |_stage| property points to itself. */ get stage(): Stage; get name(): string; set name(value: string); get parent(): DisplayObjectContainer; get alpha(): number; set alpha(value: number); get blendMode(): string; set blendMode(value: string); get scale9Grid(): Rectangle; _getScale9Grid(): Rectangle; set scale9Grid(innerRectangle: Rectangle); /** * This is always true if a filter is applied. */ get cacheAsBitmap(): boolean; _getCacheAsBitmap(): boolean; set cacheAsBitmap(value: boolean); /** * References to the internal |_filters| array and its BitmapFilter objects are never leaked * outside of this class. The get/set filters accessors always return deep clones of this * array. */ get filters(): ASArray; _getFilters(): any; set filters(value_: ASArray); get visible(): boolean; /** * Marks this display object as visible / invisible. This does not affect the bounds. */ set visible(value: boolean); get z(): number; set z(value: number); getBounds(targetCoordinateSpace: DisplayObject): Rectangle; getRect(targetCoordinateSpace: DisplayObject): Rectangle; /** * Converts a point from the global coordinate space into the local coordinate space. */ globalToLocal(point: Point): Point; /** * Converts a point form the local coordinate sapce into the global coordinate space. */ localToGlobal(point: Point): Point; globalToLocal3D(point: Point): Vector3D; localToGlobal3D(point: Point): Vector3D; local3DToGlobal(point3d: Vector3D): Point; /** * Tree visitor that lets you skip nodes or return early. */ visit(visitor: (DisplayObject: any) => VisitorFlags, visitorFlags: VisitorFlags, displayObjectFlags?: DisplayObjectFlags): void; /** * Returns the loader info for this display object's root. */ get loaderInfo(): LoaderInfo; /** * Only these objects can have graphics. */ _canHaveGraphics(): boolean; /** * Gets the graphics object of this object. Shapes, MorphShapes, and Sprites override this. */ _getGraphics(): Graphics; /** * Only these objects can have text content. */ _canHaveTextContent(): boolean; /** * Gets the text content of this object. StaticTexts and TextFields override this. */ _getTextContent(): any; /** * Lazily construct a graphics object. */ _ensureGraphics(): Graphics; /** * Sets this object's graphics or text content. Happens when an animated Shape or StaticText * object is initialized from a symbol or replaced by a timeline command using the same symbol * as this object was initialized from. */ _setStaticContentFromSymbol(symbol: DisplaySymbol): void; /** * Checks if the bounding boxes of two display objects overlap, this happens in the global * coordinate coordinate space. * * Two objects overlap even if one or both are not on the stage, as long as their bounds * in the global coordinate space overlap. */ hitTestObject(other: DisplayObject): boolean; /** * The |globalX| and |globalY| arguments are in global coordinates. The |shapeFlag| indicates * whether the hit test should be on the actual shape of the object or just its bounding box. * * Note: shapeFlag is optional, but the type coercion will do the right thing for it, so we * don't need to take the overhead from being explicit about that. */ hitTestPoint(globalX: number, globalY: number, shapeFlag: boolean): boolean; /** * Internal implementation of all point intersection checks. * * _containsPoint is used for * - mouse/drop target finding * - getObjectsUnderPoint * - hitTestPoint * * Mouse/Drop target finding and getObjectsUnderPoint require checking against the exact shape, * and making sure that the checked coordinates aren't hidden through masking or clipping. * * hitTestPoint never checks for clipping, and masking only for testingType HitTestShape. * * The `objects` object is used for collecting objects for `getObjectsUnderPoint` or looking * for a drop target. If it is supplied, objects for which `_containsPointDirectly` is true are * added to it. * * Overridden in DisplayObjectContainer, Sprite and SimpleButton. */ _containsPoint(globalX: number, globalY: number, localX: number, localY: number, testingType: HitTestingType, objects: DisplayObject[]): HitTestingResult; _containsGlobalPoint(globalX: number, globalY: number, testingType: HitTestingType, objects: DisplayObject[]): HitTestingResult; /** * Fast check if a point can intersect the receiver object. Returns true if * - the object is visible OR hit testing is performed for one of the `hitTest{Point,Object}` * methods. * - the point is within the receiver's bounds * - for testingType values other than HitTestBounds, the point intersects with the a mask, * if the object has one. * * Note that the callers are expected to have both local and global coordinates available * anyway, so _boundsAndMaskContainPoint takes both to avoid recalculating them. */ _boundsAndMaskContainPoint(globalX: number, globalY: number, localX: number, localY: number, testingType: HitTestingType): HitTestingResult; /** * Tests if the receiver's own visual content intersects with the given point. * In the base implementation, this just returns false, because not all DisplayObjects can * ever match. * Overridden in Shape, MorphShape, Sprite, Bitmap, Video, and TextField. */ _containsPointDirectly(localX: number, localY: number, globalX: number, globalY: number): boolean; get scrollRect(): Rectangle; _getScrollRect(): Rectangle; set scrollRect(value: Rectangle); get opaqueBackground(): any; /** * Sets the opaque background color. By default this is |null|, which indicates that no opaque * color is set. Otherwise this is an unsinged number. */ set opaqueBackground(value: any); /** * Returns the distance between this object and a given ancestor. */ private _getDistance; /** * Finds the nearest common ancestor with a given node. */ findNearestCommonAncestor(node: DisplayObject): DisplayObject; /** * Returns the current mouse position relative to this object. */ _getLocalMousePosition(): Point; get mouseX(): number; get mouseY(): number; debugName(withFlags?: boolean): string; debugNameShort(): string; hashCode(): number; getAncestorCount(): number; debugTrace(writer?: IndentingWriter, maxDistance?: number, name?: string): void; _addReference(): void; _removeReference(): void; /** * Returns script precedence sequence based on placeObjectTag. Creates every * time a new array, so it's safe to modify it. * @private */ _getScriptPrecedence(): number[]; get accessibilityProperties(): AccessibilityProperties; set accessibilityProperties(value: AccessibilityProperties); set blendShader(value: any); }