| 25 | CSSAttributesManager::~CSSAttributesManager() = default; |
| 26 | |
| 27 | bool CSSAttributesManager::apply(const Value& style, const CSSAttributesManagerUpdateContext& context) { |
| 28 | if (style.isNullOrUndefined()) { |
| 29 | return removeAllStyles(context); |
| 30 | } else if (style.isArray()) { |
| 31 | SmallVector<Ref<CSSAttributes>, 2> styles; |
| 32 | |
| 33 | [[maybe_unused]] size_t index = 0; |
| 34 | for (const auto& arrayItem : *style.getArray()) { |
| 35 | auto cssAttributes = castOrNull<CSSAttributes>(arrayItem.getValdiObject()); |
| 36 | if (cssAttributes == nullptr) { |
| 37 | VALDI_ERROR(context.logger, |
| 38 | "Failed to apply style: Given style {} at index {} is not a CSSAttributes object", |
| 39 | style.toString(), |
| 40 | index); |
| 41 | } else { |
| 42 | styles.emplace_back(std::move(cssAttributes)); |
| 43 | } |
| 44 | index++; |
| 45 | } |
| 46 | |
| 47 | return setStyles(std::move(styles), context); |
| 48 | } else { |
| 49 | auto cssAttributes = castOrNull<CSSAttributes>(style.getValdiObject()); |
| 50 | if (cssAttributes == nullptr) { |
| 51 | VALDI_ERROR(context.logger, |
| 52 | "Failed to apply style: Given style {} is not a CSSAttributes object", |
| 53 | style.toString()); |
| 54 | return removeAllStyles(context); |
| 55 | } |
| 56 | |
| 57 | SmallVector<Ref<CSSAttributes>, 2> styles; |
| 58 | styles.emplace_back(std::move(cssAttributes)); |
| 59 | |
| 60 | return setStyles(std::move(styles), context); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | bool CSSAttributesManager::removeAllStyles(const CSSAttributesManagerUpdateContext& context) { |
| 65 | auto changed = false; |
nothing calls this directly
no test coverage detected