summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/legacy_layout_tree_walking.cc
blob: 88ccb44c29ff15666022763e0fd6f2783dffdbd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017 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/legacy_layout_tree_walking.h"

#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"

namespace blink {

// We still have the legacy layout tree structure, which means that a multicol
// container LayoutBlockFlow will consist of a LayoutFlowThread child, followed
// by zero or more siblings of type LayoutMultiColumnSet and/or
// LayoutMultiColumnSpannerPlaceholder. NG needs to skip these special
// objects. The actual content is inside the flow thread.

LayoutObject* GetLayoutObjectForFirstChildNode(LayoutBlock* parent) {
  LayoutObject* child = parent->FirstChild();
  if (!child)
    return nullptr;
  if (child->IsLayoutFlowThread())
    return ToLayoutBlockFlow(child)->FirstChild();
  return child;
}

LayoutObject* GetLayoutObjectForParentNode(LayoutObject* object) {
  // First check that we're not walking where we shouldn't be walking.
  DCHECK(!object->IsLayoutFlowThread());
  DCHECK(!object->IsLayoutMultiColumnSet());
  DCHECK(!object->IsLayoutMultiColumnSpannerPlaceholder());

  LayoutObject* parent = object->Parent();
  if (!parent)
    return nullptr;
  if (parent->IsLayoutFlowThread())
    return parent->Parent();
  return parent;
}

bool AreNGBlockFlowChildrenInline(const LayoutBlock* block) {
  if (block->ChildrenInline())
    return true;
  if (const auto* first_child = block->FirstChild()) {
    if (first_child->IsLayoutFlowThread())
      return first_child->ChildrenInline();
  }
  return false;
}

bool IsManagedByLayoutNG(const LayoutObject& object) {
  if (!object.IsLayoutNGMixin() && !object.IsLayoutNGFlexibleBox())
    return false;
  const auto* containing_block = object.ContainingBlock();
  if (!containing_block)
    return false;
  return IsLayoutNGContainingBlock(containing_block);
}

bool IsLayoutNGContainingBlock(const LayoutBlock* containing_block) {
  if (containing_block->IsLayoutFlowThread())
    containing_block = containing_block->ContainingBlock();
  return containing_block && (containing_block->IsLayoutNGMixin() ||
                              containing_block->IsLayoutNGFlexibleBox());
}

}  // namespace blink