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

Unified Diff: ash/devtools/ui_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: nits 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
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..7741360ff6da0a26cac82d14c8bb334e2c9d854d
--- /dev/null
+++ b/ash/devtools/ui_element.cc
@@ -0,0 +1,89 @@
+// 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 "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 {
+
+int UIElement::GetNodeId() const {
+ return node_id_;
+}
+
+void UIElement::SetNodeId(int node_id) {
+ node_id_ = node_id;
+}
+
+UIElement* UIElement::GetParent() const {
+ return parent_;
+}
+
+UIElementDelegate* UIElement::delegate() const {
+ return ui_element_delegate_;
+}
+
+UIElementType UIElement::GetType() const {
+ return type_;
+}
+
+std::string UIElement::GetTypeString() const {
+ switch (type_) {
+ case UIElementType::WINDOW:
+ return "Window";
+ case UIElementType::WIDGET:
+ return "Widget";
+ case UIElementType::VIEW:
+ return "View";
+ default:
+ DCHECK(false);
+ }
+}
+
+const std::vector<UIElement*>& UIElement::GetChildren() const {
+ return children_;
+}
+
+void UIElement::AddChild(UIElement* child, UIElement* before) {
+ if (before) {
+ auto iter = std::find(children_.begin(), children_.end(), before);
+ children_.insert(iter, child);
+ } else
+ children_.push_back(child);
sadrul 2017/05/05 20:19:33 {} here too
thanhph 2017/05/08 17:03:30 Done.
+}
+
+void UIElement::RemoveChild(UIElement* child) {
+ auto iter = std::find(children_.begin(), children_.end(), child);
+ if (iter != children_.end())
+ children_.erase(iter);
+}
+
+UIElement* UIElement::ReorderChild(UIElement* child, int new_index) {
+ auto iter = children_.begin();
+ while (new_index-- > 0)
+ iter++;
+ children_.insert(iter, child);
+ if (iter != children_.begin())
+ return *std::prev(iter);
+ 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.
+}
+
+UIElement::UIElement(const UIElementType type,
+ UIElementDelegate* ui_element_delegate,
+ UIElement* parent)
+ : type_(type), parent_(parent), ui_element_delegate_(ui_element_delegate) {}
+
+UIElement::~UIElement() {
+ for (auto* child : children_)
+ if (child)
+ delete child;
+ children_.clear();
+}
+
+} // namespace devtools
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698