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/inline/ng_inline_layout_algorithm.h" | 5 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" | 7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" |
| 8 #include "core/layout/ng/inline/ng_inline_break_token.h" | 8 #include "core/layout/ng/inline/ng_inline_break_token.h" |
| 9 #include "core/layout/ng/inline/ng_inline_node.h" | 9 #include "core/layout/ng/inline/ng_inline_node.h" |
| 10 #include "core/layout/ng/inline/ng_line_box_fragment.h" | 10 #include "core/layout/ng/inline/ng_line_box_fragment.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 // Up until this point, children are placed so that the dominant baseline is | 241 // Up until this point, children are placed so that the dominant baseline is |
| 242 // at 0. Move them to the final baseline position, and set the logical top of | 242 // at 0. Move them to the final baseline position, and set the logical top of |
| 243 // the line box to the line top. | 243 // the line box to the line top. |
| 244 line_box.MoveChildrenInBlockDirection(baseline); | 244 line_box.MoveChildrenInBlockDirection(baseline); |
| 245 | 245 |
| 246 NGLayoutOpportunity line_opp = FindLayoutOpportunityForLine(); | 246 NGLayoutOpportunity line_opp = FindLayoutOpportunityForLine(); |
| 247 | 247 |
| 248 LayoutUnit inline_size = position; | 248 LayoutUnit inline_size = position; |
| 249 NGLogicalOffset offset(LogicalLeftOffset(line_opp), | 249 NGLogicalOffset offset(LogicalLeftOffset(line_opp), |
| 250 baseline - box_states_.LineBoxState().metrics.ascent); | 250 baseline - box_states_.LineBoxState().metrics.ascent); |
| 251 ApplyTextAlign(line_style, line_style.GetTextAlign(line_info->IsLastLine()), | 251 ApplyTextAlign(line_style.GetTextAlign(line_info->IsLastLine()), |
| 252 &offset.inline_offset, inline_size, line_opp.InlineSize()); | 252 &offset.inline_offset, inline_size, line_opp.InlineSize()); |
| 253 | 253 |
| 254 line_box.SetInlineSize(inline_size); | 254 line_box.SetInlineSize(inline_size); |
| 255 container_builder_.AddChild(line_box.ToLineBoxFragment(), offset); | 255 container_builder_.AddChild(line_box.ToLineBoxFragment(), offset); |
| 256 | 256 |
| 257 max_inline_size_ = std::max(max_inline_size_, inline_size); | 257 max_inline_size_ = std::max(max_inline_size_, inline_size); |
| 258 content_size_ = ComputeContentSize(*line_info, line_bottom); | 258 content_size_ = ComputeContentSize(*line_info, line_bottom); |
| 259 | 259 |
| 260 return true; | 260 return true; |
| 261 } | 261 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 text_builder->SetSize({fragment.InlineSize(), block_size}); | 304 text_builder->SetSize({fragment.InlineSize(), block_size}); |
| 305 LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; | 305 LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; |
| 306 RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment( | 306 RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment( |
| 307 item_result->item_index, item_result->start_offset, | 307 item_result->item_index, item_result->start_offset, |
| 308 item_result->end_offset); | 308 item_result->end_offset); |
| 309 line_box->AddChild(std::move(text_fragment), {position, line_top}); | 309 line_box->AddChild(std::move(text_fragment), {position, line_top}); |
| 310 | 310 |
| 311 return box_states_.OnCloseTag(item, line_box, box, baseline_type_); | 311 return box_states_.OnCloseTag(item, line_box, box, baseline_type_); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void NGInlineLayoutAlgorithm::ApplyTextAlign(const ComputedStyle& line_style, | 314 void NGInlineLayoutAlgorithm::ApplyTextAlign(ETextAlign text_align, |
| 315 ETextAlign text_align, | |
| 316 LayoutUnit* line_left, | 315 LayoutUnit* line_left, |
| 317 LayoutUnit inline_size, | 316 LayoutUnit inline_size, |
| 318 LayoutUnit available_width) { | 317 LayoutUnit available_width) { |
| 319 switch (text_align) { | 318 bool is_base_ltr = IsLtr(Node().BaseDirection()); |
| 320 case ETextAlign::kRight: | 319 // TODO(kojii): Investigate handling trailing spaces. |
| 321 case ETextAlign::kWebkitRight: | 320 // Refer to LayoutBlockFlow::UpdateLogicalWidthForAlignment(). |
| 322 // Wide lines spill out of the block based off direction. | 321 while (true) { |
| 323 // So even if text-align is right, if direction is LTR, wide lines should | 322 switch (text_align) { |
| 324 // overflow out of the right side of the block. | 323 case ETextAlign::kLeft: |
| 325 // TODO(kojii): Investigate how to handle trailing spaces. | 324 case ETextAlign::kWebkitLeft: |
| 326 if (inline_size < available_width || !line_style.IsLeftToRightDirection()) | 325 // The direction of the block should determine what happens with wide |
| 327 *line_left += available_width - inline_size; | 326 // lines. In particular with RTL blocks, wide lines should still spill |
| 328 break; | 327 // out to the left. |
| 329 default: | 328 if (!is_base_ltr && inline_size > available_width) |
| 330 // TODO(layout-dev): Implement. | 329 *line_left -= inline_size - available_width; |
| 331 // Refer to LayoutBlockFlow::UpdateLogicalWidthForAlignment(). | 330 return; |
| 332 break; | 331 case ETextAlign::kRight: |
| 332 case ETextAlign::kWebkitRight: | |
| 333 // Wide lines spill out of the block based off direction. | |
| 334 // So even if text-align is right, if direction is LTR, wide lines | |
| 335 // should overflow out of the right side of the block. | |
| 336 if (inline_size < available_width || !is_base_ltr) | |
| 337 *line_left += available_width - inline_size; | |
| 338 return; | |
| 339 case ETextAlign::kCenter: | |
| 340 case ETextAlign::kWebkitCenter: | |
| 341 if (is_base_ltr) { | |
| 342 *line_left += | |
| 343 std::max((available_width - inline_size) / 2, LayoutUnit()); | |
| 344 } else { | |
| 345 *line_left += inline_size > available_width | |
| 346 ? (available_width - inline_size) | |
| 347 : (available_width - inline_size) / 2; | |
|
eae
2017/06/19 15:36:49
Could you explain the math here please? If inline_
kojii
2017/06/20 03:52:20
It's saying: "if RTL and overflow, do 'right' alig
| |
| 348 } | |
| 349 return; | |
| 350 case ETextAlign::kStart: | |
| 351 text_align = is_base_ltr ? ETextAlign::kLeft : ETextAlign::kRight; | |
| 352 continue; | |
| 353 case ETextAlign::kEnd: | |
| 354 text_align = is_base_ltr ? ETextAlign::kRight : ETextAlign::kLeft; | |
| 355 continue; | |
| 356 case ETextAlign::kJustify: | |
| 357 // TODO(kojii): Implement. | |
| 358 return; | |
| 359 } | |
| 360 NOTREACHED(); | |
| 361 return; | |
| 333 } | 362 } |
| 334 } | 363 } |
| 335 | 364 |
| 336 LayoutUnit NGInlineLayoutAlgorithm::ComputeContentSize( | 365 LayoutUnit NGInlineLayoutAlgorithm::ComputeContentSize( |
| 337 const NGLineInfo& line_info, | 366 const NGLineInfo& line_info, |
| 338 LayoutUnit line_bottom) { | 367 LayoutUnit line_bottom) { |
| 339 LayoutUnit content_size = line_bottom; | 368 LayoutUnit content_size = line_bottom; |
| 340 | 369 |
| 341 const Vector<NGInlineItem>& items = Node().Items(); | 370 const Vector<NGInlineItem>& items = Node().Items(); |
| 342 const NGInlineItemResults& line_items = line_info.Results(); | 371 const NGInlineItemResults& line_items = line_info.Results(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 // Margin struts shouldn't need to be passed through like this once we've | 434 // Margin struts shouldn't need to be passed through like this once we've |
| 406 // removed LayoutInline splitting. | 435 // removed LayoutInline splitting. |
| 407 if (!container_builder_.BfcOffset()) { | 436 if (!container_builder_.BfcOffset()) { |
| 408 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); | 437 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); |
| 409 } | 438 } |
| 410 | 439 |
| 411 return container_builder_.ToBoxFragment(); | 440 return container_builder_.ToBoxFragment(); |
| 412 } | 441 } |
| 413 | 442 |
| 414 } // namespace blink | 443 } // namespace blink |
| OLD | NEW |