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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// 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 "components/ui_devtools/ui_element.h"
#include <algorithm>
#include "base/check_op.h"
#include "base/notreached.h"
#include "components/ui_devtools/Protocol.h"
#include "components/ui_devtools/ui_element_delegate.h"
namespace ui_devtools {
namespace {
static int node_ids = 0;
} // namespace
UIElement::ClassProperties::ClassProperties(
std::string class_name,
std::vector<UIElement::UIProperty> properties)
: class_name_(class_name), properties_(properties) {}
UIElement::ClassProperties::ClassProperties(
const UIElement::ClassProperties& other) = default;
UIElement::ClassProperties::~ClassProperties() = default;
UIElement::Source::Source(std::string path, int line)
: path_(path), line_(line) {}
// static
void UIElement::ResetNodeId() {
node_ids = 0;
}
UIElement::~UIElement() {
if (owns_children_) {
for (auto* child : children_)
delete child;
}
children_.clear();
}
std::string UIElement::GetTypeName() const {
switch (type_) {
case UIElementType::ROOT:
return "Root";
case UIElementType::WINDOW:
return "Window";
case UIElementType::WIDGET:
return "Widget";
case UIElementType::VIEW:
return "View";
case UIElementType::FRAMESINK:
return "FrameSink";
case UIElementType::SURFACE:
return "Surface";
}
NOTREACHED();
return std::string();
}
void UIElement::AddChild(UIElement* child, UIElement* before) {
if (before) {
auto iter = std::find(children_.begin(), children_.end(), before);
DCHECK(iter != children_.end());
children_.insert(iter, child);
} else {
children_.push_back(child);
}
delegate_->OnUIElementAdded(this, child);
}
void UIElement::AddOrderedChild(UIElement* child,
ElementCompare compare,
bool notify_delegate) {
auto iter =
std::lower_bound(children_.begin(), children_.end(), child, compare);
children_.insert(iter, child);
if (notify_delegate)
delegate_->OnUIElementAdded(this, child);
}
void UIElement::ClearChildren() {
children_.clear();
}
void UIElement::RemoveChild(UIElement* child, bool notify_delegate) {
if (notify_delegate)
delegate_->OnUIElementRemoved(child);
auto iter = std::find(children_.begin(), children_.end(), child);
DCHECK(iter != children_.end());
children_.erase(iter);
}
void UIElement::ReorderChild(UIElement* child, int index) {
auto i = std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
DCHECK_GE(index, 0);
DCHECK_LT(static_cast<size_t>(index), children_.size());
// If |child| is already at the desired position, there's nothing to do.
const auto pos = std::next(children_.begin(), index);
if (i == pos)
return;
// Rotate |child| to be at the desired position.
if (pos < i)
std::rotate(pos, i, std::next(i));
else
std::rotate(i, std::next(i), std::next(pos));
delegate()->OnUIElementReordered(child->parent(), child);
}
template <class T>
int UIElement::FindUIElementIdForBackendElement(T* element) const {
NOTREACHED();
return 0;
}
std::vector<UIElement::ClassProperties>
UIElement::GetCustomPropertiesForMatchedStyle() const {
return {};
}
UIElement::UIElement(const UIElementType type,
UIElementDelegate* delegate,
UIElement* parent)
: node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) {
delegate_->OnUIElementAdded(nullptr, this);
}
bool UIElement::SetPropertiesFromString(const std::string& text) {
NOTREACHED();
return false;
}
void UIElement::AddSource(std::string path, int line) {
sources_.emplace_back(path, line);
}
std::vector<UIElement::Source> UIElement::GetSources() {
if (sources_.empty())
InitSources();
return sources_;
}
} // namespace ui_devtools
|