Browse Source

Refactor StyleSheetNodeSelector for improved performance

- Use a tagged type instead of virtual calls
- Detect text elements by tag name instead of dynamic_cast
- Element's display property no longer affects the structural selectors (breaking change)
Michael Ragazzon 3 years ago
parent
commit
c8f57a8208
32 changed files with 443 additions and 1563 deletions
  1. 2 24
      CMake/FileList.cmake
  2. 22 35
      Source/Core/StyleSheetFactory.cpp
  3. 6 7
      Source/Core/StyleSheetFactory.h
  4. 2 2
      Source/Core/StyleSheetNode.cpp
  5. 1 25
      Source/Core/StyleSheetNode.h
  6. 0 52
      Source/Core/StyleSheetNodeSelector.cpp
  7. 0 60
      Source/Core/StyleSheetNodeSelector.h
  8. 0 57
      Source/Core/StyleSheetNodeSelectorEmpty.cpp
  9. 0 53
      Source/Core/StyleSheetNodeSelectorEmpty.h
  10. 0 72
      Source/Core/StyleSheetNodeSelectorFirstChild.cpp
  11. 0 53
      Source/Core/StyleSheetNodeSelectorFirstChild.h
  12. 0 72
      Source/Core/StyleSheetNodeSelectorFirstOfType.cpp
  13. 0 53
      Source/Core/StyleSheetNodeSelectorFirstOfType.h
  14. 0 72
      Source/Core/StyleSheetNodeSelectorLastChild.cpp
  15. 0 53
      Source/Core/StyleSheetNodeSelectorLastChild.h
  16. 0 72
      Source/Core/StyleSheetNodeSelectorLastOfType.cpp
  17. 0 53
      Source/Core/StyleSheetNodeSelectorLastOfType.h
  18. 0 74
      Source/Core/StyleSheetNodeSelectorNthChild.cpp
  19. 0 53
      Source/Core/StyleSheetNodeSelectorNthChild.h
  20. 0 72
      Source/Core/StyleSheetNodeSelectorNthLastChild.cpp
  21. 0 53
      Source/Core/StyleSheetNodeSelectorNthLastChild.h
  22. 0 70
      Source/Core/StyleSheetNodeSelectorNthLastOfType.cpp
  23. 0 53
      Source/Core/StyleSheetNodeSelectorNthLastOfType.h
  24. 0 70
      Source/Core/StyleSheetNodeSelectorNthOfType.cpp
  25. 0 53
      Source/Core/StyleSheetNodeSelectorNthOfType.h
  26. 0 71
      Source/Core/StyleSheetNodeSelectorOnlyChild.cpp
  27. 0 53
      Source/Core/StyleSheetNodeSelectorOnlyChild.h
  28. 0 72
      Source/Core/StyleSheetNodeSelectorOnlyOfType.cpp
  29. 0 53
      Source/Core/StyleSheetNodeSelectorOnlyOfType.h
  30. 1 1
      Source/Core/StyleSheetParser.cpp
  31. 326 0
      Source/Core/StyleSheetSelector.cpp
  32. 83 0
      Source/Core/StyleSheetSelector.h

+ 2 - 24
CMake/FileList.cmake

@@ -88,19 +88,8 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/StreamFile.h
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetFactory.h
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNode.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelector.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorEmpty.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorFirstChild.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorFirstOfType.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorLastChild.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorLastOfType.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthChild.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthLastChild.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthLastOfType.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthOfType.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorOnlyChild.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorOnlyOfType.h
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetParser.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetSelector.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Template.h
     ${PROJECT_SOURCE_DIR}/Source/Core/TemplateCache.h
     ${PROJECT_SOURCE_DIR}/Source/Core/TextureDatabase.h
@@ -379,19 +368,8 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetContainer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetFactory.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNode.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelector.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorEmpty.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorFirstChild.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorFirstOfType.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorLastChild.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorLastOfType.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthChild.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthLastChild.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthLastOfType.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorNthOfType.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorOnlyChild.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetNodeSelectorOnlyOfType.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetParser.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetSelector.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/StyleSheetSpecification.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/SystemInterface.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Template.cpp

+ 22 - 35
Source/Core/StyleSheetFactory.cpp

@@ -15,7 +15,7 @@
  *
  * 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
@@ -27,50 +27,38 @@
  */
 
 #include "StyleSheetFactory.h"
+#include "../../Include/RmlUi/Core/Log.h"
 #include "../../Include/RmlUi/Core/StyleSheetContainer.h"
-#include "StyleSheetNode.h"
 #include "StreamFile.h"
