Commit 8e7940f0 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

RubyNG: Introduce LayoutNGRubyRun

- Make LayoutNGMixin<LayoutRubyRun> a friend of LayoutRubyRun because
  LayoutNGMixin<LayoutRubyRun> accesses some private functions.

- Add an Element* argument to LayoutRubyRun.
  LayoutNGMixin assumes that the constructor of its base class has an
  Element* argument.

- The layout behavior of LayoutRubyRun is not implemented yet in
  LayoutNGRubyRun.

This CL has no behavior changes because changes are behind a
runtime flag.

Bug: 1069817
Change-Id: I3b3d99e1d0b8648305ecea1b07460a893ee9e5ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149737
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759264}
parent 9991f381
...@@ -404,6 +404,8 @@ blink_core_sources("layout") { ...@@ -404,6 +404,8 @@ blink_core_sources("layout") {
"ng/layout_ng_progress.h", "ng/layout_ng_progress.h",
"ng/layout_ng_ruby_as_block.cc", "ng/layout_ng_ruby_as_block.cc",
"ng/layout_ng_ruby_as_block.h", "ng/layout_ng_ruby_as_block.h",
"ng/layout_ng_ruby_run.cc",
"ng/layout_ng_ruby_run.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",
......
...@@ -94,7 +94,7 @@ void LayoutRubyAsInline::AddChild(LayoutObject* child, ...@@ -94,7 +94,7 @@ void LayoutRubyAsInline::AddChild(LayoutObject* child,
// (The LayoutRubyRun object will handle the details) // (The LayoutRubyRun object will handle the details)
LayoutRubyRun* last_run = LastRubyRun(this); LayoutRubyRun* last_run = LastRubyRun(this);
if (!last_run || last_run->HasRubyText()) { if (!last_run || last_run->HasRubyText()) {
last_run = LayoutRubyRun::StaticCreateRubyRun(this); last_run = LayoutRubyRun::StaticCreateRubyRun(this, *ContainingBlock());
LayoutInline::AddChild(last_run, before_child); LayoutInline::AddChild(last_run, before_child);
} }
last_run->AddChild(child); last_run->AddChild(child);
...@@ -159,7 +159,7 @@ void LayoutRubyAsBlock::AddChild(LayoutObject* child, ...@@ -159,7 +159,7 @@ void LayoutRubyAsBlock::AddChild(LayoutObject* child,
// (The LayoutRubyRun object will handle the details) // (The LayoutRubyRun object will handle the details)
LayoutRubyRun* last_run = LastRubyRun(this); LayoutRubyRun* last_run = LastRubyRun(this);
if (!last_run || last_run->HasRubyText()) { if (!last_run || last_run->HasRubyText()) {
last_run = LayoutRubyRun::StaticCreateRubyRun(this); last_run = LayoutRubyRun::StaticCreateRubyRun(this, *this);
LayoutBlockFlow::AddChild(last_run, before_child); LayoutBlockFlow::AddChild(last_run, before_child);
} }
last_run->AddChild(child); last_run->AddChild(child);
......
...@@ -33,10 +33,12 @@ ...@@ -33,10 +33,12 @@
#include "third_party/blink/renderer/core/layout/layout_ruby_base.h" #include "third_party/blink/renderer/core/layout/layout_ruby_base.h"
#include "third_party/blink/renderer/core/layout/layout_ruby_text.h" #include "third_party/blink/renderer/core/layout/layout_ruby_text.h"
#include "third_party/blink/renderer/core/layout/layout_text.h" #include "third_party/blink/renderer/core/layout/layout_text.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_ruby_run.h"
namespace blink { namespace blink {
LayoutRubyRun::LayoutRubyRun() : LayoutBlockFlow(nullptr) { LayoutRubyRun::LayoutRubyRun(Element* element) : LayoutBlockFlow(nullptr) {
DCHECK(!element);
SetInline(true); SetInline(true);
SetIsAtomicInlineLevel(true); SetIsAtomicInlineLevel(true);
} }
...@@ -103,7 +105,7 @@ void LayoutRubyRun::AddChild(LayoutObject* child, LayoutObject* before_child) { ...@@ -103,7 +105,7 @@ void LayoutRubyRun::AddChild(LayoutObject* child, LayoutObject* before_child) {
DCHECK_EQ(before_child->Parent(), this); DCHECK_EQ(before_child->Parent(), this);
LayoutObject* ruby = Parent(); LayoutObject* ruby = Parent();
DCHECK(ruby->IsRuby()); DCHECK(ruby->IsRuby());
LayoutBlock* new_run = StaticCreateRubyRun(ruby); LayoutBlock* new_run = StaticCreateRubyRun(ruby, *ContainingBlock());
ruby->AddChild(new_run, NextSibling()); ruby->AddChild(new_run, NextSibling());
// Add the new ruby text and move the old one to the new run // Add the new ruby text and move the old one to the new run
// Note: Doing it in this order and not using LayoutRubyRun's methods, // Note: Doing it in this order and not using LayoutRubyRun's methods,
...@@ -117,7 +119,7 @@ void LayoutRubyRun::AddChild(LayoutObject* child, LayoutObject* before_child) { ...@@ -117,7 +119,7 @@ void LayoutRubyRun::AddChild(LayoutObject* child, LayoutObject* before_child) {
// In this case we need insert a new run before the current one and split // In this case we need insert a new run before the current one and split
// the base. // the base.
LayoutObject* ruby = Parent(); LayoutObject* ruby = Parent();
LayoutRubyRun* new_run = StaticCreateRubyRun(ruby); LayoutRubyRun* new_run = StaticCreateRubyRun(ruby, *ContainingBlock());
ruby->AddChild(new_run, this); ruby->AddChild(new_run, this);
new_run->AddChild(child); new_run->AddChild(child);
...@@ -192,10 +194,17 @@ LayoutRubyBase* LayoutRubyRun::CreateRubyBase() const { ...@@ -192,10 +194,17 @@ LayoutRubyBase* LayoutRubyRun::CreateRubyBase() const {
} }
LayoutRubyRun* LayoutRubyRun::StaticCreateRubyRun( LayoutRubyRun* LayoutRubyRun::StaticCreateRubyRun(
const LayoutObject* parent_ruby) { const LayoutObject* parent_ruby,
const LayoutBlock& containing_block) {
DCHECK(parent_ruby); DCHECK(parent_ruby);
DCHECK(parent_ruby->IsRuby()); DCHECK(parent_ruby->IsRuby());
LayoutRubyRun* rr = new LayoutRubyRun(); LayoutRubyRun* rr;
if (RuntimeEnabledFeatures::LayoutNGRubyEnabled() &&
containing_block.IsLayoutNGObject()) {
rr = new LayoutNGRubyRun();
} else {
rr = new LayoutRubyRun(nullptr);
}
rr->SetDocumentForAnonymous(&parent_ruby->GetDocument()); rr->SetDocumentForAnonymous(&parent_ruby->GetDocument());
scoped_refptr<ComputedStyle> new_style = scoped_refptr<ComputedStyle> new_style =
ComputedStyle::CreateAnonymousStyleWithDisplay(parent_ruby->StyleRef(), ComputedStyle::CreateAnonymousStyleWithDisplay(parent_ruby->StyleRef(),
......
...@@ -38,12 +38,14 @@ namespace blink { ...@@ -38,12 +38,14 @@ namespace blink {
class LayoutRubyBase; class LayoutRubyBase;
class LayoutRubyText; class LayoutRubyText;
template <typename Base>
class LayoutNGMixin;
// LayoutRubyRun are 'inline-block/table' like objects,and wrap a single pairing // LayoutRubyRun are 'inline-block/table' like objects,and wrap a single pairing
// of a ruby base with its ruby text(s). // of a ruby base with its ruby text(s).
// See LayoutRuby.h for further comments on the structure // See LayoutRuby.h for further comments on the structure
class LayoutRubyRun final : public LayoutBlockFlow { class LayoutRubyRun : public LayoutBlockFlow {
public: public:
~LayoutRubyRun() override; ~LayoutRubyRun() override;
...@@ -69,7 +71,9 @@ class LayoutRubyRun final : public LayoutBlockFlow { ...@@ -69,7 +71,9 @@ class LayoutRubyRun final : public LayoutBlockFlow {
int& start_overhang, int& start_overhang,
int& end_overhang) const; int& end_overhang) const;
static LayoutRubyRun* StaticCreateRubyRun(const LayoutObject* parent_ruby); static LayoutRubyRun* StaticCreateRubyRun(
const LayoutObject* parent_ruby,
const LayoutBlock& containing_block);
bool CanBreakBefore(const LazyLineBreakIterator&) const; bool CanBreakBefore(const LazyLineBreakIterator&) const;
...@@ -79,13 +83,16 @@ class LayoutRubyRun final : public LayoutBlockFlow { ...@@ -79,13 +83,16 @@ class LayoutRubyRun final : public LayoutBlockFlow {
LayoutRubyBase* CreateRubyBase() const; LayoutRubyBase* CreateRubyBase() const;
private: private:
LayoutRubyRun(); // The argument must be nullptr.
explicit LayoutRubyRun(Element*);
bool IsOfType(LayoutObjectType type) const override { bool IsOfType(LayoutObjectType type) const override {
return type == kLayoutObjectRubyRun || LayoutBlockFlow::IsOfType(type); return type == kLayoutObjectRubyRun || LayoutBlockFlow::IsOfType(type);
} }
bool CreatesAnonymousWrapper() const override { return true; } bool CreatesAnonymousWrapper() const override { return true; }
void RemoveLeftoverAnonymousBlock(LayoutBlock*) override {} void RemoveLeftoverAnonymousBlock(LayoutBlock*) override {}
friend class LayoutNGMixin<LayoutRubyRun>;
}; };
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutRubyRun, IsRubyRun()); DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutRubyRun, IsRubyRun());
......
...@@ -342,6 +342,7 @@ void LayoutNGBlockFlowMixin<Base>::UpdateMargins() { ...@@ -342,6 +342,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<LayoutRubyAsBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGBlockFlowMixin<LayoutRubyRun>;
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>;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#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_ruby.h"
#include "third_party/blink/renderer/core/layout/layout_ruby_run.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"
...@@ -99,6 +100,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT ...@@ -99,6 +100,8 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutProgress>; LayoutNGBlockFlowMixin<LayoutProgress>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutRubyAsBlock>; LayoutNGBlockFlowMixin<LayoutRubyAsBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGBlockFlowMixin<LayoutRubyRun>;
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
......
...@@ -279,6 +279,7 @@ template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutBlock>; ...@@ -279,6 +279,7 @@ 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<LayoutRubyAsBlock>;
template class CORE_TEMPLATE_EXPORT LayoutNGMixin<LayoutRubyRun>;
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>;
......
...@@ -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_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_ruby.h"
#include "third_party/blink/renderer/core/layout/layout_ruby_run.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"
...@@ -51,6 +52,7 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT ...@@ -51,6 +52,7 @@ extern template class CORE_EXTERN_TEMPLATE_EXPORT
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 extern template class CORE_EXTERN_TEMPLATE_EXPORT
LayoutNGMixin<LayoutRubyAsBlock>; LayoutNGMixin<LayoutRubyAsBlock>;
extern template class CORE_EXTERN_TEMPLATE_EXPORT LayoutNGMixin<LayoutRubyRun>;
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_run.h"
namespace blink {
LayoutNGRubyRun::LayoutNGRubyRun()
: LayoutNGBlockFlowMixin<LayoutRubyRun>(nullptr) {}
LayoutNGRubyRun::~LayoutNGRubyRun() = default;
void LayoutNGRubyRun::UpdateBlockLayout(bool relayout_children) {
// TODO(crbug.com/1069817): Implement ruby-specific layout.
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_RUN_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LAYOUT_NG_RUBY_RUN_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_ruby_run.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow_mixin.h"
namespace blink {
// A LayoutNG version of LayoutRubyRun.
class CORE_EXPORT LayoutNGRubyRun final
: public LayoutNGBlockFlowMixin<LayoutRubyRun> {
public:
explicit LayoutNGRubyRun();
~LayoutNGRubyRun() override;
const char* GetName() const override { return "LayoutNGRubyRun"; }
void UpdateBlockLayout(bool relayout_children) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_LAYOUT_NG_RUBY_RUN_H_
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