ElementStyleCache.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 ClearBorder();
  50. void ClearMargin();
  51. void ClearPadding();
  52. void ClearDimensions();
  53. void ClearPosition();
  54. void ClearFloat();
  55. void ClearDisplay();
  56. void ClearWhitespace();
  57. void ClearOverflow();
  58. /// Invalidation functions for individual and grouped inherited properties
  59. void ClearLineHeight();
  60. void ClearTextAlign();
  61. void ClearTextTransform();
  62. void ClearVerticalAlign();
  63. /// Returns 'border-width' properties from element's style or local cache.
  64. void GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **border_right_width);
  65. /// Returns 'margin' properties from element's style or local cache.
  66. void GetMarginProperties(const Property **margin_top, const Property **margin_bottom, const Property **margin_left, const Property **margin_right);
  67. /// Returns 'padding' properties from element's style or local cache.
  68. void GetPaddingProperties(const Property **padding_top, const Property **padding_bottom, const Property **padding_left, const Property **padding_right);
  69. /// Returns 'width' and 'height' properties from element's style or local cache.
  70. void GetDimensionProperties(const Property **width, const Property **height);
  71. /// Returns local 'width' and 'height' properties from element's style or local cache,
  72. /// ignoring default values.
  73. void GetLocalDimensionProperties(const Property **width, const Property **height);
  74. /// Returns 'overflow' properties' values from element's style or local cache.
  75. void GetOverflow(int *overflow_x, int *overflow_y);
  76. /// Returns 'position' property value from element's style or local cache.
  77. int GetPosition();
  78. /// Returns 'float' property value from element's style or local cache.
  79. int GetFloat();
  80. /// Returns 'display' property value from element's style or local cache.
  81. int GetDisplay();
  82. /// Returns 'white-space' property value from element's style or local cache.
  83. int GetWhitespace();
  84. /// Returns 'line-height' property value from element's style or local cache.
  85. const Property *GetLineHeightProperty();
  86. /// Returns 'text-align' property value from element's style or local cache.
  87. int GetTextAlign();
  88. /// Returns 'text-transform' property value from element's style or local cache.
  89. int GetTextTransform();
  90. /// Returns 'vertical-align' property value from element's style or local cache.
  91. const Property *GetVerticalAlignProperty();
  92. private:
  93. /// Element style that owns this cache instance.
  94. ElementStyle *style;
  95. /// Cached properties.
  96. const Property *border_top_width, *border_bottom_width, *border_left_width, *border_right_width;
  97. const Property *margin_top, *margin_bottom, *margin_left, *margin_right;
  98. const Property *padding_top, *padding_bottom, *padding_left, *padding_right;
  99. const Property *width, *height;
  100. const Property *local_width, *local_height;
  101. bool have_local_width, have_local_height;
  102. int overflow_x, overflow_y;
  103. int position;
  104. int float_;
  105. int display;
  106. int whitespace;
  107. const Property *line_height;
  108. int text_align;
  109. int text_transform;
  110. const Property *vertical_align;
  111. };
  112. }
  113. }
  114. #endif