📄 renderboxmodelobject.cpp
字号:
/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#include "config.h"#include "RenderBoxModelObject.h"#include "GraphicsContext.h"#include "HTMLElement.h"#include "HTMLNames.h"#include "ImageBuffer.h"#include "RenderBlock.h"#include "RenderInline.h"#include "RenderLayer.h"#include "RenderView.h"using namespace std;namespace WebCore {using namespace HTMLNames;bool RenderBoxModelObject::s_wasFloating = false;RenderBoxModelObject::RenderBoxModelObject(Node* node) : RenderObject(node) , m_layer(0){}RenderBoxModelObject::~RenderBoxModelObject(){ // Our layer should have been destroyed and cleared by now ASSERT(!hasLayer()); ASSERT(!m_layer);}void RenderBoxModelObject::destroyLayer(){ ASSERT(hasLayer()); ASSERT(m_layer); m_layer->destroy(renderArena()); m_layer = 0; setHasLayer(false);}void RenderBoxModelObject::destroy(){ // This must be done before we destroy the RenderObject. if (m_layer) m_layer->clearClipRects(); // RenderObject::destroy calls back to destroyLayer() for layer destruction RenderObject::destroy();}bool RenderBoxModelObject::hasSelfPaintingLayer() const{ return m_layer && m_layer->isSelfPaintingLayer();}void RenderBoxModelObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle){ s_wasFloating = isFloating(); // If our z-index changes value or our visibility changes, // we need to dirty our stacking context's z-order list. if (style() && newStyle) { if (hasLayer() && (style()->hasAutoZIndex() != newStyle->hasAutoZIndex() || style()->zIndex() != newStyle->zIndex() || style()->visibility() != newStyle->visibility())) { layer()->dirtyStackingContextZOrderLists(); if (style()->hasAutoZIndex() != newStyle->hasAutoZIndex() || style()->visibility() != newStyle->visibility()) layer()->dirtyZOrderLists(); } } RenderObject::styleWillChange(diff, newStyle);}void RenderBoxModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle){ RenderObject::styleDidChange(diff, oldStyle); updateBoxModelInfoFromStyle(); if (requiresLayer()) { if (!layer()) { if (s_wasFloating && isFloating()) setChildNeedsLayout(true); m_layer = new (renderArena()) RenderLayer(this); setHasLayer(true); m_layer->insertOnlyThisLayer(); if (parent() && !needsLayout() && containingBlock()) m_layer->updateLayerPositions(); } } else if (layer() && layer()->parent()) { setHasTransform(false); // Either a transform wasn't specified or the object doesn't support transforms, so just null out the bit. setHasReflection(false); m_layer->removeOnlyThisLayer(); // calls destroyLayer() which clears m_layer if (s_wasFloating && isFloating()) setChildNeedsLayout(true); } if (m_layer) m_layer->styleChanged(diff, oldStyle);}void RenderBoxModelObject::updateBoxModelInfoFromStyle(){ // Set the appropriate bits for a box model object. Since all bits are cleared in styleWillChange, // we only check for bits that could possibly be set to true. setHasBoxDecorations(style()->hasBorder() || style()->hasBackground() || style()->hasAppearance() || style()->boxShadow()); setInline(style()->isDisplayInlineType()); setRelPositioned(style()->position() == RelativePosition);}int RenderBoxModelObject::relativePositionOffsetX() const{ if (!style()->left().isAuto()) { if (!style()->right().isAuto() && containingBlock()->style()->direction() == RTL) return -style()->right().calcValue(containingBlockWidthForContent()); return style()->left().calcValue(containingBlockWidthForContent()); } if (!style()->right().isAuto()) return -style()->right().calcValue(containingBlockWidthForContent()); return 0;}int RenderBoxModelObject::relativePositionOffsetY() const{ if (!style()->top().isAuto()) { if (!style()->top().isPercent() || containingBlock()->style()->height().isFixed()) return style()->top().calcValue(containingBlock()->availableHeight()); } else if (!style()->bottom().isAuto()) { if (!style()->bottom().isPercent() || containingBlock()->style()->height().isFixed()) return -style()->bottom().calcValue(containingBlock()->availableHeight()); } return 0;}int RenderBoxModelObject::offsetLeft() const{ // If the element is the HTML body element or does not have an associated box // return 0 and stop this algorithm. if (isBody()) return 0; RenderBoxModelObject* offsetPar = offsetParent(); int xPos = (isBox() ? toRenderBox(this)->x() : 0); // If the offsetParent of the element is null, or is the HTML body element, // return the distance between the canvas origin and the left border edge // of the element and stop this algorithm. if (offsetPar) { if (offsetPar->isBox() && !offsetPar->isBody()) xPos -= toRenderBox(offsetPar)->borderLeft(); if (!isPositioned()) { if (isRelPositioned()) xPos += relativePositionOffsetX(); RenderObject* curr = parent(); while (curr && curr != offsetPar) { // FIXME: What are we supposed to do inside SVG content? if (curr->isBox() && !curr->isTableRow()) xPos += toRenderBox(curr)->x(); curr = curr->parent(); } if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned()) xPos += toRenderBox(offsetPar)->x(); } } return xPos;}int RenderBoxModelObject::offsetTop() const{ // If the element is the HTML body element or does not have an associated box // return 0 and stop this algorithm. if (isBody()) return 0; RenderBoxModelObject* offsetPar = offsetParent(); int yPos = (isBox() ? toRenderBox(this)->y() : 0); // If the offsetParent of the element is null, or is the HTML body element, // return the distance between the canvas origin and the top border edge // of the element and stop this algorithm. if (offsetPar) { if (offsetPar->isBox() && !offsetPar->isBody()) yPos -= toRenderBox(offsetPar)->borderTop(); if (!isPositioned()) { if (isRelPositioned()) yPos += relativePositionOffsetY(); RenderObject* curr = parent(); while (curr && curr != offsetPar) { // FIXME: What are we supposed to do inside SVG content? if (curr->isBox() && !curr->isTableRow()) yPos += toRenderBox(curr)->y(); curr = curr->parent(); } if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned()) yPos += toRenderBox(offsetPar)->y(); } } return yPos;}int RenderBoxModelObject::paddingTop(bool) const{ int w = 0; Length padding = style()->paddingTop(); if (padding.isPercent()) w = containingBlock()->availableWidth(); return padding.calcMinValue(w);}int RenderBoxModelObject::paddingBottom(bool) const{ int w = 0; Length padding = style()->paddingBottom(); if (padding.isPercent()) w = containingBlock()->availableWidth(); return padding.calcMinValue(w);}int RenderBoxModelObject::paddingLeft(bool) const{ int w = 0; Length padding = style()->paddingLeft(); if (padding.isPercent()) w = containingBlock()->availableWidth(); return padding.calcMinValue(w);}int RenderBoxModelObject::paddingRight(bool) const{ int w = 0; Length padding = style()->paddingRight(); if (padding.isPercent()) w = containingBlock()->availableWidth(); return padding.calcMinValue(w);}void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, const Color& c, const FillLayer* bgLayer, int clipY, int clipH, int tx, int ty, int w, int h, InlineFlowBox* box, CompositeOperator op){ GraphicsContext* context = paintInfo.context; bool includeLeftEdge = box ? box->includeLeftEdge() : true; bool includeRightEdge = box ? box->includeRightEdge() : true; int bLeft = includeLeftEdge ? borderLeft() : 0; int bRight = includeRightEdge ? borderRight() : 0; int pLeft = includeLeftEdge ? paddingLeft() : 0; int pRight = includeRightEdge ? paddingRight() : 0; bool clippedToBorderRadius = false; if (style()->hasBorderRadius() && (includeLeftEdge || includeRightEdge)) { context->save(); context->addRoundedRectClip(IntRect(tx, ty, w, h), includeLeftEdge ? style()->borderTopLeftRadius() : IntSize(), includeRightEdge ? style()->borderTopRightRadius() : IntSize(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -