You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

css_style.hxx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*-
  2. * Copyright 2021 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #ifndef RSPAMD_CSS_STYLE_HXX
  18. #define RSPAMD_CSS_STYLE_HXX
  19. #include <memory>
  20. #include <vector>
  21. #include "css_rule.hxx"
  22. #include "css_selector.hxx"
  23. namespace rspamd::css {
  24. /*
  25. * Full CSS style representation
  26. */
  27. class css_style {
  28. public:
  29. /* Make class trivial */
  30. css_style(const css_style &other) = default;
  31. css_style(const std::shared_ptr<css_style> &_parent)
  32. : parent(_parent)
  33. {
  34. propagate_from_parent();
  35. }
  36. css_style(const std::shared_ptr<css_style> &_parent,
  37. const std::vector<std::shared_ptr<css_selector>> &_selectors)
  38. : parent(_parent)
  39. {
  40. selectors.reserve(_selectors.size());
  41. for (const auto &sel_ptr: _selectors) {
  42. selectors.emplace_back(sel_ptr);
  43. }
  44. propagate_from_parent();
  45. }
  46. private:
  47. std::vector<std::weak_ptr<css_selector>> selectors;
  48. std::weak_ptr<css_style> parent;
  49. std::vector<css_rule> rules;
  50. private:
  51. void propagate_from_parent(void); /* Construct full style using parent */
  52. };
  53. }// namespace rspamd::css
  54. #endif//RSPAMD_CSS_STYLE_HXX