/* -*- 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 "nsColor.h" #include "nsCoord.h" #include "nsMargin.h" #include "nsRect.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 "nsIAtom.h" #include "nsIURI.h" #include "nsCSSValue.h" #include "nsStyleTransformMatrix.h" #include "nsAlgorithm.h" #include "imgIRequest.h" #include "gfxRect.h" class nsIFrame; class imgIRequest; class imgIContainer; struct nsCSSValueList; // Includes nsStyleStructID. #include "nsStyleStructFwd.h" // Bits for each struct. // NS_STYLE_INHERIT_BIT defined in nsStyleStructFwd.h #define NS_STYLE_INHERIT_MASK 0x007fffff // Additional bits for nsStyleContext's mBits: // See nsStyleContext::HasTextDecorationLines #define NS_STYLE_HAS_TEXT_DECORATION_LINES 0x00800000 // See nsStyleContext::HasPseudoElementData. #define NS_STYLE_HAS_PSEUDO_ELEMENT_DATA 0x01000000 // See nsStyleContext::RelevantLinkIsVisited #define NS_STYLE_RELEVANT_LINK_VISITED 0x02000000 // See nsStyleContext::IsStyleIfVisited #define NS_STYLE_IS_STYLE_IF_VISITED 0x04000000 // See nsStyleContext::GetPseudoEnum #define NS_STYLE_CONTEXT_TYPE_MASK 0xf8000000 #define NS_STYLE_CONTEXT_TYPE_SHIFT 27 // Additional bits for nsRuleNode's mDependentBits: #define NS_RULE_NODE_GC_MARK 0x02000000 #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. // Each struct must implement a static ForceCompare() function returning a // boolean. Structs that can return a hint that doesn't guarantee that the // change will be applied to all descendants must return true from // ForceCompare(), so that we will make sure to compare those structs in // nsStyleContext::CalcStyleDifference. struct nsStyleFont { nsStyleFont(const nsFont& aFont, nsPresContext *aPresContext); nsStyleFont(const nsStyleFont& aStyleFont); nsStyleFont(nsPresContext *aPresContext); private: void Init(nsPresContext *aPresContext); public: ~nsStyleFont(void) { MOZ_COUNT_DTOR(nsStyleFont); } nsChangeHint CalcDifference(const nsStyleFont& aOther) const; #ifdef DEBUG static nsChangeHint MaxDifference(); #endif static bool ForceCompare() { return false; } 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; void Destroy(nsPresContext* aContext); 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] // was mLanguage set based on a lang attribute in the document? bool mExplicitLanguage; // [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, none nscolor mColor; }; class nsStyleGradient { 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(); NS_INLINE_DECL_REFCOUNTING(nsStyleGradient) private: ~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 ,