blob: 1ca45a6e838b6160b92a89eae3c51af65bd6f714 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "cru/ui/mapper/style/StyleRuleMapper.h"
#include "cru/common/ClonablePtr.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/style/IConditionMapper.h"
#include "cru/ui/mapper/style/IStylerMapper.h"
#include "cru/ui/style/Condition.h"
#include "cru/ui/style/StyleRule.h"
#include "cru/ui/style/Styler.h"
namespace cru::ui::mapper::style {
using namespace ui::style;
bool StyleRuleMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
return node->GetTag().CaseInsensitiveEqual(u"StyleRule");
}
ClonablePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml(
xml::XmlElementNode* node) {
std::vector<IConditionMapper*> condition_mappers =
MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
std::vector<IStylerMapper*> styler_mappers =
MapperRegistry::GetInstance()->GetMappersByInterface<IStylerMapper>();
std::vector<ClonablePtr<Condition>> conditions;
std::vector<ClonablePtr<Styler>> stylers;
for (auto child : node->GetChildren()) {
if (child->GetType() == xml::XmlNode::Type::Element) {
auto c = child->AsElement();
bool resolved = false;
for (auto condition_mapper : condition_mappers) {
if (condition_mapper->XmlElementIsOfThisType(c)) {
conditions.push_back(condition_mapper->MapConditionFromXml(c));
resolved = true;
break;
}
}
if (!resolved) {
for (auto styler_mapper : styler_mappers) {
if (styler_mapper->XmlElementIsOfThisType(c)) {
stylers.push_back(styler_mapper->MapStylerFromXml(c));
resolved = true;
break;
}
}
}
}
}
return StyleRule::Create(AndCondition::Create(std::move(conditions)),
CompoundStyler::Create(std::move(stylers)));
}
} // namespace cru::ui::mapper::style
|