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 | |
13 WindowElement::WindowElement(aura::Window* window, | |
14 UIElementDelegate* ui_element_delegate, | |
15 UIElement* parent) | |
16 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent), | |
17 window_(window) { | |
18 if (window_ && !window_->HasObserver(this)) | |
19 window_->AddObserver(this); | |
20 } | |
21 | |
22 WindowElement::~WindowElement() { | |
23 if (window_ && window_->HasObserver(this)) | |
24 window_->RemoveObserver(this); | |
25 } | |
26 | |
27 aura::Window* WindowElement::window() { | |
28 return window_; | |
29 } | |
30 | |
31 // Handles removing window_. | |
32 void WindowElement::OnWindowHierarchyChanging( | |
33 const aura::WindowObserver::HierarchyChangeParams& params) { | |
34 if (params.target == window_ && | |
35 GetUIElementDelegate()->OnUIElementRemoved(GetNodeId())) { | |
36 RemoveChildFromParent(); | |
37 Destroy(); | |
38 } | |
39 } | |
40 | |
41 // Handles adding window_. | |
42 void WindowElement::OnWindowHierarchyChanged( | |
43 const aura::WindowObserver::HierarchyChangeParams& params) { | |
44 if (window_ == params.new_parent && params.receiver == params.new_parent) { | |
45 GetUIElementDelegate()->OnUIElementAdded( | |
46 GetNodeId(), | |
47 new WindowElement(params.target, GetUIElementDelegate(), this), | |
48 GetChildren().end() - 1); | |
49 } | |
50 } | |
51 | |
52 void WindowElement::OnWindowStackingChanged(aura::Window* window) { | |
53 if (window_ == window) { | |
sadrul
2017/05/01 16:22:27
This should be a DCHECK, right?
thanhph
2017/05/03 21:58:11
Done. Only the changed window is called back here.
| |
54 std::vector<UIElement*>::iterator prev_sibling_position; | |
55 | |
56 if (GetUIElementDelegate()->OnUIElementRemoved(GetNodeId())) | |
57 prev_sibling_position = RemoveChildFromParent(); | |
58 else | |
59 prev_sibling_position = GetParent()->GetChildren().end(); | |
60 | |
61 GetUIElementDelegate()->OnUIElementAdded( | |
62 GetParent()->GetNodeId(), | |
63 new WindowElement(window, GetUIElementDelegate(), GetParent()), | |
64 prev_sibling_position); | |
sadrul
2017/05/01 16:22:27
Without doing Removed + Added, can we introduce UI
thanhph
2017/05/03 21:58:11
Done.
| |
65 Destroy(); | |
66 } | |
67 } | |
68 | |
69 void WindowElement::OnWindowBoundsChanged(aura::Window* window, | |
70 const gfx::Rect& old_bounds, | |
71 const gfx::Rect& new_bounds) { | |
72 if (window_ == window) | |
sadrul
2017/05/01 16:22:27
ditto
thanhph
2017/05/03 21:58:11
Done.
| |
73 GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId()); | |
74 } | |
75 | |
76 void WindowElement::Destroy() { | |
77 delete this; | |
78 } | |
79 | |
80 bool WindowElement::GetBounds(gfx::Rect* bounds) { | |
81 if (window_) { | |
82 *bounds = window_->bounds(); | |
83 return true; | |
84 } | |
85 return false; | |
86 } | |
87 | |
88 bool WindowElement::SetBounds(const gfx::Rect& bounds) { | |
89 if (window_) { | |
90 window_->SetBounds(bounds); | |
91 return true; | |
92 } | |
93 return false; | |
94 } | |
95 | |
96 bool WindowElement::GetVisible(bool* visible) { | |
97 if (window_) { | |
98 *visible = window_->IsVisible(); | |
99 return true; | |
100 } | |
101 return false; | |
102 } | |
103 | |
104 bool WindowElement::SetVisible(bool visible) { | |
105 if (window_) { | |
106 if (visible != window_->IsVisible()) { | |
107 if (visible) | |
108 window_->Show(); | |
109 else | |
110 window_->Hide(); | |
111 } | |
112 return true; | |
113 } | |
114 return false; | |
115 } | |
116 | |
117 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() { | |
118 if (window_) | |
119 return std::make_pair(window_, window_->GetBoundsInScreen()); | |
120 return std::make_pair(nullptr, gfx::Rect()); | |
121 } | |
122 | |
123 // static | |
124 aura::Window* WindowElement::From(UIElement* element) { | |
125 DCHECK_EQ(UIElementType::WINDOW, element->GetType()); | |
126 return static_cast<WindowElement*>(element)->window_; | |
127 } | |
128 | |
129 } // namespace devtools | |
130 } // namespace ash | |
OLD | NEW |