Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsStyleStructInlines.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
/*
8
 * Inline methods that belong in nsStyleStruct.h, except that they
9
 * require more headers.
10
 */
11
12
#ifndef nsStyleStructInlines_h_
13
#define nsStyleStructInlines_h_
14
15
#include "nsIFrame.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
20
21
inline void
22
nsStyleImage::EnsureCachedBIData() const
23
{
24
  if (!mCachedBIData) {
25
    const_cast<nsStyleImage*>(this)->mCachedBIData =
26
      mozilla::MakeUnique<CachedBorderImageData>();
27
  }
28
}
29
30
inline void
31
nsStyleImage::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) const
32
{
33
  EnsureCachedBIData();
34
  mCachedBIData->SetSubImage(aIndex, aSubImage);
35
}
36
37
inline imgIContainer*
38
nsStyleImage::GetSubImage(uint8_t aIndex) const
39
{
40
  return (mCachedBIData) ? mCachedBIData->GetSubImage(aIndex) : nullptr;
41
}
42
43
bool
44
nsStyleText::HasTextShadow() const
45
0
{
46
0
  return mTextShadow;
47
0
}
48
49
nsCSSShadowArray*
50
nsStyleText::GetTextShadow() const
51
{
52
  return mTextShadow;
53
}
54
55
bool
56
nsStyleText::NewlineIsSignificant(const nsTextFrame* aContextFrame) const
57
{
58
  NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
59
  return NewlineIsSignificantStyle() &&
60
         !aContextFrame->ShouldSuppressLineBreak() &&
61
         !aContextFrame->Style()->IsTextCombined();
62
}
63
64
bool
65
nsStyleText::WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const
66
{
67
  NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
68
  return WhiteSpaceCanWrapStyle() &&
69
         !nsSVGUtils::IsInSVGTextSubtree(aContextFrame) &&
70
         !aContextFrame->Style()->IsTextCombined();
71
}
72
73
bool
74
nsStyleText::WordCanWrap(const nsIFrame* aContextFrame) const
75
{
76
  NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
77
  return WordCanWrapStyle() && !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
78
}
79
80
bool
81
nsStyleDisplay::IsBlockInside(const nsIFrame* aContextFrame) const
82
0
{
83
0
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
84
0
  if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
85
0
    return aContextFrame->IsBlockFrame();
86
0
  }
87
0
  return IsBlockInsideStyle();
88
0
}
89
90
bool
91
nsStyleDisplay::IsBlockOutside(const nsIFrame* aContextFrame) const
92
{
93
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
94
  if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
95
    return aContextFrame->IsBlockFrame();
96
  }
97
  return IsBlockOutsideStyle();
98
}
99
100
bool
101
nsStyleDisplay::IsInlineOutside(const nsIFrame* aContextFrame) const
102
{
103
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
104
  if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
105
    return !aContextFrame->IsBlockFrame();
106
  }
107
  return IsInlineOutsideStyle();
108
}
109
110
bool
111
nsStyleDisplay::IsOriginalDisplayInlineOutside(const nsIFrame* aContextFrame) const
112
0
{
113
0
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
114
0
  if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame)) {
115
0
    return !aContextFrame->IsBlockFrame();
116
0
  }
117
0
  return IsOriginalDisplayInlineOutsideStyle();
118
0
}
119
120
mozilla::StyleDisplay
121
nsStyleDisplay::GetDisplay(const nsIFrame* aContextFrame) const
122
0
{
123
0
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
124
0
  if (nsSVGUtils::IsInSVGTextSubtree(aContextFrame) &&
125
0
      mDisplay != mozilla::StyleDisplay::None) {
126
0
    return aContextFrame->IsBlockFrame() ? mozilla::StyleDisplay::Block
127
0
                                         : mozilla::StyleDisplay::Inline;
128
0
  }
129
0
  return mDisplay;
130
0
}
131
132
bool
133
nsStyleDisplay::IsFloating(const nsIFrame* aContextFrame) const
134
{
135
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
136
  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
nsStyleDisplay::HasTransform(const nsIFrame* aContextFrame) const
144
{
145
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
146
  return HasTransformStyle() && aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms);
147
}
148
149
bool
150
nsStyleDisplay::HasPerspective(const nsIFrame* aContextFrame) const
151
{
152
  MOZ_ASSERT(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
153
  return HasPerspectiveStyle() && aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms);
154
}
155
156
bool
157
nsStyleDisplay::IsFixedPosContainingBlockForNonSVGTextFrames(
158
  mozilla::ComputedStyle& aStyle) const
