OLD | NEW |
---|---|
(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/window_element.h" | |
6 | |
7 #include "ash/devtools/ui_element_delegate.h" | |
8 #include "ui/aura/window.h" | |
9 | |
10 namespace ash { | |
11 namespace devtools { | |
12 namespace { | |
13 | |
14 int FindSibling(aura::Window* window) { | |
sadrul
2017/05/09 04:58:07
Call this: int GetIndexOfChildInParent(aura::Windo
thanhph
2017/05/09 20:52:47
Done.
| |
15 const aura::Window::Windows& siblings = window->parent()->children(); | |
16 auto it = std::find(siblings.begin(), siblings.end(), window); | |
17 DCHECK(it != siblings.end()); | |
18 return std::distance(siblings.begin(), it); | |
19 } | |
20 | |
21 } // namespace | |
22 | |
23 WindowElement::WindowElement(aura::Window* window, | |
24 UIElementDelegate* ui_element_delegate, | |
25 UIElement* parent) | |
26 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent), | |
27 window_(window) { | |
28 if (window_) | |
sadrul
2017/05/09 04:58:07
|window_| should be non-null. You should not need
thanhph
2017/05/09 20:52:47
For root ui_element tree, I assume associated wind
| |
29 window_->AddObserver(this); | |
30 } | |
31 | |
32 WindowElement::~WindowElement() { | |
33 if (window_) | |
34 window_->RemoveObserver(this); | |
35 } | |
36 | |
37 // Handles removing window_. | |
38 void WindowElement::OnWindowHierarchyChanging( | |
39 const aura::WindowObserver::HierarchyChangeParams& params) { | |
40 if (params.target == window_ && delegate()->OnUIElementRemoved(this)) { | |
41 this->parent()->RemoveChild(this); | |
42 Destroy(); | |
43 } | |
44 } | |
45 | |
46 // Handles adding window_. | |
47 void WindowElement::OnWindowHierarchyChanged( | |
48 const aura::WindowObserver::HierarchyChangeParams& params) { | |
49 if (window_ == params.new_parent && params.receiver == params.new_parent) { | |
50 AddChild(new WindowElement(params.target, delegate(), this), | |
51 children().empty() ? nullptr : children().back()); | |
52 } | |
53 } | |
54 | |
55 void WindowElement::OnWindowStackingChanged(aura::Window* window) { | |
56 DCHECK(window_ == window); | |
57 if (delegate()->IsHighlightingWindow(window)) | |
58 return; | |
59 | |
60 this->parent()->RemoveChild(this); | |
sadrul
2017/05/09 04:58:07
Don't need |this->|
Why do you need to RemoveChil
thanhph
2017/05/09 20:52:47
Done, I put this line in ReorderChild.
| |
61 this->parent()->ReorderChild(this, FindSibling(window)); | |
62 delegate()->OnUIElementReordered(this->parent(), this); | |
sadrul
2017/05/09 04:58:07
UIElement::ReorderChild() should call OnUIElementR
thanhph
2017/05/09 20:52:47
Done.
| |
63 } | |
64 | |
65 void WindowElement::OnWindowBoundsChanged(aura::Window* window, | |
66 const gfx::Rect& old_bounds, | |
67 const gfx::Rect& new_bounds) { | |
68 DCHECK(window_ == window); | |
69 delegate()->OnUIElementBoundsChanged(this); | |
70 } | |
71 | |
72 void WindowElement::Destroy() { | |
73 delete this; | |
74 } | |
75 | |
76 void WindowElement::GetBounds(gfx::Rect* bounds) const { | |
77 *bounds = window_->bounds(); | |
78 } | |
79 | |
80 void WindowElement::SetBounds(const gfx::Rect& bounds) { | |
81 window_->SetBounds(bounds); | |
82 } | |
83 | |
84 void WindowElement::GetVisible(bool* visible) const { | |
85 *visible = window_->IsVisible(); | |
86 } | |
87 | |
88 void WindowElement::SetVisible(bool visible) { | |
89 if (visible != window_->IsVisible()) { | |
sadrul
2017/05/09 04:58:07
early return
thanhph
2017/05/09 20:52:47
Done.
| |
90 if (visible) | |
91 window_->Show(); | |
92 else | |
93 window_->Hide(); | |
94 } | |
95 } | |
96 | |
97 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() | |
98 const { | |
99 return std::make_pair(window_, window_->GetBoundsInScreen()); | |
100 } | |
101 | |
102 // static | |
103 aura::Window* WindowElement::From(UIElement* element) { | |
104 DCHECK_EQ(UIElementType::WINDOW, element->type()); | |
105 return static_cast<WindowElement*>(element)->window_; | |
106 } | |
107 | |
108 } // namespace devtools | |
109 } // namespace ash | |
OLD | NEW |