StyleProperties.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <LibGfx/Font.h>
  10. #include <LibGfx/Forward.h>
  11. #include <LibWeb/CSS/ComputedValues.h>
  12. #include <LibWeb/CSS/LengthBox.h>
  13. #include <LibWeb/CSS/StyleValue.h>
  14. namespace Web::CSS {
  15. class StyleProperties : public RefCounted<StyleProperties> {
  16. public:
  17. StyleProperties();
  18. explicit StyleProperties(const StyleProperties&);
  19. static NonnullRefPtr<StyleProperties> create() { return adopt_ref(*new StyleProperties); }
  20. NonnullRefPtr<StyleProperties> clone() const;
  21. template<typename Callback>
  22. inline void for_each_property(Callback callback) const
  23. {
  24. for (auto& it : m_property_values)
  25. callback((CSS::PropertyID)it.key, *it.value);
  26. }
  27. HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>>& properties() { return m_property_values; }
  28. HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> const& properties() const { return m_property_values; }
  29. void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
  30. Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
  31. Length length_or_fallback(CSS::PropertyID, Length const& fallback) const;
  32. LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
  33. LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
  34. Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
  35. Optional<CSS::TextAlign> text_align() const;
  36. CSS::Display display() const;
  37. Optional<CSS::Float> float_() const;
  38. Optional<CSS::Clear> clear() const;
  39. Optional<CSS::Cursor> cursor() const;
  40. Optional<CSS::WhiteSpace> white_space() const;
  41. Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
  42. Optional<CSS::TextDecorationLine> text_decoration_line() const;
  43. Optional<CSS::TextDecorationStyle> text_decoration_style() const;
  44. Optional<CSS::TextTransform> text_transform() const;
  45. Optional<CSS::ListStyleType> list_style_type() const;
  46. Optional<CSS::FlexDirection> flex_direction() const;
  47. Optional<CSS::FlexWrap> flex_wrap() const;
  48. Optional<CSS::FlexBasisData> flex_basis() const;
  49. float flex_grow() const;
  50. float flex_shrink() const;
  51. Optional<CSS::AlignItems> align_items() const;
  52. float opacity() const;
  53. Optional<CSS::JustifyContent> justify_content() const;
  54. Optional<CSS::Overflow> overflow_x() const;
  55. Optional<CSS::Overflow> overflow_y() const;
  56. Optional<CSS::BoxShadowData> box_shadow() const;
  57. CSS::BoxSizing box_sizing() const;
  58. Optional<CSS::PointerEvents> pointer_events() const;
  59. Vector<CSS::Transformation> transformations() const;
  60. Gfx::Font const& computed_font() const
  61. {
  62. VERIFY(m_font);
  63. return *m_font;
  64. }
  65. void set_computed_font(NonnullRefPtr<Gfx::Font> font)
  66. {
  67. m_font = move(font);
  68. }
  69. float line_height(const Layout::Node&) const;
  70. bool operator==(const StyleProperties&) const;
  71. bool operator!=(const StyleProperties& other) const { return !(*this == other); }
  72. Optional<CSS::Position> position() const;
  73. Optional<int> z_index() const;
  74. static NonnullRefPtr<Gfx::Font> font_fallback(bool monospace, bool bold);
  75. private:
  76. friend class StyleComputer;
  77. HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> m_property_values;
  78. Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
  79. mutable RefPtr<Gfx::Font> m_font;
  80. };
  81. }