Skip to content

Commit

Permalink
fix specificity offset missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakror committed Feb 2, 2021
1 parent 12f31fc commit 98bcc50
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Samples/assets/test.rcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
div {
background: #ccc;
}

body {
display:block;
width: 100px;
height: 100px;
}
3 changes: 3 additions & 0 deletions Source/Core/StyleSheetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ int StyleSheetParser::Parse(MediaBlockListRaw& style_sheets, Stream* _stream, in
{
// Complete current block
PostprocessKeyframes(current_block.stylesheet->keyframes);
current_block.stylesheet->specificity_offset = rule_count;
style_sheets.push_back(std::move(current_block));
current_block = {};

Expand Down Expand Up @@ -626,6 +627,7 @@ int StyleSheetParser::Parse(MediaBlockListRaw& style_sheets, Stream* _stream, in
if (current_block.stylesheet)
{
PostprocessKeyframes(current_block.stylesheet->keyframes);
current_block.stylesheet->specificity_offset = rule_count;
style_sheets.push_back(std::move(current_block));
current_block = {};
}
Expand Down Expand Up @@ -703,6 +705,7 @@ int StyleSheetParser::Parse(MediaBlockListRaw& style_sheets, Stream* _stream, in
if (current_block.stylesheet)
{
PostprocessKeyframes(current_block.stylesheet->keyframes);
current_block.stylesheet->specificity_offset = rule_count;
style_sheets.push_back(std::move(current_block));
}

Expand Down
81 changes: 81 additions & 0 deletions Tests/Source/UnitTests/StyleSheet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 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 "../Common/TestsShell.h"
#include <RmlUi/Core/Context.h>
#include <RmlUi/Core/Element.h>
#include <RmlUi/Core/ElementDocument.h>
#include <doctest.h>

using namespace Rml;

static const String simple_doc_rml = R"(
<rml>
<head>
<title>Test</title>
<link type="text/rcss" href="/assets/test.rcss"/>
<style>
body {
width: 48px;
}
</style>
</head>
<body>
<div/>
</body>
</rml>
)";

TEST_CASE("stylesheet.override_basic")
{
Context* context = TestsShell::GetContext();
REQUIRE(context);

// There should be no warnings loading this document.
ElementDocument* document = context->LoadDocumentFromMemory(simple_doc_rml, "assets/");
REQUIRE(document);
document->Show();

context->Update();
context->Render();

TestsShell::RenderLoop();

// Shell default window dimensions are 1500, 800

ElementList elems;
document->GetElementsByTagName(elems, "div");
CHECK(elems.size() == 1);

CHECK(elems[0]->GetBox() == Box(Vector2f(48.0f, 100.0f)));

document->Close();

TestsShell::ShutdownShell();
}

0 comments on commit 98bcc50

Please sign in to comment.