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(WmWindow* window, | |
14 UIElementDelegate* ui_element_delegate) | |
15 : window_(window) { | |
16 this->SetUIElementDelegate(ui_element_delegate); | |
17 this->SetType(UIElementType::WINDOW); | |
18 if (window_ && !window_->aura_window()->HasObserver(this)) | |
19 window_->aura_window()->AddObserver(this); | |
20 } | |
21 | |
22 WindowElement::WindowElement(WmWindow* window, int node_id) : window_(window) { | |
23 this->SetType(UIElementType::WINDOW); | |
24 this->SetNodeId(node_id); | |
25 if (window_ && !window_->aura_window()->HasObserver(this)) | |
26 window_->aura_window()->AddObserver(this); | |
27 } | |
28 | |
29 WindowElement::~WindowElement() { | |
30 if (window_ && window_->aura_window()->HasObserver(this)) | |
31 window_->aura_window()->RemoveObserver(this); | |
32 } | |
33 | |
34 WmWindow* WindowElement::window() { | |
35 return window_; | |
36 } | |
37 | |
38 int GetNodeIdFromWindow(devtools::UIElement* ui_element, WmWindow* window) { | |
sadrul
2017/04/19 18:21:39
It doesn't look like we use this function?
thanhph
2017/04/24 15:56:50
I moved it to unittest.
| |
39 for (auto* child : ui_element->GetChildren()) { | |
40 if (child->GetType() == UIElementType::WINDOW && | |
41 static_cast<devtools::WindowElement*>(child)->window() == window) { | |
42 return child->GetNodeId(); | |
43 } | |
44 } | |
45 for (auto* child : ui_element->GetChildren()) { | |
46 if (child->GetType() == UIElementType::WINDOW) { | |
47 int node_id = GetNodeIdFromWindow(child, window); | |
48 if (node_id > 0) | |
49 return node_id; | |
50 } | |
51 } | |
52 return 0; | |
53 } | |
54 | |
55 // Handles removing window_. | |
56 void WindowElement::OnWindowHierarchyChanging( | |
57 const aura::WindowObserver::HierarchyChangeParams& params) { | |
58 if (WmWindow::Get(params.target) == window_) | |
59 GetUIElementDelegate()->OnUIElementRemoved(this->GetNodeId()); | |
60 } | |
61 | |
62 // Handles adding window_. | |
63 void WindowElement::OnWindowHierarchyChanged( | |
64 const aura::WindowObserver::HierarchyChangeParams& params) { | |
65 if (window_ == WmWindow::Get(params.new_parent) && | |
66 params.receiver == params.new_parent) { | |
67 UIElement* child_window_element = | |
68 new WindowElement(WmWindow::Get(params.target), GetUIElementDelegate()); | |
69 GetUIElementDelegate()->OnUIElementAdded( | |
70 this->GetNodeId(), child_window_element, this->GetChildren().end() - 1); | |
71 } | |
72 } | |
73 | |
74 void WindowElement::OnWindowStackingChanged(aura::Window* window) { | |
75 if (this->window_ == WmWindow::Get(window)) { | |
76 std::vector<UIElement*>::iterator prev_sibling_position = | |
77 GetUIElementDelegate()->OnUIElementRemoved(this->GetNodeId()); | |
78 GetUIElementDelegate()->OnUIElementAdded( | |
79 this->GetParent()->GetNodeId(), | |
80 new WindowElement(WmWindow::Get(window), GetUIElementDelegate()), | |
81 prev_sibling_position); | |
82 } | |
83 } | |
84 | |
85 void WindowElement::OnWindowBoundsChanged(aura::Window* window, | |
86 const gfx::Rect& old_bounds, | |
87 const gfx::Rect& new_bounds) { | |
88 if (this->window_ == WmWindow::Get(window)) | |
89 GetUIElementDelegate()->OnUIElementBoundsChanged(this->GetNodeId()); | |
90 } | |
91 | |
92 void WindowElement::Destroy() { | |
93 this->~WindowElement(); | |
94 } | |
95 | |
96 bool WindowElement::GetBounds(gfx::Rect* bounds) { | |
97 if (window_) { | |
98 *bounds = window_->GetBounds(); | |
99 return true; | |
100 } | |
101 return false; | |
102 } | |
103 | |
104 bool WindowElement::SetBounds(const gfx::Rect& bounds) { | |
105 if (window_) { | |
106 window_->SetBounds(bounds); | |
107 return true; | |
108 } | |
109 return false; | |
110 } | |
111 | |
112 bool WindowElement::GetVisible(bool* visible) { | |
113 if (window_) { | |
114 *visible = window_->IsVisible(); | |
115 return true; | |
116 } | |
117 return false; | |
118 } | |
119 | |
120 bool WindowElement::SetVisible(bool visible) { | |
121 if (window_) { | |
122 if (visible != window_->IsVisible()) { | |
123 if (visible) | |
124 window_->Show(); | |
125 else | |
126 window_->Hide(); | |
127 } | |
128 return true; | |
129 } | |
130 return false; | |
131 } | |
132 | |
133 std::pair<WmWindow*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() { | |
134 if (window_) | |
135 return std::make_pair(window_, window_->GetBoundsInScreen()); | |
136 return std::make_pair(nullptr, gfx::Rect()); | |
137 } | |
138 | |
139 // static | |
140 WmWindow* WindowElement::From(UIElement* element) { | |
141 DCHECK_EQ(UIElementType::WINDOW, element->GetType()); | |
142 return static_cast<WindowElement*>(element)->window_; | |
143 } | |
144 | |
145 } // namespace devtools | |
146 } // namespace ash | |
OLD | NEW |