}
/* Helpers to define which values are valid for which properties */
- constexpr auto is_color(void) const -> bool {
+ auto is_color(void) const -> bool {
return type == css_property_type::PROPERTY_COLOR ||
type == css_property_type::PROPERTY_BACKGROUND ||
type == css_property_type::PROPERTY_BGCOLOR ||
type == css_property_type::PROPERTY_FONT_COLOR ||
type == css_property_type::PROPERTY_FONT;
}
- constexpr auto is_dimension(void) const -> bool {
+ auto is_dimension(void) const -> bool {
return type == css_property_type::PROPERTY_HEIGHT ||
type == css_property_type::PROPERTY_WIDTH ||
type == css_property_type::PROPERTY_FONT_SIZE ||
type == css_property_type::PROPERTY_FONT;
}
- constexpr auto is_normal_number(void) const -> bool {
+
+ auto is_normal_number(void) const -> bool {
return type == css_property_type::PROPERTY_OPACITY;
}
+ auto is_display(void) const -> bool {
+ return type == css_property_type::PROPERTY_DISPLAY;
+ }
+
auto operator==(const css_property &other) const { return type == other.type; }
};
});
}
-auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
+auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> bool
{
auto it = rules.find(rule);
auto &&remote_prop = rule->get_prop();
+ auto ret = true;
+
+ if (rule->get_values().size() == 0) {
+ /* Ignore rules with no values */
+ return false;
+ }
if (it != rules.end()) {
auto &&local_rule = *it;
local_rule->override_values(*rule);
}
else {
- /* Ignore remote not important over local important */
+ /* Override remote not important over local important */
local_rule->merge_values(*rule);
}
}
local_rule->override_values(*rule);
}
else {
- /* Ignore local not important over important */
+ /* Override local not important over important */
local_rule->merge_values(*rule);
}
}
}
else if (remote_prop.flag == css_property_flag::FLAG_NOT_IMPORTANT) {
/* Ignore remote not important over local normal */
+ ret = false;
}
else {
/* Merge both */
}
}
}
+ else {
+ rules.insert(std::move(rule));
+ }
+
+ return ret;
}
}
if (next_tok.is_token()) {
const auto &parser_tok = next_tok.get_token_or_empty();
- if (parser_tok.type == css_parser_token::token_type::semicolon_token) {
+ if (parser_tok.type == css_parser_token::token_type::semicolon_token && cur_rule) {
ret.add_rule(std::move(cur_rule));
state = parse_property;
seen_not = false;
if (state == parse_value) {
auto maybe_value = allowed_property_value(cur_property, next_tok);
- if (maybe_value) {
+ if (maybe_value && cur_rule) {
msg_debug_css("added value %s to the property %s",
maybe_value.value().debug_str().c_str(),
cur_property.to_string());
using rule_shared_hash = shared_ptr_hash<css_rule>;
using rule_shared_eq = shared_ptr_equal<css_rule>;
css_declarations_block() = default;
- auto add_rule(rule_shared_ptr &&rule) -> void;
+ auto add_rule(rule_shared_ptr &&rule) -> bool;
auto get_rules(void) const -> const auto & {
return rules;
}