Line data Source code
1 : /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /*
7 : * Inline methods that belong in nsStyleStruct.h, except that they
8 : * require more headers.
9 : */
10 :
11 : #ifndef nsStyleStructInlines_h_
12 : #define nsStyleStructInlines_h_
13 :
14 : #include "nsIFrame.h"
15 : #include "nsStyleStruct.h"
16 : #include "nsIContent.h" // for GetParent()
17 : #include "nsTextFrame.h" // for nsTextFrame::ShouldSuppressLineBreak
18 : #include "nsSVGUtils.h" // for nsSVGUtils::IsInSVGTextSubtree
19 : #include "mozilla/ServoStyleSet.h"
20 :
21 : inline void
22 0 : nsStyleImage::EnsureCachedBIData() const
23 : {
24 0 : if (!mCachedBIData) {
25 : const_cast<nsStyleImage*>(this)->mCachedBIData =
26 0 : mozilla::MakeUnique<CachedBorderImageData>();
27 : }
28 0 : }
29 :
30 : inline void
31 0 : nsStyleImage::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) const
32 : {
33 0 : EnsureCachedBIData();
34 0 : mCachedBIData->SetSubImage(aIndex, aSubImage);
35 0 : }
36 :
37 : inline imgIContainer*
38 0 : nsStyleImage::GetSubImage(uint8_t aIndex) const
39 : {
40 0 : return (mCachedBIData) ? mCachedBIData->GetSubImage(aIndex) : nullptr;
41 : }
42 :
43 : bool
44 27 : nsStyleText::HasTextShadow() const
45 : {
46 27 : return mTextShadow;
47 : }
48 :
49 : nsCSSShadowArray*
50 2 : nsStyleText::GetTextShadow() const
51 : {
52 2 : return mTextShadow;
53 : }
54 :
55 : bool
56 69 : nsStyleText::NewlineIsSignificant(const nsTextFrame* aContextFrame) const
57 : {
58 69 : NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
59 109 : return NewlineIsSignificantStyle() &&
60 109 : !aContextFrame->ShouldSuppressLineBreak() &&
61 109 : !aContextFrame->StyleContext()->IsTextCombined();
62 : }
63 :
64 : bool
65 56 : nsStyleText::WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const
66 : {
67 56 : NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
68 92 : return WhiteSpaceCanWrapStyle() &&
69 92 : !nsSVGUtils::IsInSVGTextSubtree(aContextFrame) &&
70 92 : !aContextFrame->StyleContext()->IsTextCombined();
71 : }
72 :
73 : bool
74 24 : nsStyleText::WordCanWrap(const nsIFrame* aContextFrame) const
75 : {
76 24 : NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
77 24 : return WordCanWrapStyle() && !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
78 : }
79 :
80 : bool
81 : nsStyleDisplay::IsBlockInside(const nsIFrame* aContextFrame) const
82 : {
83 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
84 : if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
85 : return aContextFrame->IsBlockFrame();
86 : }
87 : return IsBlockInsideStyle();
88 : }
89 :
90 : bool
91 66 : nsStyleDisplay::IsBlockOutside(const nsIFrame* aContextFrame) const
92 : {
93 66 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
94 66 : if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
95 0 : return aContextFrame->IsBlockFrame();
96 : }
97 66 : return IsBlockOutsideStyle();
98 : }
99 :
100 : bool
101 0 : nsStyleDisplay::IsInlineOutside(const nsIFrame* aContextFrame) const
102 : {
103 0 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
104 0 : if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
105 0 : return !aContextFrame->IsBlockFrame();
106 : }
107 0 : return IsInlineOutsideStyle();
108 : }
109 :
110 : bool
111 : nsStyleDisplay::IsOriginalDisplayInlineOutside(const nsIFrame* aContextFrame) const
112 : {
113 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
114 : if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
115 : return !aContextFrame->IsBlockFrame();
116 : }
117 : return IsOriginalDisplayInlineOutsideStyle();
118 : }
119 :
120 : mozilla::StyleDisplay
121 1260 : nsStyleDisplay::GetDisplay(const nsIFrame* aContextFrame) const
122 : {
123 1260 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
124 1260 : if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame) &&
125 0 : mDisplay != mozilla::StyleDisplay::None) {
126 0 : return aContextFrame->IsBlockFrame() ? mozilla::StyleDisplay::Block
127 0 : : mozilla::StyleDisplay::Inline;
128 : }
129 1260 : return mDisplay;
130 : }
131 :
132 : bool
133 1729 : nsStyleDisplay::IsFloating(const nsIFrame* aContextFrame) const
134 : {
135 1729 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
136 1729 : return IsFloatingStyle() && !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
137 : }
138 :
139 : // If you change this function, also change the corresponding block in
140 : // nsCSSFrameConstructor::ConstructFrameFromItemInternal that references
141 : // this function in comments.
142 : bool
143 4608 : nsStyleDisplay::HasTransform(const nsIFrame* aContextFrame) const
144 : {
145 4608 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
146 4608 : return HasTransformStyle() && aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms);
147 : }
148 :
149 : template<class StyleContextLike>
150 : bool
151 2348 : nsStyleDisplay::HasFixedPosContainingBlockStyleInternal(
152 : StyleContextLike* aStyleContext) const
153 : {
154 : // NOTE: Any CSS properties that influence the output of this function
155 : // should have the CSS_PROPERTY_FIXPOS_CB set on them.
156 2348 : NS_ASSERTION(aStyleContext->ThreadsafeStyleDisplay() == this,
157 : "unexpected aStyleContext");
158 :
159 2348 : if (IsContainPaint() || HasPerspectiveStyle()) {
160 0 : return true;
161 : }
162 :
163 2348 : if (mWillChangeBitField & NS_STYLE_WILL_CHANGE_FIXPOS_CB) {
164 0 : return true;
165 : }
166 :
167 2348 : return aStyleContext->ThreadsafeStyleEffects()->HasFilters();
168 : }
169 :
170 : template<class StyleContextLike>
171 : bool
172 8 : nsStyleDisplay::IsFixedPosContainingBlockForAppropriateFrame(
173 : StyleContextLike* aStyleContext) const
174 : {
175 : // NOTE: Any CSS properties that influence the output of this function
176 : // should have the CSS_PROPERTY_FIXPOS_CB set on them.
177 16 : return HasFixedPosContainingBlockStyleInternal(aStyleContext) ||
178 16 : HasTransformStyle();
179 : }
180 :
181 : bool
182 171 : nsStyleDisplay::IsFixedPosContainingBlock(const nsIFrame* aContextFrame) const
183 : {
184 : // NOTE: Any CSS properties that influence the output of this function
185 : // should have the CSS_PROPERTY_FIXPOS_CB set on them.
186 342 : if (!HasFixedPosContainingBlockStyleInternal(aContextFrame->StyleContext()) &&
187 171 : !HasTransform(aContextFrame)) {
188 167 : return false;
189 : }
190 4 : return !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
191 : }
192 :
193 : template<class StyleContextLike>
194 : bool
195 2900 : nsStyleDisplay::HasAbsPosContainingBlockStyleInternal(
196 : StyleContextLike* aStyleContext) const
197 : {
198 : // NOTE: Any CSS properties that influence the output of this function
199 : // should have the CSS_PROPERTY_ABSPOS_CB set on them.
200 2900 : NS_ASSERTION(aStyleContext->ThreadsafeStyleDisplay() == this,
201 : "unexpected aStyleContext");
202 5665 : return IsAbsolutelyPositionedStyle() ||
203 5075 : IsRelativelyPositionedStyle() ||
204 5075 : (mWillChangeBitField & NS_STYLE_WILL_CHANGE_ABSPOS_CB);
205 : }
206 :
207 : template<class StyleContextLike>
208 : bool
209 6 : nsStyleDisplay::IsAbsPosContainingBlockForAppropriateFrame(StyleContextLike* aStyleContext) const
210 : {
211 : // NOTE: Any CSS properties that influence the output of this function
212 : // should have the CSS_PROPERTY_ABSPOS_CB set on them.
213 6 : return HasAbsPosContainingBlockStyleInternal(aStyleContext) ||
214 6 : IsFixedPosContainingBlockForAppropriateFrame(aStyleContext);
215 : }
216 :
217 : bool
218 2894 : nsStyleDisplay::IsAbsPosContainingBlock(const nsIFrame* aContextFrame) const
219 : {
220 : // NOTE: Any CSS properties that influence the output of this function
221 : // should have the CSS_PROPERTY_ABSPOS_CB set on them.
222 2894 : nsStyleContext* sc = aContextFrame->StyleContext();
223 7957 : if (!HasAbsPosContainingBlockStyleInternal(sc) &&
224 5063 : !HasFixedPosContainingBlockStyleInternal(sc) &&
225 2169 : !HasTransform(aContextFrame)) {
226 2161 : return false;
227 : }
228 733 : return !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
229 : }
230 :
231 : bool
232 454 : nsStyleDisplay::IsRelativelyPositioned(const nsIFrame* aContextFrame) const
233 : {
234 454 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
235 454 : return IsRelativelyPositionedStyle() &&
236 454 : !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
237 : }
238 :
239 : bool
240 1220 : nsStyleDisplay::IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const
241 : {
242 1220 : NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
243 1381 : return IsAbsolutelyPositionedStyle() &&
244 1381 : !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
245 : }
246 :
247 : uint8_t
248 3527 : nsStyleUserInterface::GetEffectivePointerEvents(nsIFrame* aFrame) const
249 : {
250 3527 : if (aFrame->GetContent() && !aFrame->GetContent()->GetParent()) {
251 : // The root element has a cluster of frames associated with it
252 : // (root scroll frame, canvas frame, the actual primary frame). Make
253 : // those take their pointer-events value from the root element's primary
254 : // frame.
255 81 : nsIFrame* f = aFrame->GetContent()->GetPrimaryFrame();
256 81 : if (f) {
257 81 : return f->StyleUserInterface()->mPointerEvents;
258 : }
259 : }
260 3446 : return mPointerEvents;
261 : }
262 :
263 : bool
264 0 : nsStyleBackground::HasLocalBackground() const
265 : {
266 0 : NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mImage) {
267 0 : const nsStyleImageLayers::Layer& layer = mImage.mLayers[i];
268 0 : if (!layer.mImage.IsEmpty() &&
269 0 : layer.mAttachment == NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL) {
270 0 : return true;
271 : }
272 : }
273 0 : return false;
274 : }
275 :
276 : #endif /* !defined(nsStyleStructInlines_h_) */
|