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 "mozilla/SVGUtils.h" // for SVGUtils::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 !mozilla::SVGUtils::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() &&
38 !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
41 bool nsStyleDisplay::IsBlockOutside(const nsIFrame
* aContextFrame
) const {
42 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
43 "unexpected aContextFrame");
44 if (mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
45 return aContextFrame
->IsBlockFrame();
47 return IsBlockOutsideStyle();
50 bool nsStyleDisplay::IsInlineOutside(const nsIFrame
* aContextFrame
) const {
51 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
52 "unexpected aContextFrame");
53 if (mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
54 return !aContextFrame
->IsBlockFrame();
56 return IsInlineOutsideStyle();
59 mozilla::StyleDisplay
nsStyleDisplay::GetDisplay(
60 const nsIFrame
* aContextFrame
) const {
61 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
62 "unexpected aContextFrame");
63 if (mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
) &&
64 mDisplay
!= mozilla::StyleDisplay::None
) {
65 return aContextFrame
->IsBlockFrame() ? mozilla::StyleDisplay::Block
66 : mozilla::StyleDisplay::Inline
;
71 bool nsStyleDisplay::IsFloating(const nsIFrame
* aContextFrame
) const {
72 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
73 "unexpected aContextFrame");
74 return IsFloatingStyle() &&
75 !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
78 // If you change this function, also change the corresponding block in
79 // nsCSSFrameConstructor::ConstructFrameFromItemInternal that references
80 // this function in comments.
81 bool nsStyleDisplay::HasTransform(const nsIFrame
* aContextFrame
) const {
82 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
83 "unexpected aContextFrame");
84 return HasTransformStyle() &&
85 aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
);
88 bool nsStyleDisplay::HasPerspective(const nsIFrame
* aContextFrame
) const {
89 MOZ_ASSERT(aContextFrame
->StyleDisplay() == this, "unexpected aContextFrame");
90 return HasPerspectiveStyle() &&
91 aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
);
94 bool nsStyleDisplay::IsFixedPosContainingBlockForNonSVGTextFrames(
95 const mozilla::ComputedStyle
& aStyle
) const {
96 // NOTE: Any CSS properties that influence the output of this function
97 // should have the FIXPOS_CB flag set on them.
98 NS_ASSERTION(aStyle
.StyleDisplay() == this, "unexpected aStyle");
100 if (mWillChange
.bits
& mozilla::StyleWillChangeBits::FIXPOS_CB
) {
104 return aStyle
.StyleEffects()->HasFilters() ||
105 aStyle
.StyleEffects()->HasBackdropFilters();
108 bool nsStyleDisplay::
109 IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const {
110 return IsContainPaint() || IsContainLayout();
113 bool nsStyleDisplay::IsFixedPosContainingBlockForTransformSupportingFrames()
115 // NOTE: Any CSS properties that influence the output of this function
116 // should have the FIXPOS_CB flag set on them.
117 return HasTransformStyle() || HasPerspectiveStyle();
120 bool nsStyleDisplay::IsFixedPosContainingBlock(
121 const nsIFrame
* aContextFrame
) const {
122 mozilla::ComputedStyle
* style
= aContextFrame
->Style();
123 NS_ASSERTION(style
->StyleDisplay() == this, "unexpected aContextFrame");
124 // NOTE: Any CSS properties that influence the output of this function
125 // should have the FIXPOS_CB flag set on them.
126 if (!IsFixedPosContainingBlockForNonSVGTextFrames(*style
) &&
127 (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
128 !aContextFrame
->IsFrameOfType(
129 nsIFrame::eSupportsContainLayoutAndPaint
)) &&
130 (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
131 !aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
))) {
134 if (mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
)) {
137 MOZ_ASSERT(IsAbsPosContainingBlock(aContextFrame
),
138 "Any fixed-pos CB should also be an abs-pos CB");
142 bool nsStyleDisplay::IsAbsPosContainingBlock(
143 const nsIFrame
* aContextFrame
) const {
144 mozilla::ComputedStyle
* style
= aContextFrame
->Style();
145 NS_ASSERTION(style
->StyleDisplay() == this, "unexpected aContextFrame");
146 if (!IsPositionedStyle() &&
147 !IsFixedPosContainingBlockForNonSVGTextFrames(*style
) &&
148 (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
149 !aContextFrame
->IsFrameOfType(
150 nsIFrame::eSupportsContainLayoutAndPaint
)) &&
151 (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
152 !aContextFrame
->IsFrameOfType(nsIFrame::eSupportsCSSTransforms
))) {
155 return !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
158 bool nsStyleDisplay::IsRelativelyPositioned(
159 const nsIFrame
* aContextFrame
) const {
160 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
161 "unexpected aContextFrame");
162 return IsRelativelyPositionedStyle() &&
163 !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
166 bool nsStyleDisplay::IsStickyPositioned(const nsIFrame
* aContextFrame
) const {
167 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
168 "unexpected aContextFrame");
169 return IsStickyPositionedStyle() &&
170 !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
173 bool nsStyleDisplay::IsAbsolutelyPositioned(
174 const nsIFrame
* aContextFrame
) const {
175 NS_ASSERTION(aContextFrame
->StyleDisplay() == this,
176 "unexpected aContextFrame");
177 return IsAbsolutelyPositionedStyle() &&
178 !mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame
);
181 mozilla::StylePointerEvents
nsStyleUI::GetEffectivePointerEvents(
182 nsIFrame
* aFrame
) const {
183 if (aFrame
->GetContent() && !aFrame
->GetContent()->GetParent()) {
184 // The root frame is not allowed to have pointer-events: none, or else
185 // no frames could be hit test against and scrolling the viewport would
187 return mozilla::StylePointerEvents::Auto
;
189 return mPointerEvents
;
192 bool nsStyleBackground::HasLocalBackground() const {
193 NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i
, mImage
) {
194 const nsStyleImageLayers::Layer
& layer
= mImage
.mLayers
[i
];
195 if (!layer
.mImage
.IsNone() &&
196 layer
.mAttachment
== mozilla::StyleImageLayerAttachment::Local
) {
203 #endif /* !defined(nsStyleStructInlines_h_) */