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..1fdf66c4b2da3f8943d1949d8626b1be1e305686 |
--- /dev/null |
+++ b/ash/devtools/ui_element.cc |
@@ -0,0 +1,83 @@ |
+// 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 <algorithm> |
+ |
+#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 { |
+namespace { |
+ |
+static int node_ids = 0; |
+ |
+} // namespace |
+ |
+void UIElement::SetNodeId(int node_id) { |
+ node_id_ = node_id; |
+} |
+ |
+std::string UIElement::GetTypeName() const { |
+ switch (type_) { |
+ case UIElementType::WINDOW: |
+ return "Window"; |
+ case UIElementType::WIDGET: |
+ return "Widget"; |
+ case UIElementType::VIEW: |
+ return "View"; |
+ default: |
+ DCHECK(false); |
+ } |
+} |
+ |
+void UIElement::AddChild(UIElement* child, UIElement* before) { |
+ if (child->type() == UIElementType::WINDOW && |
+ delegate_->IsHighlightingWindow( |
+ UIElement::GetBackingElement<aura::Window, WindowElement>(child))) { |
+ child->Destroy(); |
+ return; |
+ } |
+ if (before) { |
+ 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.
|
+ children_.insert(iter, child); |
+ } else { |
+ children_.push_back(child); |
+ } |
+ delegate_->OnUIElementAdded(this, child); |
+} |
+ |
+void UIElement::RemoveChild(UIElement* child) { |
+ auto iter = std::find(children_.begin(), children_.end(), child); |
+ if (iter != children_.end()) |
+ children_.erase(iter); |
+} |
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
|
+ |
+void UIElement::ReorderChild(UIElement* child, int new_index) { |
+ new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index)); |
+ auto iter = children_.begin() + new_index; |
+ 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
|
+} |
+ |
+UIElement::UIElement(const UIElementType type, |
+ UIElementDelegate* delegate, |
+ UIElement* parent) |
+ : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) { |
+ delegate_->AddNodeIdMap(this); |
+} |
+ |
+UIElement::~UIElement() { |
+ for (auto* child : children_) { |
+ if (child) |
+ delete child; |
+ } |
+ children_.clear(); |
+} |
+ |
+} // namespace devtools |
+} // namespace ash |