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

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, 8 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..0a9b4863b578cc2ba1a634da2cb3fa165369397c
--- /dev/null
+++ b/ash/devtools/ui_element.cc
@@ -0,0 +1,84 @@
+// 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() {
+ return parent_;
+}
+
+void UIElement::SetParent(UIElement* parent) {
+ parent_ = parent;
+}
+
+UIElementDelegate* UIElement::GetUIElementDelegate() {
+ return ui_element_delegate_;
+}
+
+void UIElement::SetUIElementDelegate(UIElementDelegate* ui_element_delegate) {
+ ui_element_delegate_ = ui_element_delegate;
+}
+
+UIElementType UIElement::GetType() const {
+ return type_;
+}
+
+void UIElement::SetType(UIElementType type) {
+ type_ = type;
+}
+
+std::vector<UIElement*>& UIElement::GetChildren() {
+ return children_;
+}
+
+void UIElement::SetChildren(std::vector<UIElement*>& children) {
+ children_ = children;
+}
+
+std::vector<UIElement*>::iterator UIElement::RemoveChildFromParent() {
+ if (GetParent()) {
+ std::vector<UIElement*>& siblings = GetParent()->GetChildren();
+ std::vector<UIElement*>::iterator object = std::find_if(
+ siblings.begin(), siblings.end(),
+ [&](UIElement* obj) { return obj->GetNodeId() == node_id_; });
+ if (object != siblings.end())
+ siblings.erase(object);
+ return object;
+ }
+ return children_.end();
+}
+
+UIElement::UIElement(UIElementType type,
+ UIElementDelegate* ui_element_delegate,
+ UIElement* parent) {
+ type_ = type;
+ ui_element_delegate_ = ui_element_delegate;
+ parent_ = parent;
+}
+
+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