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

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

Issue 2702853002: [LayoutNG] Shape items with context (Closed)
Patch Set: Add null check Created 3 years, 10 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
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_inline_node.h" 5 #include "core/layout/ng/ng_inline_node.h"
6 6
7 #include "core/layout/LayoutBlockFlow.h" 7 #include "core/layout/LayoutBlockFlow.h"
8 #include "core/layout/LayoutObject.h" 8 #include "core/layout/LayoutObject.h"
9 #include "core/layout/LayoutText.h" 9 #include "core/layout/LayoutText.h"
10 #include "core/layout/ng/ng_bidi_paragraph.h" 10 #include "core/layout/ng/ng_bidi_paragraph.h"
11 #include "core/layout/ng/ng_box_fragment.h" 11 #include "core/layout/ng/ng_box_fragment.h"
12 #include "core/layout/ng/ng_constraint_space_builder.h" 12 #include "core/layout/ng/ng_constraint_space_builder.h"
13 #include "core/layout/ng/ng_fragment_builder.h" 13 #include "core/layout/ng/ng_fragment_builder.h"
14 #include "core/layout/ng/ng_layout_inline_items_builder.h" 14 #include "core/layout/ng/ng_layout_inline_items_builder.h"
15 #include "core/layout/ng/ng_line_builder.h" 15 #include "core/layout/ng/ng_line_builder.h"
16 #include "core/layout/ng/ng_physical_box_fragment.h" 16 #include "core/layout/ng/ng_physical_box_fragment.h"
17 #include "core/layout/ng/ng_physical_text_fragment.h" 17 #include "core/layout/ng/ng_physical_text_fragment.h"
18 #include "core/layout/ng/ng_text_fragment.h" 18 #include "core/layout/ng/ng_text_fragment.h"
19 #include "core/layout/ng/ng_text_layout_algorithm.h" 19 #include "core/layout/ng/ng_text_layout_algorithm.h"
20 #include "core/style/ComputedStyle.h" 20 #include "core/style/ComputedStyle.h"
21 #include "platform/fonts/CharacterRange.h" 21 #include "platform/fonts/CharacterRange.h"
22 #include "platform/fonts/shaping/CachingWordShapeIterator.h" 22 #include "platform/fonts/shaping/CachingWordShapeIterator.h"
23 #include "platform/fonts/shaping/CachingWordShaper.h" 23 #include "platform/fonts/shaping/CachingWordShaper.h"
24 #include "platform/fonts/shaping/HarfBuzzShaper.h"
24 #include "platform/fonts/shaping/ShapeResultBuffer.h" 25 #include "platform/fonts/shaping/ShapeResultBuffer.h"
25 #include "wtf/text/CharacterNames.h" 26 #include "wtf/text/CharacterNames.h"
26 27
27 namespace blink { 28 namespace blink {
28 29
29 NGInlineNode::NGInlineNode(LayoutObject* start_inline, 30 NGInlineNode::NGInlineNode(LayoutObject* start_inline,
30 const ComputedStyle* block_style) 31 const ComputedStyle* block_style)
31 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline), 32 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline),
32 start_inline_(start_inline), 33 start_inline_(start_inline),
33 last_inline_(nullptr), 34 last_inline_(nullptr),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 LayoutUnit NGLayoutInlineItem::InlineSize() const { 193 LayoutUnit NGLayoutInlineItem::InlineSize() const {
193 return InlineSize(start_offset_, end_offset_); 194 return InlineSize(start_offset_, end_offset_);
194 } 195 }
195 196
196 LayoutUnit NGLayoutInlineItem::InlineSize(unsigned start, unsigned end) const { 197 LayoutUnit NGLayoutInlineItem::InlineSize(unsigned start, unsigned end) const {
197 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset()); 198 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset());
198 199
199 if (start == end) 200 if (start == end)
200 return LayoutUnit(); 201 return LayoutUnit();
201 202
202 if (!style_) { 203 if (!style_ || !shape_result_) {
203 // Bidi controls do not have widths. 204 // Bidi controls do not have widths.
204 // TODO(kojii): Atomic inline not supported yet. 205 // TODO(kojii): Atomic inline not supported yet.
205 return LayoutUnit(); 206 return LayoutUnit();
206 } 207 }
207 208
208 float total_width = 0;
209 for (const auto& result : shape_results_)
210 total_width += result->width();
211
212 if (start == start_offset_ && end == end_offset_) 209 if (start == start_offset_ && end == end_offset_)
213 return LayoutUnit(total_width); 210 return LayoutUnit(shape_result_->width());
214 211
215 return LayoutUnit(ShapeResultBuffer::getCharacterRange( 212 return LayoutUnit(ShapeResultBuffer::getCharacterRange(
216 shape_results_, Direction(), total_width, 213 shape_result_, Direction(), shape_result_->width(),
217 start - StartOffset(), end - StartOffset()) 214 start - StartOffset(), end - StartOffset())
218 .width()); 215 .width());
219 } 216 }
220 217
221 void NGInlineNode::ShapeText() { 218 void NGInlineNode::ShapeText() {
222 // TODO(layout-dev): Should pass the entire range to the shaper as context 219 // TODO(eae): Add support for shaping latin-1 text?
223 // and then shape each item based on the relevant font. 220 text_content_.ensure16Bit();
221
222 // Shape each item with the full context of the entire node.
223 HarfBuzzShaper shaper(text_content_.characters16(), text_content_.length());
224 for (auto& item : items_) { 224 for (auto& item : items_) {
225 // Skip object replacement characters and bidi control characters. 225 // Skip object replacement characters and bidi control characters.
226 if (!item.style_) 226 if (!item.style_)
227 continue; 227 continue;
228 StringView item_text(text_content_, item.start_offset_,
229 item.end_offset_ - item.start_offset_);
230 const Font& item_font = item.style_->font();
231 ShapeCache* shape_cache = item_font.shapeCache();
232 228
233 TextRun item_run(item_text); 229 item.shape_result_ = shaper.shape(&item.Style()->font(), item.Direction(),
234 item_run.setDirection(item.Direction()); 230 item.StartOffset(), item.EndOffset());
235 CachingWordShapeIterator iterator(shape_cache, item_run, &item_font);
236 RefPtr<const ShapeResult> word_result;
237 while (iterator.next(&word_result)) {
238 item.shape_results_.push_back(std::move(word_result));
239 }
240 } 231 }
241 } 232 }
242 233
243 RefPtr<NGPhysicalFragment> NGInlineNode::Layout(NGConstraintSpace*) { 234 RefPtr<NGPhysicalFragment> NGInlineNode::Layout(NGConstraintSpace*) {
244 ASSERT_NOT_REACHED(); 235 ASSERT_NOT_REACHED();
245 return nullptr; 236 return nullptr;
246 } 237 }
247 238
248 void NGInlineNode::LayoutInline(NGConstraintSpace* constraint_space, 239 void NGInlineNode::LayoutInline(NGConstraintSpace* constraint_space,
249 NGLineBuilder* line_builder) { 240 NGLineBuilder* line_builder) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 Vector<NGLayoutInlineItem>* items, 314 Vector<NGLayoutInlineItem>* items,
324 unsigned start_index, 315 unsigned start_index,
325 unsigned end_index) 316 unsigned end_index)
326 : start_item_(&(*items)[start_index]), 317 : start_item_(&(*items)[start_index]),
327 size_(end_index - start_index), 318 size_(end_index - start_index),
328 start_index_(start_index) { 319 start_index_(start_index) {
329 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size()); 320 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size());
330 } 321 }
331 322
332 } // namespace blink 323 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698