aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/style/ClickStateConditionMapper.cpp
blob: 5b25de2c9520bf3f20bb33a927ec89d87c125477 (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
#include "cru/ui/mapper/style/ClickStateConditionMapper.h"
#include "cru/common/ClonablePtr.h"
#include "cru/common/Exception.h"
#include "cru/ui/helper/ClickDetector.h"
#include "cru/ui/style/Condition.h"

namespace cru::ui::mapper::style {
bool ClickStateConditionMapper::XmlElementIsOfThisType(
    xml::XmlElementNode *node) {
  return node->GetTag().CaseInsensitiveEqual(u"ClickStateCondition");
}

ClonablePtr<ui::style::ClickStateCondition>
ClickStateConditionMapper::DoMapFromXml(xml::XmlElementNode *node) {
  auto state = helper::ClickState::None;
  auto value_attr = node->GetOptionalAttributeValueCaseInsensitive(u"value");
  if (value_attr) {
    if (value_attr->CaseInsensitiveEqual(u"none")) {
      state = helper::ClickState::None;
    } else if (value_attr->CaseInsensitiveEqual(u"hover")) {
      state = helper::ClickState::Hover;
    } else if (value_attr->CaseInsensitiveEqual(u"press")) {
      state = helper::ClickState::Press;
    } else if (value_attr->CaseInsensitiveEqual(u"pressinactive")) {
      state = helper::ClickState::PressInactive;
    } else {
      throw Exception(u"Unknown click state: " + *value_attr);
    }
  }

  return ui::style::ClickStateCondition::Create(state);
}
}  // namespace cru::ui::mapper::style