File: FillLayer.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (346 lines) | stat: -rw-r--r-- 11,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
 *           (C) 2000 Antti Koivisto (koivisto@kde.org)
 *           (C) 2000 Dirk Mueller (mueller@kde.org)
 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef FillLayer_h
#define FillLayer_h

#include "core/CoreExport.h"
#include "core/style/ComputedStyleConstants.h"
#include "core/style/StyleImage.h"
#include "platform/Length.h"
#include "platform/LengthSize.h"
#include "platform/graphics/GraphicsTypes.h"
#include "wtf/Allocator.h"
#include "wtf/RefPtr.h"

namespace blink {

struct FillSize {
  DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
  FillSize() : type(SizeLength) {}

  FillSize(EFillSizeType t, const LengthSize& l) : type(t), size(l) {}

  bool operator==(const FillSize& o) const {
    return type == o.type && size == o.size;
  }
  bool operator!=(const FillSize& o) const { return !(*this == o); }

  EFillSizeType type;
  LengthSize size;
};

// FIXME(Oilpan): Move FillLayer to Oilpan's heap.
class CORE_EXPORT FillLayer {
  USING_FAST_MALLOC(FillLayer);

 public:
  FillLayer(EFillLayerType, bool useInitialValues = false);
  ~FillLayer();

  StyleImage* image() const { return m_image.get(); }
  const Length& xPosition() const { return m_xPosition; }
  const Length& yPosition() const { return m_yPosition; }
  BackgroundEdgeOrigin backgroundXOrigin() const {
    return static_cast<BackgroundEdgeOrigin>(m_backgroundXOrigin);
  }
  BackgroundEdgeOrigin backgroundYOrigin() const {
    return static_cast<BackgroundEdgeOrigin>(m_backgroundYOrigin);
  }
  EFillAttachment attachment() const {
    return static_cast<EFillAttachment>(m_attachment);
  }
  EFillBox clip() const { return static_cast<EFillBox>(m_clip); }
  EFillBox origin() const { return static_cast<EFillBox>(m_origin); }
  EFillRepeat repeatX() const { return static_cast<EFillRepeat>(m_repeatX); }
  EFillRepeat repeatY() const { return static_cast<EFillRepeat>(m_repeatY); }
  CompositeOperator composite() const {
    return static_cast<CompositeOperator>(m_composite);
  }
  WebBlendMode blendMode() const {
    return static_cast<WebBlendMode>(m_blendMode);
  }
  const LengthSize& sizeLength() const { return m_sizeLength; }
  EFillSizeType sizeType() const {
    return static_cast<EFillSizeType>(m_sizeType);
  }
  FillSize size() const {
    return FillSize(static_cast<EFillSizeType>(m_sizeType), m_sizeLength);
  }
  EMaskSourceType maskSourceType() const {
    return static_cast<EMaskSourceType>(m_maskSourceType);
  }

  const FillLayer* next() const { return m_next; }
  FillLayer* next() { return m_next; }
  FillLayer* ensureNext() {
    if (!m_next)
      m_next = new FillLayer(type());
    return m_next;
  }

  bool isImageSet() const { return m_imageSet; }
  bool isXPositionSet() const { return m_xPosSet; }
  bool isYPositionSet() const { return m_yPosSet; }
  bool isBackgroundXOriginSet() const { return m_backgroundXOriginSet; }
  bool isBackgroundYOriginSet() const { return m_backgroundYOriginSet; }
  bool isAttachmentSet() const { return m_attachmentSet; }
  bool isClipSet() const { return m_clipSet; }
  bool isOriginSet() const { return m_originSet; }
  bool isRepeatXSet() const { return m_repeatXSet; }
  bool isRepeatYSet() const { return m_repeatYSet; }
  bool isCompositeSet() const { return m_compositeSet; }
  bool isBlendModeSet() const { return m_blendModeSet; }
  bool isSizeSet() const { return m_sizeType != SizeNone; }
  bool isMaskSourceTypeSet() const { return m_maskSourceTypeSet; }

