Commit a1ccbb60 authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] handle sizing to children and anchoring

Previously we would not relayout children if the size changed. This is
problematic for children that wish to anchor to their parent.

Bug: 821220
Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I3cbc91fd9a4d4d398d8ef3eba5f42b1f577f46f2
Reviewed-on: https://chromium-review.googlesource.com/962972Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Commit-Queue: Ian Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543361}
parent e9aa1b1b
......@@ -692,9 +692,14 @@ void UiElement::DoLayOutChildren() {
return;
}
bool requires_relayout = false;
gfx::RectF bounds;
for (auto& child : children_) {
gfx::SizeF size = child->ContributedSize();
if (child->x_anchoring() != NONE || child->y_anchoring() != NONE) {
DCHECK(!child->contributes_to_parent_bounds());
requires_relayout = true;
}
if (!child->IsVisible() || size.IsEmpty() ||
!child->contributes_to_parent_bounds()) {
continue;
......@@ -717,7 +722,13 @@ void UiElement::DoLayOutChildren() {
bounds.Inset(-x_padding_, -y_padding_);
bounds.set_origin(bounds.CenterPoint());
local_origin_ = bounds.origin();
if (bounds.size() == GetTargetSize())
return;
SetSize(bounds.width(), bounds.height());
if (requires_relayout)
LayOutChildren();
}
void UiElement::LayOutChildren() {
......
......@@ -72,10 +72,21 @@ TEST(UiElement, BoundsContainChildren) {
grand_parent->set_padding(0.1, 0.2);
grand_parent->AddChild(std::move(parent));
auto anchored = std::make_unique<UiElement>();
anchored->set_y_anchoring(BOTTOM);
anchored->set_contributes_to_parent_bounds(false);
auto* anchored_ptr = anchored.get();
grand_parent->AddChild(std::move(anchored));
grand_parent->DoLayOutChildren();
EXPECT_RECT_NEAR(
gfx::RectF(-0.5f, 0.5f, 9.4f, 7.8f),
gfx::RectF(grand_parent->local_origin(), grand_parent->size()), kEpsilon);
gfx::Point3F p;
anchored_ptr->LocalTransform().TransformPoint(&p);
EXPECT_FLOAT_EQ(-3.9, p.y());
}
TEST(UiElement, BoundsContainScaledChildren) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment