Skip to content

Commit 4239a25

Browse files
committed
vaev-layout: Don’t generate boxes for input[type="hidden"], and add basic checkbox/radio support.
1 parent 0ffbc40 commit 4239a25

File tree

1 file changed

+55
-7
lines changed
  • src/vaev-engine/layout/builder

1 file changed

+55
-7
lines changed

src/vaev-engine/layout/builder/mod.cpp

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,61 @@ SVGRoot _buildSVG(Gc::Ref<Dom::Element> el) {
399399
return svgRoot;
400400
}
401401

402-
always_inline static bool isVoidElement(Gc::Ref<Dom::Element> el) {
403-
return contains(Html::VOID_TAGS, el->qualifiedName);
404-
}
405-
406402
static void _buildVoidElement(BuilderContext bc, Gc::Ref<Dom::Element> el) {
407403
if (el->qualifiedName == Html::INPUT_TAG) {
408-
_buildInputProse(bc, el);
404+
auto type = el->getAttribute(Html::TYPE_ATTR).unwrapOr(""s);
405+
if (type == "hidden") {
406+
// Don't generate a box
407+
} else if (type == "radio" or type == "checkbox") {
408+
Math::Rectf rect = {14, 14};
409+
410+
Rc<Scene::Stack> box = makeRc<Scene::Stack>();
411+
412+
box->add(
413+
makeRc<Scene::Box>(
414+
rect,
415+
Gfx::Borders{
416+
.radii = type == "checkbox" ? 2 : 99,
417+
.widths = 1,
418+
.fills = {
419+
Gfx::BLACK,
420+
Gfx::BLACK,
421+
Gfx::BLACK,
422+
Gfx::BLACK,
423+
},
424+
.styles = {
425+
Gfx::BorderStyle::SOLID,
426+
Gfx::BorderStyle::SOLID,
427+
Gfx::BorderStyle::SOLID,
428+
Gfx::BorderStyle::SOLID,
429+
},
430+
},
431+
Gfx::Outline{}, Vec<Gfx::Fill>{Gfx::WHITE}
432+
)
433+
);
434+
435+
bool checked = el->hasAttribute(Html::CHECKED_ATTR) or el->getAttribute(Html::VALUE_ATTR).unwrapOr(""s) == "on";
436+
437+
if (checked) {
438+
box->add(
439+
makeRc<Scene::Box>(
440+
rect.shrink(2),
441+
Gfx::Borders{
442+
.radii = type == "checkbox" ? 2 : 99,
443+
.widths = 0,
444+
.fills = {
445+
},
446+
.styles = {},
447+
},
448+
Gfx::Outline{}, Vec<Gfx::Fill>{Gfx::BLUE500}
449+
)
450+
);
451+
}
452+
453+
bc.content() = Rc<Scene::Node>{box};
454+
} else {
455+
_buildInputProse(bc, el);
456+
}
409457
} else if (el->qualifiedName == Html::IMG_TAG) {
410458
_buildImage(bc, el);
411459
}
@@ -430,7 +478,7 @@ static void createAndBuildInlineFlowfromElement(BuilderContext bc, Rc<Style::Spe
430478
return;
431479
}
432480

433-
if (isVoidElement(el)) {
481+
if (el->isVoidElement()) {
434482
_buildVoidElement(bc, el);
435483
return;
436484
}
@@ -447,7 +495,7 @@ static void buildBlockFlowFromElement(BuilderContext bc, Gc::Ref<Dom::Element> e
447495
// do nothing
448496
} else if (el->qualifiedName == Svg::SVG_TAG) {
449497
bc.content() = _buildSVG(el);
450-
} else if (isVoidElement(el)) {
498+
} else if (el->isVoidElement()) {
451499
_buildVoidElement(bc, el);
452500
} else {
453501
_buildChildren(bc, el);

0 commit comments

Comments
 (0)