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 GetIndexOfChildInParent(aura::Window* window) { | |
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) | |
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 (delegate()->IsHighlightingWindow(window_)) | |
sadrul
2017/05/17 21:54:14
This would never be true, right? Because we never
thanhph
2017/05/18 14:28:16
It's true, done!
| |
41 return; | |
42 if (params.target == window_) { | |
43 parent()->RemoveChild(this); | |
44 Destroy(); | |
45 } | |
46 } | |
47 | |
48 // Handles adding window_. | |
49 void WindowElement::OnWindowHierarchyChanged( | |
50 const aura::WindowObserver::HierarchyChangeParams& params) { | |
51 if (window_ == params.new_parent && params.receiver == params.new_parent) { | |
52 if (delegate()->IsHighlightingWindow(params.target)) | |
53 return; | |
54 AddChild(new WindowElement(params.target, delegate(), this), | |
55 children().empty() ? nullptr : children().back()); | |
56 } | |
57 } | |
58 | |
59 void WindowElement::OnWindowStackingChanged(aura::Window* window) { | |
60 DCHECK_EQ(window_, window); | |
61 if (delegate()->IsHighlightingWindow(window)) | |
sadrul
2017/05/17 21:54:14
You should not need this check either. See above.
thanhph
2017/05/18 14:28:16
Done.
| |
62 return; | |
63 parent()->ReorderChild(this, GetIndexOfChildInParent(window)); | |
64 } | |
65 | |
66 void WindowElement::OnWindowBoundsChanged(aura::Window* window, | |
67 const gfx::Rect& old_bounds, | |
68 const gfx::Rect& new_bounds) { | |
69 DCHECK_EQ(window_, window); | |
70 delegate()->OnUIElementBoundsChanged(this); | |
71 } | |
72 | |
73 void WindowElement::Destroy() { | |
74 delete this; | |
75 } | |
76 | |
77 void WindowElement::GetBounds(gfx::Rect* bounds) const { | |
78 *bounds = window_->bounds(); | |
79 } | |
80 | |
81 void WindowElement::SetBounds(const gfx::Rect& bounds) { | |
82 window_->SetBounds(bounds); | |
83 } | |
84 | |
85 void WindowElement::GetVisible(bool* visible) const { | |
86 *visible = window_->IsVisible(); | |
87 } | |
88 | |
89 void WindowElement::SetVisible(bool visible) { | |
90 if (visible) | |
91 window_->Show(); | |
92 else | |
93 window_->Hide(); | |
94 } | |
95 | |
96 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() | |
97 const { | |
98 return std::make_pair(window_, window_->GetBoundsInScreen()); | |
99 } | |
100 | |
101 // static | |
102 aura::Window* WindowElement::From(UIElement* element) { | |
103 DCHECK_EQ(UIElementType::WINDOW, element->type()); | |
104 return static_cast<WindowElement*>(element)->window_; | |
105 } | |
106 | |
107 } // namespace devtools | |
108 } // namespace ash | |
OLD | NEW |