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 widget_->AddRemovalsObserver(this); | |
18 } | |
19 | |
20 WidgetElement::~WidgetElement() { | |
21 widget_->RemoveRemovalsObserver(this); | |
22 } | |
23 | |
24 void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) { | |
25 if (view != widget->GetRootView()) | |
26 return; | |
27 DCHECK_EQ(1u, children().size()); | |
28 UIElement* child = children()[0]; | |
29 RemoveChild(child); | |
30 delete child; | |
31 } | |
32 | |
33 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget, | |
34 const gfx::Rect& new_bounds) { | |
35 DCHECK_EQ(widget, widget_); | |
36 delegate()->OnUIElementBoundsChanged(this); | |
37 } | |
38 | |
39 void WidgetElement::GetBounds(gfx::Rect* bounds) const { | |
40 *bounds = widget_->GetRestoredBounds(); | |
41 } | |
42 | |
43 void WidgetElement::SetBounds(const gfx::Rect& bounds) { | |
44 widget_->SetBounds(bounds); | |
45 } | |
46 | |
47 void WidgetElement::GetVisible(bool* visible) const { | |
48 *visible = widget_->IsVisible(); | |
49 } | |
50 | |
51 void WidgetElement::SetVisible(bool visible) { | |
52 if (visible == widget_->IsVisible()) | |
53 return; | |
54 if (visible) | |
55 widget_->Show(); | |
56 else | |
57 widget_->Hide(); | |
58 } | |
59 | |
60 std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() | |
61 const { | |
62 return std::make_pair(widget_->GetNativeWindow(), | |
63 widget_->GetWindowBoundsInScreen()); | |
64 } | |
65 | |
66 // static | |
67 views::Widget* WidgetElement::From(UIElement* element) { | |
68 DCHECK_EQ(UIElementType::WIDGET, element->type()); | |
69 return static_cast<WidgetElement*>(element)->widget_; | |
70 } | |
71 | |
72 } // namespace devtools | |
73 } // namespace ash | |
OLD | NEW |