| 1 | /* |
| 2 | * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials |
| 14 | * provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 19 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 20 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 27 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #pragma once |
| 31 | |
| 32 | #include "LayoutUnit.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class FloatingObject; |
| 37 | class RenderBlockFlow; |
| 38 | class RenderObject; |
| 39 | class RenderRubyRun; |
| 40 | class RenderStyle; |
| 41 | |
| 42 | struct LineSegment; |
| 43 | |
| 44 | enum IndentTextOrNot { DoNotIndentText, IndentText }; |
| 45 | |
| 46 | class LineWidth { |
| 47 | public: |
| 48 | LineWidth(RenderBlockFlow&, bool isFirstLine, IndentTextOrNot shouldIndentText); |
| 49 | |
| 50 | bool fitsOnLine(bool ignoringTrailingSpace = false) const; |
| 51 | bool (float ) const; |
| 52 | bool fitsOnLineExcludingTrailingWhitespace(float ) const; |
| 53 | |
| 54 | float currentWidth() const { return m_committedWidth + m_uncommittedWidth; } |
| 55 | // FIXME: We should eventually replace these three functions by ones that work on a higher abstraction. |
| 56 | float uncommittedWidth() const { return m_uncommittedWidth; } |
| 57 | float committedWidth() const { return m_committedWidth; } |
| 58 | float availableWidth() const { return m_availableWidth; } |
| 59 | float logicalLeftOffset() const { return m_left; } |
| 60 | |
| 61 | bool hasCommitted() const { return m_hasCommitted; } |
| 62 | bool hasCommittedReplaced() const { return m_hasCommittedReplaced; } |
| 63 | |
| 64 | void updateAvailableWidth(LayoutUnit minimumHeight = 0_lu); |
| 65 | void shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject&); |
| 66 | void addUncommittedWidth(float delta) |
| 67 | { |
| 68 | m_uncommittedWidth += delta; |
| 69 | } |
| 70 | void addUncommittedReplacedWidth(float delta) |
| 71 | { |
| 72 | addUncommittedWidth(delta); |
| 73 | m_hasUncommittedReplaced = true; |
| 74 | } |
| 75 | void commit(); |
| 76 | void applyOverhang(const RenderRubyRun&, RenderObject* startRenderer, RenderObject* endRenderer); |
| 77 | void fitBelowFloats(bool isFirstLine = false); |
| 78 | void setTrailingWhitespaceWidth(float collapsedWhitespace, float borderPaddingMargin = 0); |
| 79 | IndentTextOrNot shouldIndentText() const { return m_shouldIndentText; } |
| 80 | |
| 81 | bool isFirstLine() const { return m_isFirstLine; } |
| 82 | |
| 83 | private: |
| 84 | void computeAvailableWidthFromLeftAndRight(); |
| 85 | bool fitsOnLineExcludingTrailingCollapsedWhitespace() const; |
| 86 | void updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWidth, float newLineLeft, float newLineRight); |
| 87 | void wrapNextToShapeOutside(bool isFirstLine); |
| 88 | |
| 89 | RenderBlockFlow& m_block; |
| 90 | float m_uncommittedWidth { 0 }; |
| 91 | float m_committedWidth { 0 }; |
| 92 | float m_overhangWidth { 0 }; // The amount by which |m_availableWidth| has been inflated to account for possible contraction due to ruby overhang. |
| 93 | float m_trailingWhitespaceWidth { 0 }; |
| 94 | float m_trailingCollapsedWhitespaceWidth { 0 }; |
| 95 | float m_left { 0 }; |
| 96 | float m_right { 0 }; |
| 97 | float m_availableWidth { 0 }; |
| 98 | bool m_isFirstLine { true }; |
| 99 | bool m_hasCommitted { false }; |
| 100 | bool m_hasCommittedReplaced { false }; |
| 101 | bool m_hasUncommittedReplaced { false }; |
| 102 | IndentTextOrNot m_shouldIndentText; |
| 103 | }; |
| 104 | |
| 105 | IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle&); |
| 106 | |
| 107 | } // namespace WebCore |
| 108 | |