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

📄 renderlayerbacking.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    } else if (m_clippingLayer) {        m_clippingLayer->removeFromParent();        delete m_clippingLayer;        m_clippingLayer = 0;        layersChanged = true;    }        if (layersChanged)        updateInternalHierarchy();    return layersChanged;}bool RenderLayerBacking::updateContentsLayer(bool needsContentsLayer){    bool layerChanged = false;    if (needsContentsLayer) {        if (!m_contentsLayer) {            m_contentsLayer = GraphicsLayer::createGraphicsLayer(this);#ifndef NDEBUG            m_contentsLayer->setName("Contents");#endif            m_contentsLayer->setDrawsContent(true);            m_contentsLayer->setDrawingPhase(GraphicsLayerPaintForegroundMask);            m_graphicsLayer->setDrawingPhase(GraphicsLayerPaintBackgroundMask);            layerChanged = true;        }    } else if (m_contentsLayer) {        m_contentsLayer->removeFromParent();        delete m_contentsLayer;        m_contentsLayer = 0;        m_graphicsLayer->setDrawingPhase(GraphicsLayerPaintAllMask);        layerChanged = true;    }    return layerChanged;}float RenderLayerBacking::compositingOpacity(float rendererOpacity) const{    float finalOpacity = rendererOpacity;        for (RenderLayer* curr = m_owningLayer->parent(); curr; curr = curr->parent()) {        // We only care about parents that are stacking contexts.        // Recall that opacity creates stacking context.        if (!curr->isStackingContext())            continue;                // If we found a compositing layer, we want to compute opacity        // relative to it. So we can break here.        if (curr->isComposited())            break;                finalOpacity *= curr->renderer()->opacity();    }    return finalOpacity;}// A simple background is either none or a solid color.static bool hasSimpleBackground(RenderStyle* style){    return !style->hasBackgroundImage();}static bool hasBorderOutlineOrShadow(RenderStyle* style){    return (style->hasBorder() || style->hasBorderRadius() || style->hasOutline() || (style->boxShadow() != 0));}bool RenderLayerBacking::rendererHasBackground() const{    // FIXME: share more code here    if (renderer()->node()->isDocumentNode()) {        RenderObject* htmlObject = renderer()->firstChild();        if (!htmlObject)            return false;                RenderStyle* style = htmlObject->style();        if (style->hasBackground())            return true;                RenderObject* bodyObject = htmlObject->firstChild();        if (!bodyObject)            return false;                style = bodyObject->style();        return style->hasBackground();    }        return renderer()->style()->hasBackground();}const Color& RenderLayerBacking::rendererBackgroundColor() const{    // FIXME: share more code here    if (renderer()->node()->isDocumentNode()) {        RenderObject* htmlObject = renderer()->firstChild();        RenderStyle* style = htmlObject->style();        if (style->hasBackground())            return style->backgroundColor();        RenderObject* bodyObject = htmlObject->firstChild();        style = bodyObject->style();        return style->backgroundColor();    }    return renderer()->style()->backgroundColor();}bool RenderLayerBacking::canBeSimpleContainerCompositingLayer() const{    RenderObject* renderObject = renderer();    if (renderObject->isReplaced() ||       // replaced objects are not containers        renderObject->hasMask())            // masks require special treatment        return false;    RenderStyle* style = renderObject->style();    // Reject anything that has a border, a border-radius or outline,    // or any background (color or image).    // FIXME: we could optimize layers for simple backgrounds.    if (hasBorderOutlineOrShadow(style) ||        style->hasBackground())        return false;    // If we have got this far and the renderer has no children, then we're ok.    if (!renderObject->firstChild())        return true;        if (renderObject->node()->isDocumentNode()) {        // Look to see if the root object has a non-simple backgound        RenderObject* rootObject = renderObject->document()->documentElement()->renderer();        if (!rootObject)            return false;                style = rootObject->style();                // Reject anything that has a border, a border-radius or outline,        // or is not a simple background (no background, or solid color).        if (hasBorderOutlineOrShadow(style) ||            !hasSimpleBackground(style))            return false;                // Now look at the body's renderer.        HTMLElement* body = renderObject->document()->body();        RenderObject* bodyObject = (body && body->hasLocalName(HTMLNames::bodyTag)) ? body->renderer() : 0;        if (!bodyObject)            return false;                style = bodyObject->style();                if (hasBorderOutlineOrShadow(style) ||            !hasSimpleBackground(style))            return false;        // Ceck to see if all the body's children are compositing layers.        if (hasNonCompositingContent())            return false;                return true;    }    // Check to see if all the renderer's children are compositing layers.    if (hasNonCompositingContent())        return false;        return true;}bool RenderLayerBacking::hasNonCompositingContent() const{    // Conservative test for having no rendered children.        // Some HTML can cause whitespace text nodes to have renderers, like:    // <div>    // <img src=...>    // </div>    // so test for 0x0 RenderTexts here    for (RenderObject* child = renderer()->firstChild(); child; child = child->nextSibling()) {        if (!child->hasLayer()) {            if (child->isRenderInline() || !child->isBox())                return true;                        if (toRenderBox(child)->width() > 0 || toRenderBox(child)->height() > 0)                return true;        }    }    // FIXME: test for overflow controls.    if (m_owningLayer->isStackingContext()) {        // Use the m_hasCompositingDescendant bit to optimize?        Vector<RenderLayer*>* negZOrderList = m_owningLayer->negZOrderList();        if (negZOrderList && negZOrderList->size() > 0) {            for (Vector<RenderLayer*>::const_iterator it = negZOrderList->begin(); it != negZOrderList->end(); ++it) {                RenderLayer* curLayer = (*it);                if (!curLayer->isComposited())                    return true;            }        }        Vector<RenderLayer*>* posZOrderList = m_owningLayer->posZOrderList();        if (posZOrderList && posZOrderList->size() > 0) {            for (Vector<RenderLayer*>::const_iterator it = posZOrderList->begin(); it != posZOrderList->end(); ++it) {                RenderLayer* curLayer = (*it);                if (!curLayer->isComposited())                    return true;            }        }    }    Vector<RenderLayer*>* normalFlowList = m_owningLayer->normalFlowList();    if (normalFlowList && normalFlowList->size() > 0) {        for (Vector<RenderLayer*>::const_iterator it = normalFlowList->begin(); it != normalFlowList->end(); ++it) {            RenderLayer* curLayer = (*it);            if (!curLayer->isComposited())                return true;        }    }    return false;}// A "simple container layer" is a RenderLayer which has no visible content to render.// It may have no children, or all its children may be themselves composited.// This is a useful optimization, because it allows us to avoid allocating backing store.bool RenderLayerBacking::isSimpleContainerCompositingLayer(){    if (m_simpleCompositingLayerStatusDirty) {        m_isSimpleContainerCompositingLayer = canBeSimpleContainerCompositingLayer();        m_simpleCompositingLayerStatusDirty = false;    }    return m_isSimpleContainerCompositingLayer;}void RenderLayerBacking::detectDrawingOptimizations(){    bool drawsContent = true;    if (isSimpleContainerCompositingLayer() || paintingGoesToWindow())        drawsContent = false;    m_graphicsLayer->setDrawsContent(drawsContent);}void RenderLayerBacking::invalidateDrawingOptimizations(){    m_simpleCompositingLayerStatusDirty = true;}void RenderLayerBacking::forceCompositingLayer(bool force){    m_forceCompositingLayer = force;}FloatPoint3D RenderLayerBacking::computeTransformOrigin(const IntRect& borderBox) const{    RenderStyle* style = renderer()->style();    FloatPoint3D origin;    origin.setX(style->transformOriginX().calcFloatValue(borderBox.width()));    origin.setY(style->transformOriginY().calcFloatValue(borderBox.height()));    origin.setZ(style->transformOriginZ());    return origin;}FloatPoint RenderLayerBacking::computePerspectiveOrigin(const IntRect& borderBox) const{    RenderStyle* style = renderer()->style();    float boxWidth = borderBox.width();    float boxHeight = borderBox.height();    FloatPoint origin;    origin.setX(style->perspectiveOriginX().calcFloatValue(boxWidth));    origin.setY(style->perspectiveOriginY().calcFloatValue(boxHeight));    return origin;}// Return the offset from the top-left of this compositing layer at which the renderer's contents are painted.IntSize RenderLayerBacking::contentOffsetInCompostingLayer(){    if (!m_compositingContentOffsetDirty)        return m_compositingContentOffset;    IntRect relativeCompositingBounds = compositor()->calculateCompositedBounds(m_owningLayer, m_owningLayer);    m_compositingContentOffset = IntSize(-relativeCompositingBounds.x(), -relativeCompositingBounds.y());    m_compositingContentOffsetDirty = false;    return m_compositingContentOffset;}IntRect RenderLayerBacking::contentsBox(const GraphicsLayer*){    if (!renderer()->isBox())        return IntRect();    IntRect contentsRect = toRenderBox(renderer())->contentBoxRect();    IntSize contentOffset = contentOffsetInCompostingLayer();    contentsRect.move(contentOffset);    return contentsRect;}// Map the given point from coordinates in the GraphicsLayer to RenderLayer coordinates.FloatPoint RenderLayerBacking::graphicsLayerToContentsCoordinates(const GraphicsLayer* graphicsLayer, const FloatPoint& point){    return point + FloatSize(graphicsLayer->offsetFromRenderer());}// Map the given point from coordinates in the RenderLayer to GraphicsLayer coordinates.FloatPoint RenderLayerBacking::contentsToGraphicsLayerCoordinates(const GraphicsLayer* graphicsLayer, const FloatPoint& point){    return point - FloatSize(graphicsLayer->offsetFromRenderer());}bool RenderLayerBacking::paintingGoesToWindow() const{    return m_owningLayer->isRootLayer();}void RenderLayerBacking::setContentsNeedDisplay(){    if (m_graphicsLayer)        m_graphicsLayer->setNeedsDisplay();    if (m_contentsLayer)        m_contentsLayer->setNeedsDisplay();}// r is in the coordinate space of the layer's render objectvoid RenderLayerBacking::setContentsNeedDisplayInRect(const IntRect& r){    if (m_graphicsLayer) {

⌨️ 快捷键说明

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