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