Commit c7759b23 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

Centralize decision on whether to create an NG LayoutObject or not.

Introduces LayoutObjectFactory, which will be used more extensively in
follow-up CLs, so that nobody creates a LayoutBlockFlow on their own,
for instance.

Change-Id: Ib9124a6f02ee1e5f1213b1b61f18e0494d7bd268
Reviewed-on: https://chromium-review.googlesource.com/1095103
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566804}
parent 2263e0ab
......@@ -170,6 +170,8 @@ blink_core_sources("layout") {
"layout_object.h",
"layout_object_child_list.cc",
"layout_object_child_list.h",
"layout_object_factory.cc",
"layout_object_factory.h",
"layout_object_inlines.h",
"layout_paged_flow_thread.cc",
"layout_paged_flow_thread.h",
......
......@@ -45,6 +45,7 @@
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_multi_column_flow_thread.h"
#include "third_party/blink/renderer/core/layout/layout_multi_column_spanner_placeholder.h"
#include "third_party/blink/renderer/core/layout/layout_object_factory.h"
#include "third_party/blink/renderer/core/layout/layout_paged_flow_thread.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/line/glyph_overflow.h"
......@@ -276,9 +277,7 @@ LayoutBlockFlow* LayoutBlockFlow::CreateAnonymous(
Document* document,
scoped_refptr<ComputedStyle> style) {
LayoutBlockFlow* layout_block_flow =
RuntimeEnabledFeatures::LayoutNGEnabled() && !style->ForceLegacyLayout()
? new LayoutNGBlockFlow(nullptr)
: new LayoutBlockFlow(nullptr);
LayoutObjectFactory::CreateBlockFlow(*document, *style);
layout_block_flow->SetDocumentForAnonymous(document);
layout_block_flow->SetStyle(style);
return layout_block_flow;
......
......@@ -70,6 +70,7 @@
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/layout_list_item.h"
#include "third_party/blink/renderer/core/layout/layout_multi_column_spanner_placeholder.h"
#include "third_party/blink/renderer/core/layout/layout_object_factory.h"
#include "third_party/blink/renderer/core/layout/layout_scrollbar_part.h"
#include "third_party/blink/renderer/core/layout/layout_table_caption.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
......@@ -79,11 +80,6 @@
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_flexible_box.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_list_item.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_marker.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_result.h"
#include "third_party/blink/renderer/core/layout/ng/ng_unpositioned_float.h"
......@@ -116,21 +112,6 @@ namespace blink {
namespace {
inline bool ShouldUseNewLayout(const Element& element,
const ComputedStyle& style) {
if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return false;
const Document& document = element.GetDocument();
bool requires_ng_block_fragmentation =
document.Printing() ||
(document.GetLayoutView() &&
document.GetLayoutView()->StyleRef().IsOverflowPaged());
if (requires_ng_block_fragmentation &&
!RuntimeEnabledFeatures::LayoutNGBlockFragmentationEnabled())
return false;
return !style.ForceLegacyLayout();
}
template <typename Predicate>
LayoutObject* FindAncestorByPredicate(const LayoutObject* descendant,
LayoutObject::AncestorSkipInfo* skip_info,
......@@ -255,13 +236,9 @@ LayoutObject* LayoutObject::CreateObject(Element* element,
case EDisplay::kBlock:
case EDisplay::kFlowRoot:
case EDisplay::kInlineBlock:
if (ShouldUseNewLayout(*element, style))
return new LayoutNGBlockFlow(element);
return new LayoutBlockFlow(element);
return LayoutObjectFactory::CreateBlockFlow(*element, style);
case EDisplay::kListItem:
if (ShouldUseNewLayout(*element, style))
return new LayoutNGListItem(element);
return new LayoutListItem(element);
return LayoutObjectFactory::CreateListItem(*element, style);
case EDisplay::kTable:
case EDisplay::kInlineTable:
return new LayoutTable(element);
......@@ -275,23 +252,15 @@ LayoutObject* LayoutObject::CreateObject(Element* element,
case EDisplay::kTableColumn:
return new LayoutTableCol(element);
case EDisplay::kTableCell:
if (ShouldUseNewLayout(*element, style))
return new LayoutNGTableCell(element);
return new LayoutTableCell(element);
return LayoutObjectFactory::CreateTableCell(*element, style);
case EDisplay::kTableCaption:
if (ShouldUseNewLayout(*element, style))
return new LayoutNGTableCaption(element);
return new LayoutTableCaption(element);
return LayoutObjectFactory::CreateTableCaption(*element, style);
case EDisplay::kWebkitBox:
case EDisplay::kWebkitInlineBox:
return new LayoutDeprecatedFlexibleBox(*element);
case EDisplay::kFlex:
case EDisplay::kInlineFlex:
if (RuntimeEnabledFeatures::LayoutNGFlexBoxEnabled() &&
ShouldUseNewLayout(*element, style)) {
return new LayoutNGFlexibleBox(element);
}
return new LayoutFlexibleBox(element);
return LayoutObjectFactory::CreateFlexibleBox(*element, style);
case EDisplay::kGrid:
case EDisplay::kInlineGrid:
return new LayoutGrid(element);
......
// Copyright 2018 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/layout_object_factory.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/layout_flexible_box.h"
#include "third_party/blink/renderer/core/layout/layout_list_item.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_view.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_flexible_box.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_list_item.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
namespace {
inline bool ShouldUseNewLayout(Document& document, const ComputedStyle& style) {
if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return false;
bool requires_ng_block_fragmentation =
document.Printing() ||
(document.GetLayoutView() &&
document.GetLayoutView()->StyleRef().IsOverflowPaged());
if (requires_ng_block_fragmentation &&
!RuntimeEnabledFeatures::LayoutNGBlockFragmentationEnabled())
return false;
return !style.ForceLegacyLayout();
}
inline Element* GetElementForLayoutObject(Node& node) {
if (node.IsElementNode())
return &ToElement(node);
// If |node| is a Document, the layout object is going to be anonymous.
DCHECK(node.IsDocumentNode());
return nullptr;
}
} // anonymous namespace
LayoutBlockFlow* LayoutObjectFactory::CreateBlockFlow(
Node& node,
const ComputedStyle& style) {
Element* element = GetElementForLayoutObject(node);
if (ShouldUseNewLayout(node.GetDocument(), style))
return new LayoutNGBlockFlow(element);
return new LayoutBlockFlow(element);
}
LayoutBlock* LayoutObjectFactory::CreateFlexibleBox(
Node& node,
const ComputedStyle& style) {
Element* element = GetElementForLayoutObject(node);
if (RuntimeEnabledFeatures::LayoutNGFlexBoxEnabled() &&
ShouldUseNewLayout(node.GetDocument(), style))
return new LayoutNGFlexibleBox(element);
return new LayoutFlexibleBox(element);
}
LayoutBlockFlow* LayoutObjectFactory::CreateListItem(
Node& node,
const ComputedStyle& style) {
Element* element = GetElementForLayoutObject(node);
if (ShouldUseNewLayout(node.GetDocument(), style))
return new LayoutNGListItem(element);
return new LayoutListItem(element);
}
LayoutTableCaption* LayoutObjectFactory::CreateTableCaption(
Node& node,
const ComputedStyle& style) {
Element* element = GetElementForLayoutObject(node);
if (ShouldUseNewLayout(node.GetDocument(), style))
return new LayoutNGTableCaption(element);
return new LayoutTableCaption(element);
}
LayoutTableCell* LayoutObjectFactory::CreateTableCell(
Node& node,
const ComputedStyle& style) {
Element* element = GetElementForLayoutObject(node);
if (ShouldUseNewLayout(node.GetDocument(), style))
return new LayoutNGTableCell(element);
return new LayoutTableCell(element);
}
} // namespace blink
// Copyright 2018 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_LAYOUT_OBJECT_FACTORY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_OBJECT_FACTORY_H_
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
class LayoutBlock;
class LayoutBlockFlow;
class LayoutTableCaption;
class LayoutTableCell;
// Helper class for creation of certain LayoutObject-derived objects that may
// need to be of different types, depending on whether or not LayoutNG is to be
// used in the given context.
class LayoutObjectFactory {
STATIC_ONLY(LayoutObjectFactory);
public:
// The following methods will create and return some LayoutObject-derived
// object. If |node| is of type Element, it will be associated with the new
// LayoutObject. Otherwise it will be assumed to be a Document node, in which
// case the LayoutObject created will be anonymous. The |style| reference
// passed will only be used to determine which object type to create.
static LayoutBlockFlow* CreateBlockFlow(Node&, const ComputedStyle&);
static LayoutBlock* CreateFlexibleBox(Node&, const ComputedStyle&);
static LayoutBlockFlow* CreateListItem(Node&, const ComputedStyle&);
static LayoutTableCaption* CreateTableCaption(Node&, const ComputedStyle&);
static LayoutTableCell* CreateTableCell(Node&, const ComputedStyle&);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_OBJECT_FACTORY_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