ElementStyleCache.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  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 ROCKETCOREELEMENTSTYLECACHE_H
  28. #define ROCKETCOREELEMENTSTYLECACHE_H
  29. #include "ElementDefinition.h"
  30. #include "../../Include/Rocket/Core/Types.h"
  31. namespace Rocket {
  32. namespace Core {
  33. class ElementStyle;
  34. /**
  35. Manages caching of layout-important properties and provides
  36. O(1) access to them (note that for invalidated cache, the access
  37. time is still O(log(N)) as per standard std::map).
  38. @author Victor Luchits
  39. */
  40. class ElementStyleCache
  41. {
  42. public:
  43. ElementStyleCache(ElementStyle *style);
  44. /// Invalidation function for all non-inherited properties
  45. void Clear();
  46. /// Invalidation function for all inherited properties
  47. void ClearInherited();
  48. /// Invalidation functions for individual and grouped non-inherited properties
  49. void ClearOffset();
  50. void ClearBorder();
  51. void ClearMargin();
  52. void ClearPadding();
  53. void ClearDimensions();
  54. void ClearPosition();
  55. void ClearFloat();
  56. void ClearDisplay();
  57. void ClearWhitespace();
  58. void ClearOverflow();
  59. /// Invalidation functions for individual and grouped inherited properties
  60. void ClearLineHeight();
  61. void ClearTextAlign();
  62. void ClearTextTransform();
  63. void ClearVerticalAlign();
  64. /// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
  65. void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );
  66. /// Returns 'border-width' properties from element's style or local cache.
  67. void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
  68. /// Returns 'margin' properties from element's style or local cache.
  69. void GetMarginProperties(const Property **margin_top, const Property **margin_bottom, const Property **margin_left, const Property **margin_right);
  70. /// Returns 'padding' properties from element's style or local cache.
  71. void GetPaddingProperties(const Property **padding_top, const Property **padding_bottom, const Property **padding_left, const Property **padding_right);
  72. /// Returns 'width' and 'height' properties from element's style or local cache.
  73. void GetDimensionProperties(const Property **width, const Property **height);
  74. /// Returns local 'width' and 'height' properties from element's style or local cache,
  75. /// ignoring default values.
  76. void GetLocalDimensionProperties(const Property **width, const Property **height);
  77. /// Returns 'overflow' properties' values from element's style or local cache.
  78. void GetOverflow(int *overflow_x, int *overflow_y);
  79. /// Returns 'position' property value from element's style or local cache.
  80. int GetPosition();
  81. /// Returns 'float' property value from element's style or local cache.
  82. int GetFloat();
  83. /// Returns 'display' property value from element's style or local cache.
  84. int GetDisplay();
  85. /// Returns 'white-space' property value from element's style or local cache.
  86. int GetWhitespace();
  87. /// Returns 'line-height' property value from element's style or local cache.
  88. const Property *GetLineHeightProperty();
  89. /// Returns 'text-align' property value from element's style or local cache.
  90. int GetTextAlign();
  91. /// Returns 'text-transform' property value from element's style or local cache.
  92. int GetTextTransform();
  93. /// Returns 'vertical-align' property value from element's style or local cache.
  94. const Property *GetVerticalAlignProperty();
  95. private:
  96. /// Element style that owns this cache instance.
  97. ElementStyle *style;
  98. /// Cached properties.
  99. const Property *top, *bottom, *left, *right;
  100. const Property *border_top_width, *border_bottom_width, *border_left_width, *border_right_width;
  101. const Property *margin_top, *margin_bottom, *margin_left, *margin_right;
  102. const Property *padding_top, *padding_bottom, *padding_left, *padding_right;
  103. const Property *width, *height;
  104. const Property *local_width, *local_height;
  105. bool have_local_width, have_local_height;
  106. int overflow_x, overflow_y;
  107. int position;
  108. int float_;
  109. int display;
  110. int whitespace;
  111. const Property *line_height;
  112. int text_align;
  113. int text_transform;
  114. const Property *vertical_align;
  115. };
  116. }
  117. }
  118. #endif