StyleProperties.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, const Length& fallback) const;
  32. 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;
  33. Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
  34. Optional<CSS::TextAlign> text_align() const;
  35. CSS::Display display() const;
  36. Optional<CSS::Float> float_() const;
  37. Optional<CSS::Clear> clear() const;
  38. Optional<CSS::Cursor> cursor() const;
  39. Optional<CSS::WhiteSpace> white_space() const;
  40. Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
  41. Optional<CSS::TextDecorationLine> text_decoration_line() const;
  42. Optional<CSS::TextTransform> text_transform() const;
  43. Optional<CSS::ListStyleType> list_style_type() const;
  44. Optional<CSS::FlexDirection> flex_direction() const;
  45. Optional<CSS::FlexWrap> flex_wrap() const;
  46. Optional<CSS::FlexBasisData> flex_basis() const;
  47. float flex_grow() const;
  48. float flex_shrink() const;
  49. Optional<CSS::AlignItems> align_items() const;
  50. float opacity() const;
  51. Optional<CSS::JustifyContent> justify_content() const;
  52. Optional<CSS::Overflow> overflow_x() const;
  53. Optional<CSS::Overflow> overflow_y() const;
  54. Optional<BackgroundRepeatData> background_repeat() const;
  55. Optional<CSS::BoxShadowData> box_shadow() const;
  56. CSS::BoxSizing box_sizing() const;
  57. Optional<CSS::PointerEvents> pointer_events() const;
  58. Vector<CSS::Transformation> transformations() const;
  59. Gfx::Font const& computed_font() const
  60. {
  61. VERIFY(m_font);
  62. return *m_font;
  63. }
  64. void set_computed_font(NonnullRefPtr<Gfx::Font> font)
  65. {
  66. m_font = move(font);
  67. }
  68. float line_height(const Layout::Node&) const;
  69. bool operator==(const StyleProperties&) const;
  70. bool operator!=(const StyleProperties& other) const { return !(*this == other); }
  71. Optional<CSS::Position> position() const;
  72. Optional<int> z_index() const;
  73. static NonnullRefPtr<Gfx::Font> font_fallback(bool monospace, bool bold);
  74. private:
  75. friend class StyleComputer;
  76. HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> m_property_values;
  77. Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
  78. mutable RefPtr<Gfx::Font> m_font;
  79. };
  80. }