ComputedValues.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2019 Michael R. P. Ragazzon
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCORERCSS_H
  28. #define ROCKETCORERCSS_H
  29. #include "Types.h"
  30. #include "Animation.h"
  31. namespace Rocket {
  32. namespace Core {
  33. namespace Style
  34. {
  35. struct LengthPercentageAuto {
  36. enum Type { Auto, Length, Percentage } type = Length;
  37. float value = 0;
  38. LengthPercentageAuto() {}
  39. LengthPercentageAuto(Type type, float value = 0) : type(type), value(value) {}
  40. };
  41. struct LengthPercentage {
  42. enum Type { Length, Percentage } type = Length;
  43. float value = 0;
  44. LengthPercentage() {}
  45. LengthPercentage(Type type, float value = 0) : type(type), value(value) {}
  46. };
  47. struct NumberAuto {
  48. enum Type { Auto, Number } type = Number;
  49. float value = 0;
  50. NumberAuto() {}
  51. NumberAuto(Type type, float value = 0) : type(type), value(value) {}
  52. };
  53. using Margin = LengthPercentageAuto;
  54. using Padding = LengthPercentage;
  55. enum class Display { None, Block, Inline, InlineBlock };
  56. enum class Position { Static, Relative, Absolute, Fixed };
  57. using Top = LengthPercentageAuto;
  58. using Right = LengthPercentageAuto;
  59. using Bottom = LengthPercentageAuto;
  60. using Left = LengthPercentageAuto;
  61. enum class Float { None, Left, Right };
  62. enum class Clear { None, Left, Right, Both };
  63. using ZIndex = NumberAuto;
  64. using Width = LengthPercentageAuto;
  65. using MinWidth = LengthPercentage;
  66. using MaxWidth = LengthPercentage;
  67. using Height = LengthPercentageAuto;
  68. using MinHeight = LengthPercentage;
  69. using MaxHeight = LengthPercentage;
  70. struct LineHeight {
  71. float value = 12.f * 1.2f; // The computed value (length)
  72. enum InheritType { Number, Length } inherit_type = Number;
  73. float inherit_value = 1.2f;
  74. LineHeight() {}
  75. LineHeight(float value, InheritType inherit_type, float inherit_value) : value(value), inherit_type(inherit_type), inherit_value(inherit_value) {}
  76. };
  77. struct VerticalAlign {
  78. enum Type { Baseline, Middle, Sub, Super, TextTop, TextBottom, Top, Bottom, Length } type;
  79. float value; // For length type
  80. VerticalAlign(Type type = Baseline) : type(type), value(0) {}
  81. VerticalAlign(float value) : type(Length), value(value) {}
  82. };
  83. enum class Overflow { Visible, Hidden, Auto, Scroll };
  84. struct Clip {
  85. // Note, internally Auto is 0 and None is -1, however, the enum must correspond to the keywords in StyleSheetSpec
  86. enum Type { Auto, None, Number };
  87. int number = 0;
  88. Clip() {}
  89. Clip(Type type, int number = 0) : number(type == Auto ? 0 : (type == None ? -1 : number)) {}
  90. };
  91. enum class Visibility { Visible, Hidden };
  92. enum class FontStyle { Normal, Italic };
  93. enum class FontWeight { Normal, Bold };
  94. enum class TextAlign { Left, Right, Center, Justify };
  95. enum class TextDecoration { None, Underline };
  96. enum class TextTransform { None, Capitalize, Uppercase, Lowercase };
  97. enum class WhiteSpace { Normal, Pre, Nowrap, Prewrap, Preline };
  98. enum class Drag { None, Drag, DragDrop, Block, Clone };
  99. enum class TabIndex { None, Auto };
  100. enum class Focus { None, Auto };
  101. enum class PointerEvents { None, Auto };
  102. using PerspectiveOrigin = LengthPercentage;
  103. using TransformOrigin = LengthPercentage;
  104. enum class OriginX { Left, Center, Right };
  105. enum class OriginY { Top, Center, Bottom };
  106. // A computed value is a value resolved as far as possible :before: updating layout. See CSS specs for details of each property.
  107. struct ComputedValues
  108. {
  109. Margin margin_top, margin_right, margin_bottom, margin_left;
  110. Padding padding_top, padding_right, padding_bottom, padding_left;
  111. float border_top_width = 0, border_right_width = 0, border_bottom_width = 0, border_left_width = 0;
  112. Colourb border_top_color{ 255, 255, 255 }, border_right_color{ 255, 255, 255 }, border_bottom_color{ 255, 255, 255 }, border_left_color{ 255, 255, 255 };
  113. Display display = Display::Inline;
  114. Position position = Position::Static;
  115. Top top{ Top::Auto };
  116. Right right{ Right::Auto };
  117. Bottom bottom{ Bottom::Auto };
  118. Left left{ Left::Auto };
  119. Float float_ = Float::None;
  120. Clear clear = Clear::None;
  121. ZIndex z_index = { ZIndex::Auto };
  122. Width width = { Width::Auto };
  123. MinWidth min_width;
  124. MaxWidth max_width{ MaxWidth::Length, -1.f };
  125. Height height = { Height::Auto };
  126. MinHeight min_height;
  127. MaxHeight max_height{ MaxHeight::Length, -1.f };
  128. LineHeight line_height;
  129. VerticalAlign vertical_align;
  130. Overflow overflow_x = Overflow::Visible, overflow_y = Overflow::Visible;
  131. Clip clip;
  132. Visibility visibility = Visibility::Visible;
  133. Colourb background_color = Colourb(255, 255, 255, 0);
  134. Colourb color = Colourb(255, 255, 255);
  135. Colourb image_color = Colourb(255, 255, 255);
  136. float opacity = 1;
  137. String font_family;
  138. String font_charset; // empty is same as "U+0020-007E"
  139. FontStyle font_style = FontStyle::Normal;
  140. FontWeight font_weight = FontWeight::Normal;
  141. float font_size = 12.f;
  142. TextAlign text_align = TextAlign::Left;
  143. TextDecoration text_decoration = TextDecoration::None;
  144. TextTransform text_transform = TextTransform::None;
  145. WhiteSpace white_space = WhiteSpace::Normal;
  146. String cursor;
  147. Drag drag = Drag::None;
  148. TabIndex tab_index = TabIndex::None;
  149. Focus focus = Focus::Auto;
  150. float scrollbar_margin = 0;
  151. PointerEvents pointer_events = PointerEvents::Auto;
  152. float perspective = 0;
  153. PerspectiveOrigin perspective_origin_x = { PerspectiveOrigin::Percentage, 50.f };
  154. PerspectiveOrigin perspective_origin_y = { PerspectiveOrigin::Percentage, 50.f };
  155. TransformRef transform;
  156. TransformOrigin transform_origin_x = { TransformOrigin::Percentage, 50.f };
  157. TransformOrigin transform_origin_y = { TransformOrigin::Percentage, 50.f };
  158. float transform_origin_z = 0.0f;
  159. TransitionList transition;
  160. AnimationList animation;
  161. };
  162. }
  163. // Resolves a computed LengthPercentage value to the base unit 'px'.
  164. // Percentages are scaled by the base_value.
  165. // Note: Auto must be manually handled during layout, here it returns zero.
  166. ROCKETCORE_API float ResolveValue(Style::LengthPercentageAuto length, float base_value);
  167. ROCKETCORE_API float ResolveValue(Style::LengthPercentage length, float base_value);
  168. using ComputedValues = Style::ComputedValues;
  169. }
  170. }
  171. #endif