1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Inline methods that belong in nsStyleStruct.h, except that they
9 * require more headers.
12 #ifndef nsStyleStructInlines_h_
13 #define nsStyleStructInlines_h_
16 #include "nsStyleStruct.h"
17 #include "nsIContent.h" // for GetParent()
18 #include "nsTextFrame.h" // for nsTextFrame::ShouldSuppressLineBreak
19 #include "nsSVGUtils.h" // for nsSVGUtils::IsInSVGTextSubtree
21 bool nsStyleText::NewlineIsSignificant(const nsTextFrame
* aContextFrame
) const {
22 NS_ASSERTION(aContextFrame
->StyleText() == this, "unexpected aContextFrame");
23 return NewlineIsSignificantStyle() &&
24 !aContextFrame
->ShouldSuppressLineBreak() &&
25 !aContextFrame
->Style()->IsTextCombined();
28 bool nsStyleText::WhiteSpaceCanWrap(const nsIFrame
* aContextFrame
) const {
29 NS_ASSERTION(aContextFrame
->StyleText() == this, "unexpected aContextFrame");
30 return WhiteSpaceCanWrapStyle() &&
31 !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
) &&
32 !aContextFrame
->Style()->IsTextCombined();
35 bool nsStyleText::WordCanWrap(const nsIFrame
* aContextFrame
) const {
36 NS_ASSERTION(aContextFrame
->StyleText() == this, "unexpected aContextFrame");
37 return WordCanWrapStyle() && !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
40 bool nsStyleDisplay::IsBlockOutside(const nsIFrame
* aContextFrame
) const {
41 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
42 "unexpected aContextFrame");
43 if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
44 return aContextFrame
->IsBlockFrame();
46 return IsBlockOutsideStyle();
49 bool nsStyleDisplay::IsInlineOutside(const nsIFrame
* aContextFrame
) const {
50 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
51 "unexpected aContextFrame");
52 if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
53 return !aContextFrame
->IsBlockFrame();
55 return IsInlineOutsideStyle();
58 mozilla::StyleDisplay
nsStyleDisplay::GetDisplay(
59 const nsIFrame
* aContextFrame
) const {
60 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
61 "unexpected aContextFrame");
62 if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame
) &&
63 mDisplay
!= mozilla::StyleDisplay::None
) {
64 return aContextFrame
->IsBlockFrame() ? mozilla::StyleDisplay::Block
65 : mozilla::StyleDisplay::Inline
;
70 bool nsStyleDisplay::IsFloating(const nsIFrame
* aContextFrame
) const {
71 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
72 "unexpected aContextFrame");
73 return IsFloatingStyle() && !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
76 // If you change this function, also change the corresponding block in
77 // nsCSSFrameConstructor::ConstructFrameFromItemInternal that references
78 // this function in comments.
79 bool nsStyleDisplay::HasTransform(const nsIFrame
* aContextFrame
) const {
80 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
81 "unexpected aContextFrame");
82 return HasTransformStyle() &&
83 aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
);
86 bool nsStyleDisplay::HasPerspective(const nsIFrame
* aContextFrame
) const {
87 MOZ_ASSERT(aContextFrame
->StyleDisplay() == this, "unexpected aContextFrame");
88 return HasPerspectiveStyle() &&
89 aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
);
92 bool nsStyleDisplay::IsFixedPosContainingBlockForNonSVGTextFrames(
93 const mozilla::ComputedStyle
& aStyle
) const {
94 // NOTE: Any CSS properties that influence the output of this function
95 // should have the FIXPOS_CB flag set on them.
96 NS_ASSERTION(aStyle
.StyleDisplay() == this, "unexpected aStyle");
98 if (mWillChange
.bits
& mozilla::StyleWillChangeBits::FIXPOS_CB
) {
102 return aStyle
.StyleEffects()->HasFilters() ||
103 aStyle
.StyleEffects()->HasBackdropFilters();
106 bool nsStyleDisplay::
107 IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const {
108 return IsContainPaint() || IsContainLayout();
111 bool nsStyleDisplay::IsFixedPosContainingBlockForTransformSupportingFrames()
113 // NOTE: Any CSS properties that influence the output of this function
114 // should have the FIXPOS_CB flag set on them.
115 return HasTransformStyle() || HasPerspectiveStyle();
118 bool nsStyleDisplay::IsFixedPosContainingBlock(
119 const nsIFrame
* aContextFrame
) const {
120 mozilla::ComputedStyle
* style
= aContextFrame
->Style();
121 NS_ASSERTION(style
->StyleDisplay() == this, "unexpected aContextFrame");
122 // NOTE: Any CSS properties that influence the output of this function
123 // should have the FIXPOS_CB flag set on them.
124 if (!IsFixedPosContainingBlockForNonSVGTextFrames(*style
) &&
125 (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
126 !aContextFrame
->IsFrameOfType(
127 nsIFrame::eSupportsContainLayoutAndPaint
)) &&
128 (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
129 !aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
))) {
132 if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
135 MOZ_ASSERT(IsAbsPosContainingBlock(aContextFrame
),
136 "Any fixed-pos CB should also be an abs-pos CB");
140 bool nsStyleDisplay::IsAbsPosContainingBlockForNonSVGTextFrames() const {
141 // NOTE: Any CSS properties that influence the output of this function
142 // should have the ABSPOS_CB set on them.
143 return IsAbsolutelyPositionedStyle() || IsRelativelyPositionedStyle() ||
144 (mWillChange
.bits
& mozilla::StyleWillChangeBits::ABSPOS_CB
);
147 bool nsStyleDisplay::IsAbsPosContainingBlock(
148 const nsIFrame
* aContextFrame
) const {
149 mozilla::ComputedStyle
* style
= aContextFrame
->Style();
150 NS_ASSERTION(style
->StyleDisplay() == this, "unexpected aContextFrame");
151 // NOTE: Any CSS properties that influence the output of this function
152 // should have the ABSPOS_CB set on them.
153 if (!IsAbsPosContainingBlockForNonSVGTextFrames() &&
154 !IsFixedPosContainingBlockForNonSVGTextFrames(*style
) &&
155 (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
156 !aContextFrame
->IsFrameOfType(
157 nsIFrame::eSupportsContainLayoutAndPaint
)) &&
158 (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
159 !aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
))) {
162 return !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
165 bool nsStyleDisplay::IsRelativelyPositioned(
166 const nsIFrame
* aContextFrame
) const {
167 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
168 "unexpected aContextFrame");
169 return IsRelativelyPositionedStyle() &&
170 !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
173 bool nsStyleDisplay::IsStickyPositioned(const nsIFrame
* aContextFrame
) const {
174 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
175 "unexpected aContextFrame");
176 return IsStickyPositionedStyle() &&
177 !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
180 bool nsStyleDisplay::IsAbsolutelyPositioned(
181 const nsIFrame
* aContextFrame
) const {
182 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
183 "unexpected aContextFrame");
184 return IsAbsolutelyPositionedStyle() &&
185 !nsSVGUtils::IsInSVGTextSubtree(aContextFrame
);
188 mozilla::StylePointerEvents
nsStyleUI::GetEffectivePointerEvents(
189 nsIFrame
* aFrame
) const {
190 if (aFrame
->GetContent() && !aFrame
->GetContent()->GetParent()) {
191 // The root frame is not allowed to have pointer-events: none, or else
192 // no frames could be hit test against and scrolling the viewport would
194 return mozilla::StylePointerEvents::Auto
;
196 return mPointerEvents
;
199 bool nsStyleBackground::HasLocalBackground() const {
200 NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i
, mImage
) {
201 const nsStyleImageLayers::Layer
& layer
= mImage
.mLayers
[i
];
202 if (!layer
.mImage
.IsNone() &&
203 layer
.mAttachment
== mozilla::StyleImageLayerAttachment::Local
) {
210 #endif /* !defined(nsStyleStructInlines_h_) */