summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/layout_tree_rebuild_root.cc
blob: 8d1fd528a07337130ba8f682f18c7ed08a33d955 (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
// 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/css/layout_tree_rebuild_root.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"

namespace blink {

Element& LayoutTreeRebuildRoot::RootElement() const {
  Node* root_node = GetRootNode();
  DCHECK(root_node);
  // We need to start from the closest non-dirty ancestor which has a
  // LayoutObject to make WhitespaceAttacher work correctly because text node
  // siblings of nodes being re-attached needs to be traversed to re-evaluate
  // the need for a LayoutText. Single roots are typically dirty, but we need an
  // extra check for IsSingleRoot() because we mark nodes which have siblings
  // removed with MarkAncestorsWithChildNeedsReattachLayoutTree() in
  // StyleEngine::MarkForWhitespaceReattachment(). In that case we need to start
  // from the ancestor to traverse all whitespace siblings.
  if (IsSingleRoot() || root_node->NeedsReattachLayoutTree() ||
      !root_node->GetLayoutObject()) {
    do {
      root_node = root_node->GetReattachParent();
    } while (root_node && !root_node->GetLayoutObject());
  }
  if (!root_node || root_node->IsDocumentNode())
    return *GetRootNode()->GetDocument().documentElement();
  return ToElement(*root_node);
}

#if DCHECK_IS_ON()
ContainerNode* LayoutTreeRebuildRoot::Parent(const Node& node) const {
  return node.GetReattachParent();
}

bool LayoutTreeRebuildRoot::IsChildDirty(const ContainerNode& node) const {
  return node.ChildNeedsReattachLayoutTree();
}
#endif  // DCHECK_IS_ON()

bool LayoutTreeRebuildRoot::IsDirty(const Node& node) const {
  return node.NeedsReattachLayoutTree();
}

void LayoutTreeRebuildRoot::ClearChildDirtyForAncestors(
    ContainerNode& parent) const {
  for (ContainerNode* ancestor = &parent; ancestor;
       ancestor = ancestor->GetReattachParent()) {
    ancestor->ClearChildNeedsReattachLayoutTree();
    DCHECK(!ancestor->NeedsReattachLayoutTree());
  }
}

}  // namespace blink