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

Side by Side Diff: ash/devtools/ui_element.cc

Issue 2899503002: Revert of 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/devtools/ui_element.h"
6
7 #include <algorithm>
8
9 #include "ash/devtools/ui_element_delegate.h"
10 #include "ash/devtools/view_element.h"
11 #include "ash/devtools/widget_element.h"
12 #include "ash/devtools/window_element.h"
13
14 namespace ash {
15 namespace devtools {
16 namespace {
17
18 static int node_ids = 0;
19
20 } // namespace
21
22 UIElement::~UIElement() {
23 for (auto* child : children_)
24 delete child;
25 children_.clear();
26 }
27
28 std::string UIElement::GetTypeName() const {
29 switch (type_) {
30 case UIElementType::WINDOW:
31 return "Window";
32 case UIElementType::WIDGET:
33 return "Widget";
34 case UIElementType::VIEW:
35 return "View";
36 }
37 }
38
39 void UIElement::AddChild(UIElement* child, UIElement* before) {
40 if (before) {
41 auto iter = std::find(children_.begin(), children_.end(), before);
42 DCHECK(iter != children_.end());
43 children_.insert(iter, child);
44 } else {
45 children_.push_back(child);
46 }
47 delegate_->OnUIElementAdded(this, child);
48 }
49
50 void UIElement::RemoveChild(UIElement* child) {
51 delegate()->OnUIElementRemoved(child);
52 auto iter = std::find(children_.begin(), children_.end(), child);
53 DCHECK(iter != children_.end());
54 children_.erase(iter);
55 }
56
57 void UIElement::ReorderChild(UIElement* child, int new_index) {
58 // Remove |child| out of vector |children_|.
59 auto iter = std::find(children_.begin(), children_.end(), child);
60 DCHECK(iter != children_.end());
61 children_.erase(iter);
62
63 // Move child to new position |new_index| in vector |children_|.
64 new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index));
65 iter = children_.begin() + new_index;
66 children_.insert(iter, child);
67 delegate()->OnUIElementReordered(child->parent(), child);
68 }
69
70 UIElement::UIElement(const UIElementType type,
71 UIElementDelegate* delegate,
72 UIElement* parent)
73 : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) {
74 delegate_->OnUIElementAdded(0, this);
75 }
76
77 } // namespace devtools
78 } // namespace ash
OLDNEW
« 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