Chromium Code Reviews| 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..f17965fa0cf4372c71217cd12b7cdf084836b62f |
| --- /dev/null |
| +++ b/ash/devtools/ui_element.cc |
| @@ -0,0 +1,91 @@ |
| +// 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 |
| + |
| +std::string UIElement::GetTypeName() const { |
| + switch (type_) { |
| + case UIElementType::WINDOW: |
| + return "Window"; |
| + case UIElementType::WIDGET: |
| + return "Widget"; |
| + case UIElementType::VIEW: |
| + return "View"; |
| + default: |
|
sadrul
2017/05/10 03:03:38
Remove default:
thanhph
2017/05/10 17:21:49
Done.
|
| + 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); |
| + DCHECK(iter != children_.end()); |
| + children_.insert(iter, child); |
| + } else { |
| + children_.push_back(child); |
| + } |
| + delegate_->OnUIElementAdded(this, child); |
| +} |
| + |
| +bool UIElement::RemoveChild(UIElement* child) { |
| + if (delegate()->OnUIElementRemoved(child)) { |
|
sadrul
2017/05/10 03:03:38
You don't need to check the return value of OnUIEl
thanhph
2017/05/10 17:21:49
Done in a slightly different way. I can't access t
|
| + auto iter = std::find(children_.begin(), children_.end(), child); |
| + if (iter != children_.end()) |
| + children_.erase(iter); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void UIElement::ReorderChild(UIElement* child, int new_index) { |
| + // Remove child out of |children|. |
| + auto iter = std::find(children_.begin(), children_.end(), child); |
| + if (iter != children_.end()) |
| + children_.erase(iter); |
| + |
| + // Move child to new position |new_index| in vector |children_|. |
| + new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index)); |
| + iter = children_.begin() + new_index; |
| + children_.insert(iter, child); |
| + delegate()->OnUIElementReordered(child->parent(), child); |
| +} |
| + |
| +UIElement::UIElement(const UIElementType type, |
| + UIElementDelegate* delegate, |
| + UIElement* parent) |
| + : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) { |
| + delegate_->OnUIElementAdded(0, this); |
| +} |
| + |
| +UIElement::~UIElement() { |
| + for (auto* child : children_) { |
| + if (child) |
|
sadrul
2017/05/10 03:03:37
You should not need this null check.
thanhph
2017/05/10 17:21:49
Done.
|
| + delete child; |
| + } |
| + children_.clear(); |
| +} |
| + |
| +} // namespace devtools |
| +} // namespace ash |