  void setImage(StyleImage* i) {
    m_image = i;
    m_imageSet = true;
  }
  void setXPosition(const Length& position) {
    m_xPosition = position;
    m_xPosSet = true;
    m_backgroundXOriginSet = false;
    m_backgroundXOrigin = LeftEdge;
  }
  void setYPosition(const Length& position) {
    m_yPosition = position;
    m_yPosSet = true;
    m_backgroundYOriginSet = false;
    m_backgroundYOrigin = TopEdge;
  }
  void setBackgroundXOrigin(BackgroundEdgeOrigin origin) {
    m_backgroundXOrigin = origin;
    m_backgroundXOriginSet = true;
  }
  void setBackgroundYOrigin(BackgroundEdgeOrigin origin) {
    m_backgroundYOrigin = origin;
    m_backgroundYOriginSet = true;
  }
  void setAttachment(EFillAttachment attachment) {
    ASSERT(!m_cachedPropertiesComputed);
    m_attachment = attachment;
    m_attachmentSet = true;
  }
  void setClip(EFillBox b) {
    ASSERT(!m_cachedPropertiesComputed);
    m_clip = b;
    m_clipSet = true;
  }
  void setOrigin(EFillBox b) {
    ASSERT(!m_cachedPropertiesComputed);
    m_origin = b;
    m_originSet = true;
  }
  void setRepeatX(EFillRepeat r) {
    m_repeatX = r;
    m_repeatXSet = true;
  }
  void setRepeatY(EFillRepeat r) {
    m_repeatY = r;
    m_repeatYSet = true;
  }
  void setComposite(CompositeOperator c) {
    m_composite = c;
    m_compositeSet = true;
  }
  void setBlendMode(WebBlendMode b) {
    m_blendMode = b;
    m_blendModeSet = true;
  }
  void setSizeType(EFillSizeType b) { m_sizeType = b; }
  void setSizeLength(const LengthSize& length) { m_sizeLength = length; }
  void setSize(const FillSize& f) {
    m_sizeType = f.type;
    m_sizeLength = f.size;
  }
  void setMaskSourceType(EMaskSourceType m) {
    m_maskSourceType = m;
    m_maskSourceTypeSet = true;
  }

  void clearImage() {
    m_image.clear();
    m_imageSet = false;
  }
  void clearXPosition() {
    m_xPosSet = false;
    m_backgroundXOriginSet = false;
  }
  void clearYPosition() {
    m_yPosSet = false;
    m_backgroundYOriginSet = false;
  }

  void clearAttachment() { m_attachmentSet = false; }
  void clearClip() { m_clipSet = false; }
  void clearOrigin() { m_originSet = false; }
  void clearRepeatX() { m_repeatXSet = false; }
  void clearRepeatY() { m_repeatYSet = false; }
  void clearComposite() { m_compositeSet = false; }
  void clearBlendMode() { m_blendModeSet = false; }
  void clearSize() { m_sizeType = SizeNone; }
  void clearMaskSourceType() { m_maskSourceTypeSet = false; }

  FillLayer& operator=(const FillLayer&);
  FillLayer(const FillLayer&);

  bool operator==(const FillLayer&) const;
  bool operator!=(const FillLayer& o) const { return !(*this == o); }

  bool containsImage(StyleImage*) const;
  bool imagesAreLoaded() const;

  bool hasImage() const {
    if (m_image)
      return true;
    return m_next ? m_next->hasImage() : false;
  }

  bool hasFixedImage() const {
    if (m_image && m_attachment == FixedBackgroundAttachment)
      return true;
    return m_next ? m_next->hasFixedImage() : false;
  }

  bool imageOccludesNextLayers(const LayoutObject&) const;
  bool hasRepeatXY() const;
  bool clipOccludesNextLayers() const;

  EFillLayerType type() const { return static_cast<EFillLayerType>(m_type); }

  void fillUnsetProperties();
  void cullEmptyLayers();

  static bool imagesIdentical(const FillLayer*, const FillLayer*);

