📄 renderstyle.cpp
字号:
/* * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) * Copyright (C) 2004, 2005, 2006, 2007, 2008 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 "RenderStyle.h"#include "CSSStyleSelector.h"#include "CachedImage.h"#include "CounterContent.h"#include "FontSelector.h"#include "RenderArena.h"#include "RenderObject.h"#include "StyleImage.h"#include <wtf/StdLibExtras.h>#include <algorithm>namespace WebCore {inline RenderStyle* defaultStyle(){ static RenderStyle* s_defaultStyle = RenderStyle::createDefaultStyle().releaseRef(); return s_defaultStyle;}PassRefPtr<RenderStyle> RenderStyle::create(){ return adoptRef(new RenderStyle());}PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle(){ return adoptRef(new RenderStyle(true));}PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other){ return adoptRef(new RenderStyle(*other));}RenderStyle::RenderStyle() : box(defaultStyle()->box) , visual(defaultStyle()->visual) , background(defaultStyle()->background) , surround(defaultStyle()->surround) , rareNonInheritedData(defaultStyle()->rareNonInheritedData) , rareInheritedData(defaultStyle()->rareInheritedData) , inherited(defaultStyle()->inherited) , m_pseudoState(PseudoUnknown) , m_affectedByAttributeSelectors(false) , m_unique(false) , m_affectedByEmpty(false) , m_emptyState(false) , m_childrenAffectedByFirstChildRules(false) , m_childrenAffectedByLastChildRules(false) , m_childrenAffectedByDirectAdjacentRules(false) , m_childrenAffectedByForwardPositionalRules(false) , m_childrenAffectedByBackwardPositionalRules(false) , m_firstChildState(false) , m_lastChildState(false) , m_childIndex(0)#if ENABLE(SVG) , m_svgStyle(defaultStyle()->m_svgStyle)#endif{ setBitDefaults(); // Would it be faster to copy this from the default style?}RenderStyle::RenderStyle(bool) : m_pseudoState(PseudoUnknown) , m_affectedByAttributeSelectors(false) , m_unique(false) , m_affectedByEmpty(false) , m_emptyState(false) , m_childrenAffectedByFirstChildRules(false) , m_childrenAffectedByLastChildRules(false) , m_childrenAffectedByDirectAdjacentRules(false) , m_childrenAffectedByForwardPositionalRules(false) , m_childrenAffectedByBackwardPositionalRules(false) , m_firstChildState(false) , m_lastChildState(false) , m_childIndex(0){ setBitDefaults(); box.init(); visual.init(); background.init(); surround.init(); rareNonInheritedData.init(); rareNonInheritedData.access()->flexibleBox.init(); rareNonInheritedData.access()->marquee.init(); rareNonInheritedData.access()->m_multiCol.init(); rareNonInheritedData.access()->m_transform.init(); rareInheritedData.init(); inherited.init();#if ENABLE(SVG) m_svgStyle.init();#endif}RenderStyle::RenderStyle(const RenderStyle& o) : RefCounted<RenderStyle>() , inherited_flags(o.inherited_flags) , noninherited_flags(o.noninherited_flags) , box(o.box) , visual(o.visual) , background(o.background) , surround(o.surround) , rareNonInheritedData(o.rareNonInheritedData) , rareInheritedData(o.rareInheritedData) , inherited(o.inherited) , m_pseudoState(o.m_pseudoState) , m_affectedByAttributeSelectors(false) , m_unique(false) , m_affectedByEmpty(false) , m_emptyState(false) , m_childrenAffectedByFirstChildRules(false) , m_childrenAffectedByLastChildRules(false) , m_childrenAffectedByDirectAdjacentRules(false) , m_childrenAffectedByForwardPositionalRules(false) , m_childrenAffectedByBackwardPositionalRules(false) , m_firstChildState(false) , m_lastChildState(false) , m_childIndex(0)#if ENABLE(SVG) , m_svgStyle(o.m_svgStyle)#endif{}void RenderStyle::inheritFrom(const RenderStyle* inheritParent){ rareInheritedData = inheritParent->rareInheritedData; inherited = inheritParent->inherited; inherited_flags = inheritParent->inherited_flags;#if ENABLE(SVG) if (m_svgStyle != inheritParent->m_svgStyle) m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());#endif}RenderStyle::~RenderStyle(){}bool RenderStyle::operator==(const RenderStyle& o) const{ // compare everything except the pseudoStyle pointer return inherited_flags == o.inherited_flags && noninherited_flags == o.noninherited_flags && box == o.box && visual == o.visual && background == o.background && surround == o.surround && rareNonInheritedData == o.rareNonInheritedData && rareInheritedData == o.rareInheritedData && inherited == o.inherited#if ENABLE(SVG) && m_svgStyle == o.m_svgStyle#endif ;}bool RenderStyle::isStyleAvailable() const{ return this != CSSStyleSelector::styleNotYetAvailable();}static inline int pseudoBit(PseudoId pseudo){ return 1 << (pseudo - 1);}bool RenderStyle::hasPseudoStyle(PseudoId pseudo) const{ ASSERT(pseudo > NOPSEUDO); ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID); return pseudoBit(pseudo) & noninherited_flags._pseudoBits;}void RenderStyle::setHasPseudoStyle(PseudoId pseudo){ ASSERT(pseudo > NOPSEUDO); ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID); noninherited_flags._pseudoBits |= pseudoBit(pseudo);}RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid){ if (!m_cachedPseudoStyle || styleType() != NOPSEUDO) return 0; RenderStyle* ps = m_cachedPseudoStyle.get(); while (ps && ps->styleType() != pid) ps = ps->m_cachedPseudoStyle.get(); return ps;}RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo){ if (!pseudo) return 0; pseudo->m_cachedPseudoStyle = m_cachedPseudoStyle; m_cachedPseudoStyle = pseudo; return m_cachedPseudoStyle.get();}bool RenderStyle::inheritedNotEqual(RenderStyle* other) const{ return inherited_flags != other->inherited_flags || inherited != other->inherited ||#if ENABLE(SVG) m_svgStyle->inheritedNotEqual(other->m_svgStyle.get()) ||#endif rareInheritedData != other->rareInheritedData;}static bool positionedObjectMoved(const LengthBox& a, const LengthBox& b){ // If any unit types are different, then we can't guarantee // that this was just a movement. if (a.left().type() != b.left().type() || a.right().type() != b.right().type() || a.top().type() != b.top().type() || a.bottom().type() != b.bottom().type()) return false; // Only one unit can be non-auto in the horizontal direction and // in the vertical direction. Otherwise the adjustment of values // is changing the size of the box. if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto()) return false; if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto()) return false; // One of the units is fixed or percent in both directions and stayed // that way in the new style. Therefore all we are doing is moving. return true;}/* compares two styles. The result gives an idea of the action that needs to be taken when replacing the old style with a new one. CbLayout: The containing block of the object needs a relayout. Layout: the RenderObject needs a relayout after the style change Visible: The change is visible, but no relayout is needed NonVisible: The object does need neither repaint nor relayout after the change. ### TODO: A lot can be optimised here based on the display type, lots of optimisations are unimplemented, and currently result in the worst case result causing a relayout of the containing block.*/StyleDifference RenderStyle::diff(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const{ changedContextSensitiveProperties = ContextSensitivePropertyNone;#if ENABLE(SVG) // This is horribly inefficient. Eventually we'll have to integrate // this more directly by calling: Diff svgDiff = svgStyle->diff(other) // and then checking svgDiff and returning from the appropriate places below. if (m_svgStyle != other->m_svgStyle) return StyleDifferenceLayout;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -