Index: ash/devtools/ui_element.cc |
diff --git a/ash/devtools/ui_element.cc b/ash/devtools/ui_element.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a6ded4a72f7b676fdc9b22751b3d5cb22238853a |
--- /dev/null |
+++ b/ash/devtools/ui_element.cc |
@@ -0,0 +1,92 @@ |
+// 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 "ash/devtools/ui_element.h" |
+#include "ash/devtools/ui_element_delegate.h" |
+#include "ash/devtools/view_element.h" |
+#include "ash/devtools/widget_element.h" |
+#include "ash/devtools/window_element.h" |
+ |
+namespace ash { |
+namespace devtools { |
+ |
+int UIElement::GetNodeId() const { |
+ return node_id_; |
+} |
+ |
+void UIElement::SetNodeId(int node_id) { |
+ node_id_ = node_id; |
+} |
+ |
+UIElement* UIElement::GetParent() { |
+ return parent_; |
+} |
+ |
+void UIElement::SetParent(UIElement* parent) { |
+ parent_ = parent; |
+} |
+ |
+UIElementDelegate* UIElement::GetUIElementDelegate() { |
+ return ui_element_delegate_; |
+} |
+ |
+void UIElement::SetUIElementDelegate(UIElementDelegate* ui_element_delegate) { |
+ ui_element_delegate_ = ui_element_delegate; |
+} |
+ |
+UIElementType UIElement::GetType() const { |
+ return type_; |
+} |
+ |
+void UIElement::SetType(UIElementType type) { |
+ type_ = type; |
+} |
+ |
+std::vector<UIElement*>& UIElement::GetChildren() { |
+ return children_; |
+} |
+ |
+void UIElement::SetChildren(std::vector<UIElement*>& children) { |
+ children_ = children; |
+} |
+ |
+std::vector<UIElement*>::iterator UIElement::RemoveChild() { |
+ for (auto* child_element : children_) |
+ if (child_element) |
+ child_element->RemoveChild(); |
+ |
+ children_.clear(); |
+ |
+ // Delete child element from vector ui_element siblings. |
+ if (GetParent()) { |
+ std::vector<UIElement*>& siblings = GetParent()->GetChildren(); |
+ std::vector<UIElement*>::iterator object = std::find_if( |
+ siblings.begin(), siblings.end(), |
+ [&](UIElement* obj) { return obj->GetNodeId() == node_id_; }); |
+ if (object != siblings.end()) { |
+ (*object)->Destroy(); |
+ siblings.erase(std::remove(siblings.begin(), siblings.end(), *object)); |
+ } |
+ return object; |
+ } |
+ return children_.end(); |
+} |
+ |
+UIElement::UIElement(UIElementType type, |
+ UIElementDelegate* ui_element_delegate, |
+ UIElement* parent) { |
+ type_ = type; |
+ ui_element_delegate_ = ui_element_delegate; |
+ parent_ = parent; |
+} |
+ |
+UIElement::~UIElement() { |
+ for (auto* child : children_) |
+ if (child) |
+ delete child; |
+ children_.clear(); |
+} |
+ |
+} // namespace devtools |
+} // namespace ash |