Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2874)

Unified Diff: ash/devtools/ui_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/devtools/ui_element.h ('k') | ash/devtools/ui_element_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0249d823d1f5ad9f2cf42c683f9dd5f4e6c99f83
--- /dev/null
+++ b/ash/devtools/ui_element.cc
@@ -0,0 +1,80 @@
+// 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
+
+UIElement::~UIElement() {
+ for (auto* child : children_)
+ delete child;
+ children_.clear();
+}
+
+std::string UIElement::GetTypeName() const {
+ switch (type_) {
+ case UIElementType::WINDOW:
+ return "Window";
+ case UIElementType::WIDGET:
+ return "Widget";
+ case UIElementType::VIEW:
+ return "View";
+ }
+ NOTREACHED();
+ return std::string();
+}
+
+void UIElement::AddChild(UIElement* child, UIElement* before) {
+ 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);
+}
+
+void UIElement::RemoveChild(UIElement* child) {
+ delegate()->OnUIElementRemoved(child);
+ auto iter = std::find(children_.begin(), children_.end(), child);
+ DCHECK(iter != children_.end());
+ children_.erase(iter);
+}
+
+void UIElement::ReorderChild(UIElement* child, int new_index) {
+ // Remove |child| out of vector |children_|.
+ auto iter = std::find(children_.begin(), children_.end(), child);
+ DCHECK(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);
+}
+
+} // namespace devtools
+} // namespace ash
« no previous file with comments | « ash/devtools/ui_element.h ('k') | ash/devtools/ui_element_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698