⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicslayerca.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 4 页
字号:
    GraphicsLayerCA* childLayerCA = static_cast<GraphicsLayerCA*>(childLayer);    BEGIN_BLOCK_OBJC_EXCEPTIONS    [hostLayerForSublayers() insertSublayer:childLayerCA->layerForSuperlayer() atIndex:index];    END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling){    // FIXME: share code with base class    ASSERT(childLayer != this);    childLayer->removeFromParent();    bool found = false;    for (unsigned i = 0; i < m_children.size(); i++) {        if (sibling == m_children[i]) {            m_children.insert(i, childLayer);            found = true;            break;        }    }    childLayer->setParent(this);    BEGIN_BLOCK_OBJC_EXCEPTIONS    GraphicsLayerCA* childLayerCA = static_cast<GraphicsLayerCA*>(childLayer);    GraphicsLayerCA* siblingLayerCA = static_cast<GraphicsLayerCA*>(sibling);    if (found)        [hostLayerForSublayers() insertSublayer:childLayerCA->layerForSuperlayer() below:siblingLayerCA->layerForSuperlayer()];    else {        m_children.append(childLayer);        [hostLayerForSublayers() addSublayer:childLayerCA->layerForSuperlayer()];    }    END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling){    // FIXME: share code with base class    ASSERT(childLayer != this);    childLayer->removeFromParent();    unsigned i;    bool found = false;    for (i = 0; i < m_children.size(); i++) {        if (sibling == m_children[i]) {            m_children.insert(i+1, childLayer);            found = true;            break;        }    }    childLayer->setParent(this);    BEGIN_BLOCK_OBJC_EXCEPTIONS    GraphicsLayerCA* childLayerCA = static_cast<GraphicsLayerCA*>(childLayer);    GraphicsLayerCA* siblingLayerCA = static_cast<GraphicsLayerCA*>(sibling);    if (found) {        [hostLayerForSublayers() insertSublayer:childLayerCA->layerForSuperlayer() above:siblingLayerCA->layerForSuperlayer()];    } else {        m_children.append(childLayer);        [hostLayerForSublayers() addSublayer:childLayerCA->layerForSuperlayer()];    }    END_BLOCK_OBJC_EXCEPTIONS}bool GraphicsLayerCA::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild){    // FIXME: share code with base class    ASSERT(!newChild->parent());    bool found = false;    for (unsigned i = 0; i < m_children.size(); i++) {        if (oldChild == m_children[i]) {            m_children[i] = newChild;            found = true;            break;        }    }    if (found) {        oldChild->setParent(0);        newChild->removeFromParent();        newChild->setParent(this);        BEGIN_BLOCK_OBJC_EXCEPTIONS        GraphicsLayerCA* oldChildCA = static_cast<GraphicsLayerCA*>(oldChild);        GraphicsLayerCA* newChildCA = static_cast<GraphicsLayerCA*>(newChild);        [hostLayerForSublayers() replaceSublayer:oldChildCA->layerForSuperlayer() with:newChildCA->layerForSuperlayer()];        END_BLOCK_OBJC_EXCEPTIONS        return true;    }    return false;}void GraphicsLayerCA::removeFromParent(){    GraphicsLayer::removeFromParent();    BEGIN_BLOCK_OBJC_EXCEPTIONS    [layerForSuperlayer() removeFromSuperlayer];                END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::setPosition(const FloatPoint& point){    // Don't short-circuit here, because position and anchor point are inter-dependent.    GraphicsLayer::setPosition(point);    // Position is offset on the layer by the layer anchor point.    CGPoint posPoint = CGPointMake(m_position.x() + m_anchorPoint.x() * m_size.width(),                                   m_position.y() + m_anchorPoint.y() * m_size.height());        BEGIN_BLOCK_OBJC_EXCEPTIONS    [primaryLayer() setPosition:posPoint];    END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::setAnchorPoint(const FloatPoint3D& point){    // Don't short-circuit here, because position and anchor point are inter-dependent.    bool zChanged = (point.z() != m_anchorPoint.z());    GraphicsLayer::setAnchorPoint(point);    BEGIN_BLOCK_OBJC_EXCEPTIONS    // set the value on the layer to the new transform.    [primaryLayer() setAnchorPoint:FloatPoint(point.x(), point.y())];    if (zChanged) {#if HAVE_MODERN_QUARTZCORE        [primaryLayer() setAnchorPointZ:m_anchorPoint.z()];#endif    }    // Position depends on anchor point, so update it now.    setPosition(m_position);    END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::setSize(const FloatSize& size){    GraphicsLayer::setSize(size);    CGRect rect = CGRectMake(0.0f,                             0.0f,                             m_size.width(),                             m_size.height());        CGPoint centerPoint = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f);        BEGIN_BLOCK_OBJC_EXCEPTIONS    if (m_transformLayer) {        [m_transformLayer.get() setBounds:rect];            // the anchor of the contents layer is always at 0.5, 0.5, so the position        // is center-relative        [m_layer.get() setPosition:centerPoint];    }        bool needTiledLayer = requiresTiledLayer(m_size);    if (needTiledLayer != m_usingTiledLayer)        swapFromOrToTiledLayer(needTiledLayer);        [m_layer.get() setBounds:rect];    // Note that we don't resize m_contentsLayer. It's up the caller to do that.    END_BLOCK_OBJC_EXCEPTIONS    // if we've changed the bounds, we need to recalculate the position    // of the layer, taking anchor point into account    setPosition(m_position);}void GraphicsLayerCA::setTransform(const TransformationMatrix& t){    GraphicsLayer::setTransform(t);        BEGIN_BLOCK_OBJC_EXCEPTIONS    CATransform3D transform;    copyTransform(transform, t);    [primaryLayer() setTransform:transform];    END_BLOCK_OBJC_EXCEPTIONS        // Remove any old transition entries for transform.    removeAllAnimationsForProperty(AnimatedPropertyWebkitTransform);    // Even if we don't have a transition in the list, the layer may still have one.    // This happens when we are setting the final transform value after an animation or    // transition has ended. In removeAnimation we toss the entry from the list but don't    // remove it from the list. That way we aren't in danger of displaying a stale transform    // in the time between removing the animation and setting the new unanimated value. We     // can't do this in removeAnimation because we don't know the new transform value there.    String keyPath = propertyIdToString(AnimatedPropertyWebkitTransform);    CALayer* layer = animatedLayer(AnimatedPropertyWebkitTransform);        for (int i = 0; ; ++i) {        String animName = keyPath + "_" + String::number(i);        if (![layer animationForKey: animName])            break;        [layer removeAnimationForKey:animName];    }}void GraphicsLayerCA::setChildrenTransform(const TransformationMatrix& t){    if (t == m_childrenTransform)        return;    GraphicsLayer::setChildrenTransform(t);    CATransform3D transform;    copyTransform(transform, t);    BEGIN_BLOCK_OBJC_EXCEPTIONS    // Set the value on the layer to the new transform.    [primaryLayer() setSublayerTransform:transform];    END_BLOCK_OBJC_EXCEPTIONS}static void moveAnimation(AnimatedPropertyID property, CALayer* fromLayer, CALayer* toLayer){    String keyPath = GraphicsLayer::propertyIdToString(property);    for (short index = 0; ; ++index) {        String animName = keyPath + "_" + String::number(index);        CAAnimation* anim = [fromLayer animationForKey:animName];        if (!anim)            break;        [anim retain];        [fromLayer removeAnimationForKey:animName];        [toLayer addAnimation:anim forKey:animName];        [anim release];    }}static void moveSublayers(CALayer* fromLayer, CALayer* toLayer){    NSArray* sublayersCopy = [[fromLayer sublayers] copy]; // Avoid mutation while enumerating, and keep the sublayers alive.    NSEnumerator* childrenEnumerator = [sublayersCopy objectEnumerator];    CALayer* layer;    while ((layer = [childrenEnumerator nextObject]) != nil) {        [layer removeFromSuperlayer];        [toLayer addSublayer:layer];    }    [sublayersCopy release];}void GraphicsLayerCA::setPreserves3D(bool preserves3D){    GraphicsLayer::setPreserves3D(preserves3D);    CGPoint point = CGPointMake(m_size.width() / 2.0f, m_size.height() / 2.0f);    CGPoint centerPoint = CGPointMake(0.5f, 0.5f);        BEGIN_BLOCK_OBJC_EXCEPTIONS    Class transformLayerClass = NSClassFromString(@"CATransformLayer");    if (preserves3D && !m_transformLayer && transformLayerClass) {        // Create the transform layer.        m_transformLayer.adoptNS([[transformLayerClass alloc] init]);        // Turn off default animations.        [m_transformLayer.get() setStyle:[NSDictionary dictionaryWithObject:nullActionsDictionary() forKey:@"actions"]];        #ifndef NDEBUG        [m_transformLayer.get() setName:[NSString stringWithFormat:@"Transform Layer CATransformLayer(%p) GraphicsLayer(%p)", m_transformLayer.get(), this]];#endif        // Copy the position from this layer.        [m_transformLayer.get() setBounds:[m_layer.get() bounds]];        [m_transformLayer.get() setPosition:[m_layer.get() position]];        [m_transformLayer.get() setAnchorPoint:[m_layer.get() anchorPoint]];#if HAVE_MODERN_QUARTZCORE        [m_transformLayer.get() setAnchorPointZ:[m_layer.get() anchorPointZ]];#endif        [m_transformLayer.get() setContentsRect:[m_layer.get() contentsRect]];#ifndef NDEBUG        [m_transformLayer.get() setZPosition:[m_layer.get() zPosition]];#endif                // The contents layer is positioned at (0,0) relative to the transformLayer.        [m_layer.get() setPosition:point];        [m_layer.get() setAnchorPoint:centerPoint];#ifndef NDEBUG        [m_layer.get() setZPosition:0.0f];#endif                // Transfer the transform over.        [m_transformLayer.get() setTransform:[m_layer.get() transform]];        [m_layer.get() setTransform:CATransform3DIdentity];                // Transfer the opacity from the old layer to the transform layer.        [m_transformLayer.get() setOpacity:m_opacity];        [m_layer.get() setOpacity:1];        // Move this layer to be a child of the transform layer.        [[m_layer.get() superlayer] replaceSublayer:m_layer.get() with:m_transformLayer.get()];        [m_transformLayer.get() addSublayer:m_layer.get()];        moveAnimation(AnimatedPropertyWebkitTransform, m_layer.get(), m_transformLayer.get());        moveSublayers(m_layer.get(), m_transformLayer.get());    } else if (!preserves3D && m_transformLayer) {        // Relace the transformLayer in the parent with this layer.        [m_layer.get() removeFromSuperlayer];        [[m_transformLayer.get() superlayer] replaceSublayer:m_transformLayer.get() with:m_layer.get()];        moveAnimation(AnimatedPropertyWebkitTransform, m_transformLayer.get(), m_layer.get());        moveSublayers(m_transformLayer.get(), m_layer.get());        // Reset the layer position and transform.        [m_layer.get() setPosition:[m_transformLayer.get() position]];        [m_layer.get() setAnchorPoint:[m_transformLayer.get() anchorPoint]];#if HAVE_MODERN_QUARTZCORE        [m_layer.get() setAnchorPointZ:[m_transformLayer.get() anchorPointZ]];#endif        [m_layer.get() setContentsRect:[m_transformLayer.get() contentsRect]];        [m_layer.get() setTransform:[m_transformLayer.get() transform]];        [m_layer.get() setOpacity:[m_transformLayer.get() opacity]];#ifndef NDEBUG        [m_layer.get() setZPosition:[m_transformLayer.get() zPosition]];#endif        // Release the transform layer.        m_transformLayer = 0;    }    END_BLOCK_OBJC_EXCEPTIONS}void GraphicsLayerCA::setMasksToBounds(bool masksToBounds){    if (masksToBounds == m_masksToBounds)        return;    GraphicsLayer::setMasksToBounds(masksToBounds);    BEGIN_BLOCK_OBJC_EXCEPTIONS    [m_layer.get() setMasksToBounds:masksToBounds];    END_BLOCK_OBJC_EXCEPTIONS#ifndef NDEBUG    updateDebugIndicators();#endif}void GraphicsLayerCA::setDrawsContent(bool drawsContent){    if (drawsContent != m_drawsContent) {        GraphicsLayer::setDrawsContent(drawsContent);        bool needTiledLayer = requiresTiledLayer(m_size);        if (needTiledLayer != m_usingTiledLayer)            swapFromOrToTiledLayer(needTiledLayer);        BEGIN_BLOCK_OBJC_EXCEPTIONS        // Clobber any existing content. If necessary, CA will create backing store on the next display.        [m_layer.get() setContents:nil];        #ifndef NDEBUG        updateDebugIndicators();#endif        END_BLOCK_OBJC_EXCEPTIONS    }}void GraphicsLayerCA::setBackgroundColor(const Color& color, const Animation* transition, double beginTime){    GraphicsLayer::setBackgroundColor(color, transition, beginTime);    BEGIN_BLOCK_OBJC_EXCEPTIONS    setHasContentsLayer(true);        if (transition && !transition->isEmptyOrZeroDuration()) {        CALayer* presLayer = [m_contentsLayer.get() presentationLayer];        // If we don't have a presentationLayer, just use the CALayer        if (!presLayer)            presLayer = m_contentsLayer.get();        // Get the current value of the background color from the layer        CGColorRef fromBackgroundColor = [presLayer backgroundColor];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -