OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
10 * disclaimer. | 10 * disclaimer. |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "core/layout/api/LineLayoutBlockFlow.h" | 33 #include "core/layout/api/LineLayoutBlockFlow.h" |
34 #include "platform/LayoutUnit.h" | 34 #include "platform/LayoutUnit.h" |
35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 class FloatingObject; | 39 class FloatingObject; |
40 class LineLayoutRubyRun; | 40 class LineLayoutRubyRun; |
41 | 41 |
42 enum IndentTextOrNot { DoNotIndentText, IndentText }; | |
43 enum WhitespaceTreatment { ExcludeWhitespace, IncludeWhitespace }; | 42 enum WhitespaceTreatment { ExcludeWhitespace, IncludeWhitespace }; |
44 | 43 |
45 class LineWidth { | 44 class LineWidth { |
46 STACK_ALLOCATED(); | 45 STACK_ALLOCATED(); |
47 public: | 46 public: |
48 LineWidth(LineLayoutBlockFlow, bool isFirstLine, IndentTextOrNot shouldInden
tText); | 47 LineWidth(LineLayoutBlockFlow, bool isFirstLine, IndentTextOrNot); |
49 | 48 |
50 bool fitsOnLine() const { return currentWidth() <= (m_availableWidth + Layou
tUnit::epsilon()); } | 49 bool fitsOnLine() const { return currentWidth() <= (m_availableWidth + Layou
tUnit::epsilon()); } |
51 bool fitsOnLine(float extra) const { return currentWidth() + extra <= (m_ava
ilableWidth + LayoutUnit::epsilon()); } | 50 bool fitsOnLine(float extra) const { return currentWidth() + extra <= (m_ava
ilableWidth + LayoutUnit::epsilon()); } |
52 bool fitsOnLine(float extra, WhitespaceTreatment whitespaceTreatment) const | 51 bool fitsOnLine(float extra, WhitespaceTreatment whitespaceTreatment) const |
53 { | 52 { |
54 return currentWidth() - (whitespaceTreatment == ExcludeWhitespace ? trai
lingWhitespaceWidth() : 0) + extra <= (m_availableWidth + LayoutUnit::epsilon())
; | 53 return currentWidth() - (whitespaceTreatment == ExcludeWhitespace ? trai
lingWhitespaceWidth() : 0) + extra <= (m_availableWidth + LayoutUnit::epsilon())
; |
55 } | 54 } |
56 | 55 |
57 // Note that m_uncommittedWidth may not be LayoutUnit-snapped at this point.
Because | 56 // Note that m_uncommittedWidth may not be LayoutUnit-snapped at this point.
Because |
58 // currentWidth() is used by the code that lays out words in a single Layout
Text, it's | 57 // currentWidth() is used by the code that lays out words in a single Layout
Text, it's |
59 // expected that offsets will not be snapped until an InlineBox boundary is
reached. | 58 // expected that offsets will not be snapped until an InlineBox boundary is
reached. |
60 float currentWidth() const { return m_committedWidth + m_uncommittedWidth; } | 59 float currentWidth() const { return m_committedWidth + m_uncommittedWidth; } |
61 | 60 |
62 // FIXME: We should eventually replace these three functions by ones that wo
rk on a higher abstraction. | 61 // FIXME: We should eventually replace these three functions by ones that wo
rk on a higher abstraction. |
63 float uncommittedWidth() const { return m_uncommittedWidth; } | 62 float uncommittedWidth() const { return m_uncommittedWidth; } |
64 float committedWidth() const { return m_committedWidth; } | 63 float committedWidth() const { return m_committedWidth; } |
65 float availableWidth() const { return m_availableWidth; } | 64 float availableWidth() const { return m_availableWidth; } |
66 float trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; } | 65 float trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; } |
67 | 66 |
68 void updateAvailableWidth(LayoutUnit minimumHeight = 0); | 67 void updateAvailableWidth(LayoutUnit minimumHeight = 0); |
69 void shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject&); | 68 void shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject&); |
70 void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; } | 69 void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; } |
71 void commit(); | 70 void commit(); |
72 void applyOverhang(LineLayoutRubyRun, LineLayoutItem startLayoutItem, LineLa
youtItem endLayoutItem); | 71 void applyOverhang(LineLayoutRubyRun, LineLayoutItem startLayoutItem, LineLa
youtItem endLayoutItem); |
73 void fitBelowFloats(bool isFirstLine = false); | 72 void fitBelowFloats(bool isFirstLine = false); |
74 void setTrailingWhitespaceWidth(float width) { m_trailingWhitespaceWidth = w
idth; } | 73 void setTrailingWhitespaceWidth(float width) { m_trailingWhitespaceWidth = w
idth; } |
75 void snapUncommittedWidth() { m_uncommittedWidth = LayoutUnit(m_uncommittedW
idth).toFloat(); } | 74 void snapUncommittedWidth() { m_uncommittedWidth = LayoutUnit(m_uncommittedW
idth).toFloat(); } |
76 | 75 |
77 bool shouldIndentText() const { return m_shouldIndentText == IndentText; } | 76 IndentTextOrNot indentText() const { return m_indentText; } |
78 | 77 |
79 private: | 78 private: |
80 void computeAvailableWidthFromLeftAndRight(); | 79 void computeAvailableWidthFromLeftAndRight(); |
81 void updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWidth, con
st float& newLineLeft, const float& newLineRight); | 80 void updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWidth, con
st float& newLineLeft, const float& newLineRight); |
82 void wrapNextToShapeOutside(bool isFirstLine); | 81 void wrapNextToShapeOutside(bool isFirstLine); |
83 | 82 |
84 LineLayoutBlockFlow m_block; | 83 LineLayoutBlockFlow m_block; |
85 float m_uncommittedWidth; | 84 float m_uncommittedWidth; |
86 float m_committedWidth; | 85 float m_committedWidth; |
87 float m_overhangWidth; // The amount by which |m_availableWidth| has been in
flated to account for possible contraction due to ruby overhang. | 86 float m_overhangWidth; // The amount by which |m_availableWidth| has been in
flated to account for possible contraction due to ruby overhang. |
88 float m_trailingWhitespaceWidth; | 87 float m_trailingWhitespaceWidth; |
89 float m_left; | 88 float m_left; |
90 float m_right; | 89 float m_right; |
91 float m_availableWidth; | 90 float m_availableWidth; |
92 bool m_isFirstLine; | 91 bool m_isFirstLine; |
93 IndentTextOrNot m_shouldIndentText; | 92 IndentTextOrNot m_indentText; |
94 }; | 93 }; |
95 | 94 |
96 } | 95 } |
97 | 96 |
98 #endif // LineWidth_h | 97 #endif // LineWidth_h |
OLD | NEW |