Coverage Report

Created: 2018-09-25 14:53

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