Commit 167ebd4a authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Inline some functions in geometry/

This is more complex than you might expect because NGLogicalSize and
NGPhysicalSize depend on each other, so I can't inline the Convert
functions in both headers. Instead, I made NGLogicalSize::ConvertToPhysical
a global function and renamed it ToNGPhysicalSize.

Change-Id: I8d781fa73d262f75cd8196509a58f67a6fb5ec54
Reviewed-on: https://chromium-review.googlesource.com/c/1311083
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604438}
parent 972ebb39
......@@ -8,17 +8,6 @@
namespace blink {
NGPhysicalSize NGLogicalSize::ConvertToPhysical(WritingMode mode) const {
return mode == WritingMode::kHorizontalTb
? NGPhysicalSize(inline_size, block_size)
: NGPhysicalSize(block_size, inline_size);
}
bool NGLogicalSize::operator==(const NGLogicalSize& other) const {
return std::tie(other.inline_size, other.block_size) ==
std::tie(inline_size, block_size);
}
std::ostream& operator<<(std::ostream& stream, const NGLogicalSize& value) {
return stream << value.inline_size << "x" << value.block_size;
}
......
......@@ -14,7 +14,6 @@
namespace blink {
struct NGLogicalOffset;
struct NGPhysicalSize;
#define NGSizeIndefinite LayoutUnit(-1)
// NGLogicalSize is the size of rect (typically a fragment) in the logical
......@@ -24,11 +23,15 @@ struct CORE_EXPORT NGLogicalSize {
NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size)
: inline_size(inline_size), block_size(block_size) {}
// Use ToNGPhysicalSize to convert to a physical size.
LayoutUnit inline_size;
LayoutUnit block_size;
NGPhysicalSize ConvertToPhysical(WritingMode mode) const;
bool operator==(const NGLogicalSize& other) const;
bool operator==(const NGLogicalSize& other) const {
return std::tie(other.inline_size, other.block_size) ==
std::tie(inline_size, block_size);
}
bool IsEmpty() const {
return inline_size == LayoutUnit() || block_size == LayoutUnit();
......
......@@ -8,18 +8,6 @@
namespace blink {
LayoutUnit NGMarginStrut::Sum() const {
if (discard_margins)
return LayoutUnit();
return std::max(quirky_positive_margin, positive_margin) + negative_margin;
}
LayoutUnit NGMarginStrut::QuirkyContainerSum() const {
if (discard_margins)
return LayoutUnit();
return positive_margin + negative_margin;
}
void NGMarginStrut::Append(const LayoutUnit& value, bool is_quirky) {
if (is_quirky_container_start && is_quirky)
return;
......
......@@ -32,11 +32,19 @@ struct CORE_EXPORT NGMarginStrut {
void Append(const LayoutUnit& value, bool is_quirky);
// Sum up negative and positive margins of this strut.
LayoutUnit Sum() const;
LayoutUnit Sum() const {
if (discard_margins)
return LayoutUnit();
return std::max(quirky_positive_margin, positive_margin) + negative_margin;
}
// Sum up non-quirky margins of this strut, used by quirky
// containers to sum up the last margin.
LayoutUnit QuirkyContainerSum() const;
LayoutUnit QuirkyContainerSum() const {
if (discard_margins)
return LayoutUnit();
return positive_margin + negative_margin;
}
// Whether there have been no margins appended to this margin strut.
bool IsEmpty() const;
......
......@@ -51,6 +51,13 @@ struct CORE_EXPORT NGPhysicalSize {
CORE_EXPORT std::ostream& operator<<(std::ostream&, const NGPhysicalSize&);
inline NGPhysicalSize ToNGPhysicalSize(const NGLogicalSize& other,
WritingMode mode) {
return mode == WritingMode::kHorizontalTb
? NGPhysicalSize(other.inline_size, other.block_size)
: NGPhysicalSize(other.block_size, other.inline_size);
}
} // namespace blink
#endif // NGPhysicalSize_h
......@@ -45,7 +45,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) {
NGConstraintSpace constraint_space =
NGConstraintSpaceBuilder(
WritingMode::kHorizontalTb,
/* icb_size */ size.ConvertToPhysical(WritingMode::kHorizontalTb))
/* icb_size */ ToNGPhysicalSize(size, WritingMode::kHorizontalTb))
.SetAvailableSize(size)
.ToConstraintSpace(WritingMode::kHorizontalTb);
......
......@@ -37,8 +37,8 @@ void LayoutNGTableCaption::CalculateAndSetMargins(
LayoutUnit caption_inline_size_in_cb_writing_mode = box_fragment.InlineSize();
LayoutUnit available_inline_size_in_cb_writing_mode =
constraint_space.AvailableSize()
.ConvertToPhysical(constraint_space.GetWritingMode())
ToNGPhysicalSize(constraint_space.AvailableSize(),
constraint_space.GetWritingMode())
.ConvertToLogical(containing_block_style.GetWritingMode())
.inline_size;
......
......@@ -158,9 +158,8 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space,
const WritingMode container_writing_mode,
const TextDirection container_direction,
NGAbsolutePhysicalPosition* position) {
NGPhysicalSize percentage_physical =
space.PercentageResolutionSize().ConvertToPhysical(
space.GetWritingMode());
NGPhysicalSize percentage_physical = ToNGPhysicalSize(
space.PercentageResolutionSize(), space.GetWritingMode());
base::Optional<LayoutUnit> margin_left;
if (!style.MarginLeft().IsAuto())
margin_left = ResolveMarginPaddingLength(space, style.MarginLeft());
......@@ -175,7 +174,7 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space,
right = ValueForLength(style.Right(), percentage_physical.width);
base::Optional<LayoutUnit> width = incoming_width;
NGPhysicalSize container_size =
space.AvailableSize().ConvertToPhysical(space.GetWritingMode());
ToNGPhysicalSize(space.AvailableSize(), space.GetWritingMode());
DCHECK_NE(container_size.width, NGSizeIndefinite);
// Solving the equation:
......@@ -321,9 +320,8 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space,
const WritingMode container_writing_mode,
const TextDirection container_direction,
NGAbsolutePhysicalPosition* position) {
NGPhysicalSize percentage_physical =
space.PercentageResolutionSize().ConvertToPhysical(
space.GetWritingMode());
NGPhysicalSize percentage_physical = ToNGPhysicalSize(
space.PercentageResolutionSize(), space.GetWritingMode());
base::Optional<LayoutUnit> margin_top;
if (!style.MarginTop().IsAuto())
......@@ -341,7 +339,7 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space,
base::Optional<LayoutUnit> height = incoming_height;
NGPhysicalSize container_size =
space.AvailableSize().ConvertToPhysical(space.GetWritingMode());
ToNGPhysicalSize(space.AvailableSize(), space.GetWritingMode());
DCHECK_NE(container_size.height, NGSizeIndefinite);
// Solving the equation:
......
......@@ -28,8 +28,8 @@ class NGAbsoluteUtilsTest : public testing::Test {
container_size_ = NGLogicalSize(LayoutUnit(200), LayoutUnit(300));
NGConstraintSpaceBuilder builder(
WritingMode::kHorizontalTb,
/* icb_size */ container_size_.ConvertToPhysical(
WritingMode::kHorizontalTb));
/* icb_size */ ToNGPhysicalSize(container_size_,
WritingMode::kHorizontalTb));
builder.SetAvailableSize(container_size_);
ltr_space_ = builder.SetTextDirection(TextDirection::kLtr)
.ToConstraintSpace(WritingMode::kHorizontalTb);
......
......@@ -147,8 +147,8 @@ void NGContainerFragmentBuilder::GetAndClearOutOfFlowDescendantCandidates(
DCHECK_GE(InlineSize(), LayoutUnit());
DCHECK_GE(BlockSize(), LayoutUnit());
NGPhysicalSize builder_physical_size{
Size().ConvertToPhysical(GetWritingMode())};
NGPhysicalSize builder_physical_size =
ToNGPhysicalSize(Size(), GetWritingMode());
for (NGOutOfFlowPositionedCandidate& candidate : oof_positioned_candidates_) {
TextDirection direction =
......
......@@ -28,7 +28,7 @@ static NGConstraintSpace ConstructConstraintSpace(
return NGConstraintSpaceBuilder(
writing_mode,
/* icb_size */ size.ConvertToPhysical(writing_mode))
/* icb_size */ ToNGPhysicalSize(size, writing_mode))
.SetAvailableSize(size)
.SetPercentageResolutionSize(size)
.SetIsFixedSizeInline(fixed_inline)
......
......@@ -110,8 +110,8 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
container_builder_->ComputeInlineContainerFragments(
&inline_container_fragments, &container_builder_size);
NGPhysicalSize container_builder_physical_size =
container_builder_size.ConvertToPhysical(
default_containing_block_.style->GetWritingMode());
ToNGPhysicalSize(container_builder_size,
default_containing_block_.style->GetWritingMode());
// Translate start/end fragments into ContainingBlockInfo.
for (auto& block_info : inline_container_fragments) {
// Variables needed to describe ContainingBlockInfo
......@@ -300,8 +300,8 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant(
// and default_container border width.
NGStaticPosition static_position(descendant.static_position);
NGPhysicalSize default_containing_block_physical_size =
default_containing_block_.content_size.ConvertToPhysical(
default_containing_block_.style->GetWritingMode());
ToNGPhysicalSize(default_containing_block_.content_size,
default_containing_block_.style->GetWritingMode());
NGPhysicalOffset default_container_physical_offset =
container_info.default_container_offset.ConvertToPhysical(
default_containing_block_.style->GetWritingMode(),
......@@ -439,8 +439,8 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::GenerateFragment(
// the constraint space in the descendant's writing mode.
WritingMode writing_mode(descendant.Style().GetWritingMode());
NGLogicalSize container_size(
container_info.content_size
.ConvertToPhysical(default_containing_block_.style->GetWritingMode())
ToNGPhysicalSize(container_info.content_size,
default_containing_block_.style->GetWritingMode())
.ConvertToLogical(writing_mode));
LayoutUnit inline_size =
......
......@@ -238,7 +238,7 @@ NGPhysicalFragment::NGPhysicalFragment(NGFragmentBuilder* builder,
unsigned sub_type)
: layout_object_(builder->layout_object_),
style_(builder->style_),
size_(builder->size_.ConvertToPhysical(builder->GetWritingMode())),
size_(ToNGPhysicalSize(builder->size_, builder->GetWritingMode())),
break_token_(std::move(builder->break_token_)),
type_(type),
sub_type_(sub_type),
......
......@@ -55,7 +55,7 @@ NGPhysicalOffsetRect ComputePhysicalRectFor(
paint_fragment.PhysicalFragment().ResolvedDirection();
const NGPhysicalSize outer_size = paint_fragment.Size();
const NGPhysicalSize physical_size =
logical_rect.size.ConvertToPhysical(writing_mode);
ToNGPhysicalSize(logical_rect.size, writing_mode);
const NGPhysicalOffset physical_offset =
logical_rect.offset.ConvertToPhysical(writing_mode, text_direction,
outer_size, physical_size);
......
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