| 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_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_break_token.h" | 7 #include "core/layout/ng/ng_break_token.h" |
| 8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.h" |
| 9 #include "core/layout/ng/ng_constraint_space_builder.h" | 9 #include "core/layout/ng/ng_constraint_space_builder.h" |
| 10 #include "core/layout/ng/ng_fragment_base.h" | 10 #include "core/layout/ng/ng_fragment_base.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 LayoutUnit adjusted_block_size(block_size); | 214 LayoutUnit adjusted_block_size(block_size); |
| 215 // Our calculated block-axis size may be indefinite at this point. | 215 // Our calculated block-axis size may be indefinite at this point. |
| 216 // If so, just leave the size as NGSizeIndefinite instead of subtracting | 216 // If so, just leave the size as NGSizeIndefinite instead of subtracting |
| 217 // borders and padding. | 217 // borders and padding. |
| 218 if (adjusted_block_size != NGSizeIndefinite) | 218 if (adjusted_block_size != NGSizeIndefinite) |
| 219 adjusted_block_size -= border_and_padding_.BlockSum(); | 219 adjusted_block_size -= border_and_padding_.BlockSum(); |
| 220 | 220 |
| 221 space_builder_ = | 221 space_builder_ = |
| 222 new NGConstraintSpaceBuilder(constraint_space_->WritingMode()); | 222 new NGConstraintSpaceBuilder(constraint_space_->WritingMode()); |
| 223 if (Style().specifiesColumns()) { | 223 if (Style().specifiesColumns()) { |
| 224 space_builder_->SetFragmentationType(FragmentColumn); | 224 space_builder_->SetFragmentationType(kFragmentColumn); |
| 225 adjusted_inline_size = | 225 adjusted_inline_size = |
| 226 ResolveUsedColumnInlineSize(adjusted_inline_size, Style()); | 226 ResolveUsedColumnInlineSize(adjusted_inline_size, Style()); |
| 227 } | 227 } |
| 228 space_builder_->SetAvailableSize( | 228 space_builder_->SetAvailableSize( |
| 229 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); | 229 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| 230 space_builder_->SetPercentageResolutionSize( | 230 space_builder_->SetPercentageResolutionSize( |
| 231 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); | 231 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| 232 | 232 |
| 233 content_size_ = border_and_padding_.block_start; | 233 content_size_ = border_and_padding_.block_start; |
| 234 | 234 |
| 235 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 235 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::kFragmentBox); |
| 236 builder_->SetDirection(constraint_space_->Direction()); | 236 builder_->SetDirection(constraint_space_->Direction()); |
| 237 builder_->SetWritingMode(constraint_space_->WritingMode()); | 237 builder_->SetWritingMode(constraint_space_->WritingMode()); |
| 238 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 238 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
| 239 current_child_ = first_child_; | 239 current_child_ = first_child_; |
| 240 if (current_child_) | 240 if (current_child_) |
| 241 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); | 241 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
| 242 | 242 |
| 243 state_ = kStateChildLayout; | 243 state_ = kStateChildLayout; |
| 244 return NotFinished; | 244 return kNotFinished; |
| 245 } | 245 } |
| 246 case kStateChildLayout: { | 246 case kStateChildLayout: { |
| 247 if (current_child_) { | 247 if (current_child_) { |
| 248 if (!LayoutCurrentChild()) | 248 if (!LayoutCurrentChild()) |
| 249 return NotFinished; | 249 return kNotFinished; |
| 250 current_child_ = current_child_->NextSibling(); | 250 current_child_ = current_child_->NextSibling(); |
| 251 if (current_child_) { | 251 if (current_child_) { |
| 252 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); | 252 space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
| 253 return NotFinished; | 253 return kNotFinished; |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 state_ = kStateFinalize; | 256 state_ = kStateFinalize; |
| 257 return NotFinished; | 257 return kNotFinished; |
| 258 } | 258 } |
| 259 case kStateFinalize: { | 259 case kStateFinalize: { |
| 260 content_size_ += border_and_padding_.block_end; | 260 content_size_ += border_and_padding_.block_end; |
| 261 | 261 |
| 262 // Recompute the block-axis size now that we know our content size. | 262 // Recompute the block-axis size now that we know our content size. |
| 263 LayoutUnit block_size = ComputeBlockSizeForFragment( | 263 LayoutUnit block_size = ComputeBlockSizeForFragment( |
| 264 ConstraintSpace(), Style(), content_size_); | 264 ConstraintSpace(), Style(), content_size_); |
| 265 | 265 |
| 266 builder_->SetBlockSize(block_size) | 266 builder_->SetBlockSize(block_size) |
| 267 .SetInlineOverflow(max_inline_size_) | 267 .SetInlineOverflow(max_inline_size_) |
| 268 .SetBlockOverflow(content_size_); | 268 .SetBlockOverflow(content_size_); |
| 269 *fragment_out = builder_->ToFragment(); | 269 *fragment_out = builder_->ToFragment(); |
| 270 state_ = kStateInit; | 270 state_ = kStateInit; |
| 271 return NewFragment; | 271 return kNewFragment; |
| 272 } | 272 } |
| 273 }; | 273 }; |
| 274 NOTREACHED(); | 274 NOTREACHED(); |
| 275 *fragment_out = nullptr; | 275 *fragment_out = nullptr; |
| 276 return NewFragment; | 276 return kNewFragment; |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool NGBlockLayoutAlgorithm::LayoutCurrentChild() { | 279 bool NGBlockLayoutAlgorithm::LayoutCurrentChild() { |
| 280 NGFragmentBase* fragment; | 280 NGFragmentBase* fragment; |
| 281 if (!current_child_->Layout(space_for_current_child_, &fragment)) | 281 if (!current_child_->Layout(space_for_current_child_, &fragment)) |
| 282 return false; | 282 return false; |
| 283 | 283 |
| 284 NGBoxStrut child_margins = ComputeMargins( | 284 NGBoxStrut child_margins = ComputeMargins( |
| 285 *space_for_current_child_, CurrentChildStyle(), | 285 *space_for_current_child_, CurrentChildStyle(), |
| 286 constraint_space_->WritingMode(), constraint_space_->Direction()); | 286 constraint_space_->WritingMode(), constraint_space_->Direction()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // Update offset if there is a clearance. | 391 // Update offset if there is a clearance. |
| 392 NGLogicalOffset offset = space_for_current_child_->Offset(); | 392 NGLogicalOffset offset = space_for_current_child_->Offset(); |
| 393 AdjustToClearance(ConstraintSpace(), CurrentChildStyle(), | 393 AdjustToClearance(ConstraintSpace(), CurrentChildStyle(), |
| 394 &offset.block_offset); | 394 &offset.block_offset); |
| 395 space_for_current_child_->SetOffset(offset); | 395 space_for_current_child_->SetOffset(offset); |
| 396 | 396 |
| 397 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( | 397 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
| 398 space_for_current_child_, fragment, margins); | 398 space_for_current_child_, fragment, margins); |
| 399 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 399 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
| 400 | 400 |
| 401 NGExclusion::Type exclusion_type = NGExclusion::NG_FLOAT_LEFT; | 401 NGExclusion::Type exclusion_type = NGExclusion::kFloatLeft; |
| 402 // Calculate the float offset if needed. | 402 // Calculate the float offset if needed. |
| 403 LayoutUnit float_offset; | 403 LayoutUnit float_offset; |
| 404 if (CurrentChildStyle().floating() == EFloat::Right) { | 404 if (CurrentChildStyle().floating() == EFloat::Right) { |
| 405 float_offset = opportunity.size.inline_size - fragment.InlineSize(); | 405 float_offset = opportunity.size.inline_size - fragment.InlineSize(); |
| 406 exclusion_type = NGExclusion::NG_FLOAT_RIGHT; | 406 exclusion_type = NGExclusion::kFloatRight; |
| 407 } | 407 } |
| 408 | 408 |
| 409 // Add the float as an exclusion. | 409 // Add the float as an exclusion. |
| 410 const NGExclusion exclusion = CreateExclusion( | 410 const NGExclusion exclusion = CreateExclusion( |
| 411 fragment, opportunity, float_offset, margins, exclusion_type); | 411 fragment, opportunity, float_offset, margins, exclusion_type); |
| 412 constraint_space_->AddExclusion(exclusion); | 412 constraint_space_->AddExclusion(exclusion); |
| 413 | 413 |
| 414 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, | 414 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, |
| 415 margins); | 415 margins); |
| 416 } | 416 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 visitor->trace(first_child_); | 450 visitor->trace(first_child_); |
| 451 visitor->trace(constraint_space_); | 451 visitor->trace(constraint_space_); |
| 452 visitor->trace(break_token_); | 452 visitor->trace(break_token_); |
| 453 visitor->trace(builder_); | 453 visitor->trace(builder_); |
| 454 visitor->trace(space_builder_); | 454 visitor->trace(space_builder_); |
| 455 visitor->trace(space_for_current_child_); | 455 visitor->trace(space_for_current_child_); |
| 456 visitor->trace(current_child_); | 456 visitor->trace(current_child_); |
| 457 } | 457 } |
| 458 | 458 |
| 459 } // namespace blink | 459 } // namespace blink |
| OLD | NEW |