From c8d918efa99edfb8d6a751cea96563cd409f4d88 Mon Sep 17 00:00:00 2001 From: Ojan Vafai Date: Wed, 15 Apr 2015 11:08:32 -0700 Subject: [PATCH] Make changing your layout manager work. If your layout manager changes, then you need to setNeedsLayout, otherwise the next frame doesn't even get scheduled. We already correctly handle going from not having layout to having one or vice versa by doing the more drastic reattaching since that requires changing your actual render class. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1060013005 --- engine/core/dom/Element.cpp | 2 ++ tests/layout/custom.sky | 45 ++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/engine/core/dom/Element.cpp b/engine/core/dom/Element.cpp index 8537adb6d5e..c3b6a981518 100644 --- a/engine/core/dom/Element.cpp +++ b/engine/core/dom/Element.cpp @@ -971,6 +971,8 @@ void Element::setLayoutManager(PassOwnPtr callback) // those are all tied to changes to the RenderStyle. markAncestorsWithChildNeedsStyleRecalc(); detach(); + } else if (callback.get() != m_layoutManager) { + setNeedsLayout(); } m_layoutManager = callback; } diff --git a/tests/layout/custom.sky b/tests/layout/custom.sky index 586dd26fe9d..e212a6e7a01 100644 --- a/tests/layout/custom.sky +++ b/tests/layout/custom.sky @@ -84,30 +84,39 @@ void main() { expect(secondChild.offsetWidth, equals(150)); assertNonChangingValues(); - parent.setLayoutManager(null); + parent.setLayoutManager(() { + parent.width = 250.0; + }); window.requestAnimationFrame((_) { - expect(parent.offsetWidth, equals(300)); - expect(parent.offsetHeight, equals(50)); - expect(parent.offsetTop, equals(0)); - expect(parent.offsetLeft, equals(0)); + expect(parent.offsetWidth, equals(250)); + assertNonChangingValues(); - expect(firstChild.offsetWidth, equals(300)); - expect(firstChild.offsetHeight, equals(25)); - expect(firstChild.offsetTop, equals(0)); - expect(firstChild.offsetLeft, equals(0)); + parent.setLayoutManager(null); - expect(secondChild.offsetWidth, equals(300)); - expect(secondChild.offsetHeight, equals(25)); - expect(secondChild.offsetTop, equals(25)); - expect(secondChild.offsetLeft, equals(0)); + window.requestAnimationFrame((_) { + expect(parent.offsetWidth, equals(300)); + expect(parent.offsetHeight, equals(50)); + expect(parent.offsetTop, equals(0)); + expect(parent.offsetLeft, equals(0)); - expect(grandChild.offsetWidth, equals(25)); - expect(grandChild.offsetHeight, equals(25)); - expect(grandChild.offsetTop, equals(0)); - expect(grandChild.offsetLeft, equals(0)); + expect(firstChild.offsetWidth, equals(300)); + expect(firstChild.offsetHeight, equals(25)); + expect(firstChild.offsetTop, equals(0)); + expect(firstChild.offsetLeft, equals(0)); - completer.complete(); + expect(secondChild.offsetWidth, equals(300)); + expect(secondChild.offsetHeight, equals(25)); + expect(secondChild.offsetTop, equals(25)); + expect(secondChild.offsetLeft, equals(0)); + + expect(grandChild.offsetWidth, equals(25)); + expect(grandChild.offsetHeight, equals(25)); + expect(grandChild.offsetTop, equals(0)); + expect(grandChild.offsetLeft, equals(0)); + + completer.complete(); + }); }); }); });