Chromium Code Reviews| 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() const { | |
| 24 return parent_; | |
| 25 } | |
| 26 | |
| 27 UIElementDelegate* UIElement::delegate() const { | |
| 28 return ui_element_delegate_; | |
| 29 } | |
| 30 | |
| 31 UIElementType UIElement::GetType() const { | |
| 32 return type_; | |
| 33 } | |
| 34 | |
| 35 std::string UIElement::GetTypeString() const { | |
| 36 switch (type_) { | |
| 37 case UIElementType::WINDOW: | |
| 38 return "Window"; | |
| 39 case UIElementType::WIDGET: | |
| 40 return "Widget"; | |
| 41 case UIElementType::VIEW: | |
| 42 return "View"; | |
| 43 default: | |
| 44 DCHECK(false); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 const std::vector<UIElement*>& UIElement::GetChildren() const { | |
| 49 return children_; | |
| 50 } | |
| 51 | |
| 52 void UIElement::AddChild(UIElement* child, UIElement* before) { | |
| 53 if (before) { | |
| 54 auto iter = std::find(children_.begin(), children_.end(), before); | |
| 55 children_.insert(iter, child); | |
| 56 } else | |
| 57 children_.push_back(child); | |
|
sadrul
2017/05/05 20:19:33
{} here too
thanhph
2017/05/08 17:03:30
Done.
| |
| 58 } | |
| 59 | |
| 60 void UIElement::RemoveChild(UIElement* child) { | |
| 61 auto iter = std::find(children_.begin(), children_.end(), child); | |
| 62 if (iter != children_.end()) | |
| 63 children_.erase(iter); | |
| 64 } | |
| 65 | |
| 66 UIElement* UIElement::ReorderChild(UIElement* child, int new_index) { | |
| 67 auto iter = children_.begin(); | |
| 68 while (new_index-- > 0) | |
| 69 iter++; | |
| 70 children_.insert(iter, child); | |
| 71 if (iter != children_.begin()) | |
| 72 return *std::prev(iter); | |
| 73 return nullptr; | |
|
sadrul
2017/05/05 20:19:33
I think this can be simpler:
new_index = std::m
thanhph
2017/05/08 17:03:30
That's correct. I removed the return part.
| |
| 74 } | |
| 75 | |
| 76 UIElement::UIElement(const UIElementType type, | |
| 77 UIElementDelegate* ui_element_delegate, | |
| 78 UIElement* parent) | |
| 79 : type_(type), parent_(parent), ui_element_delegate_(ui_element_delegate) {} | |
| 80 | |
| 81 UIElement::~UIElement() { | |
| 82 for (auto* child : children_) | |
| 83 if (child) | |
| 84 delete child; | |
| 85 children_.clear(); | |
| 86 } | |
| 87 | |
| 88 } // namespace devtools | |
| 89 } // namespace ash | |
| OLD | NEW |