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/widget_element.h" | |
6 | |
7 #include "ash/devtools/ui_element_delegate.h" | |
8 | |
9 namespace ash { | |
10 namespace devtools { | |
11 | |
12 WidgetElement::WidgetElement(views::Widget* widget, | |
13 UIElementDelegate* ui_element_delegate, | |
14 UIElement* parent) | |
15 : UIElement(UIElementType::WIDGET, ui_element_delegate, parent), | |
16 widget_(widget) { | |
17 if (!widget_->HasRemovalsObserver(this)) | |
sadrul
2017/05/01 16:22:27
There's no reason for having this check.
thanhph
2017/05/03 21:58:11
Done.
| |
18 widget_->AddRemovalsObserver(this); | |
19 } | |
20 | |
21 WidgetElement::~WidgetElement() { | |
22 if (widget_ && widget_->HasRemovalsObserver(this)) | |
sadrul
2017/05/01 16:22:27
You are never resetting |widget_|. So this check s
thanhph
2017/05/03 21:58:11
Done.
| |
23 widget_->RemoveRemovalsObserver(this); | |
24 } | |
25 | |
26 views::Widget* WidgetElement::widget() { | |
27 return widget_; | |
28 } | |
29 | |
30 void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) { | |
31 if (view == widget->GetRootView()) { | |
32 if (GetUIElementDelegate()->OnUIElementRemoved( | |
33 GetChildren()[0]->GetNodeId())) { | |
34 GetChildren()[0]->RemoveChildFromParent(); | |
35 GetChildren()[0]->Destroy(); | |
sadrul
2017/05/01 16:22:27
Can you explain this? e.g. why use GetChildren()[0
thanhph
2017/05/03 21:58:11
Widget has only 1 child which is the root view, a.
| |
36 } | |
37 } | |
38 } | |
39 | |
40 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget, | |
41 const gfx::Rect& new_bounds) { | |
42 if (widget == widget_) | |
sadrul
2017/05/01 16:22:27
This should be a DCHECK()?
thanhph
2017/05/03 21:58:10
Done.
| |
43 GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId()); | |
44 } | |
45 | |
46 void WidgetElement::Destroy() { | |
47 delete this; | |
48 } | |
49 | |
50 bool WidgetElement::GetBounds(gfx::Rect* bounds) { | |
51 if (widget_) { | |
sadrul
2017/05/01 16:22:27
Why do you need these null-checks?
thanhph
2017/05/03 21:58:11
I removed them.
| |
52 *bounds = widget_->GetRestoredBounds(); | |
53 return true; | |
54 } | |
55 return false; | |
56 } | |
57 | |
58 bool WidgetElement::SetBounds(const gfx::Rect& bounds) { | |
59 if (widget_) { | |
60 widget_->SetBounds(bounds); | |
61 return true; | |
62 } | |
63 return false; | |
64 } | |
65 | |
66 bool WidgetElement::GetVisible(bool* visible) { | |
67 if (widget_) { | |
68 *visible = widget_->IsVisible(); | |
69 return true; | |
70 } | |
71 return false; | |
72 } | |
73 | |
74 bool WidgetElement::SetVisible(bool visible) { | |
75 if (widget_) { | |
76 if (visible != widget_->IsVisible()) { | |
77 if (visible) | |
78 widget_->Show(); | |
79 else | |
80 widget_->Hide(); | |
81 } | |
82 return true; | |
83 } | |
84 return false; | |
85 } | |
86 | |
87 std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() { | |
88 if (widget_) | |
89 return std::make_pair(widget_->GetNativeWindow(), | |
90 widget_->GetWindowBoundsInScreen()); | |
91 return std::make_pair(nullptr, gfx::Rect()); | |
92 } | |
93 | |
94 // static | |
95 views::Widget* WidgetElement::From(UIElement* element) { | |
96 DCHECK_EQ(UIElementType::WIDGET, element->GetType()); | |
97 return static_cast<WidgetElement*>(element)->widget_; | |
98 } | |
99 | |
100 } // namespace devtools | |
101 } // namespace ash | |
OLD | NEW |