/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * structs that contain the data provided by nsStyleContext, the * internal API for computed style data for an element */ #ifndef nsStyleStruct_h___ #define nsStyleStruct_h___ #include "mozilla/Attributes.h" #include "mozilla/CSSVariableValues.h" #include "nsColor.h" #include "nsCoord.h" #include "nsMargin.h" #include "nsFont.h" #include "nsStyleCoord.h" #include "nsStyleConsts.h" #include "nsChangeHint.h" #include "nsPresContext.h" #include "nsCOMPtr.h" #include "nsCOMArray.h" #include "nsTArray.h" #include "nsCSSValue.h" #include "imgRequestProxy.h" #include "Orientation.h" #include "CounterStyleManager.h" class nsIFrame; class nsIURI; class imgIContainer; // Includes nsStyleStructID. #include "nsStyleStructFwd.h" // Bits for each struct. // NS_STYLE_INHERIT_BIT defined in nsStyleStructFwd.h #define NS_STYLE_INHERIT_MASK 0x000ffffff // Additional bits for nsStyleContext's mBits: // See nsStyleContext::HasTextDecorationLines #define NS_STYLE_HAS_TEXT_DECORATION_LINES 0x001000000 // See nsStyleContext::HasPseudoElementData. #define NS_STYLE_HAS_PSEUDO_ELEMENT_DATA 0x002000000 // See nsStyleContext::RelevantLinkIsVisited #define NS_STYLE_RELEVANT_LINK_VISITED 0x004000000 // See nsStyleContext::IsStyleIfVisited #define NS_STYLE_IS_STYLE_IF_VISITED 0x008000000 // See nsStyleContext::UsesGrandancestorStyle #define NS_STYLE_USES_GRANDANCESTOR_STYLE 0x010000000 // See nsStyleContext::IsShared #define NS_STYLE_IS_SHARED 0x020000000 // See nsStyleContext::AssertStructsNotUsedElsewhere // (This bit is currently only used in #ifdef DEBUG code.) #define NS_STYLE_IS_GOING_AWAY 0x040000000 // See nsStyleContext::IsDirectlyInsideRuby #define NS_STYLE_IS_DIRECTLY_INSIDE_RUBY 0x080000000 // See nsStyleContext::GetPseudoEnum #define NS_STYLE_CONTEXT_TYPE_SHIFT 32 // Additional bits for nsRuleNode's mDependentBits: #define NS_RULE_NODE_GC_MARK 0x02000000 #define NS_RULE_NODE_USED_DIRECTLY 0x04000000 #define NS_RULE_NODE_IS_IMPORTANT 0x08000000 #define NS_RULE_NODE_LEVEL_MASK 0xf0000000 #define NS_RULE_NODE_LEVEL_SHIFT 28 // The lifetime of these objects is managed by the presshell's arena. struct nsStyleFont { nsStyleFont(const nsFont& aFont, nsPresContext *aPresContext); nsStyleFont(const nsStyleFont& aStyleFont); explicit nsStyleFont(nsPresContext *aPresContext); private: void Init(nsPresContext *aPresContext); public: ~nsStyleFont(void) { MOZ_COUNT_DTOR(nsStyleFont); } nsChangeHint CalcDifference(const nsStyleFont& aOther) const; static nsChangeHint MaxDifference() { return NS_CombineHint(NS_STYLE_HINT_REFLOW, nsChangeHint_NeutralChange); } static nsChangeHint MaxDifferenceNeverInherited() { // CalcDifference never returns nsChangeHint_NeedReflow or // nsChangeHint_ClearAncestorIntrinsics as inherited hints. return NS_CombineHint(nsChangeHint_NeedReflow, nsChangeHint_ClearAncestorIntrinsics); } static nsChangeHint CalcFontDifference(const nsFont& aFont1, const nsFont& aFont2); static nscoord ZoomText(nsPresContext* aPresContext, nscoord aSize); static nscoord UnZoomText(nsPresContext* aPresContext, nscoord aSize); void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW { return aContext->PresShell()-> AllocateByObjectID(nsPresArena::nsStyleFont_id, sz); } void Destroy(nsPresContext* aContext); void EnableZoom(nsPresContext* aContext, bool aEnable); nsFont mFont; // [inherited] nscoord mSize; // [inherited] Our "computed size". Can be different // from mFont.size which is our "actual size" and is // enforced to be >= the user's preferred min-size. // mFont.size should be used for display purposes // while mSize is the value to return in // getComputedStyle() for example. uint8_t mGenericID; // [inherited] generic CSS font family, if any; // value is a kGenericFont_* constant, see nsFont.h. // MathML scriptlevel support int8_t mScriptLevel; // [inherited] // MathML mathvariant support uint8_t mMathVariant; // [inherited] // MathML displaystyle support uint8_t mMathDisplay; // [inherited] // was mLanguage set based on a lang attribute in the document? bool mExplicitLanguage; // [inherited] // should calls to ZoomText() and UnZoomText() be made to the font // size on this nsStyleFont? bool mAllowZoom; // [inherited] // The value mSize would have had if scriptminsize had never been applied nscoord mScriptUnconstrainedSize; nscoord mScriptMinSize; // [inherited] length float mScriptSizeMultiplier; // [inherited] nsCOMPtr mLanguage; // [inherited] }; struct nsStyleGradientStop { nsStyleCoord mLocation; // percent, coord, calc, none nscolor mColor; bool mIsInterpolationHint; // Use ==/!= on nsStyleGradient instead of on the gradient stop. bool operator==(const nsStyleGradientStop&) const MOZ_DELETE; bool operator!=(const nsStyleGradientStop&) const MOZ_DELETE; }; class nsStyleGradient MOZ_FINAL { public: nsStyleGradient(); uint8_t mShape; // NS_STYLE_GRADIENT_SHAPE_* uint8_t mSize; // NS_STYLE_GRADIENT_SIZE_*; // not used (must be FARTHEST_CORNER) for linear shape bool mRepeating; bool mLegacySyntax; nsStyleCoord mBgPosX; // percent, coord, calc, none nsStyleCoord mBgPosY; // percent, coord, calc, none nsStyleCoord mAngle; // none, angle nsStyleCoord mRadiusX; // percent, coord, calc, none nsStyleCoord mRadiusY; // percent, coord, calc, none // stops are in the order specified in the stylesheet nsTArray mStops; bool operator==(const nsStyleGradient& aOther) const; bool operator!=(const nsStyleGradient& aOther) const { return !(*this == aOther); } bool IsOpaque(); bool HasCalc(); uint32_t Hash(PLDHashNumber aHash); NS_INLINE_DECL_REFCOUNTING(nsStyleGradient) private: // Private destructor, to discourage deletion outside of Release(): ~nsStyleGradient() {} nsStyleGradient(const nsStyleGradient& aOther) MOZ_DELETE; nsStyleGradient& operator=(const nsStyleGradient& aOther) MOZ_DELETE; }; enum nsStyleImageType { eStyleImageType_Null, eStyleImageType_Image, eStyleImageType_Gradient, eStyleImageType_Element }; /** * Represents a paintable image of one of the following types. * (1) A real image loaded from an external source. * (2) A CSS linear or radial gradient. * (3) An element within a document, or an ,