159
{
160
  // NOTE: Any CSS properties that influence the output of this function
161
  // should have the FIXPOS_CB flag set on them.
162
  NS_ASSERTION(aStyle.ThreadsafeStyleDisplay() == this, "unexpected aStyle");
163
164
  if (mWillChangeBitField & NS_STYLE_WILL_CHANGE_FIXPOS_CB) {
165
    return true;
166
  }
167
168
  return aStyle.ThreadsafeStyleEffects()->HasFilters();
169
}
170
171
bool
172
nsStyleDisplay::IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const
173
{
174
  return IsContainPaint() || IsContainLayout();
175
}
176
177
bool
178
nsStyleDisplay::IsFixedPosContainingBlockForTransformSupportingFrames() const
179
{
180
  // NOTE: Any CSS properties that influence the output of this function
181
  // should have the FIXPOS_CB flag set on them.
182
  return HasTransformStyle() || HasPerspectiveStyle();
183
}
184
185
bool
186
nsStyleDisplay::IsFixedPosContainingBlock(const nsIFrame* aContextFrame) const
187
{
188
  mozilla::ComputedStyle* style = aContextFrame->Style();
189
  NS_ASSERTION(style->ThreadsafeStyleDisplay() == this,
190
               "unexpected aContextFrame");
191
  // NOTE: Any CSS properties that influence the output of this function
192
  // should have the FIXPOS_CB flag set on them.
193
  if (!IsFixedPosContainingBlockForNonSVGTextFrames(*style) &&
194
      (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
195
       !aContextFrame->IsFrameOfType(nsIFrame::eSupportsContainLayoutAndPaint)) &&
196
      (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
197
       !aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms))) {
198
    return false;
199
  }
200
  return !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
201
}
202
203
bool
204
nsStyleDisplay::IsAbsPosContainingBlockForNonSVGTextFrames() const
205
{
206
  // NOTE: Any CSS properties that influence the output of this function
207
  // should have the ABSPOS_CB set on them.
208
  return IsAbsolutelyPositionedStyle() ||
209
         IsRelativelyPositionedStyle() ||
210
         (mWillChangeBitField & NS_STYLE_WILL_CHANGE_ABSPOS_CB);
211
}
212
213
bool
214
nsStyleDisplay::IsAbsPosContainingBlock(const nsIFrame* aContextFrame) const
215
{
216
  mozilla::ComputedStyle *style = aContextFrame->Style();
217
  NS_ASSERTION(style->ThreadsafeStyleDisplay() == this,
218
               "unexpected aContextFrame");
219
  // NOTE: Any CSS properties that influence the output of this function
220
  // should have the ABSPOS_CB set on them.
221
  if (!IsAbsPosContainingBlockForNonSVGTextFrames() &&
222
      !IsFixedPosContainingBlockForNonSVGTextFrames(*style) &&
223
      (!IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ||
224
       !aContextFrame->IsFrameOfType(nsIFrame::eSupportsContainLayoutAndPaint)) &&
225
      (!IsFixedPosContainingBlockForTransformSupportingFrames() ||
226
       !aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms))) {
227
    return false;
228
  }
229
  return !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
230
}
231
232
bool
233
nsStyleDisplay::IsRelativelyPositioned(const nsIFrame* aContextFrame) const
234
{
235
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
236
  return IsRelativelyPositionedStyle() &&
237
         !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
238
}
239
240
bool
241
nsStyleDisplay::IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const
242
{
243
  NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
244
  return IsAbsolutelyPositionedStyle() &&
245
         !nsSVGUtils::IsInSVGTextSubtree(aContextFrame);
246
}
247
248
uint8_t
249
nsStyleUI::GetEffectivePointerEvents(nsIFrame* aFrame) const
250
{
251
  if (aFrame->GetContent() && !aFrame->GetContent()->GetParent()) {
252
    // The root element has a cluster of frames associated with it
253
    // (root scroll frame, canvas frame, the actual primary frame). Make
254
    // those take their pointer-events value from the root element's primary
255
    // frame.
256
    nsIFrame* f = aFrame->GetContent()->GetPrimaryFrame();
257
    if (f) {
258
      return f->StyleUI()->mPointerEvents;
259
    }
260
  }
261
  return mPointerEvents;
262
}
263
264
bool
265
nsStyleBackground::HasLocalBackground() const
266
{
267
  NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mImage) {
268
    const nsStyleImageLayers::Layer& layer = mImage.mLayers[i];
269
    if (!layer.mImage.IsEmpty() &&
270
        layer.mAttachment == mozilla::StyleImageLayerAttachment::Local) {
271
      return true;
272
    }
273
  }
274
  return false;
275
}
276
277
#endif /* !defined(nsStyleStructInlines_h_) */