Commit 34ded98d authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

RubyNG: Introduce LayoutNGRubyAsBlock

This CL introduces LayoutNGRubyAsBlock, which is
LayoutNGBlockFlowMixin<LayoutRubyAsBlock>.

<ruby> with display:block uses it if LayoutNGRuby flag is enabled.

This CL has no behavior changes.

Bug: 1069817
Change-Id: Ia8c80ed4727a0788f1a8c2a1a502ceabd5ebab96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147408Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759144}
parent 38cc33ef
......@@ -5,23 +5,28 @@
#include "third_party/blink/renderer/core/html/html_ruby_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/layout_object_factory.h"
#include "third_party/blink/renderer/core/layout/layout_ruby.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
HTMLRubyElement::HTMLRubyElement(Document& document)
: HTMLElement(html_names::kRubyTag, document) {}
bool HTMLRubyElement::TypeShouldForceLegacyLayout() const {
if (RuntimeEnabledFeatures::LayoutNGRubyEnabled())
return false;
UseCounter::Count(GetDocument(), WebFeature::kLegacyLayoutByRuby);
return true;
}
LayoutObject* HTMLRubyElement::CreateLayoutObject(const ComputedStyle& style,
LegacyLayout legacy) {
if (style.Display() == EDisplay::kInline) {
UseCounter::Count(GetDocument(), WebFeature::kLegacyLayoutByRuby);
if (style.Display() == EDisplay::kInline)
return new LayoutRubyAsInline(this);
}
if (style.Display() == EDisplay::kBlock) {
UseCounter::Count(GetDocument(), WebFeature::kLegacyLayoutByRuby);
return new LayoutRubyAsBlock(this);
}
if (style.Display() == EDisplay::kBlock)
return LayoutObjectFactory::CreateRubyAsBlock(this, style, legacy);
return LayoutObject::CreateObject(this, style, legacy);
}
......
......@@ -17,7 +17,7 @@ class HTMLRubyElement final : public HTMLElement {
private:
LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override;
bool TypeShouldForceLegacyLayout() const final { return true; }
bool TypeShouldForceLegacyLayout() const final;
};
} // namespace blink
......
......@@ -402,6 +402,8 @@ blink_core_sources("layout") {
"ng/layout_ng_mixin.h",
"ng/layout_ng_progress.cc",
"ng/layout_ng_progress.h",
"ng/layout_ng_ruby_as_block.cc",
"ng/layout_ng_ruby_as_block.h",
"ng/layout_ng_table_caption.cc",
"ng/layout_ng_table_caption.h",
"ng/layout_ng_table_cell.cc",
......
......@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/core/layout/ng/layout_ng_flexible_box.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_grid.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_progress.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_ruby_as_block.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_table_caption.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_inside_list_marker.h"
......@@ -210,4 +211,12 @@ LayoutProgress* LayoutObjectFactory::CreateProgress(Node* node,
return CreateObject<LayoutProgress, LayoutNGProgress>(*node, style, legacy);
}
LayoutRubyAsBlock* LayoutObjectFactory::CreateRubyAsBlock(
Node* node,
const ComputedStyle& style,
LegacyLayout legacy) {
return CreateObject<LayoutRubyAsBlock, LayoutNGRubyAsBlock>(*node, style,
legacy);
}
} // namespace blink
......@@ -17,6 +17,7 @@ class LayoutBlockFlow;
class LayoutObject;
enum class LegacyLayout;
class LayoutProgress;
class LayoutRubyAsBlock;
class LayoutTableCaption;
class LayoutTableCell;
class LayoutText;
......@@ -67,6 +68,9 @@ class LayoutObjectFactory {
static LayoutProgress* CreateProgress(Node* node,
const ComputedStyle& style,
LegacyLayout legacy);
static LayoutRubyAsBlock* CreateRubyAsBlock(Node* node,
const ComputedStyle& style,
LegacyLayout legacy);
};
} // namespace blink
......
......@@ -77,7 +77,7 @@ class LayoutRubyAsInline final : public LayoutInline {
};
// <ruby> when used as 'display:block' or 'display:inline-block'
class LayoutRubyAsBlock final : public LayoutBlockFlow {
class LayoutRubyAsBlock : public LayoutBlockFlow {
public:
LayoutRubyAsBlock(Element*);
~LayoutRubyAsBlock() override;
......@@ -90,11 +90,11 @@ class LayoutRubyAsBlock final : public LayoutBlockFlow {
protected:
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
private:
bool IsOfType(LayoutObjectType type) const override {
return type == kLayoutObjectRuby || LayoutBlockFlow::IsOfType(type);
}
private:
bool CreatesAnonymousWrapper() const override { return true; }
void RemoveLeftoverAnonymousBlock(LayoutBlock*) override { NOTREACHED(); }
};
......
......@@ -341,6 +341,7 @@ void LayoutNGBlockFlowMixin<Base>::UpdateMargins() {
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutBlockFlow>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutProgress>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutRubyAsBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutTableCaption>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutTableCell>;
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_progress.h"
#include "third_party/blink/renderer/core/layout/layout_ruby.h"
#include "third_party/blink/renderer/core/layout/layout_table_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_mixin.h"
......@@ -96,6 +97,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutBlockFlow>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutProgress>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutRubyAsBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutTableCaption>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
......
......@@ -278,6 +278,7 @@ LayoutNGMixin<Base>::UpdateInFlowBlockLayout() {
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlockFlow>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutProgress>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutRubyAsBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutTableCaption>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutTableCell>;
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_progress.h"
#include "third_party/blink/renderer/core/layout/layout_ruby.h"
#include "third_party/blink/renderer/core/layout/layout_table_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
......@@ -48,6 +49,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutBlockFlow>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT LayoutNGMixin<LayoutProgress>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutRubyAsBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutTableCaption>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/ng/layout_ng_ruby_as_block.h"
namespace blink {
LayoutNGRubyAsBlock::LayoutNGRubyAsBlock(Element* element)
: LayoutNGBlockFlowMixin<LayoutRubyAsBlock>(element) {}
LayoutNGRubyAsBlock::~LayoutNGRubyAsBlock() = default;
void LayoutNGRubyAsBlock::UpdateBlockLayout(bool relayout_children) {
UpdateNGBlockLayout();
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LAYOUT_NG_RUBY_AS_BLOCK_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LAYOUT_NG_RUBY_AS_BLOCK_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_ruby.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow_mixin.h"
namespace blink {
// A NG version of LayoutRubyAsBlock.
// This adds anonymous block building to LayoutNGBlockFlow.
class CORE_EXPORT LayoutNGRubyAsBlock
: public LayoutNGBlockFlowMixin<LayoutRubyAsBlock> {
public:
explicit LayoutNGRubyAsBlock(Element*);
~LayoutNGRubyAsBlock() override;
const char* GetName() const override { return "LayoutNGRubyAsBlock"; }
void UpdateBlockLayout(bool relayout_children) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LAYOUT_NG_RUBY_AS_BLOCK_H_
......@@ -950,6 +950,10 @@
{
name: "LayoutNGLineCache",
},
{
name: "LayoutNGRuby",
depends_on: ["LayoutNG"],
},
{
name: "LayoutNGTable",
},
......
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