-#include "StyleSheetNodeSelectorNthChild.h"
-#include "StyleSheetNodeSelectorNthLastChild.h"
-#include "StyleSheetNodeSelectorNthOfType.h"
-#include "StyleSheetNodeSelectorNthLastOfType.h"
-#include "StyleSheetNodeSelectorFirstChild.h"
-#include "StyleSheetNodeSelectorLastChild.h"
-#include "StyleSheetNodeSelectorFirstOfType.h"
-#include "StyleSheetNodeSelectorLastOfType.h"
-#include "StyleSheetNodeSelectorOnlyChild.h"
-#include "StyleSheetNodeSelectorOnlyOfType.h"
-#include "StyleSheetNodeSelectorEmpty.h"
-#include "../../Include/RmlUi/Core/Log.h"
+#include "StyleSheetNode.h"
+#include "StyleSheetSelector.h"
 
 namespace Rml {
 
 static UniquePtr<StyleSheetFactory> instance;
 
-StyleSheetFactory::StyleSheetFactory()
+StyleSheetFactory::StyleSheetFactory() :
+	selectors{
+		{"nth-child", StructuralSelectorType::Nth_Child},
+		{"nth-last-child", StructuralSelectorType::Nth_Last_Child},
+		{"nth-of-type", StructuralSelectorType::Nth_Of_Type},
+		{"nth-last-of-type", StructuralSelectorType::Nth_Last_Of_Type},
+		{"first-child", StructuralSelectorType::First_Child},
+		{"last-child", StructuralSelectorType::Last_Child},
+		{"first-of-type", StructuralSelectorType::First_Of_Type},
+		{"last-of-type", StructuralSelectorType::Last_Of_Type},
+		{"only-child", StructuralSelectorType::Only_Child},
+		{"only-of-type", StructuralSelectorType::Only_Of_Type},
+		{"empty", StructuralSelectorType::Empty},
+	}
 {}
 
-StyleSheetFactory::~StyleSheetFactory()
-{}
+StyleSheetFactory::~StyleSheetFactory() {}
 
 bool StyleSheetFactory::Initialise()
 {
 	RMLUI_ASSERT(instance == nullptr);
-
 	instance = UniquePtr<StyleSheetFactory>(new StyleSheetFactory);
-
-	instance->selectors["nth-child"] = MakeUnique<StyleSheetNodeSelectorNthChild>();
-	instance->selectors["nth-last-child"] = MakeUnique<StyleSheetNodeSelectorNthLastChild>();
-	instance->selectors["nth-of-type"] = MakeUnique<StyleSheetNodeSelectorNthOfType>();
-	instance->selectors["nth-last-of-type"] = MakeUnique<StyleSheetNodeSelectorNthLastOfType>();
-	instance->selectors["first-child"] = MakeUnique<StyleSheetNodeSelectorFirstChild>();
-	instance->selectors["last-child"] = MakeUnique<StyleSheetNodeSelectorLastChild>();
-	instance->selectors["first-of-type"] = MakeUnique<StyleSheetNodeSelectorFirstOfType>();
-	instance->selectors["last-of-type"] = MakeUnique<StyleSheetNodeSelectorLastOfType>();
-	instance->selectors["only-child"] = MakeUnique<StyleSheetNodeSelectorOnlyChild>();
-	instance->selectors["only-of-type"] = MakeUnique<StyleSheetNodeSelectorOnlyOfType>();
-	instance->selectors["empty"] = MakeUnique<StyleSheetNodeSelectorEmpty>();
-
 	return true;
 }
 
@@ -117,15 +105,14 @@ StructuralSelector StyleSheetFactory::GetSelector(const String& name)
 		it = instance->selectors.find(name.substr(0, parameter_start));
 
 	if (it == instance->selectors.end())
-		return StructuralSelector(nullptr, 0, 0);
+		return StructuralSelector(StructuralSelectorType::Invalid, 0, 0);
 
 	// Parse the 'a' and 'b' values.
 	int a = 1;
 	int b = 0;
 
 	const size_t parameter_end = name.find(')', parameter_start + 1);
-	if (parameter_start != String::npos &&
-		parameter_end != String::npos)
+	if (parameter_start != String::npos && parameter_end != String::npos)
 	{
 		String parameters = StringUtilities::StripWhitespace(name.substr(parameter_start + 1, parameter_end - (parameter_start + 1)));
 
@@ -181,7 +168,7 @@ StructuralSelector StyleSheetFactory::GetSelector(const String& name)
 		}
 	}
 
-	return StructuralSelector(it->second.get(), a, b);
+	return StructuralSelector(it->second, a, b);
 }
 
 UniquePtr<const StyleSheetContainer> StyleSheetFactory::LoadStyleSheetContainer(const String& sheet)

+ 6 - 7
Source/Core/StyleSheetFactory.h

@@ -15,7 +15,7 @@
  *
  * 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
