LayoutInlineBox.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_LAYOUTINLINEBOX_H
  29. #define RMLUI_CORE_LAYOUTINLINEBOX_H
  30. #include "../../Include/RmlUi/Core/Box.h"
  31. #include "../../Include/RmlUi/Core/ComputedValues.h"
  32. namespace Rml {
  33. class Element;
  34. class ElementText;
  35. class FontFaceHandleDefault;
  36. class LayoutBlockBox;
  37. class LayoutLineBox;
  38. /**
  39. @author Peter Curry
  40. */
  41. class LayoutInlineBox
  42. {
  43. public:
  44. /// Constructs a new inline box for an element.
  45. /// @param element[in] The element this inline box is flowing.
  46. /// @param box[in] The extents of the inline box's element.
  47. LayoutInlineBox(Element* element, const Box& box);
  48. /// Constructs a new inline box for a split box.
  49. /// @param chain[in] The box that has overflowed into us.
  50. LayoutInlineBox(LayoutInlineBox* chain);
  51. virtual ~LayoutInlineBox();
  52. /// Sets the inline box's line.
  53. /// @param line[in] The line this inline box resides in.
  54. void SetLine(LayoutLineBox* line);
  55. /// Sets the inline box's parent.
  56. /// @param parent[in] The parent this inline box resides in.
  57. void SetParent(LayoutInlineBox* parent);
  58. /// Closes the box.
  59. void Close();
  60. /// Flows the inline box's content into its parent line.
  61. /// @param[in] first_box True if this box is the first box containing content to be flowed into this line.
  62. /// @param[in] available_width The width available for flowing this box's content. This is measured from the left side of this box's content area.
  63. /// @param[in] right_spacing_width The width of the spacing that must be left on the right of the element if no overflow occurs. If overflow occurs, then the entire width can be used.
  64. /// @return The overflow box containing any content that spilled over from the flow. This must be nullptr if no overflow occured.
  65. virtual UniquePtr<LayoutInlineBox> FlowContent(bool first_box, float available_width, float right_spacing_width);
  66. /// Computes and sets the vertical position of this element, relative to its parent inline box (or block box,
  67. /// for an un-nested inline box).
  68. /// @param ascender[out] The maximum ascender of this inline box and all of its children.
  69. /// @param descender[out] The maximum descender of this inline box and all of its children.
  70. virtual void CalculateBaseline(float& ascender, float& descender);
  71. /// Offsets the baseline of this box, and all of its children, by the ascender of the parent line box.
  72. /// @param ascender[in] The ascender of the line box.
  73. virtual void OffsetBaseline(float ascender);
  74. /// Returns true if this box is capable of overflowing, or if it must be rendered on a single line.
  75. /// @return True if this box can overflow, false otherwise.
  76. virtual bool CanOverflow() const;
  77. /// Returns true if this box's element is the last child of its parent.
  78. /// @param True if this box is a last child.
  79. bool IsLastChild() const;
  80. /// Returns the inline box's offset from its line.
  81. /// @return The box's offset from its line.
  82. Vector2f GetPosition() const;
  83. /// Sets the inline box's horizontal offset from its parent's content area.
  84. /// @param position[in] The box's horizontal offset.
  85. void SetHorizontalPosition(float position);
  86. /// Sets the inline box's vertical offset from its parent's content area.
  87. /// @param position[in] The box's vertical offset.
  88. void SetVerticalPosition(float position);
  89. /// Positions the inline box's element.
  90. virtual void PositionElement();
  91. /// Sizes the inline box's element.
  92. /// @param split[in] True if this box is split, false otherwise.
  93. virtual void SizeElement(bool split);
  94. /// Returns the vertical align property of the box's element.
  95. /// @return the vertical align property, or -1 if it is set to a numerical value.
  96. Style::VerticalAlign GetVerticalAlignProperty() const;
  97. /// Returns the inline box's element.
  98. /// @return The inline box's element.
  99. Element* GetElement();
  100. /// Returns the inline box's parent.
  101. /// @param The parent of this inline box. This will be nullptr for a root-level inline box (ie, one that has a block element has a parent in the true hierarchy).
  102. LayoutInlineBox* GetParent();
  103. /// Returns the inline box's dimension box.
  104. /// @return The inline box's dimension box.
  105. const Box& GetBox() const;
  106. /// Returns the height of the inline box. This is separate from the the box, as different types of inline
  107. /// elements generate different line heights. The possible types are:
  108. /// * replaced elements (or inline-block elements), which use their entire box (including margins) as their
  109. /// height
  110. /// * non-replaced elements, which use the maximum line-height of their children
  111. /// * text elements, which use their line-height
  112. float GetHeight() const;
  113. /// Returns the baseline of the inline box.
  114. /// @return The box's baseline.
  115. float GetBaseline() const;
  116. void* operator new(size_t size);
  117. void operator delete(void* chunk, size_t size);
  118. protected:
  119. /// Returns our parent box's font face handle.
  120. /// @return The font face handle of our parent box.
  121. FontFaceHandle GetParentFont() const;
  122. // The box's element.
  123. Element* element;
  124. // The line box's offset relative to its parent block box.
  125. Vector2f position;
  126. // The element's inline box.
  127. Box box;
  128. // The inline box's width; note that this is stored separately from the box dimensions. It is only used by
  129. // nesting inline boxes, such as HTML spans containing text.
  130. float width;
  131. // The inline box's height; note that this is stored separately from the box dimensions, as inline elements
  132. // don't necessarily have identical relationships between their box dimensions and line height.
  133. float height;
  134. // The value of this box's element's vertical-align property.
  135. Style::VerticalAlign vertical_align_property;
  136. // The baseline of the inline element.
  137. float baseline;
  138. // The inline box's parent; this will be nullptr if we're not a nested inline element.
  139. LayoutInlineBox* parent;
  140. // This inline box's line.
  141. LayoutLineBox* line;
  142. Vector< LayoutInlineBox* > children;
  143. // The next link in our element's chain of inline boxes.
  144. LayoutInlineBox* chain;
  145. // True if we're a link in a chain of inline boxes flowing from previous lines.
  146. bool chained;
  147. };
  148. } // namespace Rml
  149. #endif