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 "ash/devtools/ui_element_delegate.h" |
| 8 #include "ash/devtools/view_element.h" |
| 9 #include "ash/devtools/widget_element.h" |
| 10 #include "ash/devtools/window_element.h" |
| 11 |
| 12 namespace ash { |
| 13 namespace devtools { |
| 14 |
| 15 int UIElement::GetNodeId() const { |
| 16 return node_id_; |
| 17 } |
| 18 |
| 19 void UIElement::SetNodeId(int node_id) { |
| 20 node_id_ = node_id; |
| 21 } |
| 22 |
| 23 UIElement* UIElement::GetParent() { |
| 24 return parent_; |
| 25 } |
| 26 |
| 27 void UIElement::SetParent(UIElement* parent) { |
| 28 parent_ = parent; |
| 29 } |
| 30 |
| 31 UIElementDelegate* UIElement::GetUIElementDelegate() { |
| 32 return ui_element_delegate_; |
| 33 } |
| 34 |
| 35 void UIElement::SetUIElementDelegate(UIElementDelegate* ui_element_delegate) { |
| 36 ui_element_delegate_ = ui_element_delegate; |
| 37 } |
| 38 |
| 39 UIElementType UIElement::GetType() const { |
| 40 return type_; |
| 41 } |
| 42 |
| 43 void UIElement::SetType(UIElementType type) { |
| 44 type_ = type; |
| 45 } |
| 46 |
| 47 std::vector<UIElement*>& UIElement::GetChildren() { |
| 48 return children_; |
| 49 } |
| 50 |
| 51 void UIElement::SetChildren(std::vector<UIElement*>& children) { |
| 52 children_ = children; |
| 53 } |
| 54 |
| 55 std::vector<UIElement*>::iterator UIElement::RemoveChildFromParent() { |
| 56 if (GetParent()) { |
| 57 std::vector<UIElement*>& siblings = GetParent()->GetChildren(); |
| 58 std::vector<UIElement*>::iterator object = std::find_if( |
| 59 siblings.begin(), siblings.end(), |
| 60 [&](UIElement* obj) { return obj->GetNodeId() == node_id_; }); |
| 61 if (object != siblings.end()) |
| 62 siblings.erase(object); |
| 63 return object; |
| 64 } |
| 65 return children_.end(); |
| 66 } |
| 67 |
| 68 UIElement::UIElement(UIElementType type, |
| 69 UIElementDelegate* ui_element_delegate, |
| 70 UIElement* parent) { |
| 71 type_ = type; |
| 72 ui_element_delegate_ = ui_element_delegate; |
| 73 parent_ = parent; |
| 74 } |
| 75 |
| 76 UIElement::~UIElement() { |
| 77 for (auto* child : children_) |
| 78 if (child) |
| 79 delete child; |
| 80 children_.clear(); |
| 81 } |
| 82 |
| 83 } // namespace devtools |
| 84 } // namespace ash |
OLD | NEW |