LayoutInlineBoxText.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 ROCKETCORELAYOUTINLINEBOXTEXT_H
  28. #define ROCKETCORELAYOUTINLINEBOXTEXT_H
  29. #include "LayoutInlineBox.h"
  30. #include "../../Include/Rocket/Core/String.h"
  31. namespace Rocket {
  32. namespace Core {
  33. /**
  34. @author Peter Curry
  35. */
  36. class LayoutInlineBoxText : public LayoutInlineBox
  37. {
  38. public:
  39. /// Constructs a new inline box for a text element.
  40. /// @param[in] element The element this inline box is flowing.
  41. /// @param[in] line_begin The index of the first character of the element's string this text box will render.
  42. LayoutInlineBoxText(Element* element, int line_begin = 0);
  43. virtual ~LayoutInlineBoxText();
  44. /// Returns true if this box is capable of overflowing, or if it must be rendered on a single line.
  45. /// @return True if this box can overflow, false otherwise.
  46. virtual bool CanOverflow() const;
  47. /// Flows the inline box's content into its parent line.
  48. /// @param[in] first_box True if this box is the first box containing content to be flowed into this line.
  49. /// @param available_width[in] The width available for flowing this box's content. This is measured from the left side of this box's content area.
  50. /// @param right_spacing_width[in] 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.
  51. /// @return The overflow box containing any content that spilled over from the flow. This must be NULL if no overflow occured.
  52. virtual LayoutInlineBox* FlowContent(bool first_box, float available_width, float right_spacing_width);
  53. /// Computes and sets the vertical position of this element, relative to its parent inline box (or block box,
  54. /// for an un-nested inline box).
  55. /// @param ascender[out] The maximum ascender of this inline box and all of its children.
  56. /// @param descender[out] The maximum descender of this inline box and all of its children.
  57. virtual void CalculateBaseline(float& ascender, float& descender);
  58. /// Offsets the baseline of this box, and all of its children, by the ascender of the parent line box.
  59. /// @param ascender[in] The ascender of the line box.
  60. virtual void OffsetBaseline(float ascender);
  61. /// Positions the inline box's element.
  62. virtual void PositionElement();
  63. /// Sizes the inline box's element.
  64. virtual void SizeElement(bool split);
  65. void* operator new(size_t size);
  66. void operator delete(void* chunk);
  67. private:
  68. /// Returns the box's element as a text element.
  69. /// @return The box's element cast to a text element.
  70. ElementText* GetTextElement();
  71. /// Builds a box for the first word of the element.
  72. void BuildWordBox();
  73. // The index of the first character of this line.
  74. int line_begin;
  75. // The contents on this line.
  76. WString line_contents;
  77. // True if this line can be segmented into parts, false if it consists of only a single word.
  78. bool line_segmented;
  79. };
  80. }
  81. }
  82. #endif