File: find_cc_layer.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (131 lines) | stat: -rw-r--r-- 4,634 bytes parent folder | download | duplicates (9)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/platform/testing/find_cc_layer.h"

#include "cc/layers/layer.h"
#include "cc/layers/scrollbar_layer_base.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/property_tree.h"
#include "cc/trees/scroll_node.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace blink {

Vector<cc::Layer*> CcLayersByName(cc::Layer* root, const String& name_regex) {
  Vector<cc::Layer*> layers;
  ::testing::Matcher<std::string> matcher(
      ::testing::ContainsRegex(name_regex.Utf8()));
  for (auto& layer : root->children()) {
    if (matcher.Matches(layer->DebugName()))
      layers.push_back(layer.get());
  }
  return layers;
}

Vector<const cc::Layer*> CcLayersByName(const cc::Layer* root,
                                        const String& name_regex) {
  Vector<cc::Layer*> non_const_result =
      CcLayersByName(const_cast<cc::Layer*>(root), name_regex);
  Vector<const cc::Layer*> result(non_const_result.size());
  auto it = non_const_result.begin();
  auto end = non_const_result.end();
  for (unsigned i = 0; it != end; ++it, ++i)
    result[i] = *it;
  return result;
}

Vector<cc::Layer*> CcLayersByDOMElementId(cc::Layer* root,
                                          const String& dom_id) {
  return CcLayersByName(root, String("id='") + dom_id + "'");
}

Vector<const cc::Layer*> CcLayersByDOMElementId(const cc::Layer* root,
                                                const String& dom_id) {
  Vector<cc::Layer*> non_const_result =
      CcLayersByDOMElementId(const_cast<cc::Layer*>(root), dom_id);
  Vector<const cc::Layer*> result(non_const_result.size());
  auto it = non_const_result.begin();
  auto end = non_const_result.end();
  for (unsigned i = 0; it != end; ++it, ++i)
    result[i] = *it;
  return result;
}

cc::Layer* CcLayerByCcElementId(cc::Layer* root,
                                const CompositorElementId& element_id) {
  return root->layer_tree_host()->LayerByElementId(element_id);
}

const cc::Layer* CcLayerByCcElementId(const cc::Layer* root,
                                      const CompositorElementId& element_id) {
  return CcLayerByCcElementId(const_cast<cc::Layer*>(root), element_id);
}

cc::Layer* CcLayerByOwnerNodeId(cc::Layer* root, DOMNodeId id) {
  for (auto& layer : root->children()) {
    if (layer->debug_info() && layer->debug_info()->owner_node_id == id) {
      return layer.get();
    }
  }
  return nullptr;
}

const cc::Layer* CcLayerByOwnerNodeId(const cc::Layer* root, DOMNodeId id) {
  return CcLayerByOwnerNodeId(const_cast<cc::Layer*>(root), id);
}

cc::Layer* ScrollingContentsCcLayerByScrollElementId(
    cc::Layer* root,
    const CompositorElementId& scroll_element_id) {
  const auto& scroll_tree =
      root->layer_tree_host()->property_trees()->scroll_tree();
  for (auto& layer : root->children()) {
    const auto* scroll_node = scroll_tree.Node(layer->scroll_tree_index());
    if (scroll_node && scroll_node->element_id == scroll_element_id &&
        scroll_node->transform_id == layer->transform_tree_index())
      return layer.get();
  }
  return nullptr;
}

const cc::Layer* ScrollingContentsCcLayerByScrollElementId(
    const cc::Layer* root,
    const CompositorElementId& scroll_element_id) {
  return ScrollingContentsCcLayerByScrollElementId(const_cast<cc::Layer*>(root),
                                                   scroll_element_id);
}

cc::ScrollbarLayerBase* ScrollbarLayerForScrollNode(
    cc::Layer* root,
    cc::ScrollNode* scroll_node,
    cc::ScrollbarOrientation orientation) {
  if (!scroll_node)
    return nullptr;
  for (auto& layer : root->children()) {
    if (!layer->IsScrollbarLayerForTesting())
      continue;
    auto* scrollbar_layer = static_cast<cc::ScrollbarLayerBase*>(layer.get());
    if (scrollbar_layer->scroll_element_id() == scroll_node->element_id &&
        scrollbar_layer->orientation() == orientation)
      return scrollbar_layer;
  }
  return nullptr;
}

const cc::ScrollbarLayerBase* ScrollbarLayerForScrollNode(
    const cc::Layer* root,
    const cc::ScrollNode* scroll_node,
    cc::ScrollbarOrientation orientation) {
  return ScrollbarLayerForScrollNode(const_cast<cc::Layer*>(root),
                                     const_cast<cc::ScrollNode*>(scroll_node),
                                     orientation);
}

}  // namespace blink