Skip to content

Commit 77a83b4

Browse files
committed
css: add bitfields class to ComputedStyle
1 parent f8bbb1e commit 77a83b4

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/client/cssom/computed_style.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,25 @@ namespace client_cssom
208208

209209
// Box model properties
210210
if (name == "display")
211+
{
211212
display_ = Parse::ParseSingleValue<values::computed::Display>(value);
213+
bitfields_.SetHasDisplay(true);
214+
}
212215
else if (name == "box-sizing")
216+
{
213217
box_sizing_ = Parse::ParseSingleValue<values::computed::BoxSizing>(value);
218+
bitfields_.SetHasBoxSizing(true);
219+
}
214220
else if (name == "overflow-x")
221+
{
215222
overflow_x_ = Parse::ParseSingleValue<values::computed::Overflow>(value);
223+
bitfields_.SetHasOverflowX(true);
224+
}
216225
else if (name == "overflow-y")
226+
{
217227
overflow_y_ = Parse::ParseSingleValue<values::computed::Overflow>(value);
228+
bitfields_.SetHasOverflowY(true);
229+
}
218230

219231
// Margin
220232
if (name == "margin-top")
@@ -355,7 +367,7 @@ namespace client_cssom
355367
else if (name == "transform")
356368
{
357369
transform_ = Parse::ParseSingleValue<values::specified::Transform>(value).toComputedValue(context);
358-
has_transform_ = transform_.empty() == false;
370+
bitfields_.SetHasTransform(transform_.empty() == false);
359371
}
360372
}
361373

src/client/cssom/computed_style.hpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace client_cssom
177177
}
178178

179179
// 3D Transforms
180-
inline const bool hasTransform() const { return has_transform_; }
180+
inline const bool hasTransform() const { return bitfields_.HasTransform(); }
181181
inline const values::computed::Transform &transform() const { return transform_; }
182182
inline const size_t applyTransformTo(glm::mat4 &matrix) const { return transform_.applyTo(matrix); }
183183

@@ -229,7 +229,7 @@ namespace client_cssom
229229
values::CSSFloat flex_shrink_ = 1.0f;
230230

231231
// Grid
232-
// TODO
232+
// TODO(yorkie): add grid properties when needed.
233233

234234
// Visibility and UI
235235
std::optional<Visibility> visibility_ = Visibility::kVisible;
@@ -251,7 +251,33 @@ namespace client_cssom
251251
values::computed::Color background_color_ = values::computed::Color::Transparent();
252252

253253
// 3D Transforms
254-
bool has_transform_ = false;
255254
values::computed::Transform transform_;
255+
256+
private: // Bitfields for computed style properties.
257+
#define ADD_BOOLEAN_BITFIELD(PRIVATE_NAME, PUBLIC_NAME) \
258+
public: \
259+
bool PUBLIC_NAME() const { return PRIVATE_NAME; } \
260+
void Set##PUBLIC_NAME(bool new_value) { PRIVATE_NAME = new_value; } \
261+
\
262+
private: \
263+
unsigned PRIVATE_NAME : 1
264+
265+
class ComputedStyleBitfields
266+
{
267+
public:
268+
explicit ComputedStyleBitfields()
269+
: has_transform_(false)
270+
{
271+
}
272+
273+
ADD_BOOLEAN_BITFIELD(has_display_, HasDisplay);
274+
ADD_BOOLEAN_BITFIELD(has_box_sizing_, HasBoxSizing);
275+
ADD_BOOLEAN_BITFIELD(has_overflow_x_, HasOverflowX);
276+
ADD_BOOLEAN_BITFIELD(has_overflow_y_, HasOverflowY);
277+
ADD_BOOLEAN_BITFIELD(has_transform_, HasTransform);
278+
};
279+
#undef ADD_BOOLEAN_BITFIELD
280+
281+
ComputedStyleBitfields bitfields_;
256282
};
257283
}

0 commit comments

Comments
 (0)