summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/svg/pattern_attributes.h
blob: 9f17ae8c23bd401ee1ea49f73e378df732e55237 (plain)
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
/*
 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
 *
 * 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 THIRD_PARTY_BLINK_RENDERER_CORE_SVG_PATTERN_ATTRIBUTES_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_PATTERN_ATTRIBUTES_H_

#include "third_party/blink/renderer/core/svg/svg_length.h"
#include "third_party/blink/renderer/core/svg/svg_preserve_aspect_ratio.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"

namespace blink {

class SVGPatternElement;

class PatternAttributes final {
  DISALLOW_NEW();

 public:
  PatternAttributes()
      : x_(MakeGarbageCollected<SVGLength>(SVGLengthMode::kWidth)),
        y_(MakeGarbageCollected<SVGLength>(SVGLengthMode::kHeight)),
        width_(MakeGarbageCollected<SVGLength>(SVGLengthMode::kWidth)),
        height_(MakeGarbageCollected<SVGLength>(SVGLengthMode::kHeight)),
        view_box_(),
        preserve_aspect_ratio_(MakeGarbageCollected<SVGPreserveAspectRatio>()),
        pattern_units_(SVGUnitTypes::kSvgUnitTypeObjectboundingbox),
        pattern_content_units_(SVGUnitTypes::kSvgUnitTypeUserspaceonuse),
        pattern_content_element_(nullptr),
        x_set_(false),
        y_set_(false),
        width_set_(false),
        height_set_(false),
        view_box_set_(false),
        preserve_aspect_ratio_set_(false),
        pattern_units_set_(false),
        pattern_content_units_set_(false),
        pattern_transform_set_(false),
        pattern_content_element_set_(false) {}

  SVGLength* X() const { return x_.Get(); }
  SVGLength* Y() const { return y_.Get(); }
  SVGLength* Width() const { return width_.Get(); }
  SVGLength* Height() const { return height_.Get(); }
  FloatRect ViewBox() const { return view_box_; }
  SVGPreserveAspectRatio* PreserveAspectRatio() const {
    return preserve_aspect_ratio_.Get();
  }
  SVGUnitTypes::SVGUnitType PatternUnits() const { return pattern_units_; }
  SVGUnitTypes::SVGUnitType PatternContentUnits() const {
    return pattern_content_units_;
  }
  AffineTransform PatternTransform() const { return pattern_transform_; }
  const SVGPatternElement* PatternContentElement() const {
    return pattern_content_element_;
  }

  void SetX(SVGLength* value) {
    x_ = value;
    x_set_ = true;
  }

  void SetY(SVGLength* value) {
    y_ = value;
    y_set_ = true;
  }

  void SetWidth(SVGLength* value) {
    width_ = value;
    width_set_ = true;
  }

  void SetHeight(SVGLength* value) {
    height_ = value;
    height_set_ = true;
  }

  void SetViewBox(const FloatRect& value) {
    view_box_ = value;
    view_box_set_ = true;
  }

  void SetPreserveAspectRatio(SVGPreserveAspectRatio* value) {
    preserve_aspect_ratio_ = value;
    preserve_aspect_ratio_set_ = true;
  }

  void SetPatternUnits(SVGUnitTypes::SVGUnitType value) {
    pattern_units_ = value;
    pattern_units_set_ = true;
  }

  void SetPatternContentUnits(SVGUnitTypes::SVGUnitType value) {
    pattern_content_units_ = value;
    pattern_content_units_set_ = true;
  }

  void SetPatternTransform(const AffineTransform& value) {
    pattern_transform_ = value;
    pattern_transform_set_ = true;
  }

  void SetPatternContentElement(const SVGPatternElement* value) {
    pattern_content_element_ = value;
    pattern_content_element_set_ = true;
  }

  bool HasX() const { return x_set_; }
  bool HasY() const { return y_set_; }
  bool HasWidth() const { return width_set_; }
  bool HasHeight() const { return height_set_; }
  bool HasViewBox() const { return view_box_set_; }
  bool HasPreserveAspectRatio() const { return preserve_aspect_ratio_set_; }
  bool HasPatternUnits() const { return pattern_units_set_; }
  bool HasPatternContentUnits() const { return pattern_content_units_set_; }
  bool HasPatternTransform() const { return pattern_transform_set_; }
  bool HasPatternContentElement() const { return pattern_content_element_set_; }

  void Trace(blink::Visitor* visitor) {
    visitor->Trace(x_);
    visitor->Trace(y_);
    visitor->Trace(width_);
    visitor->Trace(height_);
    visitor->Trace(preserve_aspect_ratio_);
    visitor->Trace(pattern_content_element_);
  }

 private:
  // Properties
  Member<SVGLength> x_;
  Member<SVGLength> y_;
  Member<SVGLength> width_;
  Member<SVGLength> height_;
  FloatRect view_box_;
  Member<SVGPreserveAspectRatio> preserve_aspect_ratio_;
  SVGUnitTypes::SVGUnitType pattern_units_;
  SVGUnitTypes::SVGUnitType pattern_content_units_;
  AffineTransform pattern_transform_;
  Member<const SVGPatternElement> pattern_content_element_;

  // Property states
  bool x_set_ : 1;
  bool y_set_ : 1;
  bool width_set_ : 1;
  bool height_set_ : 1;
  bool view_box_set_ : 1;
  bool preserve_aspect_ratio_set_ : 1;
  bool pattern_units_set_ : 1;
  bool pattern_content_units_set_ : 1;
  bool pattern_transform_set_ : 1;
  bool pattern_content_element_set_ : 1;
};

// Wrapper object for the PatternAttributes part object.
class PatternAttributesWrapper
    : public GarbageCollected<PatternAttributesWrapper> {
 public:
  PatternAttributesWrapper() = default;

  PatternAttributes& Attributes() { return attributes_; }
  void Set(const PatternAttributes& attributes) { attributes_ = attributes; }
  void Trace(blink::Visitor* visitor) { visitor->Trace(attributes_); }

 private:
  PatternAttributes attributes_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_PATTERN_ATTRIBUTES_H_