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

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

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: Remove visibility check for window and view elements. 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
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 std::string UIElement::GetTypeName() const {
23 switch (type_) {
24 case UIElementType::WINDOW:
25 return "Window";
26 case UIElementType::WIDGET:
27 return "Widget";
28 case UIElementType::VIEW:
29 return "View";
30 }
31 }
32
33 void UIElement::AddChild(UIElement* child, UIElement* before) {
34 if (before) {
35 auto iter = std::find(children_.begin(), children_.end(), before);
36 DCHECK(iter != children_.end());
37 children_.insert(iter, child);
38 } else {
39 children_.push_back(child);
40 }
41 delegate_->OnUIElementAdded(this, child);
42 }
43
44 void UIElement::RemoveChild(UIElement* child) {
45 delegate()->OnUIElementRemoved(child);
46 auto iter = std::find(children_.begin(), children_.end(), child);
47 if (iter != children_.end())
sadrul 2017/05/17 21:54:13 Can this be a DCHECK()? i.e. DCHECK(iter != childr
thanhph 2017/05/18 14:28:15 Done. Also changed to use DCHECK in ReOrder.
48 children_.erase(iter);
49 }
50
51 void UIElement::ReorderChild(UIElement* child, int new_index) {
52 // Remove |child| out of vector |children_|.
53 auto iter = std::find(children_.begin(), children_.end(), child);
54 if (iter != children_.end())
55 children_.erase(iter);
56
57 // Move child to new position |new_index| in vector |children_|.
58 new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index));
59 iter = children_.begin() + new_index;
60 children_.insert(iter, child);
61 delegate()->OnUIElementReordered(child->parent(), child);
62 }
63
64 UIElement::UIElement(const UIElementType type,
65 UIElementDelegate* delegate,
66 UIElement* parent)
67 : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) {
68 delegate_->OnUIElementAdded(0, this);
69 }
70
71 UIElement::~UIElement() {
72 for (auto* child : children_)
73 delete child;
74 children_.clear();
75 }
76
77 } // namespace devtools
78 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698