/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/ArenaObjectID.h" #include "mozilla/Attributes.h" #include "mozilla/CSSVariableValues.h" #include "mozilla/SheetType.h" #include "mozilla/StaticPtr.h" #include "mozilla/StyleStructContext.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" #include // offsetof() #include class nsIFrame; class nsIURI; class nsStyleContext; class nsTextFrame; class imgIContainer; struct nsStyleVisibility; // Includes nsStyleStructID. #include "nsStyleStructFwd.h" // Bits for each struct. // NS_STYLE_INHERIT_BIT defined in nsStyleStructFwd.h #define NS_STYLE_INHERIT_MASK 0x000ffffff // Bits for inherited structs. #define NS_STYLE_INHERITED_STRUCT_MASK \ ((nsStyleStructID_size_t(1) << nsStyleStructID_Inherited_Count) - 1) // Bits for reset structs. #define NS_STYLE_RESET_STRUCT_MASK \ (((nsStyleStructID_size_t(1) << nsStyleStructID_Reset_Count) - 1) \ << nsStyleStructID_Inherited_Count) // 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::HasChildThatUsesGrandancestorStyle #define NS_STYLE_CHILD_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::ShouldSuppressLineBreak #define NS_STYLE_SUPPRESS_LINEBREAK 0x080000000 // See nsStyleContext::IsInDisplayNoneSubtree #define NS_STYLE_IN_DISPLAY_NONE_SUBTREE 0x100000000 // See nsStyleContext::FindChildWithRules #define NS_STYLE_INELIGIBLE_FOR_SHARING 0x200000000 // See nsStyleContext::HasChildThatUsesResetStyle #define NS_STYLE_HAS_CHILD_THAT_USES_RESET_STYLE 0x400000000 // See nsStyleContext::GetPseudoEnum #define NS_STYLE_CONTEXT_TYPE_SHIFT 35 // Additional bits for nsRuleNode's mDependentBits: #define NS_RULE_NODE_IS_ANIMATION_RULE 0x01000000 // Free bit here! #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 // Additional bits for nsRuleNode's mNoneBits: #define NS_RULE_NODE_HAS_ANIMATION_DATA 0x80000000 static_assert(int(mozilla::SheetType::Count) - 1 <= (NS_RULE_NODE_LEVEL_MASK >> NS_RULE_NODE_LEVEL_SHIFT), "NS_RULE_NODE_LEVEL_MASK cannot fit SheetType"); static_assert(NS_STYLE_INHERIT_MASK == (1 << nsStyleStructID_Length) - 1, "NS_STYLE_INHERIT_MASK is not correct"); static_assert((NS_RULE_NODE_IS_ANIMATION_RULE & NS_STYLE_INHERIT_MASK) == 0, "NS_RULE_NODE_IS_ANIMATION_RULE must not overlap the style struct bits."); /** * These *_Simple types are used to map Gecko types to layout-equivalent but * simpler Rust types, to aid Rust binding generation. * * If something in this types or the assertions below needs to change, ask * bholley, heycam or emilio before! * *
*/ struct nsPoint_Simple { nscoord x, y; }; static_assert(sizeof(nsPoint_Simple) == sizeof(nsPoint), "Wrong nsPoint_Simple size"); static_assert(offsetof(nsPoint_Simple, x) == offsetof(nsPoint, x), "Wrong nsPoint_Simple member alignment"); static_assert(offsetof(nsPoint_Simple, y) == offsetof(nsPoint, y), "Wrong nsPoint_Simple member alignment"); /** *
*/ struct nsMargin_Simple { nscoord top, right, bottom, left; }; static_assert(sizeof(nsMargin_Simple) == sizeof(nsMargin), "Wrong nsMargin_Simple size"); static_assert(offsetof(nsMargin_Simple, top) == offsetof(nsMargin, top), "Wrong nsMargin_Simple member alignment"); static_assert(offsetof(nsMargin_Simple, right) == offsetof(nsMargin, right), "Wrong nsMargin_Simple member alignment"); static_assert(offsetof(nsMargin_Simple, bottom) == offsetof(nsMargin, bottom), "Wrong nsMargin_Simple member alignment"); static_assert(offsetof(nsMargin_Simple, left) == offsetof(nsMargin, left), "Wrong nsMargin_Simple member alignment"); /** *
*/ struct nsRect_Simple { nscoord x, y, width, height; }; static_assert(sizeof(nsRect_Simple) == sizeof(nsRect), "Wrong nsRect_Simple size"); static_assert(offsetof(nsRect_Simple, x) == offsetof(nsRect, x), "Wrong nsRect_Simple member alignment"); static_assert(offsetof(nsRect_Simple, y) == offsetof(nsRect, y), "Wrong nsRect_Simple member alignment"); static_assert(offsetof(nsRect_Simple, width) == offsetof(nsRect, width), "Wrong nsRect_Simple member alignment"); static_assert(offsetof(nsRect_Simple, height) == offsetof(nsRect, height), "Wrong nsRect_Simple member alignment"); // The lifetime of these objects is managed by the presshell's arena. struct nsStyleFont { nsStyleFont(const nsFont& aFont, StyleStructContext aContext); nsStyleFont(const nsStyleFont& aStyleFont); explicit nsStyleFont(StyleStructContext aContext); ~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 DifferenceAlwaysHandledForDescendants() { // CalcDifference never returns the reflow hints that are sometimes // handled for descendants as hints not handled for descendants. return nsChangeHint_NeedReflow | nsChangeHint_ReflowChangesSizeOrPosition | nsChangeHint_ClearAncestorIntrinsics; } /** * Return aSize multiplied by the current text zoom factor (in aPresContext). * aSize is allowed to be negative, but the caller is expected to deal with * negative results. The result is clamped to nscoord_MIN .. nscoord_MAX. */ static nscoord ZoomText(StyleStructContext aContext, nscoord aSize); /** * Return aSize divided by the current text zoom factor (in aPresContext). * aSize is allowed to be negative, but the caller is expected to deal with * negative results. The result is clamped to nscoord_MIN .. nscoord_MAX. */ static nscoord UnZoomText(nsPresContext* aPresContext, nscoord aSize); static already_AddRefed GetLanguage(StyleStructContext aPresContext); void* operator new(size_t sz, nsStyleFont* aSelf) CPP_THROW_NEW { return aSelf; } void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW { return aContext->PresShell()-> AllocateByObjectID(mozilla::eArenaObjectID_nsStyleFont, 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] // allow different min font-size for certain cases uint8_t mMinFontSizeRatio; // [inherited] percent * 100 // 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 = delete; bool operator!=(const nsStyleGradientStop&) const = delete; }; class nsStyleGradient 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) = delete; nsStyleGradient& operator=(const nsStyleGradient& aOther) = 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 ,