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

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

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: address comments. 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 default:
sadrul 2017/05/10 03:03:38 Remove default:
thanhph 2017/05/10 17:21:49 Done.
31 DCHECK(false);
32 }
33 }
34
35 void UIElement::AddChild(UIElement* child, UIElement* before) {
36 if (child->type() == UIElementType::WINDOW &&
37 delegate_->IsHighlightingWindow(
38 UIElement::GetBackingElement<aura::Window, WindowElement>(child))) {
39 child->Destroy();
40 return;
41 }
42 if (before) {
43 auto iter = std::find(children_.begin(), children_.end(), before);
44 DCHECK(iter != children_.end());
45 children_.insert(iter, child);
46 } else {
47 children_.push_back(child);
48 }
49 delegate_->OnUIElementAdded(this, child);
50 }
51
52 bool UIElement::RemoveChild(UIElement* child) {
53 if (delegate()->OnUIElementRemoved(child)) {
sadrul 2017/05/10 03:03:38 You don't need to check the return value of OnUIEl
thanhph 2017/05/10 17:21:49 Done in a slightly different way. I can't access t
54 auto iter = std::find(children_.begin(), children_.end(), child);
55 if (iter != children_.end())
56 children_.erase(iter);
57 return true;
58 }
59 return false;
60 }
61
62 void UIElement::ReorderChild(UIElement* child, int new_index) {
63 // Remove child out of |children|.
64 auto iter = std::find(children_.begin(), children_.end(), child);
65 if (iter != children_.end())
66 children_.erase(iter);
67
68 // Move child to new position |new_index| in vector |children_|.
69 new_index = std::min(children_.size() - 1, static_cast<size_t>(new_index));
70 iter = children_.begin() + new_index;
71 children_.insert(iter, child);
72 delegate()->OnUIElementReordered(child->parent(), child);
73 }
74
75 UIElement::UIElement(const UIElementType type,
76 UIElementDelegate* delegate,
77 UIElement* parent)
78 : node_id_(++node_ids), type_(type), parent_(parent), delegate_(delegate) {
79 delegate_->OnUIElementAdded(0, this);
80 }
81
82 UIElement::~UIElement() {
83 for (auto* child : children_) {
84 if (child)
sadrul 2017/05/10 03:03:37 You should not need this null check.
thanhph 2017/05/10 17:21:49 Done.
85 delete child;
86 }
87 children_.clear();
88 }
89
90 } // namespace devtools
91 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698