@@ -34,17 +34,16 @@
 namespace Rml {
 
 class StyleSheetContainer;
-class StyleSheetNodeSelector;
+enum class StructuralSelectorType;
 struct StructuralSelector;
 
 /**
-	Creates stylesheets on the fly as needed. The factory keeps a cache of built sheets for optimisation.
+    Creates stylesheets on the fly as needed. The factory keeps a cache of built sheets for optimisation.
 
-	@author Lloyd Weehuizen
+    @author Lloyd Weehuizen
  */
 
-class StyleSheetFactory
-{
+class StyleSheetFactory {
 public:
 	~StyleSheetFactory();
 
@@ -77,7 +76,7 @@ private:
 	StyleSheets stylesheets;
 
 	// Custom complex selectors available for style sheets.
-	using SelectorMap = UnorderedMap<String, UniquePtr<StyleSheetNodeSelector>>;
+	using SelectorMap = UnorderedMap<String, StructuralSelectorType>;
 	SelectorMap selectors;
 };
 

+ 2 - 2
Source/Core/StyleSheetNode.cpp

@@ -31,7 +31,7 @@
 #include "../../Include/RmlUi/Core/Profiling.h"
 #include "../../Include/RmlUi/Core/StyleSheet.h"
 #include "StyleSheetFactory.h"
-#include "StyleSheetNodeSelector.h"
+#include "StyleSheetSelector.h"
 #include <algorithm>
 
 namespace Rml {
@@ -267,7 +267,7 @@ inline bool StyleSheetNode::MatchStructuralSelector(const Element* element) cons
 {
 	for (auto& node_selector : structural_selectors)
 	{
-		if (!node_selector.selector->IsApplicable(element, node_selector.a, node_selector.b))
+		if (!IsSelectorApplicable(element, node_selector))
 			return false;
 	}
 

+ 1 - 25
Source/Core/StyleSheetNode.h

@@ -31,36 +31,12 @@
 
 #include "../../Include/RmlUi/Core/PropertyDictionary.h"
 #include "../../Include/RmlUi/Core/Types.h"
-#include <tuple>
+#include "StyleSheetSelector.h"
 
 namespace Rml {
 
 struct StyleSheetIndex;
 class StyleSheetNode;
-class StyleSheetNodeSelector;
-
-struct StructuralSelector {
-	StructuralSelector(StyleSheetNodeSelector* selector, int a, int b) : selector(selector), a(a), b(b) {}
-	StyleSheetNodeSelector* selector;
-	int a;
-	int b;
-};
-inline bool operator==(const StructuralSelector& a, const StructuralSelector& b)
-{
-	return a.selector == b.selector && a.a == b.a && a.b == b.b;
-}
-inline bool operator<(const StructuralSelector& a, const StructuralSelector& b)
-{
-	return std::tie(a.selector, a.a, a.b) < std::tie(b.selector, b.a, b.b);
-}
-
-enum class SelectorCombinator : byte {
-	None,
-	Child,             // The 'E > F' combinator: Matches if F is a child of E.
-	NextSibling,       // The 'E + F' combinator: Matches if F is immediately preceded by E.
-	SubsequentSibling, // The 'E ~ F' combinator: Matches if F is preceded by E.
-};
-
 using StructuralSelectorList = Vector<StructuralSelector>;
 using StyleSheetNodeList = Vector<UniquePtr<StyleSheetNode>>;
 

+ 0 - 52
Source/Core/StyleSheetNodeSelector.cpp

@@ -1,52 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-StyleSheetNodeSelector::StyleSheetNodeSelector()
-{
-}
-
-StyleSheetNodeSelector::~StyleSheetNodeSelector()
-{
-}
-
-// Returns true if a positive integer can be found for n in the equation an + b = count.
-bool StyleSheetNodeSelector::IsNth(int a, int b, int count)
-{
-	int x = count;
-	x -= b;
-	if (a != 0)
-		x /= a;
-
-	return (x >= 0 && x * a + b == count);
-}
-
-} // namespace Rml

+ 0 - 60
Source/Core/StyleSheetNodeSelector.h

@@ -1,60 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTOR_H
-#define RMLUI_CORE_STYLESHEETNODESELECTOR_H
-
-namespace Rml {
-
-class Element;
-
-/**
-	The ABC for any complex node selector, such as structural selectors.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelector();
-	virtual ~StyleSheetNodeSelector();
-
-	/// Returns true if the the node this selector is discriminating for is applicable to a given element.
-	/// @param element[in] The element to determine node applicability for.
-	/// @param a[in] For counting selectors, this is the 'a' variable of an + b.
-	/// @param b[in] For counting selectors, this is the 'b' variable of an + b.
-	virtual bool IsApplicable(const Element* element, int a, int b) = 0;
-
-protected:
-	/// Returns true if a positive integer can be found for n in the equation an + b = count.
-	bool IsNth(int a, int b, int count);
-};
-
-} // namespace Rml
-#endif

+ 0 - 57
Source/Core/StyleSheetNodeSelectorEmpty.cpp

@@ -1,57 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorEmpty.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorEmpty::StyleSheetNodeSelectorEmpty()
-{
-}
-
-StyleSheetNodeSelectorEmpty::~StyleSheetNodeSelectorEmpty()
-{
-}
-
-// Returns true if the element has no DOM children.
-bool StyleSheetNodeSelectorEmpty::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	for (int i = 0; i < element->GetNumChildren(); ++i)
-	{
-		if (element->GetChild(i)->GetDisplay() != Style::Display::None)
-			return false;
-	}
-
-	return true;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorEmpty.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTOREMPTY_H
-#define RMLUI_CORE_STYLESHEETNODESELECTOREMPTY_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for an empty node.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorEmpty : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorEmpty();
-	virtual ~StyleSheetNodeSelectorEmpty();
-
-	// Returns true if the element has no DOM children.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorFirstChild.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorFirstChild.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorFirstChild::StyleSheetNodeSelectorFirstChild()
-{
-}
-
-StyleSheetNodeSelectorFirstChild::~StyleSheetNodeSelectorFirstChild()
-{
-}
-
-// Returns true if the element is the first DOM child in its parent.
-bool StyleSheetNodeSelectorFirstChild::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	int child_index = 0;
-	while (child_index < parent->GetNumChildren())
-	{
-		// If this child (the first non-text child) is our element, then the selector succeeds.
-		Element* child = parent->GetChild(child_index);
-		if (child == element)
-			return true;
-
-		// If this child is not a text element, then the selector fails; this element is non-trivial.
-		if (rmlui_dynamic_cast< ElementText* >(child) == nullptr &&
-			child->GetDisplay() != Style::Display::None)
-			return false;
-
-		// Otherwise, skip over the text element to find the last non-trivial element.
-		child_index++;
-	}
-
-	return false;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorFirstChild.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORFIRSTCHILD_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORFIRSTCHILD_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the first generic child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorFirstChild : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorFirstChild();
-	virtual ~StyleSheetNodeSelectorFirstChild();
-
-	// Returns true if the element is the first DOM child in its parent.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorFirstOfType.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorFirstOfType.h"
-#include "../../Include/RmlUi/Core/Element.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorFirstOfType::StyleSheetNodeSelectorFirstOfType()
-{
-}
-
-StyleSheetNodeSelectorFirstOfType::~StyleSheetNodeSelectorFirstOfType()
-{
-}
-
-// Returns true if the element is the first DOM child in its parent of its type.
-bool StyleSheetNodeSelectorFirstOfType::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	int child_index = 0;
-	while (child_index < parent->GetNumChildren())
-	{
-		// If this child is our element, then it's the first one we've found with our tag; the selector succeeds.
-		Element* child = parent->GetChild(child_index);
-		if (child == element)
-			return true;
-
-		// Otherwise, if this child shares our element's tag, then our element is not the first tagged child; the
-		// selector fails.
-		if (child->GetTagName() == element->GetTagName() &&
-			child->GetDisplay() != Style::Display::None)
-			return false;
-
-		child_index++;
-	}
-
-	return false;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorFirstOfType.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORFIRSTOFTYPE_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORFIRSTOFTYPE_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the first child of its type.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorFirstOfType : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorFirstOfType();
-	virtual ~StyleSheetNodeSelectorFirstOfType();
-
-	/// Returns true if the element is the first DOM child in its parent of its type.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorLastChild.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorLastChild.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorLastChild::StyleSheetNodeSelectorLastChild()
-{
-}
-
-StyleSheetNodeSelectorLastChild::~StyleSheetNodeSelectorLastChild()
-{
-}
-
-// Returns true if the element is the last DOM child in its parent.
-bool StyleSheetNodeSelectorLastChild::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	int child_index = parent->GetNumChildren() - 1;
-	while (child_index >= 0)
-	{
-		// If this child (the last non-text child) is our element, then the selector succeeds.
-		Element* child = parent->GetChild(child_index);
-		if (child == element)
-			return true;
-
-		// If this child is not a text element, then the selector fails; this element is non-trivial.
-		if (rmlui_dynamic_cast< ElementText* >(child) == nullptr &&
-			child->GetDisplay() != Style::Display::None)
-			return false;
-
-		// Otherwise, skip over the text element to find the last non-trivial element.
-		child_index--;
-	}
-
-	return false;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorLastChild.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORLASTCHILD_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORLASTCHILD_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the last generic child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorLastChild : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorLastChild();
-	virtual ~StyleSheetNodeSelectorLastChild();
-
-	// Returns true if the element is the last DOM child in its parent.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorLastOfType.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorLastOfType.h"
-#include "../../Include/RmlUi/Core/Element.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorLastOfType::StyleSheetNodeSelectorLastOfType()
-{
-}
-
-StyleSheetNodeSelectorLastOfType::~StyleSheetNodeSelectorLastOfType()
-{
-}
-
-// Returns true if the element is the last DOM child in its parent.
-bool StyleSheetNodeSelectorLastOfType::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	int child_index = parent->GetNumChildren() - 1;
-	while (child_index >= 0)
-	{
-		// If this child is our element, then it's the first one we've found with our tag; the selector succeeds.
-		Element* child = parent->GetChild(child_index);
-		if (child == element)
-			return true;
-
-		// Otherwise, if this child shares our element's tag, then our element is not the first tagged child; the
-		// selector fails.
-		if (child->GetTagName() == element->GetTagName() &&
-			child->GetDisplay() != Style::Display::None)
-			return false;
-
-		child_index--;
-	}
-
-	return false;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorLastOfType.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORLASTOFTYPE_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORLASTOFTYPE_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the first child of its type.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorLastOfType : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorLastOfType();
-	virtual ~StyleSheetNodeSelectorLastOfType();
-
-	// Returns true if the element is the last DOM child in its parent.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 74
Source/Core/StyleSheetNodeSelectorNthChild.cpp

@@ -1,74 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorNthChild.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-#include "../../Include/RmlUi/Core/Log.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorNthChild::StyleSheetNodeSelectorNthChild()
-{
-}
-
-StyleSheetNodeSelectorNthChild::~StyleSheetNodeSelectorNthChild()
-{
-}
-
-// Returns true if the element index is (n * a) + b for a given integer value of n.
-bool StyleSheetNodeSelectorNthChild::IsApplicable(const Element* element, int a, int b)
-{
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	// Start counting elements until we find this one.
-	int element_index = 1;
-	for (int i = 0; i < parent->GetNumChildren(); i++)
-	{
-		Element* child = parent->GetChild(i);
-
-		// Skip text nodes.
-		if (rmlui_dynamic_cast< ElementText* >(child) != nullptr)
-			continue;
-
-		// If we've found our element, then break; the current index is our element's index.
-		if (child == element)
-			break;
-
-		// Skip nodes without a display type.
-		if (child->GetDisplay() == Style::Display::None)
-			continue;
-
-		element_index++;
-	}
-
-	return IsNth(a, b, element_index);
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorNthChild.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORNTHCHILD_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORNTHCHILD_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the nth generic child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorNthChild : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorNthChild();
-	virtual ~StyleSheetNodeSelectorNthChild();
-
-	// Returns true if the element index is (n * a) + b for a given integer value of n.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorNthLastChild.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorNthLastChild.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorNthLastChild::StyleSheetNodeSelectorNthLastChild()
-{
-}
-
-StyleSheetNodeSelectorNthLastChild::~StyleSheetNodeSelectorNthLastChild()
-{
-}
-
-// Returns true if the element's reverse index is (n * a) + b for a given integer value of n.
-bool StyleSheetNodeSelectorNthLastChild::IsApplicable(const Element* element, int a, int b)
-{
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	// Start counting elements until we find this one.
-	int element_index = 1;
-	for (int i = parent->GetNumChildren() - 1; i >= 0; --i)
-	{
-		Element* child = parent->GetChild(i);
-
-		// Skip text nodes.
-		if (rmlui_dynamic_cast< ElementText* >(child) != nullptr)
-			continue;
-
-		// If we've found our element, then break; the current index is our element's index.
-		if (child == element)
-			break;
-
-		if (child->GetDisplay() == Style::Display::None)
-			continue;
-
-		element_index++;
-	}
-
-	return IsNth(a, b, element_index);
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorNthLastChild.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORNTHLASTCHILD_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORNTHLASTCHILD_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the nth-last generic child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorNthLastChild : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorNthLastChild();
-	virtual ~StyleSheetNodeSelectorNthLastChild();
-
-	// Returns true if the element's reverse index is (n * a) + b for a given integer value of n.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 70
Source/Core/StyleSheetNodeSelectorNthLastOfType.cpp

@@ -1,70 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorNthLastOfType.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorNthLastOfType::StyleSheetNodeSelectorNthLastOfType()
-{
-}
-
-StyleSheetNodeSelectorNthLastOfType::~StyleSheetNodeSelectorNthLastOfType()
-{
-}
-
-// Returns true if the element index is (n * a) + b for a given integer value of n.
-bool StyleSheetNodeSelectorNthLastOfType::IsApplicable(const Element* element, int a, int b)
-{
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	// Start counting elements until we find this one.
-	int element_index = 1;
-	for (int i = parent->GetNumChildren() - 1; i >= 0; --i)
-	{
-		Element* child = parent->GetChild(i);
-
-		// If we've found our element, then break; the current index is our element's index.
-		if (child == element)
-			break;
-
-		// Skip nodes that don't share our tag.
-		if (child->GetTagName() != element->GetTagName() ||
-			child->GetDisplay() == Style::Display::None)
-			continue;
-
-		element_index++;
-	}
-
-	return IsNth(a, b, element_index);
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorNthLastOfType.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORNTHLASTOFTYPE_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORNTHLASTOFTYPE_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the nth-last generic child of its type.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorNthLastOfType : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorNthLastOfType();
-	virtual ~StyleSheetNodeSelectorNthLastOfType();
-
-	// Returns true if the element index is (n * a) + b for a given integer value of n.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 70
Source/Core/StyleSheetNodeSelectorNthOfType.cpp

@@ -1,70 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorNthOfType.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorNthOfType::StyleSheetNodeSelectorNthOfType()
-{
-}
-
-StyleSheetNodeSelectorNthOfType::~StyleSheetNodeSelectorNthOfType()
-{
-}
-
-// Returns true if the element index is (n * a) + b for a given integer value of n.
-bool StyleSheetNodeSelectorNthOfType::IsApplicable(const Element* element, int a, int b)
-{
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	// Start counting elements until we find this one.
-	int element_index = 1;
-	for (int i = 0; i < parent->GetNumChildren(); ++i)
-	{
-		Element* child = parent->GetChild(i);
-
-		// If we've found our element, then break; the current index is our element's index.
-		if (child == element)
-			break;
-
-		// Skip nodes that don't share our tag.
-		if (child->GetTagName() != element->GetTagName() ||
-			child->GetDisplay() == Style::Display::None)
-			continue;
-
-		element_index++;
-	}
-
-	return IsNth(a, b, element_index);
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorNthOfType.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORNTHOFTYPE_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORNTHOFTYPE_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the nth generic child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorNthOfType : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorNthOfType();
-	virtual ~StyleSheetNodeSelectorNthOfType();
-
-	// Returns true if the element index is (n * a) + b for a given integer value of n.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 71
Source/Core/StyleSheetNodeSelectorOnlyChild.cpp

@@ -1,71 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorOnlyChild.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorOnlyChild::StyleSheetNodeSelectorOnlyChild()
-{
-}
-
-StyleSheetNodeSelectorOnlyChild::~StyleSheetNodeSelectorOnlyChild()
-{
-}
-
-// Returns true if the element is the only non-trivial DOM child of its parent.
-bool StyleSheetNodeSelectorOnlyChild::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	for (int i = 0; i < parent->GetNumChildren(); ++i)
-	{
-		Element* child = parent->GetChild(i);
-
-		// Skip the child if it is our element.
-		if (child == element)
-			continue;
-
-		// Skip the child if it is trivial.
-		if (rmlui_dynamic_cast< const ElementText* >(element) != nullptr ||
-			child->GetDisplay() == Style::Display::None)
-			continue;
-
-		return false;
-	}
-
-	return true;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorOnlyChild.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORONLYCHILD_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORONLYCHILD_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for an only child.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorOnlyChild : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorOnlyChild();
-	virtual ~StyleSheetNodeSelectorOnlyChild();
-
-	// Returns true if the element is the only non-trivial DOM child of its parent.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 0 - 72
Source/Core/StyleSheetNodeSelectorOnlyOfType.cpp

@@ -1,72 +0,0 @@
-/*
- * 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 "StyleSheetNodeSelectorOnlyOfType.h"
-#include "../../Include/RmlUi/Core/ElementText.h"
-
-namespace Rml {
-
-StyleSheetNodeSelectorOnlyOfType::StyleSheetNodeSelectorOnlyOfType()
-{
-}
-
-StyleSheetNodeSelectorOnlyOfType::~StyleSheetNodeSelectorOnlyOfType()
-{
-}
-
-// Returns true if the element is the only DOM child of its parent of its type.
-bool StyleSheetNodeSelectorOnlyOfType::IsApplicable(const Element* element, int RMLUI_UNUSED_PARAMETER(a), int RMLUI_UNUSED_PARAMETER(b))
-{
-	RMLUI_UNUSED(a);
-	RMLUI_UNUSED(b);
-
-	Element* parent = element->GetParentNode();
-	if (parent == nullptr)
-		return false;
-
-	for (int i = 0; i < parent->GetNumChildren(); ++i)
-	{
-		Element* child = parent->GetChild(i);
-
-		// Skip the child if it is our element.
-		if (child == element)
-			continue;
-
-		// Skip the child if it does not share our tag.
-		if (child->GetTagName() != element->GetTagName() ||
-			child->GetDisplay() == Style::Display::None)
-			continue;
-
-		// We've found a similarly-tagged child to our element; selector fails.
-		return false;
-	}
-
-	return true;
-}
-
-} // namespace Rml

+ 0 - 53
Source/Core/StyleSheetNodeSelectorOnlyOfType.h

@@ -1,53 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef RMLUI_CORE_STYLESHEETNODESELECTORONLYOFTYPE_H
-#define RMLUI_CORE_STYLESHEETNODESELECTORONLYOFTYPE_H
-
-#include "StyleSheetNodeSelector.h"
-
-namespace Rml {
-
-/**
-	A node selector for the only child of its type.
-
-	@author Peter Curry
- */
-
-class StyleSheetNodeSelectorOnlyOfType : public StyleSheetNodeSelector
-{
-public:
-	StyleSheetNodeSelectorOnlyOfType();
-	virtual ~StyleSheetNodeSelectorOnlyOfType();
-
-	// Returns true if the element is the only DOM child of its parent of its type.
-	bool IsApplicable(const Element* element, int a, int b) override;
-};
-
-} // namespace Rml
-#endif

+ 1 - 1
Source/Core/StyleSheetParser.cpp

@@ -948,7 +948,7 @@ StyleSheetNode* StyleSheetParser::ImportProperties(StyleSheetNode* node, String
 				{
 					String pseudo_class_name = identifier.substr(1);
 					StructuralSelector node_selector = StyleSheetFactory::GetSelector(pseudo_class_name);
-					if (node_selector.selector)
+					if (node_selector.type != StructuralSelectorType::Invalid)
 						structural_pseudo_classes.push_back(node_selector);
 					else
 						pseudo_classes.push_back(pseudo_class_name);

+ 326 - 0
Source/Core/StyleSheetSelector.cpp

@@ -0,0 +1,326 @@
+/*
+ * 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 "StyleSheetSelector.h"
+#include "../../Include/RmlUi/Core/Element.h"
+#include "StyleSheetNode.h"
+
+namespace Rml {
+
+static inline bool IsTextElement(const Element* element)
+{
+	return element->GetTagName() == "#text";
+}
+
+// Returns true if a positive integer can be found for n in the equation an + b = count.
+static bool IsNth(int a, int b, int count)
+{
+	int x = count;
+	x -= b;
+	if (a != 0)
+		x /= a;
+
+	return (x >= 0 && x * a + b == count);
+}
+
+bool IsSelectorApplicable(const Element* element, StructuralSelector selector)
+{
+	RMLUI_ASSERT(element);
+
+	switch (selector.type)
+	{
+	case StructuralSelectorType::Nth_Child:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		// Start counting elements until we find this one.
+		int element_index = 1;
+		for (int i = 0; i < parent->GetNumChildren(); i++)
+		{
+			Element* child = parent->GetChild(i);
+
+			// Skip text nodes.
+			if (IsTextElement(child))
+				continue;
+
+			// If we've found our element, then break; the current index is our element's index.
+			if (child == element)
+				break;
+
+			element_index++;
+		}
+
+		return IsNth(selector.a, selector.b, element_index);
+	}
+	break;
+	case StructuralSelectorType::Nth_Last_Child:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		// Start counting elements until we find this one.
+		int element_index = 1;
+		for (int i = parent->GetNumChildren() - 1; i >= 0; --i)
+		{
+			Element* child = parent->GetChild(i);
+
+			// Skip text nodes.
+			if (IsTextElement(child))
+				continue;
+
+			// If we've found our element, then break; the current index is our element's index.
+			if (child == element)
+				break;
+
+			element_index++;
+		}
+
+		return IsNth(selector.a, selector.b, element_index);
+	}
+	break;
+	case StructuralSelectorType::Nth_Of_Type:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		// Start counting elements until we find this one.
+		int element_index = 1;
+		const int num_children = parent->GetNumChildren();
+		for (int i = 0; i < num_children; i++)
+		{
+			Element* child = parent->GetChild(i);
+
+			// If we've found our element, then break; the current index is our element's index.
+			if (child == element)
+				break;
+
+			// Skip nodes that don't share our tag.
+			if (child->GetTagName() != element->GetTagName())
+				continue;
+
+			element_index++;
+		}
+
+		return IsNth(selector.a, selector.b, element_index);
+	}
+	break;
+	case StructuralSelectorType::Nth_Last_Of_Type:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		// Start counting elements until we find this one.
+		int element_index = 1;
+		for (int i = parent->GetNumChildren() - 1; i >= 0; --i)
+		{
+			Element* child = parent->GetChild(i);
+
+			// If we've found our element, then break; the current index is our element's index.
+			if (child == element)
+				break;
+
+			// Skip nodes that don't share our tag.
+			if (child->GetTagName() != element->GetTagName())
+				continue;
+
+			element_index++;
+		}
+
+		return IsNth(selector.a, selector.b, element_index);
+	}
+	break;
+	case StructuralSelectorType::First_Child:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		int child_index = 0;
+		while (child_index < parent->GetNumChildren())
+		{
+			// If this child (the first non-text child) is our element, then the selector succeeds.
+			Element* child = parent->GetChild(child_index);
+			if (child == element)
+				return true;
+
+			// If this child is not a text element, then the selector fails; this element is non-trivial.
+			if (!IsTextElement(child))
+				return false;
+
+			// Otherwise, skip over the text element to find the last non-trivial element.
+			child_index++;
+		}
+
+		return false;
+	}
+	break;
+	case StructuralSelectorType::Last_Child:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		int child_index = parent->GetNumChildren() - 1;
+		while (child_index >= 0)
+		{
+			// If this child (the last non-text child) is our element, then the selector succeeds.
+			Element* child = parent->GetChild(child_index);
+			if (child == element)
+				return true;
+
+			// If this child is not a text element, then the selector fails; this element is non-trivial.
+			if (!IsTextElement(child))
+				return false;
+
+			// Otherwise, skip over the text element to find the last non-trivial element.
+			child_index--;
+		}
+
+		return false;
+	}
+	break;
+	case StructuralSelectorType::First_Of_Type:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		int child_index = 0;
+		while (child_index < parent->GetNumChildren())
+		{
+			// If this child is our element, then it's the first one we've found with our tag; the selector succeeds.
+			Element* child = parent->GetChild(child_index);
+			if (child == element)
+				return true;
+
+			// Otherwise, if this child shares our element's tag, then our element is not the first tagged child; the selector fails.
+			if (child->GetTagName() == element->GetTagName())
+				return false;
+
+			child_index++;
+		}
+
+		return false;
+	}
+	break;
+	case StructuralSelectorType::Last_Of_Type:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		int child_index = parent->GetNumChildren() - 1;
+		while (child_index >= 0)
+		{
+			// If this child is our element, then it's the first one we've found with our tag; the selector succeeds.
+			Element* child = parent->GetChild(child_index);
+			if (child == element)
+				return true;
+
+			// Otherwise, if this child shares our element's tag, then our element is not the first tagged child; the selector fails.
+			if (child->GetTagName() == element->GetTagName())
+				return false;
+
+			child_index--;
+		}
+
+		return false;
+	}
+	break;
+	case StructuralSelectorType::Only_Child:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		const int num_children = parent->GetNumChildren();
+		for (int i = 0; i < num_children; i++)
+		{
+			Element* child = parent->GetChild(i);
+
+			// Skip the child if it is our element.
+			if (child == element)
+				continue;
+
+			// Skip the child if it is trivial.
+			if (IsTextElement(child))
+				continue;
+
+			return false;
+		}
+
+		return true;
+	}
+	break;
+	case StructuralSelectorType::Only_Of_Type:
+	{
+		Element* parent = element->GetParentNode();
+		if (!parent)
+			return false;
+
+		const int num_children = parent->GetNumChildren();
+		for (int i = 0; i < num_children; i++)
+		{
+			Element* child = parent->GetChild(i);
+
+			// Skip the child if it is our element.
+			if (child == element)
+				continue;
+
+			// Skip the child if it does not share our tag.
+			if (child->GetTagName() != element->GetTagName())
+				continue;
+
+			// We've found a similarly-tagged child to our element; selector fails.
+			return false;
+		}
+
+		return true;
+	}
+	break;
+	case StructuralSelectorType::Empty:
+	{
+		return element->GetNumChildren() == 0;
+	}
+	break;
+	case StructuralSelectorType::Invalid:
+	{
+		RMLUI_ERROR;
+	}
+	break;
+	}
+
+	return false;
+}
+
+} // namespace Rml

+ 83 - 0
Source/Core/StyleSheetSelector.h

@@ -0,0 +1,83 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef RMLUI_CORE_STYLESHEETSELECTOR_H
+#define RMLUI_CORE_STYLESHEETSELECTOR_H
+
+#include "../../Include/RmlUi/Core/Types.h"
+#include <tuple>
+
+namespace Rml {
+
+class Element;
+
+enum class StructuralSelectorType {
+	Invalid,
+	Nth_Child,
+	Nth_Last_Child,
+	Nth_Of_Type,
+	Nth_Last_Of_Type,
+	First_Child,
+	Last_Child,
+	First_Of_Type,
+	Last_Of_Type,
+	Only_Child,
+	Only_Of_Type,
+	Empty
+};
+
+struct StructuralSelector {
+	StructuralSelector(StructuralSelectorType type, int a, int b) : type(type), a(a), b(b) {}
+	StructuralSelectorType type;
+	// For counting selectors, the following are the 'a' and 'b' variables of an + b.
+	int a;
+	int b;
+};
+inline bool operator==(const StructuralSelector& a, const StructuralSelector& b)
+{
+	return a.type == b.type && a.a == b.a && a.b == b.b;
+}
+inline bool operator<(const StructuralSelector& a, const StructuralSelector& b)
+{
+	return std::tie(a.type, a.a, a.b) < std::tie(b.type, b.a, b.b);
+}
+
+enum class SelectorCombinator : byte {
+	None,
+	Child,             // The 'E > F' combinator: Matches if F is a child of E.
+	NextSibling,       // The 'E + F' combinator: Matches if F is immediately preceded by E.
+	SubsequentSibling, // The 'E ~ F' combinator: Matches if F is preceded by E.
+};
+
+/// Returns true if the the node the given selector is discriminating for is applicable to a given element.
+/// @param element[in] The element to determine node applicability for.
+/// @param selector[in] The selector to test against the element.
+bool IsSelectorApplicable(const Element* element, StructuralSelector selector);
+
+} // namespace Rml
+#endif