Commit 0cb2da98 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Add "use first line style" to NGConstraintSpace

This patch adds UseFirstLineStyle() to NGConstraintSpace, and
removes NGBaselineAlgorithmType::kAtomicInlineForFirstLine.

The distinction between kAtomicInline and kAtomicInlineForFirstLine
are not available in many cases, and these values are exclusive.
Having UseFirstLineStyle() in NGConstraintSpace is more reasonable.

Bug: 636993
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I19e4124e82b86ba87318f6a08aa47e958dbf53ad
Reviewed-on: https://chromium-review.googlesource.com/688259
Commit-Queue: Koji Ishii <kojii@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@{#505324}
parent f9274eb1
...@@ -16,8 +16,6 @@ class NGLayoutInputNode; ...@@ -16,8 +16,6 @@ class NGLayoutInputNode;
enum class NGBaselineAlgorithmType { enum class NGBaselineAlgorithmType {
// Compute baselines for atomic inlines. // Compute baselines for atomic inlines.
kAtomicInline, kAtomicInline,
// Compute baselines for atomic inlines using the first line style.
kAtomicInlineForFirstLine,
// Compute baseline of first line box. // Compute baseline of first line box.
kFirstLine kFirstLine
}; };
......
...@@ -312,10 +312,7 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline( ...@@ -312,10 +312,7 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline(
ConstraintSpace().WritingMode(), ConstraintSpace().WritingMode(),
ToNGPhysicalBoxFragment(*item_result->layout_result->PhysicalFragment())); ToNGPhysicalBoxFragment(*item_result->layout_result->PhysicalFragment()));
NGLineHeightMetrics metrics = fragment.BaselineMetrics( NGLineHeightMetrics metrics = fragment.BaselineMetrics(
{line_info.UseFirstLineStyle() {NGBaselineAlgorithmType::kAtomicInline, baseline_type_});
? NGBaselineAlgorithmType::kAtomicInlineForFirstLine
: NGBaselineAlgorithmType::kAtomicInline,
baseline_type_});
box->metrics.Unite(metrics); box->metrics.Unite(metrics);
LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; LayoutUnit line_top = item_result->margins.block_start - metrics.ascent;
...@@ -499,7 +496,7 @@ void NGInlineLayoutAlgorithm::PropagateBaselinesFromChildren() { ...@@ -499,7 +496,7 @@ void NGInlineLayoutAlgorithm::PropagateBaselinesFromChildren() {
for (const auto& request : requests) { for (const auto& request : requests) {
switch (request.algorithm_type) { switch (request.algorithm_type) {
case NGBaselineAlgorithmType::kAtomicInline: case NGBaselineAlgorithmType::kAtomicInline:
case NGBaselineAlgorithmType::kAtomicInlineForFirstLine: // Propagate from the last line box.
for (unsigned i = container_builder_.Children().size(); i--;) { for (unsigned i = container_builder_.Children().size(); i--;) {
if (AddBaseline(request, container_builder_.Children()[i].get(), if (AddBaseline(request, container_builder_.Children()[i].get(),
container_builder_.Offsets()[i].block_offset)) container_builder_.Offsets()[i].block_offset))
...@@ -507,6 +504,7 @@ void NGInlineLayoutAlgorithm::PropagateBaselinesFromChildren() { ...@@ -507,6 +504,7 @@ void NGInlineLayoutAlgorithm::PropagateBaselinesFromChildren() {
} }
break; break;
case NGBaselineAlgorithmType::kFirstLine: case NGBaselineAlgorithmType::kFirstLine:
// Propagate from the first line box.
for (unsigned i = 0; i < container_builder_.Children().size(); i++) { for (unsigned i = 0; i < container_builder_.Children().size(); i++) {
if (AddBaseline(request, container_builder_.Children()[i].get(), if (AddBaseline(request, container_builder_.Children()[i].get(),
container_builder_.Offsets()[i].block_offset)) container_builder_.Offsets()[i].block_offset))
......
...@@ -482,10 +482,9 @@ NGLineBreaker::LineBreakState NGLineBreaker::HandleAtomicInline( ...@@ -482,10 +482,9 @@ NGLineBreaker::LineBreakState NGLineBreaker::HandleAtomicInline(
// Request to compute baseline during the layout, except when we know the box // Request to compute baseline during the layout, except when we know the box
// would synthesize box-baseline. // would synthesize box-baseline.
if (NGBaseline::ShouldPropagateBaselines(layout_box)) { if (NGBaseline::ShouldPropagateBaselines(layout_box)) {
space_builder.SetUseFirstLineStyle(line_info.UseFirstLineStyle());
space_builder.AddBaselineRequest( space_builder.AddBaselineRequest(
{line_info.UseFirstLineStyle() {NGBaselineAlgorithmType::kAtomicInline,
? NGBaselineAlgorithmType::kAtomicInlineForFirstLine
: NGBaselineAlgorithmType::kAtomicInline,
IsHorizontalWritingMode(constraint_space_.WritingMode()) IsHorizontalWritingMode(constraint_space_.WritingMode())
? FontBaseline::kAlphabeticBaseline ? FontBaseline::kAlphabeticBaseline
: FontBaseline::kIdeographicBaseline}); : FontBaseline::kIdeographicBaseline});
......
...@@ -1209,7 +1209,6 @@ void NGBlockLayoutAlgorithm::PropagateBaselinesFromChildren() { ...@@ -1209,7 +1209,6 @@ void NGBlockLayoutAlgorithm::PropagateBaselinesFromChildren() {
for (const auto& request : requests) { for (const auto& request : requests) {
switch (request.algorithm_type) { switch (request.algorithm_type) {
case NGBaselineAlgorithmType::kAtomicInline: case NGBaselineAlgorithmType::kAtomicInline:
case NGBaselineAlgorithmType::kAtomicInlineForFirstLine:
for (unsigned i = container_builder_.Children().size(); i--;) { for (unsigned i = container_builder_.Children().size(); i--;) {
if (AddBaseline(request, container_builder_.Children()[i].get(), if (AddBaseline(request, container_builder_.Children()[i].get(),
container_builder_.Offsets()[i].block_offset)) container_builder_.Offsets()[i].block_offset))
......
...@@ -515,10 +515,8 @@ void NGBlockNode::CopyBaselinesFromOldLayout( ...@@ -515,10 +515,8 @@ void NGBlockNode::CopyBaselinesFromOldLayout(
for (const auto& request : requests) { for (const auto& request : requests) {
switch (request.algorithm_type) { switch (request.algorithm_type) {
case NGBaselineAlgorithmType::kAtomicInline: case NGBaselineAlgorithmType::kAtomicInline:
AddAtomicInlineBaselineFromOldLayout(request, false, builder); AddAtomicInlineBaselineFromOldLayout(
break; request, constraint_space.UseFirstLineStyle(), builder);
case NGBaselineAlgorithmType::kAtomicInlineForFirstLine:
AddAtomicInlineBaselineFromOldLayout(request, true, builder);
break; break;
case NGBaselineAlgorithmType::kFirstLine: { case NGBaselineAlgorithmType::kFirstLine: {
LayoutUnit position = box_->FirstLineBoxBaseline(); LayoutUnit position = box_->FirstLineBoxBaseline();
......
...@@ -27,6 +27,7 @@ NGConstraintSpace::NGConstraintSpace( ...@@ -27,6 +27,7 @@ NGConstraintSpace::NGConstraintSpace(
NGFragmentationType block_direction_fragmentation_type, NGFragmentationType block_direction_fragmentation_type,
bool is_new_fc, bool is_new_fc,
bool is_anonymous, bool is_anonymous,
bool use_first_line_style,
const NGMarginStrut& margin_strut, const NGMarginStrut& margin_strut,
const NGBfcOffset& bfc_offset, const NGBfcOffset& bfc_offset,
const WTF::Optional<NGBfcOffset>& floats_bfc_offset, const WTF::Optional<NGBfcOffset>& floats_bfc_offset,
...@@ -51,6 +52,7 @@ NGConstraintSpace::NGConstraintSpace( ...@@ -51,6 +52,7 @@ NGConstraintSpace::NGConstraintSpace(
block_direction_fragmentation_type_(block_direction_fragmentation_type), block_direction_fragmentation_type_(block_direction_fragmentation_type),
is_new_fc_(is_new_fc), is_new_fc_(is_new_fc),
is_anonymous_(is_anonymous), is_anonymous_(is_anonymous),
use_first_line_style_(use_first_line_style),
writing_mode_(writing_mode), writing_mode_(writing_mode),
direction_(static_cast<unsigned>(direction)), direction_(static_cast<unsigned>(direction)),
margin_strut_(margin_strut), margin_strut_(margin_strut),
......
...@@ -95,6 +95,13 @@ class CORE_EXPORT NGConstraintSpace final ...@@ -95,6 +95,13 @@ class CORE_EXPORT NGConstraintSpace final
// any borders or padding. // any borders or padding.
bool IsAnonymous() const { return is_anonymous_; } bool IsAnonymous() const { return is_anonymous_; }
// Whether to use the ':first-line' style or not.
// Note, this is not about the first line of the content to layout, but
// whether the constraint space itself is on the first line, such as when it's
// an inline block.
// Also note this is true only when the document has ':first-line' rules.
bool UseFirstLineStyle() const { return use_first_line_style_; }
// Whether exceeding the AvailableSize() triggers the presence of a scrollbar // Whether exceeding the AvailableSize() triggers the presence of a scrollbar
// for the indicated direction. // for the indicated direction.
// If exceeded the current layout should be aborted and invoked again with a // If exceeded the current layout should be aborted and invoked again with a
...@@ -201,6 +208,7 @@ class CORE_EXPORT NGConstraintSpace final ...@@ -201,6 +208,7 @@ class CORE_EXPORT NGConstraintSpace final
NGFragmentationType block_direction_fragmentation_type, NGFragmentationType block_direction_fragmentation_type,
bool is_new_fc, bool is_new_fc,
bool is_anonymous, bool is_anonymous,
bool use_first_line_style,
const NGMarginStrut& margin_strut, const NGMarginStrut& margin_strut,
const NGBfcOffset& bfc_offset, const NGBfcOffset& bfc_offset,
const WTF::Optional<NGBfcOffset>& floats_bfc_offset, const WTF::Optional<NGBfcOffset>& floats_bfc_offset,
...@@ -232,6 +240,7 @@ class CORE_EXPORT NGConstraintSpace final ...@@ -232,6 +240,7 @@ class CORE_EXPORT NGConstraintSpace final
unsigned is_new_fc_ : 1; unsigned is_new_fc_ : 1;
unsigned is_anonymous_ : 1; unsigned is_anonymous_ : 1;
unsigned use_first_line_style_ : 1;
unsigned writing_mode_ : 3; unsigned writing_mode_ : 3;
unsigned direction_ : 1; unsigned direction_ : 1;
......
...@@ -27,6 +27,7 @@ NGConstraintSpaceBuilder::NGConstraintSpaceBuilder(NGWritingMode writing_mode, ...@@ -27,6 +27,7 @@ NGConstraintSpaceBuilder::NGConstraintSpaceBuilder(NGWritingMode writing_mode,
fragmentation_type_(kFragmentNone), fragmentation_type_(kFragmentNone),
is_new_fc_(false), is_new_fc_(false),
is_anonymous_(false), is_anonymous_(false),
use_first_line_sytle_(false),
text_direction_(static_cast<unsigned>(TextDirection::kLtr)), text_direction_(static_cast<unsigned>(TextDirection::kLtr)),
exclusion_space_(nullptr) {} exclusion_space_(nullptr) {}
...@@ -130,6 +131,12 @@ NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetIsAnonymous( ...@@ -130,6 +131,12 @@ NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetIsAnonymous(
return *this; return *this;
} }
NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetUseFirstLineStyle(
bool use_first_line_sytle) {
use_first_line_sytle_ = use_first_line_sytle;
return *this;
}
NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetUnpositionedFloats( NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetUnpositionedFloats(
Vector<RefPtr<NGUnpositionedFloat>>& unpositioned_floats) { Vector<RefPtr<NGUnpositionedFloat>>& unpositioned_floats) {
unpositioned_floats_ = unpositioned_floats; unpositioned_floats_ = unpositioned_floats;
...@@ -229,9 +236,9 @@ RefPtr<NGConstraintSpace> NGConstraintSpaceBuilder::ToConstraintSpace( ...@@ -229,9 +236,9 @@ RefPtr<NGConstraintSpace> NGConstraintSpaceBuilder::ToConstraintSpace(
is_inline_direction_triggers_scrollbar_, is_inline_direction_triggers_scrollbar_,
is_block_direction_triggers_scrollbar_, is_block_direction_triggers_scrollbar_,
static_cast<NGFragmentationType>(fragmentation_type_), is_new_fc_, static_cast<NGFragmentationType>(fragmentation_type_), is_new_fc_,
is_anonymous_, margin_strut, bfc_offset, floats_bfc_offset, is_anonymous_, use_first_line_sytle_, margin_strut, bfc_offset,
exclusion_space, unpositioned_floats_, clearance_offset, floats_bfc_offset, exclusion_space, unpositioned_floats_,
baseline_requests_)); clearance_offset, baseline_requests_));
} }
return WTF::AdoptRef(new NGConstraintSpace( return WTF::AdoptRef(new NGConstraintSpace(
out_writing_mode, static_cast<TextDirection>(text_direction_), out_writing_mode, static_cast<TextDirection>(text_direction_),
...@@ -242,9 +249,9 @@ RefPtr<NGConstraintSpace> NGConstraintSpaceBuilder::ToConstraintSpace( ...@@ -242,9 +249,9 @@ RefPtr<NGConstraintSpace> NGConstraintSpaceBuilder::ToConstraintSpace(
is_block_direction_triggers_scrollbar_, is_block_direction_triggers_scrollbar_,
is_inline_direction_triggers_scrollbar_, is_inline_direction_triggers_scrollbar_,
static_cast<NGFragmentationType>(fragmentation_type_), is_new_fc_, static_cast<NGFragmentationType>(fragmentation_type_), is_new_fc_,
is_anonymous_, margin_strut, bfc_offset, floats_bfc_offset, is_anonymous_, use_first_line_sytle_, margin_strut, bfc_offset,
exclusion_space, unpositioned_floats_, clearance_offset, floats_bfc_offset, exclusion_space, unpositioned_floats_,
baseline_requests_)); clearance_offset, baseline_requests_));
} }
} // namespace blink } // namespace blink
...@@ -55,6 +55,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -55,6 +55,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
NGConstraintSpaceBuilder& SetFragmentationType(NGFragmentationType); NGConstraintSpaceBuilder& SetFragmentationType(NGFragmentationType);
NGConstraintSpaceBuilder& SetIsNewFormattingContext(bool is_new_fc); NGConstraintSpaceBuilder& SetIsNewFormattingContext(bool is_new_fc);
NGConstraintSpaceBuilder& SetIsAnonymous(bool is_anonymous); NGConstraintSpaceBuilder& SetIsAnonymous(bool is_anonymous);
NGConstraintSpaceBuilder& SetUseFirstLineStyle(bool use_first_line_sytle);
NGConstraintSpaceBuilder& SetUnpositionedFloats( NGConstraintSpaceBuilder& SetUnpositionedFloats(
Vector<RefPtr<NGUnpositionedFloat>>& unpositioned_floats); Vector<RefPtr<NGUnpositionedFloat>>& unpositioned_floats);
...@@ -103,6 +104,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -103,6 +104,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
unsigned fragmentation_type_ : 2; unsigned fragmentation_type_ : 2;
unsigned is_new_fc_ : 1; unsigned is_new_fc_ : 1;
unsigned is_anonymous_ : 1; unsigned is_anonymous_ : 1;
unsigned use_first_line_sytle_ : 1;
unsigned text_direction_ : 1; unsigned text_direction_ : 1;
NGMarginStrut margin_strut_; NGMarginStrut margin_strut_;
......
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