Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ash/devtools/ui_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "ash/devtools/ui_element_delegate.h"
7 #include "ash/devtools/view_element.h"
8 #include "ash/devtools/widget_element.h"
9 #include "ash/devtools/window_element.h"
10
11 namespace ash {
12 namespace devtools {
13
14 int UIElement::GetNodeId() const {
15 return node_id_;
16 }
17
18 void UIElement::SetNodeId(int node_id) {
19 node_id_ = node_id;
20 }
21
22 UIElement* UIElement::GetParent() {
23 return parent_;
24 }
25
26 void UIElement::SetParent(UIElement* parent) {
27 parent_ = parent;
28 }
29
30 UIElementDelegate* UIElement::GetUIElementDelegate() {
31 return ui_element_delegate_;
32 }
33
34 void UIElement::SetUIElementDelegate(UIElementDelegate* ui_element_delegate) {
35 ui_element_delegate_ = ui_element_delegate;
36 }
37
38 UIElementType UIElement::GetType() const {
39 return type_;
40 }
41
42 void UIElement::SetType(UIElementType type) {
43 type_ = type;
44 }
45
46 std::vector<UIElement*>& UIElement::GetChildren() {
47 return children_;
48 }
49
50 void UIElement::SetChildren(std::vector<UIElement*>& children) {
51 children_ = children;
52 }
53
54 std::vector<UIElement*>::iterator UIElement::RemoveChild() {
55 for (auto* child_element : children_)
56 if (child_element)
57 child_element->RemoveChild();
58
59 children_.clear();
60
61 // Delete child element from vector ui_element siblings.
62 if (GetParent()) {
63 std::vector<UIElement*>& siblings = GetParent()->GetChildren();
64 std::vector<UIElement*>::iterator object = std::find_if(
65 siblings.begin(), siblings.end(),
66 [&](UIElement* obj) { return obj->GetNodeId() == node_id_; });
67 if (object != siblings.end()) {
68 (*object)->Destroy();
69 siblings.erase(std::remove(siblings.begin(), siblings.end(), *object));
70 }
71 return object;
72 }
73 return children_.end();
74 }
75
76 UIElement::UIElement(UIElementType type,
77 UIElementDelegate* ui_element_delegate,
78 UIElement* parent) {
79 type_ = type;
80 ui_element_delegate_ = ui_element_delegate;
81 parent_ = parent;
82 }
83
84 UIElement::~UIElement() {
85 for (auto* child : children_)
86 if (child)
87 delete child;
88 children_.clear();
89 }
90
91 } // namespace devtools
92 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698