OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/devtools/ui_element.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "ash/devtools/ui_element_delegate.h" | |
10 #include "ash/devtools/view_element.h" | |
11 #include "ash/devtools/widget_element.h" | |
12 #include "ash/devtools/window_element.h" | |
13 | |
14 namespace ash { | |
15 namespace devtools { | |
16 namespace { | |
17 | |
18 static int node_ids = 0; | |
19 | |
20 } // namespace | |
21 | |
22 void UIElement::SetNodeId(int node_id) { | |
23 node_id_ = node_id; | |
24 } | |
25 | |
26 std::string UIElement::GetTypeName() const { | |
27 switch (type_) { | |
28 case UIElementType::WINDOW: | |
29 return "Window"; | |
30 case UIElementType::WIDGET: | |
31 return "Widget"; | |
32 case UIElementType::VIEW: | |
33 return "View"; | |
34 default: | |
35 DCHECK(false); | |
36 } | |
37 } | |
38 | |
39 void UIElement::AddChild(UIElement* child, UIElement* before) { | |
40 if (child->type() == UIElementType::WINDOW && | |
41 delegate_->IsHighlightingWindow( | |
42 UIElement::GetBackingElement<aura::Window, WindowElement>(child))) { | |
43 child->Destroy(); | |
44 return; | |
45 } | |
46 if (before) { | |
47 auto iter = std::find(children_.begin(), children_.end(), before); | |
sadrul
2017/05/09 04:58:06
Can you add a DCHECK(iter != children_.end()) here
thanhph
2017/05/09 20:52:46
Done.
| |
48 children_.insert(iter, child); | |
49 } else { | |
50 children_.push_back(child); | |
51 } | |
52 delegate_->OnUIElementAdded(this, child); | |
53 } | |
54 | |
55 void UIElement::RemoveChild(UIElement* child) { | |
56 auto iter = std::find(children_.begin(), children_.end(), child); | |
57 if (iter != children_.end()) | |
58 children_.erase(iter); | |
59 } | |
sadrul
2017/05/09 04:58:06
You should call delegate_->OnUIElementRemoved(chil
thanhph
2017/05/09 20:52:46
Done. To get this to work, I need UIElement::Remov
| |
60 | |
61 void UIElement::ReorderChild(UIElement* child, int new_index) { | |
62 new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index)); | |
63 auto iter = children_.begin() + new_index; | |
64 children_.insert(iter, child); | |
sadrul
2017/05/09 04:58:06
delegate_->OnUIElementReordered(child, new_index)
thanhph
2017/05/09 20:52:46
Done, this interfaces instead takes
delegate()->O
| |
65 } | |
66 | |
67 UIElement::UIElement(const UIElementType type, | |
68 UIElementDelegate* delegate, | |
69 UIElement* parent) | |
70 : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) { | |
71 delegate_->AddNodeIdMap(this); | |
72 } | |
73 | |
74 UIElement::~UIElement() { | |
75 for (auto* child : children_) { | |
76 if (child) | |
77 delete child; | |
78 } | |
79 children_.clear(); | |
80 } | |
81 | |
82 } // namespace devtools | |
83 } // namespace ash | |
OLD | NEW |