Commit 1c4f51eb authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Remove an unnecessary duplicate call to ComputePadding

Also, makes CalculateBorderScrollbarPadding equivalent to
ComputeBorder + ComputePadding + GetScrollbarSizes.

This also makes the padding set on the fragment more correct.

R=eae@chromium.org

Bug: 635619
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I8db38ca5955d30fa789a636e5c6deb2ec1fd1829
Reviewed-on: https://chromium-review.googlesource.com/1169321
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582272}
parent 3a1ad4a1
......@@ -347,8 +347,12 @@ NGLogicalOffset NGBlockLayoutAlgorithm::CalculateLogicalOffset(
}
scoped_refptr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() {
NGBoxStrut borders = ComputeBorders(ConstraintSpace(), Node());
NGBoxStrut padding = ComputePadding(ConstraintSpace(), Node());
border_scrollbar_padding_ =
CalculateBorderScrollbarPadding(ConstraintSpace(), Node());
ConstraintSpace().IsAnonymous()
? NGBoxStrut()
: borders + padding + Node().GetScrollbarSizes();
NGLogicalSize border_box_size = CalculateBorderBoxSize(
ConstraintSpace(), Node(), CalculateDefaultBlockSize());
......@@ -630,7 +634,7 @@ scoped_refptr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() {
container_builder_.SetEndMarginStrut(end_margin_strut);
container_builder_.SetIntrinsicBlockSize(intrinsic_block_size_);
container_builder_.SetPadding(ComputePadding(ConstraintSpace(), Style()));
container_builder_.SetPadding(padding);
// We only finalize for fragmentation if the fragment has a BFC block offset.
// This may occur with a zero block size fragment. We need to know the BFC
......
......@@ -684,6 +684,22 @@ NGBoxStrut ComputeBorders(const NGConstraintSpace& constraint_space,
return borders;
}
NGBoxStrut ComputeBorders(const NGConstraintSpace& constraint_space,
const NGLayoutInputNode node) {
// If we are producing an anonymous fragment (e.g. a column), it has no
// borders, padding or scrollbars. Using the ones from the container can only
// cause trouble.
if (constraint_space.IsAnonymous())
return NGBoxStrut();
if (node.GetLayoutBox()->IsTableCell()) {
LayoutBox* box = node.GetLayoutBox();
return NGBoxStrut(box->BorderStart(), box->BorderEnd(), box->BorderBefore(),
box->BorderAfter());
}
return ComputeBorders(constraint_space, node.Style());
}
NGBoxStrut ComputePadding(const NGConstraintSpace& constraint_space,
const ComputedStyle& style) {
// If we are producing an anonymous fragment (e.g. a column) we shouldn't
......@@ -703,6 +719,27 @@ NGBoxStrut ComputePadding(const NGConstraintSpace& constraint_space,
return padding;
}
NGBoxStrut ComputePadding(const NGConstraintSpace& constraint_space,
const NGLayoutInputNode node) {
// If we are producing an anonymous fragment (e.g. a column), it has no
// borders, padding or scrollbars. Using the ones from the container can only
// cause trouble.
if (constraint_space.IsAnonymous())
return NGBoxStrut();
NGBoxStrut padding = ComputePadding(constraint_space, node.Style());
if (node.GetLayoutBox()->IsTableCell()) {
// Use values calculated by the table layout code
const LayoutTableCell* cell = ToLayoutTableCell(node.GetLayoutBox());
// TODO(karlo): intrinsic padding can sometimes be negative; that
// seems insane, but works in the old code; in NG it trips
// DCHECKs.
padding.block_start += LayoutUnit(cell->IntrinsicPaddingBefore());
padding.block_end += LayoutUnit(cell->IntrinsicPaddingAfter());
}
return padding;
}
void ResolveInlineMargins(const ComputedStyle& style,
const ComputedStyle& containing_block_style,
LayoutUnit available_inline_size,
......@@ -813,29 +850,13 @@ LayoutUnit ConstrainByMinMax(LayoutUnit length,
NGBoxStrut CalculateBorderScrollbarPadding(
const NGConstraintSpace& constraint_space,
const NGBlockNode node) {
const ComputedStyle& style = node.Style();
// If we are producing an anonymous fragment (e.g. a column), it has no
// borders, padding or scrollbars. Using the ones from the container can only
// cause trouble.
if (constraint_space.IsAnonymous())
return NGBoxStrut();
NGBoxStrut border_intrinsic_padding;
if (node.GetLayoutBox()->IsTableCell()) {
// Use values calculated by the table layout code
const LayoutTableCell* cell = ToLayoutTableCell(node.GetLayoutBox());
// TODO(karlo): intrinsic padding can sometimes be negative; that
// seems insane, but works in the old code; in NG it trips
// DCHECKs.
border_intrinsic_padding = NGBoxStrut(
cell->BorderStart(), cell->BorderEnd(),
cell->BorderBefore() + LayoutUnit(cell->IntrinsicPaddingBefore()),
cell->BorderAfter() + LayoutUnit(cell->IntrinsicPaddingAfter()));
} else {
border_intrinsic_padding = ComputeBorders(constraint_space, style);
}
return border_intrinsic_padding + ComputePadding(constraint_space, style) +
node.GetScrollbarSizes();
return ComputeBorders(constraint_space, node) +
ComputePadding(constraint_space, node) + node.GetScrollbarSizes();
}
NGLogicalSize CalculateBorderBoxSize(const NGConstraintSpace& constraint_space,
......
......@@ -168,12 +168,18 @@ CORE_EXPORT NGBoxStrut ComputeMarginsForSelf(const NGConstraintSpace&,
CORE_EXPORT NGBoxStrut ComputeMinMaxMargins(const ComputedStyle& parent_style,
NGLayoutInputNode child);
CORE_EXPORT NGBoxStrut ComputeBorders(const NGConstraintSpace& constraint_space,
CORE_EXPORT NGBoxStrut ComputeBorders(const NGConstraintSpace&,
const ComputedStyle&);
CORE_EXPORT NGBoxStrut ComputeBorders(const NGConstraintSpace&,
const NGLayoutInputNode);
CORE_EXPORT NGBoxStrut ComputePadding(const NGConstraintSpace&,
const ComputedStyle&);
CORE_EXPORT NGBoxStrut ComputePadding(const NGConstraintSpace&,
const NGLayoutInputNode);
// Convert inline margins from computed to used values. This will resolve 'auto'
// values and over-constrainedness. This uses the available size from the
// constraint space and inline size to compute the margins that are auto, if
......
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