Commit 644db273 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Use WritingDirectionMode in NGStaticPosition

This patch changes |NGLogicalStaticPosition| and
|NGPhysicalStaticPosition| to use |WritingDirectionMode|
and |WritingModeConverter|.

Bug: 1091797
Change-Id: Id5232652e76a393bc2efad33202801d9a3b04518
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2374930
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803223}
parent e36abea9
...@@ -9,9 +9,8 @@ ...@@ -9,9 +9,8 @@
#include "third_party/blink/renderer/core/layout/geometry/logical_offset.h" #include "third_party/blink/renderer/core/layout/geometry/logical_offset.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h" #include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_size.h" #include "third_party/blink/renderer/core/layout/geometry/physical_size.h"
#include "third_party/blink/renderer/core/layout/geometry/writing_mode_converter.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h" #include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"
namespace blink { namespace blink {
...@@ -25,8 +24,8 @@ struct CORE_EXPORT NGLogicalStaticPosition { ...@@ -25,8 +24,8 @@ struct CORE_EXPORT NGLogicalStaticPosition {
enum InlineEdge { kInlineStart, kInlineCenter, kInlineEnd }; enum InlineEdge { kInlineStart, kInlineCenter, kInlineEnd };
enum BlockEdge { kBlockStart, kBlockCenter, kBlockEnd }; enum BlockEdge { kBlockStart, kBlockCenter, kBlockEnd };
inline NGPhysicalStaticPosition inline NGPhysicalStaticPosition ConvertToPhysical(
ConvertToPhysical(WritingMode, TextDirection, const PhysicalSize& size) const; const WritingModeConverter& converter) const;
LogicalOffset offset; LogicalOffset offset;
InlineEdge inline_edge; InlineEdge inline_edge;
...@@ -42,12 +41,10 @@ struct CORE_EXPORT NGPhysicalStaticPosition { ...@@ -42,12 +41,10 @@ struct CORE_EXPORT NGPhysicalStaticPosition {
HorizontalEdge horizontal_edge; HorizontalEdge horizontal_edge;
VerticalEdge vertical_edge; VerticalEdge vertical_edge;
NGLogicalStaticPosition ConvertToLogical(WritingMode writing_mode, NGLogicalStaticPosition ConvertToLogical(
TextDirection direction, const WritingModeConverter& converter) const {
const PhysicalSize& size) const {
LogicalOffset logical_offset = LogicalOffset logical_offset =
offset.ConvertToLogical(writing_mode, direction, /* outer_size */ size, converter.ToLogical(offset, /* inner_size */ PhysicalSize());
/* inner_size */ PhysicalSize());
using InlineEdge = NGLogicalStaticPosition::InlineEdge; using InlineEdge = NGLogicalStaticPosition::InlineEdge;
using BlockEdge = NGLogicalStaticPosition::BlockEdge; using BlockEdge = NGLogicalStaticPosition::BlockEdge;
...@@ -55,9 +52,9 @@ struct CORE_EXPORT NGPhysicalStaticPosition { ...@@ -55,9 +52,9 @@ struct CORE_EXPORT NGPhysicalStaticPosition {
InlineEdge inline_edge; InlineEdge inline_edge;
BlockEdge block_edge; BlockEdge block_edge;
switch (writing_mode) { switch (converter.GetWritingMode()) {
case WritingMode::kHorizontalTb: case WritingMode::kHorizontalTb:
inline_edge = ((horizontal_edge == kLeft) == IsLtr(direction)) inline_edge = ((horizontal_edge == kLeft) == converter.IsLtr())
? InlineEdge::kInlineStart ? InlineEdge::kInlineStart
: InlineEdge::kInlineEnd; : InlineEdge::kInlineEnd;
block_edge = (vertical_edge == kTop) ? BlockEdge::kBlockStart block_edge = (vertical_edge == kTop) ? BlockEdge::kBlockStart
...@@ -65,21 +62,21 @@ struct CORE_EXPORT NGPhysicalStaticPosition { ...@@ -65,21 +62,21 @@ struct CORE_EXPORT NGPhysicalStaticPosition {
break; break;
case WritingMode::kVerticalRl: case WritingMode::kVerticalRl:
case WritingMode::kSidewaysRl: case WritingMode::kSidewaysRl:
inline_edge = ((vertical_edge == kTop) == IsLtr(direction)) inline_edge = ((vertical_edge == kTop) == converter.IsLtr())
? InlineEdge::kInlineStart ? InlineEdge::kInlineStart
: InlineEdge::kInlineEnd; : InlineEdge::kInlineEnd;
block_edge = (horizontal_edge == kRight) ? BlockEdge::kBlockStart block_edge = (horizontal_edge == kRight) ? BlockEdge::kBlockStart
: BlockEdge::kBlockEnd; : BlockEdge::kBlockEnd;
break; break;
case WritingMode::kVerticalLr: case WritingMode::kVerticalLr:
inline_edge = ((vertical_edge == kTop) == IsLtr(direction)) inline_edge = ((vertical_edge == kTop) == converter.IsLtr())
? InlineEdge::kInlineStart ? InlineEdge::kInlineStart
: InlineEdge::kInlineEnd; : InlineEdge::kInlineEnd;
block_edge = (horizontal_edge == kLeft) ? BlockEdge::kBlockStart block_edge = (horizontal_edge == kLeft) ? BlockEdge::kBlockStart
: BlockEdge::kBlockEnd; : BlockEdge::kBlockEnd;
break; break;
case WritingMode::kSidewaysLr: case WritingMode::kSidewaysLr:
inline_edge = ((vertical_edge == kBottom) == IsLtr(direction)) inline_edge = ((vertical_edge == kBottom) == converter.IsLtr())
? InlineEdge::kInlineStart ? InlineEdge::kInlineStart
: InlineEdge::kInlineEnd; : InlineEdge::kInlineEnd;
block_edge = (horizontal_edge == kLeft) ? BlockEdge::kBlockStart block_edge = (horizontal_edge == kLeft) ? BlockEdge::kBlockStart
...@@ -88,7 +85,7 @@ struct CORE_EXPORT NGPhysicalStaticPosition { ...@@ -88,7 +85,7 @@ struct CORE_EXPORT NGPhysicalStaticPosition {
} }
// Adjust for uncommon "center" static-positions. // Adjust for uncommon "center" static-positions.
switch (writing_mode) { switch (converter.GetWritingMode()) {
case WritingMode::kHorizontalTb: case WritingMode::kHorizontalTb:
inline_edge = (horizontal_edge == kHorizontalCenter) inline_edge = (horizontal_edge == kHorizontalCenter)
? InlineEdge::kInlineCenter ? InlineEdge::kInlineCenter
...@@ -115,12 +112,9 @@ struct CORE_EXPORT NGPhysicalStaticPosition { ...@@ -115,12 +112,9 @@ struct CORE_EXPORT NGPhysicalStaticPosition {
}; };
inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical( inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical(
WritingMode writing_mode, const WritingModeConverter& converter) const {
TextDirection direction,
const PhysicalSize& size) const {
PhysicalOffset physical_offset = PhysicalOffset physical_offset =
offset.ConvertToPhysical(writing_mode, direction, /* outer_size */ size, converter.ToPhysical(offset, /* inner_size */ PhysicalSize());
/* inner_size */ PhysicalSize());
using HorizontalEdge = NGPhysicalStaticPosition::HorizontalEdge; using HorizontalEdge = NGPhysicalStaticPosition::HorizontalEdge;
using VerticalEdge = NGPhysicalStaticPosition::VerticalEdge; using VerticalEdge = NGPhysicalStaticPosition::VerticalEdge;
...@@ -128,9 +122,9 @@ inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical( ...@@ -128,9 +122,9 @@ inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical(
HorizontalEdge horizontal_edge; HorizontalEdge horizontal_edge;
VerticalEdge vertical_edge; VerticalEdge vertical_edge;
switch (writing_mode) { switch (converter.GetWritingMode()) {
case WritingMode::kHorizontalTb: case WritingMode::kHorizontalTb:
horizontal_edge = ((inline_edge == kInlineStart) == IsLtr(direction)) horizontal_edge = ((inline_edge == kInlineStart) == converter.IsLtr())
? HorizontalEdge::kLeft ? HorizontalEdge::kLeft
: HorizontalEdge::kRight; : HorizontalEdge::kRight;
vertical_edge = (block_edge == kBlockStart) ? VerticalEdge::kTop vertical_edge = (block_edge == kBlockStart) ? VerticalEdge::kTop
...@@ -140,28 +134,28 @@ inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical( ...@@ -140,28 +134,28 @@ inline NGPhysicalStaticPosition NGLogicalStaticPosition::ConvertToPhysical(
case WritingMode::kSidewaysRl: case WritingMode::kSidewaysRl:
horizontal_edge = (block_edge == kBlockEnd) ? HorizontalEdge::kLeft horizontal_edge = (block_edge == kBlockEnd) ? HorizontalEdge::kLeft
: HorizontalEdge::kRight; : HorizontalEdge::kRight;
vertical_edge = ((inline_edge == kInlineStart) == IsLtr(direction)) vertical_edge = ((inline_edge == kInlineStart) == converter.IsLtr())
? VerticalEdge::kTop ? VerticalEdge::kTop
: VerticalEdge::kBottom; : VerticalEdge::kBottom;
break; break;
case WritingMode::kVerticalLr: case WritingMode::kVerticalLr:
horizontal_edge = (block_edge == kBlockStart) ? HorizontalEdge::kLeft horizontal_edge = (block_edge == kBlockStart) ? HorizontalEdge::kLeft
: HorizontalEdge::kRight; : HorizontalEdge::kRight;
vertical_edge = ((inline_edge == kInlineStart) == IsLtr(direction)) vertical_edge = ((inline_edge == kInlineStart) == converter.IsLtr())
? VerticalEdge::kTop ? VerticalEdge::kTop
: VerticalEdge::kBottom; : VerticalEdge::kBottom;
break; break;
case WritingMode::kSidewaysLr: case WritingMode::kSidewaysLr:
horizontal_edge = (block_edge == kBlockStart) ? HorizontalEdge::kLeft horizontal_edge = (block_edge == kBlockStart) ? HorizontalEdge::kLeft
: HorizontalEdge::kRight; : HorizontalEdge::kRight;
vertical_edge = ((inline_edge == kInlineEnd) == IsLtr(direction)) vertical_edge = ((inline_edge == kInlineEnd) == converter.IsLtr())
? VerticalEdge::kTop ? VerticalEdge::kTop
: VerticalEdge::kBottom; : VerticalEdge::kBottom;
break; break;
} }
// Adjust for uncommon "center" static-positions. // Adjust for uncommon "center" static-positions.
switch (writing_mode) { switch (converter.GetWritingMode()) {
case WritingMode::kHorizontalTb: case WritingMode::kHorizontalTb:
horizontal_edge = (inline_edge == kInlineCenter) horizontal_edge = (inline_edge == kInlineCenter)
? HorizontalEdge::kHorizontalCenter ? HorizontalEdge::kHorizontalCenter
......
...@@ -253,14 +253,16 @@ TEST_P(NGStaticPositionTest, Convert) { ...@@ -253,14 +253,16 @@ TEST_P(NGStaticPositionTest, Convert) {
// It asserts that it is the same as the expected physical static-position, // It asserts that it is the same as the expected physical static-position,
// then performs the same operation in reverse. // then performs the same operation in reverse.
NGPhysicalStaticPosition physical_result = data.logical.ConvertToPhysical( const WritingModeConverter converter({data.writing_mode, data.direction},
data.writing_mode, data.direction, PhysicalSize(100, 100)); PhysicalSize(100, 100));
NGPhysicalStaticPosition physical_result =
data.logical.ConvertToPhysical(converter);
EXPECT_EQ(physical_result.offset, data.physical.offset); EXPECT_EQ(physical_result.offset, data.physical.offset);
EXPECT_EQ(physical_result.horizontal_edge, data.physical.horizontal_edge); EXPECT_EQ(physical_result.horizontal_edge, data.physical.horizontal_edge);
EXPECT_EQ(physical_result.vertical_edge, data.physical.vertical_edge); EXPECT_EQ(physical_result.vertical_edge, data.physical.vertical_edge);
NGLogicalStaticPosition logical_result = data.physical.ConvertToLogical( NGLogicalStaticPosition logical_result =
data.writing_mode, data.direction, PhysicalSize(100, 100)); data.physical.ConvertToLogical(converter);
EXPECT_EQ(logical_result.offset, data.logical.offset); EXPECT_EQ(logical_result.offset, data.logical.offset);
EXPECT_EQ(logical_result.inline_edge, data.logical.inline_edge); EXPECT_EQ(logical_result.inline_edge, data.logical.inline_edge);
EXPECT_EQ(logical_result.block_edge, data.logical.block_edge); EXPECT_EQ(logical_result.block_edge, data.logical.block_edge);
......
...@@ -152,10 +152,10 @@ NGLogicalStaticPosition LayoutBoxUtils::ComputeStaticPositionFromLegacy( ...@@ -152,10 +152,10 @@ NGLogicalStaticPosition LayoutBoxUtils::ComputeStaticPositionFromLegacy(
// why we use |TextDirection::kLtr| for the first conversion. // why we use |TextDirection::kLtr| for the first conversion.
logical_static_position = logical_static_position =
logical_static_position logical_static_position
.ConvertToPhysical(container_writing_mode, TextDirection::kLtr, .ConvertToPhysical(
container_size) {{container_writing_mode, TextDirection::kLtr}, container_size})
.ConvertToLogical(container_writing_mode, container_direction, .ConvertToLogical(
container_size); {{container_writing_mode, container_direction}, container_size});
// Finally we shift the static-position from being relative to the // Finally we shift the static-position from being relative to the
// padding-box, to the border-box. // padding-box, to the border-box.
......
...@@ -40,10 +40,10 @@ void NGContainerFragmentBuilder::PropagateChildData( ...@@ -40,10 +40,10 @@ void NGContainerFragmentBuilder::PropagateChildData(
const LogicalOffset& child_offset, const LogicalOffset& child_offset,
const LayoutInline* inline_container) { const LayoutInline* inline_container) {
// Collect the child's out of flow descendants. // Collect the child's out of flow descendants.
const WritingModeConverter converter(GetWritingDirection(), child.Size());
for (const auto& descendant : child.OutOfFlowPositionedDescendants()) { for (const auto& descendant : child.OutOfFlowPositionedDescendants()) {
NGLogicalStaticPosition static_position = NGLogicalStaticPosition static_position =
descendant.static_position.ConvertToLogical(GetWritingMode(), descendant.static_position.ConvertToLogical(converter);
Direction(), child.Size());
static_position.offset += child_offset; static_position.offset += child_offset;
const LayoutInline* new_inline_container = descendant.inline_container; const LayoutInline* new_inline_container = descendant.inline_container;
...@@ -66,22 +66,21 @@ void NGContainerFragmentBuilder::PropagateChildData( ...@@ -66,22 +66,21 @@ void NGContainerFragmentBuilder::PropagateChildData(
if (fragment->HasOutOfFlowPositionedFragmentainerDescendants()) { if (fragment->HasOutOfFlowPositionedFragmentainerDescendants()) {
const auto& out_of_flow_fragmentainer_descendants = const auto& out_of_flow_fragmentainer_descendants =
fragment->OutOfFlowPositionedFragmentainerDescendants(); fragment->OutOfFlowPositionedFragmentainerDescendants();
const WritingModeConverter empty_outer_size(GetWritingDirection(),
PhysicalSize());
for (const auto& descendant : out_of_flow_fragmentainer_descendants) { for (const auto& descendant : out_of_flow_fragmentainer_descendants) {
const NGPhysicalContainerFragment* containing_block_fragment = const NGPhysicalContainerFragment* containing_block_fragment =
descendant.containing_block_fragment.get(); descendant.containing_block_fragment.get();
if (!containing_block_fragment) if (!containing_block_fragment)
containing_block_fragment = fragment; containing_block_fragment = fragment;
LogicalOffset containing_block_offset = LogicalOffset containing_block_offset = converter.ToLogical(
descendant.containing_block_offset.ConvertToLogical( descendant.containing_block_offset, PhysicalSize());
GetWritingMode(), Direction(), child.Size(), PhysicalSize());
if (!child.IsFragmentainerBox()) if (!child.IsFragmentainerBox())
containing_block_offset.block_offset += child_offset.block_offset; containing_block_offset.block_offset += child_offset.block_offset;
NGLogicalStaticPosition static_position = NGLogicalStaticPosition static_position =
descendant.static_position.ConvertToLogical( descendant.static_position.ConvertToLogical(empty_outer_size);
GetWritingMode(), Direction(), PhysicalSize());
oof_positioned_fragmentainer_descendants_.emplace_back( oof_positioned_fragmentainer_descendants_.emplace_back(
descendant.node, static_position, descendant.inline_container, descendant.node, static_position, descendant.inline_container,
/* needs_block_offset_adjustment */ false, /* needs_block_offset_adjustment */ false,
......
...@@ -560,10 +560,10 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate( ...@@ -560,10 +560,10 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate(
NGLogicalStaticPosition candidate_static_position = NGLogicalStaticPosition candidate_static_position =
static_position static_position
.ConvertToPhysical(writing_mode_, default_direction, .ConvertToPhysical({{writing_mode_, default_direction},
container_physical_content_size) container_physical_content_size})
.ConvertToLogical(candidate_writing_mode, candidate_direction, .ConvertToLogical({{candidate_writing_mode, candidate_direction},
container_physical_content_size); container_physical_content_size});
// Need a constraint space to resolve offsets. // Need a constraint space to resolve offsets.
NGConstraintSpaceBuilder builder(writing_mode_, candidate_writing_mode, NGConstraintSpaceBuilder builder(writing_mode_, candidate_writing_mode,
...@@ -665,10 +665,10 @@ void NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant( ...@@ -665,10 +665,10 @@ void NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant(
NGLogicalStaticPosition descendant_static_position = NGLogicalStaticPosition descendant_static_position =
static_position static_position
.ConvertToPhysical(default_writing_mode, default_direction, .ConvertToPhysical({{default_writing_mode, default_direction},
container_physical_content_size) container_physical_content_size})
.ConvertToLogical(descendant_writing_mode, descendant_direction, .ConvertToLogical({{descendant_writing_mode, descendant_direction},
container_physical_content_size); container_physical_content_size});
// Need a constraint space to resolve offsets. // Need a constraint space to resolve offsets.
NGConstraintSpaceBuilder builder(default_writing_mode, NGConstraintSpaceBuilder builder(default_writing_mode,
......
...@@ -162,12 +162,13 @@ NGPhysicalBoxFragment::RareData::RareData(NGBoxFragmentBuilder* builder, ...@@ -162,12 +162,13 @@ NGPhysicalBoxFragment::RareData::RareData(NGBoxFragmentBuilder* builder,
: mathml_paint_info(std::move(builder->mathml_paint_info_)) { : mathml_paint_info(std::move(builder->mathml_paint_info_)) {
oof_positioned_fragmentainer_descendants.ReserveCapacity( oof_positioned_fragmentainer_descendants.ReserveCapacity(
builder->oof_positioned_fragmentainer_descendants_.size()); builder->oof_positioned_fragmentainer_descendants_.size());
const WritingModeConverter converter(
{builder->Style().GetWritingMode(), builder->Direction()}, size);
for (const auto& descendant : for (const auto& descendant :
builder->oof_positioned_fragmentainer_descendants_) { builder->oof_positioned_fragmentainer_descendants_) {
oof_positioned_fragmentainer_descendants.emplace_back( oof_positioned_fragmentainer_descendants.emplace_back(
descendant.node, descendant.node,
descendant.static_position.ConvertToPhysical( descendant.static_position.ConvertToPhysical(converter),
builder->Style().GetWritingMode(), builder->Direction(), size),
descendant.inline_container, descendant.inline_container,
descendant.fragmentainer_consumed_block_size, descendant.fragmentainer_consumed_block_size,
descendant.containing_block_offset.ConvertToPhysical( descendant.containing_block_offset.ConvertToPhysical(
......
...@@ -57,11 +57,12 @@ NGPhysicalContainerFragment::NGPhysicalContainerFragment( ...@@ -57,11 +57,12 @@ NGPhysicalContainerFragment::NGPhysicalContainerFragment(
if (oof_positioned_descendants_) { if (oof_positioned_descendants_) {
oof_positioned_descendants_->ReserveCapacity( oof_positioned_descendants_->ReserveCapacity(
builder->oof_positioned_descendants_.size()); builder->oof_positioned_descendants_.size());
const WritingModeConverter converter(
{builder->Style().GetWritingMode(), builder->Direction()}, size);
for (const auto& descendant : builder->oof_positioned_descendants_) { for (const auto& descendant : builder->oof_positioned_descendants_) {
oof_positioned_descendants_->emplace_back( oof_positioned_descendants_->emplace_back(
descendant.node, descendant.node,
descendant.static_position.ConvertToPhysical( descendant.static_position.ConvertToPhysical(converter),
builder->Style().GetWritingMode(), builder->Direction(), size),
descendant.inline_container); descendant.inline_container);
} }
} }
......
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