  EFillBox thisOrNextLayersClipMax() const {
    computeCachedPropertiesIfNeeded();
    return static_cast<EFillBox>(m_thisOrNextLayersClipMax);
  }
  bool thisOrNextLayersUseContentBox() const {
    computeCachedPropertiesIfNeeded();
    return m_thisOrNextLayersUseContentBox;
  }
  bool thisOrNextLayersHaveLocalAttachment() const {
    computeCachedPropertiesIfNeeded();
    return m_thisOrNextLayersHaveLocalAttachment;
  }
  void computeCachedPropertiesIfNeeded() const;

  static EFillAttachment initialFillAttachment(EFillLayerType) {
    return ScrollBackgroundAttachment;
  }
  static EFillBox initialFillClip(EFillLayerType) { return BorderFillBox; }
  static EFillBox initialFillOrigin(EFillLayerType type) {
    return type == BackgroundFillLayer ? PaddingFillBox : BorderFillBox;
  }
  static EFillRepeat initialFillRepeatX(EFillLayerType) { return RepeatFill; }
  static EFillRepeat initialFillRepeatY(EFillLayerType) { return RepeatFill; }
  static CompositeOperator initialFillComposite(EFillLayerType) {
    return CompositeSourceOver;
  }
  static WebBlendMode initialFillBlendMode(EFillLayerType) {
    return WebBlendModeNormal;
  }
  static EFillSizeType initialFillSizeType(EFillLayerType) {
    return SizeLength;
  }
  static LengthSize initialFillSizeLength(EFillLayerType) {
    return LengthSize();
  }
  static FillSize initialFillSize(EFillLayerType type) {
    return FillSize(initialFillSizeType(type), initialFillSizeLength(type));
  }
  static Length initialFillXPosition(EFillLayerType) {
    return Length(0.0, Percent);
  }
  static Length initialFillYPosition(EFillLayerType) {
    return Length(0.0, Percent);
  }
  static StyleImage* initialFillImage(EFillLayerType) { return 0; }
  static EMaskSourceType initialFillMaskSourceType(EFillLayerType) {
    return MaskAlpha;
  }

 private:
  friend class ComputedStyle;

  FillLayer() {}

  bool imageIsOpaque(const LayoutObject&) const;
  bool imageTilesLayer() const;

  FillLayer* m_next;

  Persistent<StyleImage> m_image;

  Length m_xPosition;
  Length m_yPosition;

  LengthSize m_sizeLength;

  unsigned m_attachment : 2;         // EFillAttachment
  unsigned m_clip : 2;               // EFillBox
  unsigned m_origin : 2;             // EFillBox
  unsigned m_repeatX : 3;            // EFillRepeat
  unsigned m_repeatY : 3;            // EFillRepeat
  unsigned m_composite : 4;          // CompositeOperator
  unsigned m_sizeType : 2;           // EFillSizeType
  unsigned m_blendMode : 5;          // WebBlendMode
  unsigned m_maskSourceType : 1;     // EMaskSourceType
  unsigned m_backgroundXOrigin : 2;  // BackgroundEdgeOrigin
  unsigned m_backgroundYOrigin : 2;  // BackgroundEdgeOrigin

  unsigned m_imageSet : 1;
  unsigned m_attachmentSet : 1;
  unsigned m_clipSet : 1;
  unsigned m_originSet : 1;
  unsigned m_repeatXSet : 1;
  unsigned m_repeatYSet : 1;
  unsigned m_xPosSet : 1;
  unsigned m_yPosSet : 1;
  unsigned m_backgroundXOriginSet : 1;
  unsigned m_backgroundYOriginSet : 1;
  unsigned m_compositeSet : 1;
  unsigned m_blendModeSet : 1;
  unsigned m_maskSourceTypeSet : 1;

  unsigned m_type : 1;  // EFillLayerType

  // EFillBox, maximum m_clip value from this to bottom layer
  mutable unsigned m_thisOrNextLayersClipMax : 2;
  // True if any of this or subsequent layers has content-box clip or origin.
  mutable unsigned m_thisOrNextLayersUseContentBox : 1;
  // True if any of this or subsequent layers has local attachment.
  mutable unsigned m_thisOrNextLayersHaveLocalAttachment : 1;
  // Set once any of the above is accessed. The layers will be frozen
  // thereafter.
  mutable unsigned m_cachedPropertiesComputed : 1;
};

}  // namespace blink

#endif  // FillLayer_h