Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: ash/devtools/widget_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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))
18 widget_->AddRemovalsObserver(this);
19 }
20
21 WidgetElement::~WidgetElement() {
22 if (widget_ && widget_->HasRemovalsObserver(this))
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 (delegate()->OnUIElementRemoved(GetChildren()[0]->GetNodeId())) {
33 GetChildren()[0]->RemoveChildFromParent();
34 GetChildren()[0]->Destroy();
35 }
36 }
37 }
38
39 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget,
40 const gfx::Rect& new_bounds) {
41 if (widget == widget_)
42 delegate()->OnUIElementBoundsChanged(GetNodeId());
43 }
44
45 void WidgetElement::Destroy() {
46 delete this;
47 }
48
49 bool WidgetElement::GetBounds(gfx::Rect* bounds) {
50 if (widget_) {
51 *bounds = widget_->GetRestoredBounds();
52 return true;
53 }
54 return false;
55 }
56
57 bool WidgetElement::SetBounds(const gfx::Rect& bounds) {
58 if (widget_) {
59 widget_->SetBounds(bounds);
60 return true;
61 }
62 return false;
63 }
64
65 bool WidgetElement::GetVisible(bool* visible) {
66 if (widget_) {
67 *visible = widget_->IsVisible();
68 return true;
69 }
70 return false;
71 }
72
73 bool WidgetElement::SetVisible(bool visible) {
74 if (widget_) {
75 if (visible != widget_->IsVisible()) {
76 if (visible)
77 widget_->Show();
78 else
79 widget_->Hide();
80 }
81 return true;
82 }
83 return false;
84 }
85
86 std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() {
87 if (widget_)
88 return std::make_pair(widget_->GetNativeWindow(),
89 widget_->GetWindowBoundsInScreen());
90 return std::make_pair(nullptr, gfx::Rect());
91 }
92
93 // static
94 views::Widget* WidgetElement::From(UIElement* element) {
95 DCHECK_EQ(UIElementType::WIDGET, element->GetType());
96 return static_cast<WidgetElement*>(element)->widget_;
97 }
98
99 } // namespace devtools
100 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698