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 @@ ...@@ -5,23 +5,28 @@
#include "third_party/blink/renderer/core/html/html_ruby_element.h" #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/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/core/layout/layout_ruby.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink { namespace blink {
HTMLRubyElement::HTMLRubyElement(Document& document) HTMLRubyElement::HTMLRubyElement(Document& document)
: HTMLElement(html_names::kRubyTag, 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, LayoutObject* HTMLRubyElement::CreateLayoutObject(const ComputedStyle& style,
LegacyLayout legacy) { LegacyLayout legacy) {
if (style.Display() == EDisplay::kInline) { if (style.Display() == EDisplay::kInline)
UseCounter::Count(GetDocument(), WebFeature::kLegacyLayoutByRuby);
return new LayoutRubyAsInline(this); return new LayoutRubyAsInline(this);
} if (style.Display() == EDisplay::kBlock)
if (style.Display() == EDisplay::kBlock) { return LayoutObjectFactory::CreateRubyAsBlock(this, style, legacy);
UseCounter::Count(GetDocument(), WebFeature::kLegacyLayoutByRuby);
return new LayoutRubyAsBlock(this);
}
return LayoutObject::CreateObject(this, style, legacy); return LayoutObject::CreateObject(this, style, legacy);
} }
......
...@@ -17,7 +17,7 @@ class HTMLRubyElement final : public HTMLElement { ...@@ -17,7 +17,7 @@ class HTMLRubyElement final : public HTMLElement {
private: private:
LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override; LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override;
bool TypeShouldForceLegacyLayout() const final { return true; } bool TypeShouldForceLegacyLayout() const final;
}; };
} // namespace blink } // namespace blink
......
...@@ -402,6 +402,8 @@ blink_core_sources("layout") { ...@@ -402,6 +402,8 @@ blink_core_sources("layout") {
"ng/layout_ng_mixin.h", "ng/layout_ng_mixin.h",
"ng/layout_ng_progress.cc", "ng/layout_ng_progress.cc",
"ng/layout_ng_progress.h", "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.cc",
"ng/layout_ng_table_caption.h", "ng/layout_ng_table_caption.h",
"ng/layout_ng_table_cell.cc", "ng/layout_ng_table_cell.cc",
......
...@@ -27,6 +27,7 @@ ...@@ -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_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_grid.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_progress.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_caption.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_table_cell.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" #include "third_party/blink/renderer/core/layout/ng/list/layout_ng_inside_list_marker.h"
...@@ -210,4 +211,12 @@ LayoutProgress* LayoutObjectFactory::CreateProgress(Node* node, ...@@ -210,4 +211,12 @@ LayoutProgress* LayoutObjectFactory::CreateProgress(Node* node,
return CreateObject<LayoutProgress, LayoutNGProgress>(*node, style, legacy); 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 } // namespace blink
...@@ -17,6 +17,7 @@ class LayoutBlockFlow; ...@@ -17,6 +17,7 @@ class LayoutBlockFlow;
class LayoutObject; class LayoutObject;
enum class LegacyLayout; enum class LegacyLayout;
class LayoutProgress; class LayoutProgress;
class LayoutRubyAsBlock;
class LayoutTableCaption; class LayoutTableCaption;
class LayoutTableCell; class LayoutTableCell;
class LayoutText; class LayoutText;
...@@ -67,6 +68,9 @@ class LayoutObjectFactory { ...@@ -67,6 +68,9 @@ class LayoutObjectFactory {
static LayoutProgress* CreateProgress(Node* node, static LayoutProgress* CreateProgress(Node* node,
const ComputedStyle& style, const ComputedStyle& style,
LegacyLayout legacy); LegacyLayout legacy);
static LayoutRubyAsBlock* CreateRubyAsBlock(Node* node,
const ComputedStyle& style,
LegacyLayout legacy);
}; };
} // namespace blink } // namespace blink
......
...@@ -77,7 +77,7 @@ class LayoutRubyAsInline final : public LayoutInline { ...@@ -77,7 +77,7 @@ class LayoutRubyAsInline final : public LayoutInline {
}; };
// <ruby> when used as 'display:block' or 'display:inline-block' // <ruby> when used as 'display:block' or 'display:inline-block'
class LayoutRubyAsBlock final : public LayoutBlockFlow { class LayoutRubyAsBlock : public LayoutBlockFlow {
public: public:
LayoutRubyAsBlock(Element*); LayoutRubyAsBlock(Element*);
~LayoutRubyAsBlock() override; ~LayoutRubyAsBlock() override;
...@@ -90,11 +90,11 @@ class LayoutRubyAsBlock final : public LayoutBlockFlow { ...@@ -90,11 +90,11 @@ class LayoutRubyAsBlock final : public LayoutBlockFlow {
protected: protected:
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override; void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
private:
bool IsOfType(LayoutObjectType type) const override { bool IsOfType(LayoutObjectType type) const override {
return type == kLayoutObjectRuby || LayoutBlockFlow::IsOfType(type); return type == kLayoutObjectRuby || LayoutBlockFlow::IsOfType(type);
} }
private:
bool CreatesAnonymousWrapper() const override { return true; } bool CreatesAnonymousWrapper() const override { return true; }
void RemoveLeftoverAnonymousBlock(LayoutBlock*) override { NOTREACHED(); } void RemoveLeftoverAnonymousBlock(LayoutBlock*) override { NOTREACHED(); }
}; };
......
...@@ -341,6 +341,7 @@ void LayoutNGBlockFlowMixin<Base>::UpdateMargins() { ...@@ -341,6 +341,7 @@ void LayoutNGBlockFlowMixin<Base>::UpdateMargins() {
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutBlockFlow>; template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutBlockFlow>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutProgress>; 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<LayoutTableCaption>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutTableCell>; template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutTableCell>;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/layout/layout_block_flow.h" #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_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_progress.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_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h" #include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_mixin.h" #include "third_party/blink/renderer/core/layout/ng/layout_ng_mixin.h"
...@@ -96,6 +97,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT ...@@ -96,6 +97,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutBlockFlow>; LayoutNGBlockFlowMixin<LayoutBlockFlow>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutProgress>; LayoutNGBlockFlowMixin<LayoutProgress>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutRubyAsBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutTableCaption>; LayoutNGBlockFlowMixin<LayoutTableCaption>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
......
...@@ -278,6 +278,7 @@ LayoutNGMixin<Base>::UpdateInFlowBlockLayout() { ...@@ -278,6 +278,7 @@ LayoutNGMixin<Base>::UpdateInFlowBlockLayout() {
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>; template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlockFlow>; template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlockFlow>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutProgress>; 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<LayoutTableCaption>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutTableCell>; template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutTableCell>;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/core_export.h" #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_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_progress.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_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.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>; ...@@ -48,6 +49,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutBlockFlow>; LayoutNGMixin<LayoutBlockFlow>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT LayoutNGMixin<LayoutProgress>; 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 extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutTableCaption>; LayoutNGMixin<LayoutTableCaption>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT 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 @@ ...@@ -950,6 +950,10 @@
{ {
name: "LayoutNGLineCache", name: "LayoutNGLineCache",
}, },
{
name: "LayoutNGRuby",
depends_on: ["LayoutNG"],
},
{ {
name: "LayoutNGTable", 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