LayoutLineBox.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 ROCKETCORELAYOUTLINEBOX_H
  28. #define ROCKETCORELAYOUTLINEBOX_H
  29. #include "LayoutInlineBox.h"
  30. namespace Rocket {
  31. namespace Core {
  32. class LayoutBlockBox;
  33. /**
  34. @author Peter Curry
  35. */
  36. class LayoutLineBox
  37. {
  38. public:
  39. LayoutLineBox(LayoutBlockBox* parent);
  40. ~LayoutLineBox();
  41. /// Closes the line box, positioning all inline elements within it.
  42. /// @param overflow[in] The overflow box from a split inline box that caused this line to close. Leave this as NULL if we closed naturally.
  43. /// @return If there was any overflow, this will be the last element generated by the spilling content. Otherwise, this will be NULL.
  44. LayoutInlineBox* Close(LayoutInlineBox* overflow = NULL);
  45. /// Closes one of the line box's inline boxes.
  46. /// @param inline_box[in] The inline box to close. This should always be the line box's open box.
  47. void CloseInlineBox(LayoutInlineBox* inline_box);
  48. /// Attempts to add a new element to this line box. If it can't fit, or needs to be split, new line boxes will
  49. /// be created. The inline box for the final section of the element will be returned.
  50. /// @param element[in] The element to fit into this line box.
  51. /// @param box[in] The element's extents.
  52. /// @return The inline box for the element.
  53. LayoutInlineBox* AddElement(Element* element, const Box& box);
  54. /// Attempts to add a new inline box to this line. If it can't fit, or needs to be split, new line boxes will
  55. /// be created. The inline box for the final section of the element will be returned.
  56. /// @param box[in] The inline box to be added to the line.
  57. /// @return The final inline box.
  58. LayoutInlineBox* AddBox(LayoutInlineBox* box);
  59. /// Adds an inline box as a chained hierarchy overflowing to this line. The chain will be extended into
  60. /// this line box.
  61. /// @param split_box[in] The box overflowed from a previous line.
  62. void AddChainedBox(LayoutInlineBox* chained_box);
  63. /// Returns the position of the line box, relative to its parent's block box's content area.
  64. /// @return The position of the line box.
  65. const Vector2f& GetPosition() const;
  66. /// Returns the position of the line box, relative to its parent's block box's offset parent.
  67. /// @return The relative position of the line box.
  68. Vector2f GetRelativePosition() const;
  69. /// Returns the dimensions of the line box.
  70. /// @return The dimensions of the line box.
  71. const Vector2f& GetDimensions() const;
  72. /// Returns the line box's open inline box.
  73. /// @return The line's open inline box, or NULL if it currently has none.
  74. LayoutInlineBox* GetOpenInlineBox();
  75. /// Returns the line's containing block box.
  76. /// @return The line's block box.
  77. LayoutBlockBox* GetBlockBox();
  78. void* operator new(size_t size);
  79. void operator delete(void* chunk);
  80. private:
  81. /// Appends an inline box to the end of the line box's list of inline boxes.
  82. void AppendBox(LayoutInlineBox* box);
  83. typedef std::vector< LayoutInlineBox* > InlineBoxList;
  84. // The block box containing this line.
  85. LayoutBlockBox* parent;
  86. // The top-left position of the line box; this is set when the first inline box is placed.
  87. Vector2f position;
  88. bool position_set;
  89. // The width and height of the line box; this is set when the line box is placed.
  90. Vector2f dimensions;
  91. bool wrap_content;
  92. // The horizontal cursor. This is where the next inline box will be placed along the line.
  93. float box_cursor;
  94. // The list of inline boxes in this line box. These line boxes may be parented to others in this list.
  95. InlineBoxList inline_boxes;
  96. // The open inline box; this is NULL if all inline boxes are closed.
  97. LayoutInlineBox* open_inline_box;
  98. };
  99. }
  100. }
  101. #endif