Bug 1730256 [wpt PR 30555] - Move getWindowSegments to visualViewport.segments, a...
[gecko.git] / layout / style / nsStyleStructInlines.h
blob5f745a69137dfc6b07a227177cd84bd7865ff6de
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/. */
7 /*
8 * Inline methods that belong in nsStyleStruct.h, except that they
9 * require more headers.
12 #ifndef nsStyleStructInlines_h_
13 #define nsStyleStructInlines_h_
15 #include "nsIFrame.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;
68 return mDisplay;
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 return FIXPOS_CB_NON_SVG for will-change.
98 NS_ASSERTION(aStyle.StyleDisplay() == this, "unexpected aStyle");
100 if (mWillChange.bits & mozilla::StyleWillChangeBits::FIXPOS_CB_NON_SVG) {
101 return true;
104 return aStyle.StyleEffects()->HasFilters() ||
105 aStyle.StyleEffects()->HasBackdropFilters();
108 bool nsStyleDisplay::
109 IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const {
110 return IsContainPaint() || IsContainLayout() ||
111 mWillChange.bits & mozilla::StyleWillChangeBits::CONTAIN;
114 bool nsStyleDisplay::IsFixedPosContainingBlockForTransformSupportingFrames()
115 const {
116 // NOTE: Any CSS properties that influence the output of this function
117 // should also look at mWillChange as necessary.
118 return HasTransformStyle() || HasPerspectiveStyle() ||
119 mWillChange.bits & mozilla::StyleWillChangeBits::PERSPECTIVE;
122 bool nsStyleDisplay::IsFixedPosContainingBlock(
123 const nsIFrame* aContextFrame) const {
124 const auto* style = aContextFrame->Style();
125 NS_ASSERTION(style->StyleDisplay() == this, "unexpected aContextFrame");
126 // NOTE: Any CSS properties that influence the output of this function
127 // should also handle will-change appropriately.
128 if (mozilla::SVGUtils::IsInSVGTextSubtree(aContextFrame)) {
129 return false;
131 if (IsFixedPosContainingBlockForNonSVGTextFrames(*style)) {
132 return true;
134 if (IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() &&
135 aContextFrame->IsFrameOfType(nsIFrame::eSupportsContainLayoutAndPaint)) {
136 return true;
138 if (IsFixedPosContainingBlockForTransformSupportingFrames() &&
139 aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms)) {
140 return true;
142 return false;
145 bool nsStyleDisplay::IsAbsPosContainingBlock(
146 const nsIFrame* aContextFrame) const {
147 NS_ASSERTION(aContextFrame->StyleDisplay() == this,
148 "unexpected aContextFrame");
149 if (IsFixedPosContainingBlock(aContextFrame)) {
150 return true;
152 // NOTE: Any CSS properties that influence the output of this function
153 // should also handle will-change appropriately.
154 return IsPositionedStyle() &&
155 !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 const 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
186 // not work.
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) {
197 return true;
200 return false;
203 #endif /* !defined(nsStyleStructInlines_h_) */