LayoutDetails.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 RMLUI_CORE_LAYOUTDETAILS_H
  29. #define RMLUI_CORE_LAYOUTDETAILS_H
  30. #include "LayoutBlockBox.h"
  31. namespace Rml {
  32. class Box;
  33. /**
  34. Layout functions for sizing elements.
  35. Corresponds to the CSS 2.1 specification, 'Section 10. Visual formatting model details'.
  36. */
  37. class LayoutDetails
  38. {
  39. public:
  40. /// Generates the box for an element.
  41. /// @param[out] box The box to be built.
  42. /// @param[in] containing_block The dimensions of the content area of the block containing the element.
  43. /// @param[in] element The element to build the box for.
  44. /// @param[in] inline_element True if the element is placed in an inline context, false if not.
  45. /// @param[in] override_shrink_to_fit_width Provide a fixed shrink-to-fit width instead of formatting the element when its properties allow shrinking.
  46. static void BuildBox(Box& box, Vector2f containing_block, Element* element, bool inline_element = false, float override_shrink_to_fit_width = -1);
  47. /// Generates the box for an element placed in a block box.
  48. /// @param[out] box The box to be built.
  49. /// @param[out] min_height The minimum height of the element's box.
  50. /// @param[out] max_height The maximum height of the element's box.
  51. /// @param[in] containing_box The block box containing the element.
  52. /// @param[in] element The element to build the box for.
  53. /// @param[in] inline_element True if the element is placed in an inline context, false if not.
  54. /// @param[in] override_shrink_to_fit_width Provide a fixed shrink-to-fit width instead of formatting the element when its properties allow shrinking.
  55. static void BuildBox(Box& box, float& min_height, float& max_height, LayoutBlockBox* containing_box, Element* element, bool inline_element, float override_shrink_to_fit_width = -1);
  56. // Retrieves the minimum and maximum width from an element's computed values.
  57. static void GetMinMaxWidth(float& min_width, float& max_width, const ComputedValues& computed, const Box& box, float containing_block_width);
  58. // Retrieves the minimum and maximum height from an element's computed values.
  59. static void GetMinMaxHeight(float& min_height, float& max_height, const ComputedValues& computed, const Box& box, float containing_block_height);
  60. // Retrieves the minimum and maximum height, set to the box's content height if it is definite (>= 0), otherwise retrieves the minimum and maximum heights from an element's computed values.
  61. static void GetDefiniteMinMaxHeight(float& min_height, float& max_height, const ComputedValues& computed, const Box& box, float containing_block_height);
  62. /// Returns the fully-resolved, fixed-width and -height containing block from a block box.
  63. /// @param[in] containing_box The leaf box.
  64. /// @return The dimensions of the content area, using the latest fixed dimensions for width and height in the hierarchy.
  65. static Vector2f GetContainingBlock(const LayoutBlockBox* containing_box);
  66. /// Builds margins of a Box, and resolves any auto width or height for non-inline elements. The height may be left unresolved if it depends on the element's children.
  67. /// @param[in,out] box The box to generate. The padding and borders must be set on the box already. The content area is used instead of the width and height properties, and -1 means auto width/height.
  68. /// @param[in] min_size The element's minimum width and height.
  69. /// @param[in] max_size The element's maximum width and height.
  70. /// @param[in] containing_block The size of the containing block.
  71. /// @param[in] element The element the box is being generated for.
  72. /// @param[in] inline_element True when the element is an inline element.
  73. /// @param[in] replaced_element True when the element is a replaced element.
  74. /// @param[in] override_shrink_to_fit_width Provide a fixed shrink-to-fit width instead of formatting the element when its properties allow shrinking.
  75. static void BuildBoxSizeAndMargins(Box& box, Vector2f min_size, Vector2f max_size, Vector2f containing_block, Element* element, bool inline_element, bool replaced_element, float override_shrink_to_fit_width = -1);
  76. private:
  77. /// Formats the element and returns the width of its contents.
  78. static float GetShrinkToFitWidth(Element* element, Vector2f containing_block);
  79. /// Calculates and returns the content size for replaced elements.
  80. static Vector2f CalculateSizeForReplacedElement(Vector2f specified_content_size, Vector2f min_size, Vector2f max_size, Vector2f intrinsic_size, float intrinsic_ratio);
  81. /// Builds the block-specific width and horizontal margins of a Box.
  82. /// @param[in,out] box The box to generate. The padding and borders must be set on the box already. The content area is used instead of the width property, and -1 means auto width.
  83. /// @param[in] computed The computed values of the element the box is being generated for.
  84. /// @param[in] min_width The minimum content width of the element.
  85. /// @param[in] max_width The maximum content width of the element.
  86. /// @param[in] containing_block The size of the containing block.
  87. /// @param[in] element The element the box is being generated for.
  88. /// @param[in] replaced_element True when the element is a replaced element.
  89. /// @param[in] override_shrink_to_fit_width Provide a fixed shrink-to-fit width instead of formatting the element when its properties allow shrinking.
  90. static void BuildBoxWidth(Box& box, const ComputedValues& computed, float min_width, float max_width, Vector2f containing_block, Element* element, bool replaced_element, float override_shrink_to_fit_width = -1);
  91. /// Builds the block-specific height and vertical margins of a Box.
  92. /// @param[in,out] box The box to generate. The padding and borders must be set on the box already. The content area is used instead of the height property, and -1 means auto height.
  93. /// @param[in] computed The computed values of the element the box is being generated for.
  94. /// @param[in] min_height The minimum content height of the element.
  95. /// @param[in] max_height The maximum content height of the element.
  96. /// @param[in] containing_block_height The height of the containing block.
  97. static void BuildBoxHeight(Box& box, const ComputedValues& computed, float min_height, float max_height, float containing_block_height);
  98. };
  99. } // namespace Rml
  100. #endif