Commit 8e815bf3 authored by Christian Biesinger's avatar Christian Biesinger

[layoutng] Avoid some virtual function calls in NGBlockNode

No need to call IsLayoutBlock/IsLayoutNGMixin twice

R=eae@chromium.org, mstensho@chromium.org

Change-Id: Id63f3833040d4eb58dd67dcb204a139522e08a9b
Reviewed-on: https://chromium-review.googlesource.com/c/1308653
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604117}
parent 4bbcebe0
...@@ -240,7 +240,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout( ...@@ -240,7 +240,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout(
layout_result = LayoutWithAlgorithm(*this, constraint_space, break_token, layout_result = LayoutWithAlgorithm(*this, constraint_space, break_token,
/* ignored */ nullptr); /* ignored */ nullptr);
FinishLayout(constraint_space, break_token, layout_result); FinishLayout(block_flow, constraint_space, break_token, layout_result);
if (old_scrollbars != GetScrollbarSizes()) { if (old_scrollbars != GetScrollbarSizes()) {
// If our scrollbars have changed, we need to relayout because either: // If our scrollbars have changed, we need to relayout because either:
// - Our size has changed (if shrinking to fit), or // - Our size has changed (if shrinking to fit), or
...@@ -254,7 +254,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout( ...@@ -254,7 +254,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout(
PaintLayerScrollableArea::FreezeScrollbarsScope freeze_scrollbars; PaintLayerScrollableArea::FreezeScrollbarsScope freeze_scrollbars;
layout_result = LayoutWithAlgorithm(*this, constraint_space, break_token, layout_result = LayoutWithAlgorithm(*this, constraint_space, break_token,
/* ignored */ nullptr); /* ignored */ nullptr);
FinishLayout(constraint_space, break_token, layout_result); FinishLayout(block_flow, constraint_space, break_token, layout_result);
} }
return layout_result; return layout_result;
...@@ -274,7 +274,8 @@ void NGBlockNode::PrepareForLayout() { ...@@ -274,7 +274,8 @@ void NGBlockNode::PrepareForLayout() {
ToLayoutNGListItem(box_)->UpdateMarkerTextIfNeeded(); ToLayoutNGListItem(box_)->UpdateMarkerTextIfNeeded();
} }
void NGBlockNode::FinishLayout(const NGConstraintSpace& constraint_space, void NGBlockNode::FinishLayout(LayoutBlockFlow* block_flow,
const NGConstraintSpace& constraint_space,
const NGBreakToken* break_token, const NGBreakToken* break_token,
scoped_refptr<NGLayoutResult> layout_result) { scoped_refptr<NGLayoutResult> layout_result) {
if (!IsBlockLayoutComplete(constraint_space, *layout_result)) if (!IsBlockLayoutComplete(constraint_space, *layout_result))
...@@ -282,8 +283,7 @@ void NGBlockNode::FinishLayout(const NGConstraintSpace& constraint_space, ...@@ -282,8 +283,7 @@ void NGBlockNode::FinishLayout(const NGConstraintSpace& constraint_space,
DCHECK(layout_result->PhysicalFragment()); DCHECK(layout_result->PhysicalFragment());
if (box_->IsLayoutNGMixin()) { if (block_flow) {
LayoutBlockFlow* block_flow = ToLayoutBlockFlow(box_);
block_flow->SetCachedLayoutResult(constraint_space, break_token, block_flow->SetCachedLayoutResult(constraint_space, break_token,
*layout_result); *layout_result);
NGLayoutInputNode first_child = FirstChild(); NGLayoutInputNode first_child = FirstChild();
...@@ -799,9 +799,9 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout( ...@@ -799,9 +799,9 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout(
ToLayoutBlock(box_)->CreatesNewFormattingContext()); ToLayoutBlock(box_)->CreatesNewFormattingContext());
WritingMode writing_mode = Style().GetWritingMode(); WritingMode writing_mode = Style().GetWritingMode();
LayoutBlock* block = box_->IsLayoutBlock() ? ToLayoutBlock(box_) : nullptr;
const NGConstraintSpace* old_space = const NGConstraintSpace* old_space =
box_->IsLayoutBlock() ? ToLayoutBlock(box_)->CachedConstraintSpace() block ? block->CachedConstraintSpace() : nullptr;
: nullptr;
if (!old_space || box_->NeedsLayout() || *old_space != constraint_space) { if (!old_space || box_->NeedsLayout() || *old_space != constraint_space) {
LayoutUnit inline_size = LayoutUnit inline_size =
CalculateAvailableInlineSizeForLegacy(*box_, constraint_space); CalculateAvailableInlineSizeForLegacy(*box_, constraint_space);
...@@ -835,7 +835,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout( ...@@ -835,7 +835,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout(
} }
box_->ComputeAndSetBlockDirectionMargins(box_->ContainingBlock()); box_->ComputeAndSetBlockDirectionMargins(box_->ContainingBlock());
if (box_->IsLayoutNGMixin() && box_->NeedsLayout()) { if (box_->NeedsLayout() && box_->IsLayoutNGMixin()) {
ToLayoutBlockFlow(box_)->LayoutBlockFlow::UpdateBlockLayout(true); ToLayoutBlockFlow(box_)->LayoutBlockFlow::UpdateBlockLayout(true);
} else { } else {
box_->ForceLayout(); box_->ForceLayout();
...@@ -846,8 +846,8 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout( ...@@ -846,8 +846,8 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout(
// container (e.g. objects with intrinsic ratio and percentage block size) // container (e.g. objects with intrinsic ratio and percentage block size)
// in a subsequent layout pass might otherwise become wrong. // in a subsequent layout pass might otherwise become wrong.
box_->ClearOverrideContainingBlockContentSize(); box_->ClearOverrideContainingBlockContentSize();
if (box_->IsLayoutBlock()) if (block)
ToLayoutBlock(box_)->SetCachedConstraintSpace(constraint_space); block->SetCachedConstraintSpace(constraint_space);
} }
NGLogicalSize box_size(box_->LogicalWidth(), box_->LogicalHeight()); NGLogicalSize box_size(box_->LogicalWidth(), box_->LogicalHeight());
// TODO(kojii): Implement use_first_line_style. // TODO(kojii): Implement use_first_line_style.
......
...@@ -104,7 +104,10 @@ class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode { ...@@ -104,7 +104,10 @@ class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode {
private: private:
void PrepareForLayout(); void PrepareForLayout();
void FinishLayout(const NGConstraintSpace&, // If this node is a LayoutNGMixin, the caller must pass the layout object for
// this node cast to a LayoutBlockFlow as the first argument.
void FinishLayout(LayoutBlockFlow*,
const NGConstraintSpace&,
const NGBreakToken*, const NGBreakToken*,
scoped_refptr<NGLayoutResult>); scoped_refptr<NGLayoutResult>);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment