| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- /*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019-2025 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- #include "../../../Source/Core/Layout/FormattingContextDebug.h"
- #include "../../../Source/Core/Layout/LayoutNode.h"
- #include "../Common/TestsShell.h"
- #include "../Common/TypesToString.h"
- #include <RmlUi/Core/ComputedValues.h>
- #include <RmlUi/Core/Context.h>
- #include <RmlUi/Core/Core.h>
- #include <RmlUi/Core/Element.h>
- #include <RmlUi/Core/ElementDocument.h>
- #include <RmlUi/Core/ElementText.h>
- #include <RmlUi/Core/ElementUtilities.h>
- #include <RmlUi/Debugger/Debugger.h>
- #include <doctest.h>
- using namespace Rml;
- struct ElementLayoutInfo {
- ElementLayoutInfo(int tree_depth, const String& address, const Box& box, Vector2f absolute_offset) :
- tree_depth(tree_depth), address(address), box(box), absolute_offset(absolute_offset)
- {}
- int tree_depth;
- String address;
- Box box;
- Vector2f absolute_offset;
- bool operator==(const ElementLayoutInfo& other) const
- {
- return tree_depth == other.tree_depth && address == other.address && box == other.box && absolute_offset == other.absolute_offset;
- }
- bool operator!=(const ElementLayoutInfo& other) const { return !(*this == other); }
- String ToString() const
- {
- return String(size_t(4 * tree_depth), ' ') +
- CreateString("%s :: box = %g x %g (outer %g x %g) :: absolute_offset = %g x %g", address.c_str(), box.GetSize().x, box.GetSize().y,
- box.GetSizeAcross(BoxDirection::Horizontal, BoxArea::Margin), box.GetSizeAcross(BoxDirection::Vertical, BoxArea::Margin),
- absolute_offset.x, absolute_offset.y);
- }
- };
- static Vector<ElementLayoutInfo> CaptureLayoutTree(Element* root_element)
- {
- Vector<ElementLayoutInfo> layout_info_list;
- ElementUtilities::VisitElementsDepthOrder(root_element, [&](Element* element, int tree_depth) {
- layout_info_list.emplace_back(tree_depth, element->GetAddress(false, false), element->GetBox(), element->GetAbsoluteOffset());
- });
- return layout_info_list;
- }
- static void LogLayoutTree(const Vector<ElementLayoutInfo>& layout_info_list)
- {
- String message = "Element layout tree:\n";
- for (const auto& layout_info : layout_info_list)
- message += layout_info.ToString() + "\n";
- Rml::Log::Message(Rml::Log::LT_DEBUG, "%s", message.c_str());
- }
- static const String document_isolation_rml = R"(
- <rml>
- <head>
- <link type="text/rcss" href="/assets/rml.rcss"/>
- <style>
- body {
- width: 800px;
- height: 600px;
- background-color: #ddd;
- font-family: LatoLatin;
- font-size: 14px;
- }
- scrollbarvertical {
- width: 12px;
- cursor: arrow;
- margin-right: -1px;
- padding-right: 1px;
- }
- scrollbarvertical slidertrack {
- background-color: #f0f0f0;
- }
- scrollbarvertical sliderbar {
- background-color: #666;
- }
- .container {
- width: 200px;
- margin: 20px;
- padding: 10px;
- background-color: #bbb;
- }
- .container > div {
- background-color: #aaa;
- margin: 5px;
- padding: 10px;
- }
- #flex-container {
- display: flex;
- flex-direction: column;
- }
- #overflow-container {
- overflow: auto;
- height: 150px;
- }
- #absolute-container {
- position: absolute;
- top: 300px;
- left: 300px;
- }
- </style>
- </head>
- <body>
- <div class="container" id="flex-container">
- <div>Flex item 1</div>
- <div id="flex-item">Flex item 2</div>
- <div id="flex-item-next">Flex item 3</div>
- </div>
- <div class="container" id="overflow-container">
- <div>Overflow item 1</div>
- <div id="overflow-item">Overflow item 2</div>
- <div>Overflow item 3</div>
- <div>Overflow item 4</div>
- <div>Overflow item 5</div>
- </div>
- <div class="container" id="absolute-container">
- <div id="absolute-item">Absolute item 1</div>
- <div>Absolute item 2</div>
- </div>
- <div class="container" id="normal-container">
- <div id="normal-item">Normal block box</div>
- </div>
- </body>
- </rml>
- )";
- TEST_CASE("LayoutIsolation.InsideOutsideFormattingContexts")
- {
- Context* context = TestsShell::GetContext();
- ElementDocument* document = context->LoadDocumentFromMemory(document_isolation_rml);
- document->Show();
- TestsShell::RenderLoop();
- SUBCASE("Flex")
- {
- Element* element = document->GetElementById("flex-item");
- Element* next_sibling = element->GetNextSibling();
- Element* normal_container = document->GetElementById("normal-container");
- Element* normal_item = document->GetElementById("normal-item");
- const Vector2f absolute_offset_element = element->GetAbsoluteOffset();
- const Vector2f absolute_offset_next_sibling = next_sibling->GetAbsoluteOffset();
- const Vector2f absolute_offset_normal_container = normal_container->GetAbsoluteOffset();
- const Vector2f absolute_offset_normal_item = normal_item->GetAbsoluteOffset();
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(element->GetAbsoluteOffset() == absolute_offset_element);
- CHECK(next_sibling->GetAbsoluteOffset() != absolute_offset_next_sibling);
- CHECK(normal_container->GetAbsoluteOffset() != absolute_offset_normal_container);
- CHECK(normal_item->GetAbsoluteOffset() != absolute_offset_normal_item);
- }
- SUBCASE("Overflow")
- {
- Element* element = document->GetElementById("overflow-item");
- Element* next_sibling = element->GetNextSibling();
- Element* normal_container = document->GetElementById("normal-container");
- Element* normal_item = document->GetElementById("normal-item");
- const Vector2f absolute_offset_element = element->GetAbsoluteOffset();
- const Vector2f absolute_offset_next_sibling = next_sibling->GetAbsoluteOffset();
- const Vector2f absolute_offset_normal_container = normal_container->GetAbsoluteOffset();
- const Vector2f absolute_offset_normal_item = normal_item->GetAbsoluteOffset();
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(element->GetAbsoluteOffset() == absolute_offset_element);
- CHECK(next_sibling->GetAbsoluteOffset() != absolute_offset_next_sibling);
- CHECK(normal_container->GetAbsoluteOffset() == absolute_offset_normal_container);
- CHECK(normal_item->GetAbsoluteOffset() == absolute_offset_normal_item);
- }
- SUBCASE("Absolute")
- {
- Element* element = document->GetElementById("absolute-item");
- Element* next_sibling = element->GetNextSibling();
- REQUIRE(element);
- REQUIRE(next_sibling);
- const Vector2f absolute_offset_element = element->GetAbsoluteOffset();
- const Vector2f absolute_offset_next_sibling = next_sibling->GetAbsoluteOffset();
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(element->GetAbsoluteOffset() == absolute_offset_element);
- CHECK(next_sibling->GetAbsoluteOffset() != absolute_offset_next_sibling);
- }
- SUBCASE("Normal")
- {
- Element* element = document->GetElementById("normal-item");
- REQUIRE(element);
- const float initial_width = element->GetBox().GetSize().x;
- element->SetProperty("width", "250px");
- TestsShell::RenderLoop();
- float new_width = element->GetBox().GetSize().x;
- CHECK(new_width != initial_width);
- CHECK(new_width == doctest::Approx(250.0f));
- }
- document->Close();
- TestsShell::ShutdownShell();
- }
- #ifdef RMLUI_DEBUG
- // Wrap all the following tests under this condition, since the format independent debug tracker is only available in debug mode.
- TEST_CASE("LayoutIsolation.FullLayoutFormatIndependentCount")
- {
- Context* context = TestsShell::GetContext();
- ElementDocument* document = nullptr;
- {
- FormattingContextDebugTracker format_independent_tracker;
- document = context->LoadDocumentFromMemory(document_isolation_rml);
- document->Show();
- TestsShell::RenderLoop();
- format_independent_tracker.LogMessage();
- const auto count_level_1 = std::count_if(format_independent_tracker.GetEntries().begin(), format_independent_tracker.GetEntries().end(),
- [](const auto& entry) { return entry.level == 1 && !entry.from_cache; });
- CHECK_MESSAGE(count_level_1 == 3, "Expecting one entry for each of flex, overflow, and absolute");
- // There are quite a few flex item format occurrences being performed currently. We might reduce the following
- // number while working on the flex formatting engine. If this fails for any other reason, it is likely a bug.
- CHECK(format_independent_tracker.CountEntries() == 10);
- CHECK(format_independent_tracker.CountFormattedEntries() == 10);
- }
- {
- FormattingContextDebugTracker format_independent_tracker;
- Element* element = document->GetElementById("flex-item");
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- const auto count_level_1 = std::count_if(format_independent_tracker.GetEntries().begin(), format_independent_tracker.GetEntries().end(),
- [](const auto& entry) { return entry.level == 1 && !entry.from_cache; });
- CHECK_MESSAGE(count_level_1 == 1, "Only the flexbox should be formatted, the others should be cached");
- }
- document->Close();
- TestsShell::ShutdownShell();
- }
- static const String document_isolation_absolute_rml = R"(
- <rml>
- <head>
- <link type="text/rcss" href="/assets/rml.rcss"/>
- <style>
- body {
- width: 800px;
- height: 600px;
- background-color: #ddd;
- font-family: LatoLatin;
- font-size: 14px;
- }
- scrollbarvertical {
- width: 12px;
- cursor: arrow;
- margin-right: -1px;
- padding-right: 1px;
- }
- scrollbarvertical slidertrack {
- background-color: #f0f0f0;
- }
- scrollbarvertical sliderbar {
- background-color: #666;
- }
- .container {
- width: 200px;
- margin: 20px;
- padding: 10px;
- background-color: #bbb;
- }
- .container > div {
- background-color: #aaa;
- margin: 5px;
- padding: 10px;
- }
- #absolute-container {
- position: absolute;
- top: 300px;
- left: 300px;
- width: 30%;
- }
- </style>
- </head>
- <body>
- <div class="container" id="absolute-container">
- <div id="absolute-item">Absolutely positioned box</div>
- </div>
- <div class="container" id="normal-container">
- <div id="normal-item">Normal block box</div>
- </div>
- </body>
- </rml>
- )";
- TEST_CASE("LayoutIsolation.Absolute")
- {
- Context* context = TestsShell::GetContext();
- ElementDocument* document = context->LoadDocumentFromMemory(document_isolation_absolute_rml);
- document->Show();
- TestsShell::RenderLoop();
- FormattingContextDebugTracker format_independent_tracker;
- SUBCASE("Modify absolute content")
- {
- Element* element = document->GetElementById("absolute-item");
- const float initial_height = element->GetOffsetHeight();
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(element->GetOffsetHeight() != initial_height);
- CHECK(format_independent_tracker.CountFormattedEntries() == 1);
- }
- SUBCASE("Modify absolute width")
- {
- Element* container = document->GetElementById("absolute-container");
- Element* element = document->GetElementById("absolute-item");
- const float container_initial_width = container->GetOffsetWidth();
- const float element_initial_width = element->GetOffsetWidth();
- container->SetProperty("width", "300px");
- DebugLogDirtyLayoutTree(document);
- document->UpdatePropertiesForDebug();
- DebugLogDirtyLayoutTree(document);
- TestsShell::RenderLoop();
- CHECK(container->GetOffsetWidth() != container_initial_width);
- CHECK(element->GetOffsetWidth() != element_initial_width);
- // The following could in principle be reduced to 1, since the size of an absolute element should not affect the
- // layout of the formatting context it takes part in.
- CHECK(format_independent_tracker.CountEntries() == 2);
- CHECK(format_independent_tracker.CountFormattedEntries() == 2);
- }
- SUBCASE("Modify document width")
- {
- Element* container = document->GetElementById("absolute-container");
- Element* element = document->GetElementById("absolute-item");
- const float document_width = document->GetOffsetWidth();
- const float container_width = container->GetOffsetWidth();
- const float element_width = element->GetOffsetWidth();
- document->SetProperty("width", "1000px");
- TestsShell::RenderLoop();
- CHECK(document->GetOffsetWidth() != document_width);
- CHECK(container->GetOffsetWidth() != container_width);
- CHECK(element->GetOffsetWidth() != element_width);
- }
- SUBCASE("Modify normal content")
- {
- Element* element = document->GetElementById("normal-item");
- const float initial_height = element->GetOffsetHeight();
- LogLayoutTree(CaptureLayoutTree(document));
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(element->GetOffsetHeight() != initial_height);
- CHECK(format_independent_tracker.CountFormattedEntries() == 1);
- }
- SUBCASE("Modify normal content and absolute content")
- {
- Element* absolute_element = document->GetElementById("absolute-item");
- Element* normal_element = document->GetElementById("normal-item");
- const float absolute_initial_height = absolute_element->GetOffsetHeight();
- const float normal_initial_height = normal_element->GetOffsetHeight();
- rmlui_dynamic_cast<ElementText*>(absolute_element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- rmlui_dynamic_cast<ElementText*>(normal_element->GetFirstChild())->SetText("Modified text that is long enough to cause line break");
- TestsShell::RenderLoop();
- CHECK(absolute_element->GetOffsetHeight() != absolute_initial_height);
- CHECK(normal_element->GetOffsetHeight() != normal_initial_height);
- CHECK(format_independent_tracker.CountFormattedEntries() == 2);
- }
- format_independent_tracker.LogMessage();
- document->Close();
- TestsShell::ShutdownShell();
- }
- static const String layout_isolation_hidden_absolute_rml = R"(
- <rml>
- <head>
- <title>Demo</title>
- <link type="text/rcss" href="/assets/rml.rcss"/>
- <style>
- body {
- font-family: LatoLatin;
- font-size: 14px;
- border: 5px #a66;
- background: #cca;
- color: black;
- top: 200px;
- right: 300px;
- bottom: 200px;
- left: 300px;
- }
- div {
- width: 300px;
- height: 200px;
- left: 100px;
- top: 100px;
- }
- .hide {
- display: none;
- }
- .absolute {
- position: absolute;
- }
- .wide {
- width: 400px;
- }
- </style>
- </head>
- <body id="body">
- This is a sample.
- <div id="child">Child element</div>
- </body>
- </rml>
- )";
- TEST_CASE("LayoutIsolation.HiddenSkipsFormatting")
- {
- Context* context = TestsShell::GetContext();
- ElementDocument* document = context->LoadDocumentFromMemory(layout_isolation_hidden_absolute_rml);
- Element* element = document->GetElementById("child");
- element->SetClass("hide", true);
- SUBCASE("Static") {}
- SUBCASE("Absolute")
- {
- element->SetClass("absolute", true);
- }
- FormattingContextDebugTracker format_independent_tracker;
- document->Show();
- TestsShell::RenderLoop();
- CHECK(format_independent_tracker.CountFormattedEntries() == 1);
- rmlui_dynamic_cast<ElementText*>(element->GetFirstChild())->SetText("Modified text");
- CHECK(format_independent_tracker.CountFormattedEntries() == 1);
- // Modifying text in a hidden element should not trigger a new layout.
- TestsShell::RenderLoop();
- CHECK(format_independent_tracker.CountFormattedEntries() == 1);
- format_independent_tracker.LogMessage();
- document->Close();
- TestsShell::ShutdownShell();
- }
- TEST_CASE("LayoutIsolation.HiddenToggleAndModify")
- {
- Context* context = TestsShell::GetContext();
- ElementDocument* document = context->LoadDocumentFromMemory(layout_isolation_hidden_absolute_rml);
- Element* element = document->GetElementById("child");
- element->SetClass("hide", true);
- float element_offset_left = 0;
- SUBCASE("Static")
- {
- element_offset_left = 305;
- }
- SUBCASE("Absolute")
- {
- element->SetClass("absolute", true);
- element_offset_left = 405;
- }
- document->Show();
- TestsShell::RenderLoop();
- CHECK(element->IsVisible() == false);
- element->SetClass("hide", false);
- document->UpdatePropertiesForDebug();
- TestsShell::RenderLoop();
- CHECK(element->GetAbsoluteLeft() == element_offset_left);
- CHECK(element->IsVisible() == true);
- CHECK(element->GetComputedValues().width().value == 300);
- CHECK(element->GetOffsetWidth() == 300.f);
- element->SetClass("hide", true);
- document->UpdatePropertiesForDebug();
- TestsShell::RenderLoop();
- CHECK(element->IsVisible() == false);
- CHECK(element->GetComputedValues().width().value == 300);
- CHECK(element->GetOffsetWidth() == 300.f);
- element->SetClass("wide", true);
- document->UpdatePropertiesForDebug();
- TestsShell::RenderLoop();
- CHECK(element->IsVisible() == false);
- CHECK(element->GetComputedValues().width().value == 400);
- CHECK(element->GetOffsetWidth() == 300.f);
- element->SetClass("hide", false);
- document->UpdatePropertiesForDebug();
- TestsShell::RenderLoop();
- CHECK(element->IsVisible() == true);
- CHECK(element->GetComputedValues().width().value == 400);
- CHECK(element->GetOffsetWidth() == 400.f);
- document->Close();
- TestsShell::ShutdownShell();
- }
- static const String layout_isolation_document_rml = R"(
- <rml>
- <head>
- <title>Demo</title>
- <link type="text/rcss" href="/assets/rml.rcss"/>
- <style>
- body {
- font-family: LatoLatin;
- font-size: 14px;
- border: 5px #a66;
- background: #cca;
- color: black;
- top: 200px;
- right: 300px;
- bottom: 200px;
- left: 300px;
- }
- </style>
- </head>
- <body>
- This is a sample.
- </body>
- </rml>
- )";
- TEST_CASE("LayoutIsolation.Document")
- {
- Context* context = TestsShell::GetContext();
- REQUIRE(context->GetDimensions() == Rml::Vector2i{1500, 800});
- FormattingContextDebugTracker format_independent_tracker;
- ElementDocument* document = context->LoadDocumentFromMemory(layout_isolation_document_rml);
- document->Show();
- TestsShell::RenderLoop();
- CHECK(document->GetOffsetWidth() == 900.f);
- CHECK(document->GetOffsetHeight() == 400.f);
- SUBCASE("Modify absolute content")
- {
- context->SetDimensions(Rml::Vector2i{1600, 900});
- document->UpdatePropertiesForDebug();
- TestsShell::RenderLoop();
- CHECK(document->GetOffsetWidth() == 1000.f);
- CHECK(document->GetOffsetHeight() == 500.f);
- CHECK(format_independent_tracker.CountFormattedEntries() == 2);
- }
- format_independent_tracker.LogMessage();
- document->Close();
- TestsShell::ShutdownShell();
- }
- static const String rml_flexbox_shrink_to_fit_nested = R"(
- <rml>
- <head>
- <title>Flex - Shrink-to-fit 01</title>
- <link type="text/rcss" href="/../Tests/Data/style.rcss"/>
- <style>
- body { width: 10000px; height: 2000px; }
- .shrink-to-fit {
- float: left;
- clear: both;
- margin: 10px 0;
- border: 2px #e8e8e8;
- }
- .outer {
- display: inline-flex;
- border: 1px red;
- padding: 30px;
- }
- .inner {
- border: 1px blue;
- padding: 30px;
- }
- </style>
- </head>
- <body>
- <div class="shrink-to-fit">
- Before
- <div class="outer">
- %s
- <div id="innermost" class="inner">Flex</div>
- %s
- </div>
- After
- </div>
- </body>
- </rml>
- )";
- TEST_CASE("LayoutIsolation.FlexFormat.shrink-to-fit")
- {
- Context* context = TestsShell::GetContext();
- REQUIRE(context);
- // The number of flex format count listed in this mapping is not an end-all be-all, but we should be made aware if
- // it changes, especially for the worse.
- const UnorderedMap<int, int> expected_num_nest_levels_versus_num_flex_formats = {
- {1, 3},
- {2, 8},
- {3, 13},
- {4, 18},
- {5, 23},
- {6, 28},
- {7, 33},
- {8, 38},
- {9, 43},
- {10, 48},
- };
- for (int num_nest_levels = 1; num_nest_levels <= 10; num_nest_levels++)
- {
- const Rml::String document_rml = Rml::CreateString(rml_flexbox_shrink_to_fit_nested.c_str(),
- StringUtilities::RepeatString(R"(<div class="inner"><div class="outer">)", num_nest_levels - 1).c_str(),
- StringUtilities::RepeatString(R"(</div></div>)", num_nest_levels - 1).c_str());
- FormattingContextDebugTracker format_independent_tracker;
- ElementDocument* document = context->LoadDocumentFromMemory(document_rml);
- document->Show();
- TestsShell::RenderLoop();
- int num_flex_formats = 0;
- for (const auto& entry : format_independent_tracker.GetEntries())
- {
- if (entry.context_type == FormattingContextType::Flex && !entry.from_cache)
- num_flex_formats += 1;
- }
- CHECK(num_flex_formats == expected_num_nest_levels_versus_num_flex_formats.at(num_nest_levels));
- document->Close();
- }
- TestsShell::ShutdownShell();
- }
- TEST_CASE("LayoutIsolation.FlexFormat.shrink-to-fit.cache")
- {
- Context* context = TestsShell::GetContext();
- REQUIRE(context);
- constexpr int num_nest_levels = 2;
- const Rml::String document_rml = Rml::CreateString(rml_flexbox_shrink_to_fit_nested.c_str(),
- StringUtilities::RepeatString(R"(<div class="inner"><div class="outer">)", num_nest_levels - 1).c_str(),
- StringUtilities::RepeatString(R"(</div></div>)", num_nest_levels - 1).c_str());
- ElementDocument* document = nullptr;
- {
- FormattingContextDebugTracker format_independent_tracker;
- document = context->LoadDocumentFromMemory(document_rml);
- document->Show();
- TestsShell::RenderLoop();
- MESSAGE("Initial layout: ", format_independent_tracker.CountFormattedEntries());
- }
- {
- FormattingContextDebugTracker format_independent_tracker;
- document->GetElementById("innermost")->SetInnerRML("Flex");
- TestsShell::RenderLoop();
- MESSAGE("With cache: ", format_independent_tracker.CountFormattedEntries());
- }
- {
- FormattingContextDebugTracker format_independent_tracker;
- document->GetElementById("innermost")->SetInnerRML("Flex");
- document->SetAttribute("rmlui-disable-layout-cache", true);
- TestsShell::RenderLoop();
- MESSAGE("Without cache: ", format_independent_tracker.CountFormattedEntries());
- }
- document->Close();
- TestsShell::ShutdownShell();
- }
- #endif // RMLUI_DEBUG
|