ElementStyleCache.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICOREELEMENTSTYLECACHE_H
  29. #define RMLUICOREELEMENTSTYLECACHE_H
  30. #include "ElementDefinition.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. namespace Rml {
  33. namespace Core {
  34. class ElementStyle;
  35. /**
  36. Manages caching of layout-important properties and provides
  37. O(1) access to them (note that for invalidated cache, the access
  38. time is still O(log(N)) as per standard std::map).
  39. @author Victor Luchits
  40. */
  41. class ElementStyleCache
  42. {
  43. public:
  44. ElementStyleCache(ElementStyle *style);
  45. /// Invalidation function for all non-inherited properties
  46. void Clear();
  47. /// Invalidation function for all inherited properties
  48. void ClearInherited();
  49. /// Invalidation functions for individual and grouped non-inherited properties
  50. void ClearOffset();
  51. void ClearBorder();
  52. void ClearMargin();
  53. void ClearPadding();
  54. void ClearDimensions();
  55. void ClearPosition();
  56. void ClearFloat();
  57. void ClearDisplay();
  58. void ClearWhitespace();
  59. void ClearOverflow();
  60. /// Invalidation functions for individual and grouped inherited properties
  61. void ClearLineHeight();
  62. void ClearTextAlign();
  63. void ClearTextTransform();
  64. void ClearVerticalAlign();
  65. void ClearPointerEvents();
  66. /// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
  67. void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );
  68. /// Returns 'border-width' properties from element's style or local cache.
  69. void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
  70. /// Returns 'margin' properties from element's style or local cache.
  71. void GetMarginProperties(const Property **margin_top, const Property **margin_bottom, const Property **margin_left, const Property **margin_right);
  72. /// Returns 'padding' properties from element's style or local cache.
  73. void GetPaddingProperties(const Property **padding_top, const Property **padding_bottom, const Property **padding_left, const Property **padding_right);
  74. /// Returns 'width' and 'height' properties from element's style or local cache.
  75. void GetDimensionProperties(const Property **width, const Property **height);
  76. /// Returns local 'width' and 'height' properties from element's style or local cache,
  77. /// ignoring default values.
  78. void GetLocalDimensionProperties(const Property **width, const Property **height);
  79. /// Returns 'overflow' properties' values from element's style or local cache.
  80. void GetOverflow(int *overflow_x, int *overflow_y);
  81. /// Returns 'position' property value from element's style or local cache.
  82. int GetPosition();
  83. /// Returns 'float' property value from element's style or local cache.
  84. int GetFloat();
  85. /// Returns 'display' property value from element's style or local cache.
  86. int GetDisplay();
  87. /// Returns 'white-space' property value from element's style or local cache.
  88. int GetWhitespace();
  89. /// Returns 'pointer-events' property value from element's style or local cache.
  90. int GetPointerEvents();
  91. /// Returns 'line-height' property value from element's style or local cache.
  92. const Property *GetLineHeightProperty();
  93. /// Returns 'text-align' property value from element's style or local cache.
  94. int GetTextAlign();
  95. /// Returns 'text-transform' property value from element's style or local cache.
  96. int GetTextTransform();
  97. /// Returns 'vertical-align' property value from element's style or local cache.
  98. const Property *GetVerticalAlignProperty();
  99. private:
  100. /// Element style that owns this cache instance.
  101. ElementStyle *style;
  102. /// Cached properties.
  103. const Property *top, *bottom, *left, *right;
  104. const Property *border_top_width, *border_bottom_width, *border_left_width, *border_right_width;
  105. const Property *margin_top, *margin_bottom, *margin_left, *margin_right;
  106. const Property *padding_top, *padding_bottom, *padding_left, *padding_right;
  107. const Property *width, *height;
  108. const Property *local_width, *local_height;
  109. bool have_local_width, have_local_height;
  110. int overflow_x, overflow_y;
  111. int position;
  112. int float_;
  113. int display;
  114. int whitespace;
  115. const Property *line_height;
  116. int text_align;
  117. int text_transform;
  118. const Property *vertical_align;
  119. int pointer_events;
  120. };
  121. }
  122. }
  123. #endif