LayoutStyle.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Optional.h>
  28. #include <LibWeb/CSS/LengthBox.h>
  29. #include <LibWeb/CSS/StyleValue.h>
  30. namespace Web {
  31. class InitialValues {
  32. public:
  33. static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
  34. };
  35. class LayoutStyle {
  36. public:
  37. Optional<int> z_index() const { return m_z_index; }
  38. CSS::TextAlign text_align() const { return m_text_align; }
  39. CSS::Position position() const { return m_position; }
  40. CSS::WhiteSpace white_space() const { return m_white_space; }
  41. const Length& width() const { return m_width; }
  42. const Length& min_width() const { return m_min_width; }
  43. const Length& max_width() const { return m_max_width; }
  44. const Length& height() const { return m_height; }
  45. const Length& min_height() const { return m_min_height; }
  46. const Length& max_height() const { return m_max_height; }
  47. const LengthBox& offset() const { return m_offset; }
  48. const LengthBox& margin() const { return m_margin; }
  49. const LengthBox& padding() const { return m_padding; }
  50. protected:
  51. Optional<int> m_z_index;
  52. CSS::TextAlign m_text_align;
  53. CSS::Position m_position;
  54. CSS::WhiteSpace m_white_space { InitialValues::white_space() };
  55. Length m_width;
  56. Length m_min_width;
  57. Length m_max_width;
  58. Length m_height;
  59. Length m_min_height;
  60. Length m_max_height;
  61. LengthBox m_offset;
  62. LengthBox m_margin;
  63. LengthBox m_padding;
  64. };
  65. class ImmutableLayoutStyle final : public LayoutStyle {
  66. };
  67. class MutableLayoutStyle final : public LayoutStyle {
  68. public:
  69. void set_z_index(Optional<int> value) { m_z_index = value; }
  70. void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; }
  71. void set_position(CSS::Position position) { m_position = position; }
  72. void set_white_space(CSS::WhiteSpace value) { m_white_space = value; }
  73. void set_width(const Length& width) { m_width = width; }
  74. void set_min_width(const Length& width) { m_min_width = width; }
  75. void set_max_width(const Length& width) { m_max_width = width; }
  76. void set_height(const Length& height) { m_height = height; }
  77. void set_min_height(const Length& height) { m_min_height = height; }
  78. void set_max_height(const Length& height) { m_max_height = height; }
  79. void set_offset(const LengthBox& offset) { m_offset = offset; }
  80. void set_margin(const LengthBox& margin) { m_margin = margin; }
  81. void set_padding(const LengthBox& padding) { m_padding = padding; }
  82. };
  83. }