Chromium Code Reviews| 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_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" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return InlineSize(start_offset_, end_offset_); | 212 return InlineSize(start_offset_, end_offset_); |
| 213 } | 213 } |
| 214 | 214 |
| 215 LayoutUnit NGLayoutInlineItem::InlineSize(unsigned start, unsigned end) const { | 215 LayoutUnit NGLayoutInlineItem::InlineSize(unsigned start, unsigned end) const { |
| 216 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset()); | 216 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset()); |
| 217 | 217 |
| 218 if (start == end) | 218 if (start == end) |
| 219 return LayoutUnit(); | 219 return LayoutUnit(); |
| 220 | 220 |
| 221 if (!style_ || !shape_result_) { | 221 if (!style_ || !shape_result_) { |
| 222 // Bidi controls do not have widths. | 222 DCHECK(start == start_offset_ && end == end_offset_); |
| 223 // TODO(kojii): Atomic inline not supported yet. | 223 DCHECK(!IsAtomicInlineLevel()) << "Use NGLineBuilder::InlineSize"; |
| 224 DCHECK(!layout_object_ || | |
| 225 layout_object_->isFloatingOrOutOfFlowPositioned()); | |
| 226 // Bidi controls and out-of-flow objects do not have in-flow widths. | |
| 224 return LayoutUnit(); | 227 return LayoutUnit(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 if (start == start_offset_ && end == end_offset_) | 230 if (start == start_offset_ && end == end_offset_) |
| 228 return LayoutUnit(shape_result_->width()); | 231 return LayoutUnit(shape_result_->width()); |
| 229 | 232 |
| 230 return LayoutUnit(ShapeResultBuffer::getCharacterRange( | 233 return LayoutUnit(ShapeResultBuffer::getCharacterRange( |
| 231 shape_result_, Direction(), shape_result_->width(), | 234 shape_result_, Direction(), shape_result_->width(), |
| 232 start - StartOffset(), end - StartOffset()) | 235 start - StartOffset(), end - StartOffset()) |
| 233 .width()); | 236 .width()); |
| 234 } | 237 } |
| 235 | 238 |
| 239 RefPtr<NGLayoutResult> NGLayoutInlineItem::Layout( | |
| 240 const NGConstraintSpace& parent_space) const { | |
| 241 DCHECK(IsAtomicInlineLevel()); | |
| 242 | |
| 243 NGBlockNode* node = new NGBlockNode(layout_object_); | |
| 244 // TODO(kojii): Keep node in NGLayoutInlineItem. | |
| 245 const ComputedStyle& style = node->Style(); | |
| 246 NGConstraintSpaceBuilder constraint_space_builder(&parent_space); | |
|
ikilpatrick
2017/03/16 16:15:40
we should do this in the parents call, ::Layout ta
kojii
2017/03/16 16:48:45
Moved this function to NGLineBuilder, please see t
| |
| 247 RefPtr<NGConstraintSpace> constraint_space = | |
| 248 constraint_space_builder.SetIsNewFormattingContext(true) | |
| 249 .SetIsShrinkToFit(true) | |
| 250 .SetTextDirection(style.direction()) | |
| 251 .ToConstraintSpace(FromPlatformWritingMode(style.getWritingMode())); | |
| 252 return node->Layout(constraint_space.get()); | |
| 253 } | |
| 254 | |
| 236 void NGLayoutInlineItem::GetFallbackFonts( | 255 void NGLayoutInlineItem::GetFallbackFonts( |
| 237 HashSet<const SimpleFontData*>* fallback_fonts, | 256 HashSet<const SimpleFontData*>* fallback_fonts, |
| 238 unsigned start, | 257 unsigned start, |
| 239 unsigned end) const { | 258 unsigned end) const { |
| 240 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset()); | 259 DCHECK(start >= StartOffset() && start <= end && end <= EndOffset()); |
| 241 | 260 |
| 242 // TODO(kojii): Implement |start| and |end|. | 261 // TODO(kojii): Implement |start| and |end|. |
| 243 shape_result_->fallbackFonts(fallback_fonts); | 262 shape_result_->fallbackFonts(fallback_fonts); |
| 244 } | 263 } |
| 245 | 264 |
| 246 void NGInlineNode::ShapeText() { | 265 void NGInlineNode::ShapeText() { |
| 247 // TODO(eae): Add support for shaping latin-1 text? | 266 // TODO(eae): Add support for shaping latin-1 text? |
| 248 text_content_.ensure16Bit(); | 267 text_content_.ensure16Bit(); |
| 249 | 268 |
| 250 // Shape each item with the full context of the entire node. | 269 // Shape each item with the full context of the entire node. |
| 251 HarfBuzzShaper shaper(text_content_.characters16(), text_content_.length()); | 270 HarfBuzzShaper shaper(text_content_.characters16(), text_content_.length()); |
| 252 for (auto& item : items_) { | 271 for (auto& item : items_) { |
| 253 // Skip object replacement characters and bidi control characters. | 272 // Skip non-text items; e.g., bidi controls, atomic inlines, out-of-flow |
| 273 // objects. | |
| 254 if (!item.style_) | 274 if (!item.style_) |
| 255 continue; | 275 continue; |
| 256 | 276 |
| 257 item.shape_result_ = shaper.shape(&item.Style()->font(), item.Direction(), | 277 item.shape_result_ = shaper.shape(&item.Style()->font(), item.Direction(), |
| 258 item.StartOffset(), item.EndOffset()); | 278 item.StartOffset(), item.EndOffset()); |
| 259 } | 279 } |
| 260 } | 280 } |
| 261 | 281 |
| 262 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace*, NGBreakToken*) { | 282 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace*, NGBreakToken*) { |
| 263 ASSERT_NOT_REACHED(); | 283 ASSERT_NOT_REACHED(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) | 318 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) |
| 299 .ToConstraintSpace(writing_mode); | 319 .ToConstraintSpace(writing_mode); |
| 300 NGLineBuilder line_builder(this, constraint_space.get(), nullptr); | 320 NGLineBuilder line_builder(this, constraint_space.get(), nullptr); |
| 301 Layout(&line_builder); | 321 Layout(&line_builder); |
| 302 MinMaxContentSize sizes; | 322 MinMaxContentSize sizes; |
| 303 sizes.min_content = line_builder.MaxInlineSize(); | 323 sizes.min_content = line_builder.MaxInlineSize(); |
| 304 | 324 |
| 305 // max-content is the width without any line wrapping. | 325 // max-content is the width without any line wrapping. |
| 306 // TODO(kojii): Implement hard breaks (<br> etc.) to break. | 326 // TODO(kojii): Implement hard breaks (<br> etc.) to break. |
| 307 for (const auto& item : items_) | 327 for (const auto& item : items_) |
| 308 sizes.max_content += item.InlineSize(); | 328 sizes.max_content += line_builder.InlineSize(item); |
| 309 | 329 |
| 310 return sizes; | 330 return sizes; |
| 311 } | 331 } |
| 312 | 332 |
| 313 NGLayoutInputNode* NGInlineNode::NextSibling() { | 333 NGLayoutInputNode* NGInlineNode::NextSibling() { |
| 314 if (!IsPrepareLayoutFinished()) | 334 if (!IsPrepareLayoutFinished()) |
| 315 PrepareLayout(); | 335 PrepareLayout(); |
| 316 return next_sibling_; | 336 return next_sibling_; |
| 317 } | 337 } |
| 318 | 338 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 Vector<NGLayoutInlineItem>* items, | 384 Vector<NGLayoutInlineItem>* items, |
| 365 unsigned start_index, | 385 unsigned start_index, |
| 366 unsigned end_index) | 386 unsigned end_index) |
| 367 : start_item_(&(*items)[start_index]), | 387 : start_item_(&(*items)[start_index]), |
| 368 size_(end_index - start_index), | 388 size_(end_index - start_index), |
| 369 start_index_(start_index) { | 389 start_index_(start_index) { |
| 370 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size()); | 390 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size()); |
| 371 } | 391 } |
| 372 | 392 |
| 373 } // namespace blink | 393 } // namespace blink |
| OLD | NEW |