OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ng/ng_text_layout_algorithm.h" | 5 #include "core/layout/ng/ng_text_layout_algorithm.h" |
6 | 6 |
7 #include "core/layout/ng/ng_box_fragment.h" | 7 #include "core/layout/ng/ng_box_fragment.h" |
8 #include "core/layout/ng/ng_break_token.h" | 8 #include "core/layout/ng/ng_break_token.h" |
9 #include "core/layout/ng/ng_constraint_space.h" | 9 #include "core/layout/ng/ng_constraint_space.h" |
10 #include "core/layout/ng/ng_fragment_builder.h" | 10 #include "core/layout/ng/ng_fragment_builder.h" |
11 #include "core/layout/ng/ng_inline_node.h" | 11 #include "core/layout/ng/ng_inline_node.h" |
12 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | |
12 #include "core/layout/ng/ng_line_builder.h" | 13 #include "core/layout/ng/ng_line_builder.h" |
13 #include "core/layout/ng/ng_text_fragment.h" | 14 #include "core/layout/ng/ng_text_fragment.h" |
14 #include "core/style/ComputedStyle.h" | 15 #include "core/style/ComputedStyle.h" |
15 #include "platform/text/TextBreakIterator.h" | 16 #include "platform/text/TextBreakIterator.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 NGTextLayoutAlgorithm::NGTextLayoutAlgorithm( | 20 NGTextLayoutAlgorithm::NGTextLayoutAlgorithm( |
20 NGInlineNode* inline_box, | 21 NGInlineNode* inline_box, |
21 NGConstraintSpace* constraint_space, | 22 NGConstraintSpace* constraint_space, |
(...skipping 15 matching lines...) Expand all Loading... | |
37 | 38 |
38 void NGTextLayoutAlgorithm::LayoutInline(NGLineBuilder* line_builder) { | 39 void NGTextLayoutAlgorithm::LayoutInline(NGLineBuilder* line_builder) { |
39 // TODO(kojii): Make this tickable. Each line is easy. Needs more thoughts | 40 // TODO(kojii): Make this tickable. Each line is easy. Needs more thoughts |
40 // for each fragment in a line. Bidi reordering is probably atomic. | 41 // for each fragment in a line. Bidi reordering is probably atomic. |
41 // TODO(kojii): oof is not well-thought yet. The bottom static position may be | 42 // TODO(kojii): oof is not well-thought yet. The bottom static position may be |
42 // in the next line, https://github.com/w3c/csswg-drafts/issues/609 | 43 // in the next line, https://github.com/w3c/csswg-drafts/issues/609 |
43 const String& text_content = inline_box_->Text(); | 44 const String& text_content = inline_box_->Text(); |
44 DCHECK(!text_content.isEmpty()); | 45 DCHECK(!text_content.isEmpty()); |
45 // TODO(kojii): Give the locale to LazyLineBreakIterator. | 46 // TODO(kojii): Give the locale to LazyLineBreakIterator. |
46 LazyLineBreakIterator line_break_iterator(text_content); | 47 LazyLineBreakIterator line_break_iterator(text_content); |
48 | |
47 unsigned current_offset = 0; | 49 unsigned current_offset = 0; |
48 line_builder->SetStart(0, current_offset); | 50 line_builder->SetStart(0, current_offset); |
51 line_builder->FindNextLayoutOpportunity(); | |
kojii
2017/03/09 03:01:54
It looks more natural to call this at the end of |
Gleb Lanbin
2017/03/09 22:26:45
done. Although I think it adds an additional side
kojii
2017/03/10 03:12:43
Yeah, I was thinking of this, eae@ misunderstood t
| |
49 const unsigned end_offset = text_content.length(); | 52 const unsigned end_offset = text_content.length(); |
50 while (current_offset < end_offset) { | 53 while (current_offset < end_offset) { |
51 // Find the next break opportunity. | 54 // Find the next break opportunity. |
52 int tmp_next_breakable_offset = -1; | 55 int tmp_next_breakable_offset = -1; |
53 line_break_iterator.isBreakable(current_offset + 1, | 56 line_break_iterator.isBreakable(current_offset + 1, |
54 tmp_next_breakable_offset); | 57 tmp_next_breakable_offset); |
55 current_offset = | 58 current_offset = |
56 tmp_next_breakable_offset >= 0 ? tmp_next_breakable_offset : end_offset; | 59 tmp_next_breakable_offset >= 0 ? tmp_next_breakable_offset : end_offset; |
57 DCHECK_LE(current_offset, end_offset); | 60 DCHECK_LE(current_offset, end_offset); |
58 | 61 |
59 // Advance the break opportunity to the end of hangable characters; e.g., | 62 // Advance the break opportunity to the end of hangable characters; e.g., |
60 // spaces. | 63 // spaces. |
61 // Unlike the ICU line breaker, LazyLineBreakIterator breaks before | 64 // Unlike the ICU line breaker, LazyLineBreakIterator breaks before |
62 // breakable spaces, and expect the line breaker to handle spaces | 65 // breakable spaces, and expect the line breaker to handle spaces |
63 // differently. This logic computes in the ICU way; break after spaces, and | 66 // differently. This logic computes in the ICU way; break after spaces, and |
64 // handle spaces as hangable characters. | 67 // handle spaces as hangable characters. |
65 unsigned start_of_hangables = current_offset; | 68 unsigned start_of_hangables = current_offset; |
66 while (current_offset < end_offset && | 69 while (current_offset < end_offset && |
67 IsHangable(text_content[current_offset])) | 70 IsHangable(text_content[current_offset])) |
68 current_offset++; | 71 current_offset++; |
69 | 72 |
70 // Set the end to the next break opportunity. | 73 // Set the end to the next break opportunity. |
71 line_builder->SetEnd(current_offset); | 74 line_builder->SetEnd(current_offset); |
72 | 75 |
73 // If there are more available spaces, mark the break opportunity and fetch | 76 // If there are more available spaces, mark the break opportunity and fetch |
74 // more text. | 77 // more text. |
75 if (line_builder->CanFitOnLine()) { | 78 if (line_builder->CanFitOnLine()) { |
ikilpatrick
2017/03/09 22:00:51
we also need logic to check if the height of the l
Gleb Lanbin
2017/03/09 22:26:45
good point. added TODO for now
kojii
2017/03/10 03:12:43
TODO sounds good for now. I think this will be a c
| |
76 line_builder->SetBreakOpportunity(); | 79 line_builder->SetBreakOpportunity(); |
77 continue; | 80 continue; |
78 } | 81 } |
79 | 82 |
80 // Compute hangable characters if exists. | 83 // Compute hangable characters if exists. |
81 if (current_offset != start_of_hangables) { | 84 if (current_offset != start_of_hangables) { |
82 line_builder->SetStartOfHangables(start_of_hangables); | 85 line_builder->SetStartOfHangables(start_of_hangables); |
83 // If text before hangables can fit, include it in the current line. | 86 // If text before hangables can fit, include it in the current line. |
84 if (line_builder->CanFitOnLine()) | 87 if (line_builder->CanFitOnLine()) |
85 line_builder->SetBreakOpportunity(); | 88 line_builder->SetBreakOpportunity(); |
86 } | 89 } |
87 | 90 |
88 if (!line_builder->HasBreakOpportunity()) { | 91 if (!line_builder->HasBreakOpportunity()) { |
89 // The first word (break opportunity) did not fit on the line. | 92 // The first word (break opportunity) did not fit on the line. |
90 // Create a line including items that don't fit, allowing them to | 93 // Create a line including items that don't fit, allowing them to |
91 // overflow. | 94 // overflow. |
92 line_builder->CreateLine(); | 95 line_builder->CreateLine(); |
93 } else { | 96 } else { |
94 line_builder->CreateLineUpToLastBreakOpportunity(); | 97 line_builder->CreateLineUpToLastBreakOpportunity(); |
95 | 98 |
96 // Items after the last break opportunity were sent to the next line. | 99 // Items after the last break opportunity were sent to the next line. |
97 // Set the break opportunity, or create a line if the word doesn't fit. | 100 // Set the break opportunity, or create a line if the word doesn't fit. |
98 if (line_builder->HasItems()) { | 101 if (line_builder->HasItems()) { |
99 if (!line_builder->CanFitOnLine()) | 102 if (!line_builder->CanFitOnLine()) |
100 line_builder->CreateLine(); | 103 line_builder->CreateLine(); |
101 else | 104 else |
102 line_builder->SetBreakOpportunity(); | 105 line_builder->SetBreakOpportunity(); |
103 } | 106 } |
104 } | 107 } |
108 line_builder->FindNextLayoutOpportunity(); | |
kojii
2017/03/09 03:01:54
and at the end of |CreateLineUpToLastBreakOpportun
Gleb Lanbin
2017/03/09 22:26:45
Done.
| |
105 } | 109 } |
106 | 110 |
107 // If inline children ended with items left in the line builder, create a line | 111 // If inline children ended with items left in the line builder, create a line |
108 // for them. | 112 // for them. |
109 if (line_builder->HasItems()) | 113 if (line_builder->HasItems()) |
110 line_builder->CreateLine(); | 114 line_builder->CreateLine(); |
111 } | 115 } |
112 | 116 |
113 } // namespace blink | 117 } // namespace blink |
OLD | NEW |