Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_text_layout_algorithm.cc

Issue 2772503004: [LayoutNG] Add NGInlineBreakToken and back of NGInlineLayoutAlgorithm (Closed)
Patch Set: Resolved merge conflicts Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/layout/ng/ng_text_layout_algorithm.h"
6
7 #include "core/layout/ng/ng_box_fragment.h"
8 #include "core/layout/ng/ng_break_token.h"
9 #include "core/layout/ng/ng_constraint_space.h"
10 #include "core/layout/ng/ng_fragment_builder.h"
11 #include "core/layout/ng/ng_inline_node.h"
12 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
13 #include "core/layout/ng/ng_line_builder.h"
14 #include "core/layout/ng/ng_text_fragment.h"
15 #include "core/style/ComputedStyle.h"
16 #include "platform/text/TextBreakIterator.h"
17
18 namespace blink {
19
20 NGTextLayoutAlgorithm::NGTextLayoutAlgorithm(
21 NGInlineNode* inline_box,
22 NGBreakToken* break_token)
23 : inline_box_(inline_box),
24 break_token_(break_token) {
25 DCHECK(inline_box_);
26 }
27
28 RefPtr<NGLayoutResult> NGTextLayoutAlgorithm::Layout() {
29 NOTREACHED();
30 return nullptr;
31 }
32
33 static bool IsHangable(UChar ch) {
34 return ch == ' ';
35 }
36
37 void NGTextLayoutAlgorithm::LayoutInline(NGLineBuilder* line_builder) {
38 // TODO(kojii): Make this tickable. Each line is easy. Needs more thoughts
39 // for each fragment in a line. Bidi reordering is probably atomic.
40 // TODO(kojii): oof is not well-thought yet. The bottom static position may be
41 // in the next line, https://github.com/w3c/csswg-drafts/issues/609
42 const String& text_content = inline_box_->Text();
43 DCHECK(!text_content.isEmpty());
44 // TODO(kojii): Give the locale to LazyLineBreakIterator.
45 LazyLineBreakIterator line_break_iterator(text_content);
46 unsigned current_offset = 0;
47 line_builder->SetStart(0, current_offset);
48 const unsigned end_offset = text_content.length();
49 while (current_offset < end_offset) {
50 // Find the next break opportunity.
51 int tmp_next_breakable_offset = -1;
52 line_break_iterator.isBreakable(current_offset + 1,
53 tmp_next_breakable_offset);
54 current_offset =
55 tmp_next_breakable_offset >= 0 ? tmp_next_breakable_offset : end_offset;
56 DCHECK_LE(current_offset, end_offset);
57
58 // Advance the break opportunity to the end of hangable characters; e.g.,
59 // spaces.
60 // Unlike the ICU line breaker, LazyLineBreakIterator breaks before
61 // breakable spaces, and expect the line breaker to handle spaces
62 // differently. This logic computes in the ICU way; break after spaces, and
63 // handle spaces as hangable characters.
64 unsigned start_of_hangables = current_offset;
65 while (current_offset < end_offset &&
66 IsHangable(text_content[current_offset]))
67 current_offset++;
68
69 // Set the end to the next break opportunity.
70 line_builder->SetEnd(current_offset);
71
72 // If there are more available spaces, mark the break opportunity and fetch
73 // more text.
74 // TODO(layout-ng): check if the height of the linebox can fit within
75 // the current opportunity.
76 if (line_builder->CanFitOnLine()) {
77 line_builder->SetBreakOpportunity();
78 continue;
79 }
80
81 // Compute hangable characters if exists.
82 if (current_offset != start_of_hangables) {
83 line_builder->SetStartOfHangables(start_of_hangables);
84 // If text before hangables can fit, include it in the current line.
85 if (line_builder->CanFitOnLine())
86 line_builder->SetBreakOpportunity();
87 }
88
89 if (!line_builder->HasBreakOpportunity()) {
90 // The first word (break opportunity) did not fit on the line.
91 // Create a line including items that don't fit, allowing them to
92 // overflow.
93 line_builder->CreateLine();
94 } else {
95 line_builder->CreateLineUpToLastBreakOpportunity();
96
97 // Items after the last break opportunity were sent to the next line.
98 // Set the break opportunity, or create a line if the word doesn't fit.
99 if (line_builder->HasItems()) {
100 if (!line_builder->CanFitOnLine())
101 line_builder->CreateLine();
102 else
103 line_builder->SetBreakOpportunity();
104 }
105 }
106 }
107
108 // If inline children ended with items left in the line builder, create a line
109 // for them.
110 if (line_builder->HasItems())
111 line_builder->CreateLine();
112 }
113
114 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698